将 RSA 密钥放入 Azure Key Vault

Mer*_*ick 21 automation ssh git azure ssh-keys

如何将我的密钥对(通常是 id_rsa 和 id_rsa.pub)存储在 azure 密钥保管库中。我想将公钥放在我的 GIT 服务中,并允许虚拟机从 Azure 密钥保管库下载私钥 -> 以便它可以安全地访问 GIT。

我尝试制作一对 PEM 文件并将它们组合成一个 pfx 并将其作为秘密上传,但我返回的文件似乎与任一 pem 文件完全不同。

我还尝试将我的密钥手动输入 Azure,但它会将换行符转换为空格。

Shu*_*bao 31

可以使用Azure CLI上传id_rsa到 Azure Key Vault。

azure keyvault secret set --name shui --vault-name shui --file ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)

你可以-h用来获取帮助。

--file <file-name>                 the file that contains the secret value to be uploaded; cannot be used along with the --value or --json-value flag
Run Code Online (Sandbox Code Playgroud)

您还可以从密钥保管库下载机密。

az keyvault secret download --name shui --vault-name shui --file ~/.ssh/id_rsa
Run Code Online (Sandbox Code Playgroud)

我比较了我实验室的钥匙。他们是一样的。

  • 仅供参考,以下是获取秘密“get”的正确方法不再有效。`az keyvault secret 下载 --name &lt;KeyNameHere&gt; --vault-name &lt;vaultNamehere&gt; --file &lt;filename here&gt;` (2认同)

Hig*_*ife 15

水生宝之前的回答显示了使用 Azure CLI 1.0(节点)存储机密的命令。对于Azure CLI 2.0 (Python),请使用以下语法:

设置/存储密钥:

az keyvault secret set --vault-name 'myvault' -n 'secret-name' -f '~/.ssh/id_rsa'
Run Code Online (Sandbox Code Playgroud)

参数:

Arguments
    --name -n    [Required]: Name of the secret.
    --vault-name [Required]: Name of the key vault.
    --description          : Description of the secret contents (e.g. password, connection string,
                             etc).
    --disabled             : Create secret in disabled state.  Allowed values: false, true.
    --expires              : Expiration UTC datetime  (Y-m-d'T'H:M:S'Z').
    --not-before           : Key not usable before the provided UTC datetime  (Y-m-d'T'H:M:S'Z').
    --tags                 : Space-separated tags in 'key[=value]' format. Use '' to clear existing
                             tags.

Content Source Arguments
    --encoding -e          : Source file encoding. The value is saved as a tag (`file-
                             encoding=<val>`) and used during download to automatically encode the
                             resulting file.  Allowed values: ascii, base64, hex, utf-16be,
                             utf-16le, utf-8.  Default: utf-8.
    --file -f              : Source file for secret. Use in conjunction with '--encoding'.
    --value                : Plain text secret value. Cannot be used with '--file' or '--encoding'.

Global Arguments
    --debug                : Increase logging verbosity to show all debug logs.
    --help -h              : Show this help message and exit.
    --output -o            : Output format.  Allowed values: json, jsonc, table, tsv.  Default:
                             json.
    --query                : JMESPath query string. See http://jmespath.org/ for more information
                             and examples.
    --verbose              : Increase logging verbosity. Use --debug for full debug logs.
Run Code Online (Sandbox Code Playgroud)

检索/获取密钥:

~/.ssh/mykey使用jq 实用程序将密钥保存到文件中

az keyvault secret show --vault-name myvault --name 'secret-name' | jq -r .value > ~/.ssh/mykey
Run Code Online (Sandbox Code Playgroud)

文件可能会打印一个尾随换行符,您可以使用 perl one-liner 将其删除:

perl -pi -e 'chomp if eof' ~/.ssh/mykey

# Set permissions to user-read only
chmod 600 ~/.ssh/mykey
Run Code Online (Sandbox Code Playgroud)

从私钥文件生成公钥...

ssh-keygen -y -f ~/.ssh/myfile > ~/.ssh/myfile.pub
Run Code Online (Sandbox Code Playgroud)