-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(konnect): add support for basic auth credentials for consumers (#…
…625) * feat(konnect): add support for basic auth credentials for consumers * Apply suggestions from code review Co-authored-by: Grzegorz Burzyński <[email protected]> * chore: refactor getServiceRef * fix: watch for consumer changes in CredentialBasicAuth reconciler * fix: fix handling Consumer deletion for credentials * refactor(konnect): refactor ReferencedKongConsumerIsBeingDeleted handling * Update controller/konnect/errors.go Co-authored-by: Grzegorz Burzyński <[email protected]> --------- Co-authored-by: Grzegorz Burzyński <[email protected]>
- Loading branch information
Showing
25 changed files
with
1,353 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ packages: | |
PluginSDK: | ||
UpstreamsSDK: | ||
MeSDK: | ||
CredentialBasicAuthSDK: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
kind: KonnectAPIAuthConfiguration | ||
apiVersion: konnect.konghq.com/v1alpha1 | ||
metadata: | ||
name: konnect-api-auth-dev-1 | ||
namespace: default | ||
spec: | ||
type: token | ||
token: kpat_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
serverURL: us.api.konghq.com | ||
--- | ||
kind: KonnectGatewayControlPlane | ||
apiVersion: konnect.konghq.com/v1alpha1 | ||
metadata: | ||
name: test-cp-basic-auth | ||
namespace: default | ||
spec: | ||
name: test-cp-basic-auth | ||
labels: | ||
app: test-cp-basic-auth | ||
key1: test-cp-basic-auth | ||
konnect: | ||
authRef: | ||
name: konnect-api-auth-dev-1 | ||
--- | ||
kind: KongConsumer | ||
apiVersion: configuration.konghq.com/v1 | ||
metadata: | ||
name: consumer1 | ||
namespace: default | ||
username: consumer1 | ||
spec: | ||
controlPlaneRef: | ||
type: konnectNamespacedRef | ||
konnectNamespacedRef: | ||
name: test-cp-basic-auth | ||
--- | ||
apiVersion: configuration.konghq.com/v1alpha1 | ||
kind: CredentialBasicAuth | ||
metadata: | ||
name: basic-auth-1 | ||
namespace: default | ||
spec: | ||
consumerRef: | ||
name: consumer1 | ||
password: pass | ||
username: username |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package konnect | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1" | ||
) | ||
|
||
const ( | ||
// IndexFieldCredentialBasicAuthReferencesKongConsumer is the index name for CredentialBasicAuth -> Consumer. | ||
IndexFieldCredentialBasicAuthReferencesKongConsumer = "kongCredentialsBasicAuthConsumerRef" | ||
) | ||
|
||
// IndexOptionsForCredentialsBasicAuth returns required Index options for CredentialBasicAuth. | ||
func IndexOptionsForCredentialsBasicAuth() []ReconciliationIndexOption { | ||
return []ReconciliationIndexOption{ | ||
{ | ||
IndexObject: &configurationv1alpha1.CredentialBasicAuth{}, | ||
IndexField: IndexFieldCredentialBasicAuthReferencesKongConsumer, | ||
ExtractValue: kongCredentialBasicAuthReferencesConsumer, | ||
}, | ||
} | ||
} | ||
|
||
// kongCredentialBasicAuthReferencesConsumer returns the name of referenced Consumer. | ||
func kongCredentialBasicAuthReferencesConsumer(obj client.Object) []string { | ||
cred, ok := obj.(*configurationv1alpha1.CredentialBasicAuth) | ||
if !ok { | ||
return nil | ||
} | ||
return []string{cred.Spec.ConsumerRef.Name} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ops | ||
|
||
import ( | ||
"context" | ||
|
||
sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations" | ||
) | ||
|
||
// CredentialBasicAuthSDK is the interface for the Konnect CredentialBasicAuthSDK. | ||
type CredentialBasicAuthSDK interface { | ||
CreateBasicAuthWithConsumer(ctx context.Context, req sdkkonnectops.CreateBasicAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateBasicAuthWithConsumerResponse, error) | ||
DeleteBasicAuthWithConsumer(ctx context.Context, request sdkkonnectops.DeleteBasicAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteBasicAuthWithConsumerResponse, error) | ||
UpsertBasicAuthWithConsumer(ctx context.Context, request sdkkonnectops.UpsertBasicAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.UpsertBasicAuthWithConsumerResponse, error) | ||
} |
Oops, something went wrong.