使用过滤器迁移AZ KeyVault Secrets
我有以下问题。 我有一个shell脚本,将价值和秘密从1个保管库复制到另一个保管库。 我还为此找到了一个Powershell脚本。
但是我真正的问题是我可以做到这一点,以便它仅从给定列表中传输值。 例如SecretFilter? 如果是在Powershell或Bash中,对我来说没有什么区别。 谢谢大家!
以下是我为Bash和PowerShell找到的脚本
#!/bin/sh
#
# az account set --subscription "BCONN-DEV"
# az keyvault list -o table
# => westeurope kv-aks-accept-001 rg-aks-accept-001
# => westeurope kv-aks-dev-001 rg-aks-dev-001
#=> westeurope kv-aks-prod-001 rg-aks-prod-001
SECRETS="enkrs-secret-0e enkrs-secret-0a enkrs-secret-0b"
SOURCE_KEYVAULT="enkrs-kv01"
DESTINATION_KEYVAULT="enkrs-kv02"
for SECRET in $SECRETS; do
az keyvault secret show --vault-name $SOURCE_KEYVAULT --name "$SECRET" --output json > "$SECRET".json
NAME=$(jq --raw-output '.name' "$SECRET".json)
VALUE=$(jq --raw-output '.value' "$SECRET".json)
EXPIRES=$(jq --raw-output '.attributes.expires' "$SECRET".json)
DESCRIPTION=$(jq --raw-output '.contentType' "$SECRET".json)
rm "$SECRET".json
if [ "$EXPIRES" = "null" ]; then
az keyvault secret set --vault-name $DESTINATION_KEYVAULT --name "$NAME" --value "$VALUE" --description "$DESCRIPTION"
else
EXPIRES=$(echo "$EXPIRES" | cut -c-10)
az keyvault secret set --vault-name $DESTINATION_KEYVAULT --name "$NAME" --value "$VALUE" --description "$DESCRIPTION" --expires "$EXPIRES"
fi
done
i have the following question.
I have a shell script that copies the values and secrets from 1 vault to another.
I have also found a Powershell script for this.
But my real question is can i make it so that it only transfers the values from a given list.
Such as a secretfilter?
If it is in powershell or bash makes no difference for me.
Thank you all in advance!
Below are the scripts i found for bash and powershell
#!/bin/sh
#
# az account set --subscription "BCONN-DEV"
# az keyvault list -o table
# => westeurope kv-aks-accept-001 rg-aks-accept-001
# => westeurope kv-aks-dev-001 rg-aks-dev-001
#=> westeurope kv-aks-prod-001 rg-aks-prod-001
SECRETS="enkrs-secret-0e enkrs-secret-0a enkrs-secret-0b"
SOURCE_KEYVAULT="enkrs-kv01"
DESTINATION_KEYVAULT="enkrs-kv02"
for SECRET in $SECRETS; do
az keyvault secret show --vault-name $SOURCE_KEYVAULT --name "$SECRET" --output json > "$SECRET".json
NAME=$(jq --raw-output '.name' "$SECRET".json)
VALUE=$(jq --raw-output '.value' "$SECRET".json)
EXPIRES=$(jq --raw-output '.attributes.expires' "$SECRET".json)
DESCRIPTION=$(jq --raw-output '.contentType' "$SECRET".json)
rm "$SECRET".json
if [ "$EXPIRES" = "null" ]; then
az keyvault secret set --vault-name $DESTINATION_KEYVAULT --name "$NAME" --value "$VALUE" --description "$DESCRIPTION"
else
EXPIRES=$(echo "$EXPIRES" | cut -c-10)
az keyvault secret set --vault-name $DESTINATION_KEYVAULT --name "$NAME" --value "$VALUE" --description "$DESCRIPTION" --expires "$EXPIRES"
fi
done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您提供了解析秘密的静态列表,则可以使用变量来完成,例如:
然后,您需要更改此行:
在此内容中:
另外,您将值分配给了某些变量的顶部。您的脚本...
您将这些变量重新分配到其他变量
这是多余的,无用的,只需选择一个名称并将其在脚本中使用即可。另外,您正在声明无需在任何地方使用的变量
azsub
,因此假设脚本中没有任何代码,则可以将其删除。Assuming you're providing a static list of secrets to parse, this can be done by using a variable, let's say:
then you need to change this line:
into this:
Also, you're assigning values to some variables on the top of your script...
and you're re-assigning those variables to other variables
this is redundant and useless, just pick one name and use it in your script. Also, you're declaring the variable
azsub
which is not used anywhere, so assuming there isn't any more code into the script you can just remove it.您只需要创建一个秘密名称列表并循环通过。
这是使用PowerShell和Azure CLI的样本:
You just need to create a list of secret names and loop through.
Here is a sample using PowerShell and Azure CLI: