Skip to content

Conversation

@AddRain1
Copy link
Contributor

@AddRain1 AddRain1 commented Dec 8, 2025

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:

feat(scope): add new feature
fix(scope): fix bug
docs(scope): update documentation
chore(scope): update build tool or dependencies
ref(scope): refactor code
clean(scope): provider cleanup
test(scope): add tests
perf(scope): improve performance
desig(scope): improve design

Where scope is optionally one of:

  • charts
  • release
  • testing
  • security
  • templating

Checklist

  • I have read the contribution guidelines
  • All commits are signed with git commit --signoff
  • My changes have reasonable test coverage
  • All tests pass with make test
  • I ensured my PR is ready for review with make reviewable

@github-actions github-actions bot added kind/feature Categorizes issue or PR as related to a new feature. size/m labels Dec 8, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

"encoding/json"

esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 why v1beta1?

Comment on lines +300 to +355

// 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
}
}
}

Copy link
Member

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. size/m

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

fetch all Azure KV/secret and KV/certificate in separate ClusterExternalSecret

2 participants