# AZ-401: Key Vault Integration with Azure Pipelines and GitHub Actions

Configure existing-vault secret retrieval through Azure Pipelines linked variable groups and GitHub OIDC, then verify selected names, runtime access, mapping changes and protected handling.

Author: LearningPathX Editorial Team
Content version: 1.0
Published: 2026-12-04T04:08:27.455477+00:00
HTML: https://learningpathx.com/guide/AZ-401/az-401-key-vault-integration-with-azure-pipelines-and-github-actions.html

## AZ-401: Key Vault Integration with Azure Pipelines and GitHub Actions

Link selected secret names from an existing Azure Key Vault to an Azure Pipelines variable group, or retrieve the selected secret during an already federated GitHub Actions job. In both cases, verify the actual identity, vault permission and network path before trusting a successful consumer. Keep name selection, current-value retrieval and log protection as separate checks: a connection that can authenticate has not yet proved that it can read the intended secret safely.

This procedure implements both connector paths in existing authorized nonproduction environments. The GitHub path uses established OpenID Connect (OIDC) authentication and an approved Azure command-line interface (CLI) environment. It does not create a vault, provision a new identity or report live retrieval results. The examples describe proposed operations and evidence, not tests performed for this article.

## Record the existing resources and intended consumer

Use Azure Pipelines Workload Identity and Service Connections and GitHub Actions OpenID Connect Trust for Azure to establish the two actual authentication contexts first. Secrets Keys Certificates and Sensitive Deployment Assets supplies the distinction between a secret, a key, a certificate and its authorized consumer.

Record these owner-approved inputs without recording secret values:

* The existing vault, its tenant, permission model, network configuration and responsible owner.
* The existing Azure project and service connection, its actual principal, the new test variable-group name and the one approved pipeline consumer.
* The existing GitHub repository, workflow/job, allowed event/reference, federated principal and approved runner/tool versions.
* One pre-existing permitted nonproduction secret, its exact name and an owner-controlled validation or rotation reference.
* A non-disclosing consumer that can distinguish an acceptable value from missing or unusable input.
* Approved negative cases, starting configuration and ownership of every temporary change.

Azure Key Vault vaults hold keys, secrets and certificates. Managed Hardware Security Module (HSM) pools have a different, key-focused scope. The Azure Pipelines variable-group connector maps secrets; it does not turn keys or certificates into secret variables. Confirm the selected object type before diagnosing an apparently missing name.

Keep identity authentication, secret authorization and reachability distinct. A pipeline run can select the right identity and still lack vault access; an authorized identity can still be unable to reach the vault through the actual connector or runner path. An administrator's successful browser access does not prove the pipeline path works.

## Check the supported Azure connector boundary

The variable-group creator needs at least Library Creator permission and the relevant service-connection User role. The service connection must already represent the intended Azure identity. Have the vault owner verify its appropriate secret permissions under the vault's actual model.

For role-based access control (RBAC), the connector documentation supports vaults accessible through a public endpoint and identifies appropriate secret roles, such as Key Vault Secrets User, according to the operation. Its private-endpoint RBAC case is not supported. A public endpoint does not mean anonymous access or permission to open the vault to every network.

For an existing access-policy vault, inspect the applicable secret Get and List grants for the actual connection principal. Do not combine access-policy instructions with an RBAC vault and assume both models are active. The need to select names and retrieve values must be checked against the real configuration.

Choose an existing supported arrangement for this exercise. If the selected private/network configuration is incompatible, stop the connector operation and return that limitation to its owners. Do not switch permission models, remove network restrictions or create a replacement vault merely to obtain a successful demonstration.

## Create the linked Azure Pipelines variable group

In the existing Azure DevOps project:

1. Open Pipelines, then Library, and choose + Variable group.
2. Enter the owned test-group name and an explanation of its intended consumer.
3. Enable Link secrets from an Azure key vault as variables.
4. Select the actual recorded service connection and use Authorize where required.
5. Select the existing vault. Complete the documented vault authorization through its owner where that control applies.
6. Choose + Add, select only the approved secret names, choose OK and then Save.
7. Reopen the group and compare its connection, vault and mapped-name set with the input record.

A name appearing in the selector is configuration evidence, not an observed runtime read. Keep unrelated vault names out of the group. Do not add a key or certificate because its display name resembles the intended secret.

Have the owner permit only the selected test pipeline to consume the group through the existing approved setup. Bind that actual group in the pipeline's validated variable-group consumption configuration, preserving unrelated variables and permissions. Reusable YAML Templates Variables and Classic Task Groups covers that reuse boundary; this connector procedure does not invent a generic consumer definition or task-input name.

