简体   繁体   English

使用来自 Linux 的证书对 Azure 进行身份验证

[英]Authenticate to Azure with certificate from Linux

I am trying to log in to Azure from a Powershell Core script with Az module.我正在尝试从带有 Az 模块的 Powershell 核心脚本登录到 Azure。 This requires using a self signed certificate that is uploaded to Azure.这需要使用上传到 Azure 的自签名证书。

I tried creating a certificate using:我尝试使用以下方法创建证书:

openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /etc/ssl/private/key.pem -out /etc/ssl/private/cert.pem -subj "/C=LV/ST=Some-State/L=LV/O=IT/OU=IT"

and using the thumbprint to login, but Powershell gives me this error:并使用指纹登录,但 Powershell 给了我这个错误:

Connect-AzAccount : Unix LocalMachine X509Store is limited to the Root and CertificateAuthority stores.

Not sure what this means.不知道这意味着什么。

Problem is similar to this issue https://github.com/Azure/azure-powershell/issues/8658问题类似于此问题https://github.com/Azure/azure-powershell/issues/8658

But not sure how to interpret the answers there.但不确定如何解释那里的答案。 No experience with certificates and limited exp with Linux.没有证书经验和 Linux 的有限经验。

To answer my own question, I finally somewhat figured it out.为了回答我自己的问题,我终于有点想通了。 Steps:脚步:

#create certs
openssl req -new -x509 -newkey rsa:2048 -keyout localhost.key -out localhost.cer -days 365 -subj /CN=localhost

#create pfx
openssl pkcs12 -export -out localhost.pfx -inkey localhost.key -in localhost.cer

#You will need to specify some password for it
#Now use the generated cer file and import it in your Azure portal, AzureAD->app registrations->your created SP->Certificates and secrets. Can also use powershell to do this.

#import the PFX to your machines cert store
$StoreName = [System.Security.Cryptography.X509Certificates.StoreName]::My 
$StoreLocation = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser 
$Store = [System.Security.Cryptography.X509Certificates.X509Store]::new($StoreName, $StoreLocation) 
$Flag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable 
$Certificate = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new("path to your pfx","the pfx password you specified on step 2",$Flag) 
$Store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite) 
$Store.Add($Certificate) 
$Store.Close() 

$tenantId = 'look in your azure portal' 
$appId = 'app id of the service principal you created, look in your azure portal'
$thumbprint = $certificate.thumbprint

Connect-AzAccount -ApplicationId $appId -Tenant $tenantId -CertificateThumbprint $thumbprint

That's it, you will automatically, non-interactively connect to your Azure tenant from a Linux machine or Docker, using Powershell Core and can execute all the commands your SP role allows. That's it, you will automatically, non-interactively connect to your Azure tenant from a Linux machine or Docker, using Powershell Core and can execute all the commands your SP role allows. You can re-use the PFX file, just first time is manual, afterwards host it somewhere and load it with a script using curl or similar.您可以重复使用 PFX 文件,只是第一次是手动的,然后将它托管在某个地方并使用 curl 或类似的脚本加载它。

Note: I don't know much about certificates and what security implications all this could have, use at your own risk.注意:我不太了解证书以及所有这些可能产生的安全隐患,使用风险自负。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PowerShell 7 在 Linux 上,使用证书对 Azure 进行身份验证 - PowerShell 7 on Linux, using Certificate to Authenticate to Azure Linux和Mac上的Azure CLI:证书问题 - Azure CLI on Linux and Mac: certificate trouble Azure - Linux WebApp - 链的根证书 - Azure - Linux WebApp - Root certificate for chain 从Linux服务器向Google Cloud Platform进行身份验证 - authenticate to Google Cloud Platform from a Linux Server 如何从Windows客户端向Linux服务器进行身份验证 - how to authenticate to a linux server (from a Windows client) 使用 pyodbc 从 Linux 向 Windows SQL Server 进行身份验证 - Authenticate from Linux to Windows SQL Server with pyodbc 在 Linux Azure VM 的 /var/lib/waagent/ 中找不到 SSL 证书 - SSL Certificate is not found in /var/lib/waagent/ for Linux Azure VM 将上传到 Azure 门户的 TLS 证书加载到 Linux 应用服务容器中 - Loading a TLS certificate uploaded to the Azure portal into a Linux app service container 使用 python 脚本从本地 linux 主机验证用户 - authenticate a user from local linux host using python script 使用python 3在Linux中对用户进行身份验证 - Authenticate user in linux with python 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM