Design and implement a strategy for managing sensitive information in automation
Learning objectives
- Retrieve necessary secrets through the correct identity, network and data-plane permissions.
- Rotate keys, password-style secrets and certificates according to their different consumers.
- Consume secure files and scoped GitHub secrets without widening untrusted access.
- Diagnose and contain exposure using nonsecret evidence.
Authorize retrieval before relying on masking
Key Vault retrieval needs the intended principal's data-plane permission, runner network reach and permission to use the pipeline connection or secret resource. Managing the vault through Azure Resource Manager does not itself grant secret-value access. Use an appropriate RBAC data role, or the relevant Get/List permissions in the legacy access-policy model. A principal that can alter legacy policies may grant itself data access, limiting separation through management rights in that model.
A Key Vault-linked Azure Pipelines variable group maps selected secret names and retrieves their latest values at runtime. Updating an already mapped secret value does not require copying it into the group. Adding/deleting names needs mapping changes. This is secret integration, not a general projection of key and certificate objects. Authorize the intended pipeline and connection, then expose variables only where required.
Alternatively, AzureKeyVault@2 uses azureSubscription, KeyVaultName and SecretsFilter. A blanket * filter is not least privilege. RunAsPreJob: true exposes retrieved variables throughout the job rather than only subsequent tasks, so enable it only for that need. Distinguish a missing name, unmapped name, denied data access and blocked runner network during diagnosis.
In GitHub Actions, first establish the approved Azure identity through the supported login/federation route. After a successful login with the intended client, tenant and subscription, a particular secret can be retrieved with:
SECRET_VALUE=$(az keyvault secret show --name "$SECRET_NAME" --vault-name "$KEYVAULT_NAME" --query value -o tsv)
printf '::add-mask::%s\n' "$SECRET_VALUE"
Use trusted nonsecret names, check retrieval success before consumption, disable shell tracing and register masking before possible output. Privately hand the value to the intended consumer. The adopted workflow uses azure/login then azure/CLI; its $GITHUB_ENV handoff exposes the value to later steps in that job. A direct consumer-only handoff is narrower where feasible. Single-line environment-file syntax does not serialize every multiline secret. Do not print the value or its containing JSON, and verify the actual consumer's authenticated outcome rather than a success message. The source's action versions are not asserted to be the newest.
Rotate the object its consumer actually uses
Secrets store values, keys support cryptographic operations, and certificates have certificate/key/secret-related components. Permissions and lifecycles differ. Secret-read access can expose a certificate's associated secret portion, not merely public metadata.
For cryptographic keys, use rotation and policy authority such as the applicable Key Vault Crypto Officer role. Configure Rotate/Notify lifetime actions and new-version expiry. Before-expiry actions require expiry information. The adopted guidance specifies a minimum seven-day rotation interval; sample P18M, P2Y and P30D values are examples, not universal compliance standards.
az keyvault key rotation-policy update with the real vault, key name and policy file changes policy; az keyvault key rotate creates a version on demand. Inspect policy and resulting version separately. Versionless references permit latest-version discovery, but consumer refresh and data-key rewrapping are service-dependent. Retain old key versions needed by encrypted material. A new vault version does not prove external ciphertext was rewrapped or every consumer refreshed; account for transition timing and costs.
Handle password rotation as a multi-system change
The adopted single-credential SQL tutorial is a fallback when managed identity/Entra authentication does not fit. SecretNearExpiry triggers Event Grid and a Function with vault/SQL authority. It uses CredentialId, ProviderAddress and ValidityPeriodDays, validates the connection, generates a password, writes a new vault version and then updates SQL's password.
The writes are not atomic. In an illustrative partial failure, Vault accepts the new version but SQL rejects its update. “Latest secret exists” is true, while “replacement credential authenticates” is false. Track nonsecret version/provider outcomes and reconcile current state before replaying. Avoid overlapping rotations. The cited two-hour Event Grid retry window is bounded recovery, not an indefinite guarantee. Parsing an event version while retrieving the current secret by name does not establish duplicate-event idempotency.
A controlled near-expiry test needs both a new vault version and successful SQL authentication using its replacement. Record version metadata and connection outcome without reproducing sample output containing the password. No rotation or live credential test was performed for this lesson.
Verify certificate issuance and serving separately
Choose supported partner-CA issuance/renewal or import according to the issuer and material. Manual import does not automatically gain partner-CA renewal. Track asynchronous enrollment to completion. Imported PEM/PFX material must include the private key and specify vault/certificate names. Policy is optional, but any supplied policy must match what Key Vault parses from the file.
After renewal, verify that the consuming endpoint serves the intended certificate and chain. Object upload or enrollment completion does not by itself deploy the certificate to its consumer.
Protect file-shaped credentials
Upload Azure Pipelines sensitive files through Pipelines → Library → Secure files, then configure library/user rights, permitted pipelines and relevant approvals/checks. Management rights, pipeline authorization and approval are distinct. File contents are replaced deliberately rather than edited in place; inspect consumers before retiring old material.
For YAML, authorize the pipeline under selected file → Pipeline permissions. The adopted source states that all classic pipelines can access secure files; this distinguishes pipeline authorization and does not let every user bypass library security. Bind the actual download path through the named task:
- task: DownloadSecureFile@1
name: signingMaterial
inputs:
secureFile: 'approved-signing-material.pfx'
The authorized consumer uses $(signingMaterial.secureFilePath) with its documented file argument and appropriate private-material permissions. Do not guess a workspace location or copy a public-CA example's world-readable permissions to a private signing key. Avoid copies in logs, caches and artifacts. Removing the temporary file cannot delete a copy already published elsewhere. The example performs no signing.
Scope GitHub secrets to trusted consumers
Choose repository, environment or organization scope according to the consuming jobs and protection policy. An unset secret expression can become an empty string rather than fail automatically. Check required input presence without printing its contents so a missing credential does not trigger an unintended anonymous/default target.
Fork-origin, Dependabot and reusable workflows have different passing rules. A caller's access does not automatically pass secrets to a reusable workflow. Declare supported forwarding deliberately and keep restricted workflows restricted; do not expose deployment credentials to untrusted code merely to make a job run.
Use minimum token permissions, narrow secret retrieval and separation of privileged steps from untrusted content. Actions can obtain github.token implicitly. Prefer supported secret inputs or scoped environment delivery over command arguments or generated source. Avoid echo, shell tracing, environment dumps, Authorization headers, exception payloads and secret-bearing temporary artifacts.
Masking reduces accidental exposure in expected log representations. It cannot prevent a malicious process from encoding or transmitting a secret it can read. Restrict process access before relying on redaction. Diagnose a failed deployment through input presence, nonsecret destination identity, permissions and sanitized errors. If exposure occurs, revoke/rotate and investigate use; deleting a log line or dismissing an alert does not invalidate the credential.
Summary
Keep retrieval permissions, consumer access and lifecycle evidence explicit. A stored new version is not a verified credential transition, and a completed certificate upload is not endpoint adoption. Protect secure-file and workflow-secret inputs at their true authorization boundaries. Successful deployment or logs without visible redaction do not prove that no leakage occurred.
