-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: fetch all Azure KV secret and certificates in separate ClusterExternalSecret #5691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: fetch all Azure KV secret and certificates in separate ClusterExternalSecret #5691
Conversation
|
| "encoding/json" | ||
|
|
||
| esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1" | ||
| esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 why v1beta1?
|
|
||
| // Certificates | ||
| certsPager := a.certsClient.NewListCertificatePropertiesPager(nil) | ||
| for certsPager.More() { | ||
| page, err := certsPager.NextPage(ctx) | ||
| metrics.ObserveAPICall(constants.ProviderAzureKV, constants.CallAzureKVGetCertificate, err) | ||
| if err != nil { | ||
| return nil, parseNewSDKError(err) | ||
| } | ||
|
|
||
| for _, cert := range page.Value { | ||
| if cert == nil || cert.ID == nil { | ||
| continue | ||
| } | ||
|
|
||
| name := cert.ID.Name() | ||
|
|
||
| resp, err := a.certsClient.GetCertificate(ctx, name, "", nil) | ||
| if err != nil { | ||
| return nil, parseNewSDKError(err) | ||
| } | ||
|
|
||
| if resp.CER != nil { | ||
| secretsMap["cert/"+name] = resp.CER | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Keys | ||
| keysPager := a.keysClient.NewListKeyPropertiesPager(nil) | ||
| for keysPager.More() { | ||
| page, err := keysPager.NextPage(ctx) | ||
| metrics.ObserveAPICall(constants.ProviderAzureKV, constants.CallAzureKVGetKey, err) | ||
| if err != nil { | ||
| return nil, parseNewSDKError(err) | ||
| } | ||
|
|
||
| for _, keyProps := range page.Value { | ||
| if keyProps == nil || keyProps.KID == nil { | ||
| continue | ||
| } | ||
|
|
||
| name := keyProps.KID.Name() | ||
|
|
||
| resp, err := a.keysClient.GetKey(ctx, name, "", nil) | ||
| if err != nil { | ||
| return nil, parseNewSDKError(err) | ||
| } | ||
|
|
||
| if resp.Key != nil { | ||
| jwkBytes, _ := json.Marshal(resp.Key) | ||
| secretsMap["key/"+name] = jwkBytes | ||
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current users will have a breaking change if exposed to this logic. We are failing if there are no valid permissions for certificates and keys -- instead we should log the error and continue to avoid breaking changes for setup that did not give cert/key permissions to external-secrets.
|
|
||
| if resp.Key != nil { | ||
| jwkBytes, _ := json.Marshal(resp.Key) | ||
| secretsMap["key/"+name] = jwkBytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure we want to leave this key in a format that is incompatible with Kubernetes Secret regex?
It means a dataFrom.find targeting key vault will always fail unless the user manipulates the keys.



Problem Statement
When using dataFrom.find.path in Azure Key Vault, using path "cert/" obtains both certificates and secrets. We want to sepaate the fetching by specific prefixes.
Related Issue
Fixes #4541
Proposed Changes
This update enhances the Azure provider by adding end-to-end support for secrets, certificates, and keys when using the new SDK. The function now iterates through the SDK pagers, fetches certificate/key data, JSON-encodes JWKs, and returns a unified map.
Format
Please ensure that your PR follows the following format for the title:
Where
scopeis optionally one of:Checklist
git commit --signoffmake testmake reviewable