Stage Secrets
How Integration Hub stores the secrets that API, PGP and SFTP stages use in Key Vault, and how to use $env: and $kv: tokens to choose where each secret comes from.
Some stages need secrets, for example the password for a remote API, a PGP private key, or an SSH private key. Integration Hub keeps these secrets in the Domain's Key Vault, named {prefix}-{domainCode}-key (for example p1-wsc-whd-key). API Management, the Logic Apps and the Function App read the secrets from there at run time.
A secret must never be written into a stage file, because stage files are kept in the Integration Hub repository. Instead, each secret field holds a token that tells the deployment where the secret comes from:
| Token | Example | Where the secret comes from | What the deployment does |
|---|---|---|---|
$env: | "password": "$env:REMOTE_API_PASSWORD" | An Azure DevOps variable in the variable group of the environment. | Writes the value of the variable to a Key Vault secret. |
$kv: | "password": "$kv:dm1-remote-api-password" | A Key Vault secret that you create in the Domain's Key Vault. | Does not write the secret. Checks that it exists and can be used, and then uses it. |
You can use both kinds of token in the same stage, for example an $env: token for a client ID and a $kv: token for a client secret. Use $kv: when the secret values must not be kept in Azure DevOps, for example when the customer's security team puts all secrets into the Key Vault themselves. Also use $kv: for RSA PGP and SSH keys, which are too long for an Azure DevOps variable.
A literal value in a secret field stops the deployment.
Token Format
$env:is followed by the name of the Azure DevOps variable: letters, digits and_.$kv:is followed by the name of the Key Vault secret: letters, digits and-.- In the secret fields of API stages, and in outbound API
headervalues, a token can be part of a longer value, for example"Authorization": "Bearer $kv:partner-api-token". - In PGP and SFTP stages, each secret field must be exactly one token.
- The
in-apipublicAuth.issuerSigningKeysvalue is a comma-separated list of$env:and$kv:tokens, with no literal entries. Each entry must be exactly one token, and an$env:variable can hold several comma-separated keys.
Stages and Fields That Hold Secrets
These stage fields are secret fields. All other fields are deployed as they are, and can still use $env: tokens in the usual way.
| Stages | Fields |
|---|---|
in-api | publicAuth.tenantId, publicAuth.applicationId, publicAuth.issuerSigningKeys, publicAuth.value, publicAuth.fieldValue |
out-proxy-api, out-proxy-api-store-response, out-proxy-api-store-response-binary, out-form-data | In the authentication section: basic.userName, basic.password, oauth2.authenticationUrl, oauth2.body, custom.authenticationUrl and custom.body. |
sync-api-to-api | The same fields as in-api and the outbound API stages, in the stage's in-api and out-proxy-api-store-response actions. |
pgp-encrypt, pgp-decrypt | publicKeySecretName, privateKeySecretName, passPhraseSecretName |
in-sftp, out-sftp, out-sftp-binary | sftpDetails.sshPrivateKeySecretName |
Some fields are not secrets, but can still read a value from Key Vault:
- Outbound API
headervalues, in the stage'sheaderand in theauthenticationsection. A literal value, for exampleapplication/json, is used as written. A value with an$env:or$kv:token is read from Key Vault, for example an API key. - The
in-apipublicAuth.headerName. It can be a literal header name, one$env:token or one$kv:token.
$kv: tokens can only be used in these fields and in the secret fields. The managedIdentity authentication option has no secrets.
Azure DevOps Variable Secrets
For an $env: token, add an Azure DevOps variable with that name to the variable group of each environment, and set its value to the secret value in the format that the field needs.
Do not mark these variables as secret in Azure DevOps. Azure Pipelines does not give secret variables to the deployment scripts, so the deployment reads them as empty, and pre-flight validation stops the deployment. Use the Azure DevOps library and pipeline permissions to control who can see the values.
An Azure DevOps variable can hold a maximum of 4,096 characters. The Base64 encoded value of an RSA key is longer than this. For example, an RSA 4096 PGP private key is about 9,000 characters, and an RSA 4096 SSH private key is about 4,500 characters. For these keys, use a $kv: token. An $env: token only works for small keys, for example Ed25519 or ECDSA keys, and for the PGP passphrase.
The deployment writes each value to a Key Vault secret with a fixed name: the Domain code, a hyphen, and the variable name. In the variable name, each _ and each character that is not a letter, a digit or a hyphen becomes a hyphen. For example, $env:REMOTE_API_PASSWORD in Domain dm1 gives the secret dm1-REMOTE-API-PASSWORD.
- The deployment writes a new secret version only when the value has changed, or when the secret does not exist yet.
- The value in Azure DevOps always wins. A change made to the secret directly in the Key Vault is replaced at the next deployment.
- For API stages, the deployment also creates an API Management named value that refers to the Key Vault secret, and the API Management policy uses the named value. The secret value is not written into the policy.
Key Vault Secrets
For a $kv: token, create the secret in the Domain's Key Vault before you deploy, with the value in the format that the field needs.
- The deployment never writes or changes these secrets.
- The secret must be enabled, must not be expired, and must have a value.
- For API stages, the deployment creates an API Management named value that refers to the secret, in the same way as for
$env:tokens. - To create the secrets, you need an access policy on the Key Vault that lets you set secrets. Add the users or Entra groups that need this access to the
keyVaultAdminslist of the Domain. An access policy added by hand is removed by the next deployment.
The Domain's Key Vault is created by the first deployment of the Domain. When a new Domain uses $kv: tokens, pre-flight validation shows a warning that the Key Vault is not deployed yet, and the deployment continues. After the first deployment, create the secrets, and then deploy again.
Secret Value Formats
The format is the same for both kinds of token: the value of the Azure DevOps variable, or the value of the Key Vault secret.
| Secret | Format |
|---|---|
| API credentials, URLs, bodies and header values | The plain value, not encoded. |
in-api tenantId and applicationId | A GUID, for example 00000000-0000-0000-0000-000000000000. |
| PGP public and private keys | The Base64 encoded ASCII-armored key, including the -----BEGIN PGP ... KEY BLOCK----- and -----END PGP ... KEY BLOCK----- lines. See PGP Secret Formats. |
| PGP passphrase | The Base64 encoded passphrase. |
| SSH private key | The Base64 encoded private key file, in OpenSSH, RSA, EC or PKCS#8 format. See SSH Private Key Format. |
Pre-Flight Validation
Pre-flight validation checks the secrets before anything is deployed, and stops the deployment when:
- A secret field has a literal value, and not an
$env:or$kv:token. - A
$kv:token is used in a field that is not read from Key Vault. - An Azure DevOps variable is missing or empty, or is marked as secret.
- A Key Vault secret does not exist in the Domain's Key Vault, or cannot be used (disabled, expired, not yet valid, or empty).
- A
tenantIdorapplicationIdvalue is not a GUID. - A PGP key or passphrase is not valid Base64, a key is not the expected type (for example a public key in place of a private key), or the key checksum does not match.
- An SSH private key is not valid Base64, is not a supported private key, cannot be read, or is encrypted and the
sshPrivateKeyPassphrasedoes not unlock it. - The Key Vault secret name made from an
$env:token is not valid, or is longer than 127 characters. - The Key Vault secret name made from an
$env:token is the same as a$kv:secret in the same Domain. The deployment would replace the secret that you created. - The domains file or a stage file still has a
secretProvisioningModesetting. See the upgrade notes.
Last updated on