Multiple Azure Keyvaults With Different Environments
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 23.1k
- Forks
- 1.1k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 9
Description
I have a file that is encrypted with an Azure keyvault key from Azure cloud. I want to encrypt with an additional key from a vault in Azure US Government cloud. I'm using CLI mode. I understand that I can set AZURE_ENVIROMENT=AzureUsGovernmentCloud to use that cloud. Unfortunately sops applies the same credential for both azure keys and one will always fail to encrypt with 401 Unauthorized.
Start with a .sops.yaml like this:
creation_rules:
- path_rules: secrets.yaml
azure_keyvault: https://myvault.vault.azure.net/keys/mykey/someversion
Steps to validate current config:
az cloud set --name azurecloud
az account set --subscription my-cloud-sub
sops -d secrets.yaml
Add the us gov key, updating sops.yaml to something like this:
creation_rules:
- path_rules: secrets.yaml
azure_keyvault: https://myvault.vault.usgovcloudapi.net/keys/mygovkey/someversion,https://myvault.vault.azure.net/keys/mykey/someversion
Steps (fails with 401):
az cloud set --name azureusgovernment
az account set --subscription my-gov-sub
AZURE_ENVIRONMENT='AzureUsGovernmentCloud' sops updatekeys secrets.yaml
Note failure:
error updating one or more master keys: [failed to encrypt new data key with master key "https://myvault.vault.azure.net/keys/mykey/someversion": failed to encrypt sops data key with Azure Key Vault key 'https://myvault.vault.azure.net/keys/mykey/someversion': POST https://myvault.vault.azure.net/keys/mykey/someversion/encrypt
--------------------------------------------------------------------------------
RESPONSE 401: 401 Unauthorized
ERROR CODE: Unauthorized
--------------------------------------------------------------------------------
{
"error": {
"code": "Unauthorized",
"message": "AKV10032: Invalid issuer. Expected one of https://sts.windows.net/<azure cloud tenant id>/, found https://sts.windows.net/<azure gov cloud tenant id>/."
}
}
--------------------------------------------------------------------------------
]
Based on the order of operations, I assume the gov encryption key was used successfully? The error states the original azure key (which is listed second in the example file) cannot be used because the login context is for the government cloud.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CLI sops updatekeys flow and the .sops.yaml Azure Key Vault configuration, reproducing the commands for Azure Cloud and Azure Government shown in the issue. Trace how credentials and environments are selected for each key; done means both vaults can be updated with their respective cloud credentials without the 401 issuer error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, go
- Domain
- cli, cloud, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100