Skip to content

feat(azure-pipelines): add service principal authentication via reusable Azure provider - #7931

Open
m-amaresh wants to merge 2 commits into
kedacore:mainfrom
m-amaresh:main
Open

feat(azure-pipelines): add service principal authentication via reusable Azure provider#7931
m-amaresh wants to merge 2 commits into
kedacore:mainfrom
m-amaresh:main

Conversation

@m-amaresh

@m-amaresh m-amaresh commented Jul 23, 2026

Copy link
Copy Markdown

Provide a description of what has been changed

Adds Microsoft Entra service principal authentication to the Azure Pipelines scaler.

Following maintainer feedback on #7578, the credential handling is implemented as a
reusable azureServicePrincipal authentication provider on TriggerAuthentication
and ClusterTriggerAuthentication, living in pkg/scalers/azure, instead of being
local to the Azure Pipelines scaler. Other Azure scalers can adopt it in follow-ups
via azure.IsServicePrincipalAuthConfigured / azure.NewServicePrincipalCredential.

What's included

  • New AzureServicePrincipal TriggerAuthentication spec: tenantId, clientId,
    clientSecret, clientCertificate, clientCertificatePassword, cloud,
    activeDirectoryEndpoint, with admission-webhook validation and regenerated CRDs.
  • azure.NewServicePrincipalCredential: client-secret and certificate (PKCS#12 / PEM)
    credentials, sovereign clouds (US Gov, China), and Private cloud support
    (instance discovery disabled).
  • Resolver support in pkg/scaling/resolver to read the referenced Secrets.
  • Azure Pipelines auth refactored into configureAzurePipelinesAuth with an explicit
    auth type. Existing precedence is preserved — PAT wins, then Azure AD Workload
    Identity — with service principal added as a fallback when neither is configured.
  • Unit tests (provider, webhook, resolver, scaler) and an e2e test.

Reviewer notes

  • ⚠️ The e2e test (tests/scalers/azure/azure_pipelines_sp) needs the shared CI
    service principal (TF_AZURE_SP_APP_ID / AZURE_SP_KEY / TF_AZURE_SP_TENANT)
    added to the Azure DevOps organization with read access to the agent pool and its
    job requests. This is a kedacore infra prerequisite — happy to coordinate.
  • No behavior change for existing PAT or workload-identity users.

Checklist

  • When introducing a new scaler, I agree with the scaling governance policy
  • I have verified that my change is according to the deprecations & breaking changes policy
  • Tests have been added (if applicable)
  • Ensure make generate-scalers-schema has been run to update any outdated generated files
  • Changelog has been updated and is aligned with our changelog requirements, only when the change impacts end users
  • A PR is opened to update our Helm chart (repo) (if applicable, ie. when deployment manifests are modified)
  • A PR is opened to update the documentation on (repo) (if applicable)
  • Commits are signed with Developer Certificate of Origin (DCO - learn more)

Fixes #4853
Relates to #7581

Relates to #7578
Relates to kedacore/keda-docs#1814
Relates to kedacore/charts#888

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! 🙏

Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected.

While you are waiting, make sure to:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient.

Learn more about our contribution guide.

@keda-automation
keda-automation requested a review from a team July 23, 2026 21:55
@snyk-io

snyk-io Bot commented Jul 23, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@keda-automation
keda-automation requested a review from a team July 23, 2026 21:55
logger := logr.Discard()

meta, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: metadata, ResolvedEnv: nil, AuthParams: authParams, TriggerIndex: testData.triggerIndex}, http.DefaultClient)
meta, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: metadata, ResolvedEnv: nil, AuthParams: authParams, TriggerIndex: testData.triggerIndex}, http.DefaultClient)

@semgrep-code-kedacore semgrep-code-kedacore Bot Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider to use well-defined context

🧼 Fixed in commit 6799601 🧼

}
logger := logr.Discard()
_, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: nil, AuthParams: authParams}, http.DefaultClient)
_, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: nil, AuthParams: authParams}, http.DefaultClient)

@semgrep-code-kedacore semgrep-code-kedacore Bot Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider to use well-defined context

🧁 Fixed in commit 6799601 🧁

logger := logr.Discard()

_, _, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams}, http.DefaultClient)
_, err := parseAzurePipelinesMetadata(context.TODO(), logger, &scalersconfig.ScalerConfig{TriggerMetadata: testData.metadata, ResolvedEnv: testData.resolvedEnv, AuthParams: testData.authParams}, http.DefaultClient)

@semgrep-code-kedacore semgrep-code-kedacore Bot Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider to use well-defined context

🧼 Fixed in commit 6799601 🧼

@m-amaresh m-amaresh changed the title Adds Microsoft Entra **service principal** authentication to the Azure Pipelines scaler Adds Microsoft Entra service principal authentication to the Azure Pipelines scaler Jul 24, 2026
@m-amaresh m-amaresh changed the title Adds Microsoft Entra service principal authentication to the Azure Pipelines scaler feat(azure-pipelines): add service principal authentication via reusable Azure provider Jul 25, 2026
@m-amaresh
m-amaresh marked this pull request as ready for review July 28, 2026 13:11
@m-amaresh

Copy link
Copy Markdown
Author

This PR is now ready for review

@deepakbshetty

Copy link
Copy Markdown

Hi @m-amaresh , Merge conflict. Would you consider adding resolvedEnv i.e. environment variables for service principal as supported by azidentity - https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/azidentity/README.md#service-principal-with-secret

@m-amaresh

Copy link
Copy Markdown
Author

@deepakbshetty I prefer to keep this PR scoped to adding reusable service principal auth and wiring it into the az devops scaler only. Also those env vars come from the process env which here is the operator pod that means one service principal for the entire cluster.

…ble Azure auth provider

Introduce a reusable `azureServicePrincipal` authentication provider on
TriggerAuthentication/ClusterTriggerAuthentication and wire it into the
Azure Pipelines scaler. Per maintainer feedback on kedacore#7578, the provider
lives in pkg/scalers/azure so other Azure scalers can adopt it, rather
than being scoped to the Azure Pipelines scaler alone.

- Add AzureServicePrincipal spec (tenantId, clientId, clientSecret,
  clientCertificate, clientCertificatePassword, cloud,
  activeDirectoryEndpoint) with webhook validation and generated CRDs
- Add azure.NewServicePrincipalCredential supporting client secret and
  PKCS#12/PEM certificate credentials, sovereign clouds, and private
  cloud (with instance discovery disabled)
- Resolve provider secrets in scale_resolvers into azureServicePrincipal*
  auth params
- Refactor Azure Pipelines auth into configureAzurePipelinesAuth with an
  explicit auth type; preserve existing PAT > workload identity precedence
  and add service principal as a fallback
- Add unit tests and an e2e test (tests/scalers/azure/azure_pipelines_sp)

Signed-off-by: m-amaresh <115941749+m-amaresh@users.noreply.github.com>
…tently

Signed-off-by: m-amaresh <115941749+m-amaresh@users.noreply.github.com>
@deepakbshetty

deepakbshetty commented Aug 1, 2026

Copy link
Copy Markdown

Hi @m-amaresh That's fine if you want to keep you PR scope as-is. The environment variables on triggerauth are retrieved from individual deployment see existing personalAccessTokenFromEnv and not from keda operator as per my understanding.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authenticating with Azure DevOps using SPN

2 participants