Lesson 3 of 4 Source Control and Deployment Pipelines

Secrets Management for Database Pipelines

This lesson explains workload identity federation for pipelines and how to store and protect the secrets that remain.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how OIDC federated credentials replace client secrets.
  • Distinguish between repository, environment and organization secrets and Key Vault.
  • Describe how to respond to a leaked secret.

Workload identity federation

Workload identity federation lets GitHub Actions or Azure Pipelines obtain Microsoft Entra tokens without a client secret. A Microsoft Entra app registration or user-assigned managed identity has a federated credential that trusts tokens issued by GitHub's OpenID Connect (OIDC) provider for a specific subject, such as a branch (repo:contoso/inventory:ref:refs/heads/main), a pull request or an environment (repo:contoso/inventory:environment:production). The workflow requests an ID token, azure/login exchanges it, and later steps get database tokens for the same identity, which has a database user with the deployment permissions it needs.

permissions:
  id-token: write      # allow the job to request an OIDC token
  contents: read

steps:
  - uses: azure/login@v2
    with:
      client-id: ${{ vars.AZURE_CLIENT_ID }}
      tenant-id: ${{ vars.AZURE_TENANT_ID }}
      subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
  - uses: azure/[email protected]
    with:
      connection-string: "Server=sql-contoso.database.windows.net;Database=Inventory;Authentication=Active Directory Default;Encrypt=True"
      path: database/Inventory.sqlproj
      action: publish
Match the pairs

Federated credential subjects

Exam skills 2.3.6

Match each federated credential subject with what it trusts.

Log in to try this activity Interactive activities are free with an account.

Storing remaining secrets

Some values must still be secret, such as a third-party API key or a SQL password for a test container. The options are compared in the following table.

StoreScope and behaviour
Repository secretAvailable to workflows in the repository; masked in logs
Environment secretReleased only to jobs that target the environment, after its protection rules pass
Organization secretShared by selected repositories
Azure Key VaultCentral store with RBAC, rotation and auditing; read at run time by an authorized identity

Identifiers such as client IDs and subscription IDs are not secrets and can be stored as variables. Secrets are never echoed, written to files committed to the repository, or passed on command lines that are logged.

Sort into groups

Secret or variable?

Exam skills 2.3.6

Decide how each value should be stored for a GitHub Actions pipeline.

Log in to try this activity Interactive activities are free with an account.

Detecting and handling leaks

GitHub secret scanning detects known secret formats in repositories, and push protection blocks pushes that contain them. When a secret leaks, it must be rotated or revoked immediately: removing it from the latest commit or rewriting history does not help, because clones, forks and logs may already contain it.

Scenario questions

A leaked secret

Exam skills 2.3.6

Choose the right response to a leaked secret.

Log in to try this activity Interactive activities are free with an account.
Worked example

Removing a client secret from a pipeline

A GitHub Actions workflow deploys a dacpac with a service principal's client secret stored as a repository secret. Security requires that no long-lived Azure credentials exist for the pipeline, and only the production environment may deploy to production. What should the developer configure?

Add a federated credential to the app registration with the subject repo:org/repo:environment:production, grant the identity a database user with deployment permissions, set permissions: id-token: write, and use azure/login with the client, tenant and subscription IDs in the job that targets the production environment. Then delete the client secret. Moving the secret to Key Vault would still leave a long-lived credential, and an environment secret limits who can use the secret but does not remove it.

Check yourself

Which workflow permission does GitHub Actions need for OIDC login to Azure?

Show answer

id-token: write, so the job can request an OIDC token.

Exam Tips

Remember for the exam

  • No stored Azure secret: OIDC federated credential with azure/login and id-token: write.
  • Scope the federated credential's subject to a branch or environment.
  • Environment secrets are released only after the environment's protection rules pass.
  • Leaked secrets must be rotated, not just deleted from Git.