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: publishFederated credential subjects
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.
| Store | Scope and behaviour |
|---|---|
| Repository secret | Available to workflows in the repository; masked in logs |
| Environment secret | Released only to jobs that target the environment, after its protection rules pass |
| Organization secret | Shared by selected repositories |
| Azure Key Vault | Central 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.
Secret or variable?
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.
A leaked secret
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.
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.