Run the existing harmless consumer. Retain the pipeline revision, group identity, selected name and non-disclosing consumer result. Establish that the run used this group and vault path rather than an old inline value or another variable with the same name. Save success alone is insufficient.

## Verify values and reconcile changes to names

The linked group stores the selected names rather than copying secret values into its configuration. Pipelines retrieve current values from the vault at runtime. Updating an existing secret's value therefore differs from changing which names exist or are selected.

For a controlled owner-managed value update, retain the owner's version/change reference and run the consumer again. Verify the expected behavior without printing the value or a secret-derived hash. Do not rotate a shared production credential merely to exercise this connector.

Added and deleted vault names do not automatically reconcile the group's mapping. Use this sequence:

1. Compare the approved vault-name inventory with the group's actual selected names.
2. To include another already permitted test secret, reopen the group, use + Add, select that name and save.
3. Remove an obsolete selection from the group through its owner, save and inspect the resulting name set.
4. Re-run the actual consumer and distinguish a missing mapping from a mapped name whose vault object or permission is now unavailable.

If the owner separately authorizes a test-name lifecycle, record its restoration plan first. Do not delete a real secret to manufacture a missing-name failure. Restoring a variable-group selection cannot restore a deleted vault object or reverse a credential rotation.

## Prepare the existing GitHub OIDC retrieval job

Use the established federated job and identity from GitHub Actions OpenID Connect Trust for Azure. Confirm its actual trust conditions and current repository context, including any applicable immutable-subject behavior. Token issuance permission, Azure token exchange and permission to read this vault remain separate boundaries.

The job needs the appropriate `id-token: write` permission and a supported Azure login step. That permission allows requesting an identity token; it grants no Azure secret access. Verify the principal's actual vault permission and the runner's network path independently. Preserve any existing environment protection and event restrictions.

Microsoft's Key Vault workflow sample is dated July 2025 and includes example action versions. Do not treat those versions as the current supported baseline. Keep the existing reviewed login/tooling implementation and check its actual versions and compatibility before editing the retrieval step. If a compatible authenticated CLI context is absent, stop instead of guessing an action version or installing an unreviewed helper.

Map the actual approved vault and secret names into the existing step's `KEYVAULT_NAME` and `KEYVAULT_SECRET_NAME` environment inputs. Use the repository's approved configuration scope. These names identify resources; the retrieved secret remains in the vault until the job reads it. Do not paste its value into workflow source or create an unnecessary duplicate GitHub secret.

## Retrieve and pass one bounded test secret

The following Bash fragment belongs inside the existing authenticated CLI step, not in a new stand-alone workflow. Before using it, the owner must independently establish that the original test-secret value is nonempty, single-line text suitable for this handling path, with no carriage returns, line feeds or percent characters. Bash command substitution strips trailing line feeds from its output. The post-capture `case` check therefore examines only the remaining captured representation; it cannot prove that the original value had no trailing line feed. Do not use this fragment to establish that prerequisite or to serialize arbitrary secrets. Other representations require the owner's validated handling path.

```bash
set +x
: "${KEYVAULT_NAME:?Set the approved existing vault name}"
: "${KEYVAULT_SECRET_NAME:?Set the approved existing secret name}"
: "${GITHUB_ENV:?Use the approved GitHub Actions step context}"

if ! RETRIEVED_VALUE="$(az keyvault secret show \
  --vault-name "$KEYVAULT_NAME" \
  --name "$KEYVAULT_SECRET_NAME" \
  --query value --output tsv)"; then
  printf '%s\n' 'Secret retrieval failed' >&2
  exit 1
fi

case "$RETRIEVED_VALUE" in
  ''|*$'\r'*|*$'\n'*|*'%'*)
    unset RETRIEVED_VALUE
    printf '%s\n' 'Secret representation is outside this example' >&2
    exit 1
    ;;
esac

printf '::add-mask::%s\n' "$RETRIEVED_VALUE"
printf 'RETRIEVED_VALUE=%s\n' "$RETRIEVED_VALUE" >> "$GITHUB_ENV"
unset RETRIEVED_VALUE
```

The command captures the selected value, registers masking before onward use, and places it in the job's environment-file path for a subsequent step. The masking directive is a runner control message, not an invitation to echo the value elsewhere. Disabling shell tracing does not establish that every invoked tool or consumer is safe.

Use the existing approved consumer in a subsequent step of that job. It should read the environment value and return only the agreed non-sensitive result. Do not add the value to job outputs, artifacts, debug dumps or a deployment command's visible arguments. The example's environment-file handling is temporary runner state; it is not a new vault, a cross-job secret store or automatic synchronization into GitHub's secret settings.

Record the actual vault/name selection, job revision, principal and consumer result. A message saying that retrieval succeeded is not itself proof that the intended consumer received a usable value.

## Test the failed boundary without widening access

Use separately approved harmless cases on both platforms. The following table is an acceptance plan, not executed output:

| Case | Evidence to retain |
| --- | --- |
| Approved identity and selected existing secret | Actual connector/job selection, successful retrieval path and non-disclosing consumer result |
| Wrong or owner-confirmed missing name | Actual requested/mapped name and the failure, separated from authentication or network errors |
| Owned test identity lacks secret-read permission | Actual principal and authorization denial; no broad role grant to conceal it |
| Vault is unreachable from the actual path | Network/connectivity diagnostic, recorded separately from a permission denial |
| Existing value changes through its owner | New run and expected consumer behavior correlated with the owner's change record |
| Mapping or workflow name changes | Saved selection/configuration and evidence that the intended name, rather than an old value, was used |

Do not remove a shared identity's access or break a shared network rule to force a negative test. If no safe denied identity or network case is available, inspect the actual configuration and record the untested path explicitly.

A cached application result can conceal a failed read. Likewise, a missing variable can originate in mapping, workflow event access or consumer configuration. Preserve the decisive diagnostic before changing anything; adding every secret or granting broad vault administration destroys the test's meaning.

## Inspect logs and restore owned settings

Review successful and failed runs for exposure in task output, shell traces, error streams, transformed values and consumer diagnostics. GitHub's secure-use guidance states that automatic redaction is not guaranteed. Masking is one control within a reviewed execution path, not permission to print secrets and check whether they disappear.

Repository, environment and organization secret access have their own scope and event conditions. An environment does not isolate a self-hosted runner, and a vault connector does not make untrusted workflow code safe. Keep the permitted execution context and privileges intact while testing.

If a value is exposed, use the owner's incident process to restrict the exposed evidence and rotate or revoke the affected credential as appropriate. A cleaned log does not make the exposed value trustworthy again.

Restore only the test group's selected names, pipeline binding/authorization and workflow-step changes deliberately introduced here. Have the owners verify the retained consumer behavior. Remove an owned test group only after checking its actual consumers; preserve shared connections, the existing vault, identity grants and unrelated secrets.

The final record should explain which identity retrieves which name through which path, how changed names are reconciled, what the consumer actually demonstrated and which negative cases remain untested. Keep storage, federation, connector retrieval and application validation as separate results.

## Authoritative Sources

* [Link a variable group to secrets in Azure Key Vault](https://learn.microsoft.com/en-us/azure/devops/pipelines/library/link-variable-groups-to-key-vaults?view=azure-devops) — Mapping, creation steps, permissions, runtime values and network limitations.
* [Integrate Azure Key Vault into a GitHub Actions workflow](https://learn.microsoft.com/en-us/azure/developer/github/github-actions-key-vault) — Federated retrieval, CLI capture, masking and subsequent-step handling; dated sample versions.
* [Configuring OpenID Connect in Azure](https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-azure) — Token permission, actual trust conditions and Azure exchange.
* [Azure Key Vault basic concepts](https://learn.microsoft.com/en-us/azure/key-vault/general/basic-concepts) — Secret consumers, object types and vault versus Managed HSM scope.
* [Connect to Azure with an Azure Resource Manager service connection](https://learn.microsoft.com/en-us/azure/devops/pipelines/library/connect-to-azure?view=azure-devops) — Applicable established Azure Pipelines identity and connection routes.
* [Using secrets in GitHub Actions](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets) — Configuration scopes and workflow secret-access conditions.
* [Secure use reference](https://docs.github.com/en/actions/reference/security/secure-use) — Least privilege, untrusted execution, masking limits and exposure handling.

## Related Reading

* Prerequisite: [AZ-401: Azure Pipelines Workload Identity and Service Connections](https://learningpathx.com/guide/az-401/az-401-azure-pipelines-workload-identity-and-service-connections.html)
* Prerequisite: [AZ-401: GitHub Actions OpenID Connect Trust for Azure](https://learningpathx.com/guide/az-401/az-401-github-actions-openid-connect-trust-for-azure.html)
* Prerequisite: [AZ-401: Secrets Keys Certificates and Sensitive Deployment Assets](https://learningpathx.com/guide/az-401/az-401-secrets-keys-certificates-and-sensitive-deployment-assets.html)
* Related: [AZ-401: Reusable YAML Templates Variables and Classic Task Groups](https://learningpathx.com/guide/az-401/az-401-reusable-yaml-templates-variables-and-classic-task-groups.html)
