如何使用 Azure KeyVault 证书为 Azure Container Registry 与 PowerShell Azure AZ 签署 Docker Image?

问题描述 投票:0回答:0

我们将证书存储在 Azure Key Vault 中。我可以成功下载并使用其中一个证书编写 PFX 文件,代码基于 Microsoft 文档。Get-AzKeyVaultCertificate.

有一个问题是,我不能用PFX文件签署一个Docker镜像。我需要使用一个PEM文件来代替。我看到的所有Docker文档都使用PEM文件,就像Docker.com的这个例子一样。内容信任

我已经在自己的 Azure 订阅中成功地使用在我的密钥库中创建的自签名证书,然后使用 AZ CLI 将证书下载为 PEM。使用PowerShell AZ似乎没有办法将证书下载为PEM。我想,这让我不得不将PFX转换为PEM。我需要能够将其作为一个DevOps过程来做,所以重复性是必要的。我看到的大多数例子都表明,我应该使用openssl.exe。我不想使用openssl。如果可能的话,我想用 "原生 "Powershell的方式来完成这个任务。

微软的链接显示了以下代码来下载一个证书并创建一个PFX文件。

$cert = Get-AzKeyVaultCertificate -VaultName "ContosoKV01" -Name "TestCert01"
$secret = Get-AzKeyVaultSecret -VaultName $vaultName -Name $cert.Name  
$secretByte = [Convert]::FromBase64String($secret.SecretValueText)  
$x509Cert = new-object System.Security.Cryptography.X509Certificates.X509Certificate2
$x509Cert.Import($secretByte, "", "Exportable,PersistKeySet")
$type = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pfx 
$pfxFileByte = $x509Cert.Export($type, $password)
[System.IO.File]::WriteAllBytes("KeyValt.pfx", $pfxFileByte)` 

Docker文档只涉及PEM文件。

docker trust key load key.pem --name jeff
Loading key from "key.pem"...
Enter passphrase for new jeff key with ID 8ae710e:
Repeat passphrase for new jeff key with ID 8ae710e:
Successfully imported key from key.pem

我如何弥补这个差距?

azure powershell docker signing
© www.soinside.com 2019 - 2024. All rights reserved.