Created
September 23, 2022 15:09
-
-
Save realrubberduckdev/14b38960a66bb33365af3aaadafcebc9 to your computer and use it in GitHub Desktop.
Certificate generation for - Azure DevOps service connection with Service Principal using Certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$CertificateNamePrefix, | |
[int]$ExpiryInDays | |
) | |
$unsecurePassword = Read-Host "Enter password for certificate" -AsSecureString | |
$certFileName = "$CertificateNamePrefix-cert.pem" | |
$certPrivateKeyFileName = "$CertificateNamePrefix-key.pem" | |
$certPackFileName = "$CertificateNamePrefix-pack.pfx" | |
$certPemWithBagAttributesFileName = "$CertificateNamePrefix-PemWithBagAttributes.pem" | |
# generate cert.pem to be uploaded for spn | |
openssl req -x509 -days $ExpiryInDays -newkey rsa:2048 -keyout $certPrivateKeyFileName -out $certFileName | |
Read-Host “Check that $certFileName and $certPrivateKeyFileName are generated. Then press ENTER to continue...” | |
# generate pack to put private key and cert (public key) together | |
openssl pkcs12 -inkey $certPrivateKeyFileName -in $certFileName -export -out $certPackFileName -passout "pass:$unsecurePassword" | |
Read-Host “Check that $certPackFileName is generated. Then press ENTER to continue...” | |
# generate merged pem for pasting into Azure DevOps servce connection configuraiton | |
openssl pkcs12 -in $certPackFileName -passin "pass:$unsecurePassword" -out $certPemWithBagAttributesFileName -nodes | |
Write-Host "Upload $certFileName to Azure Service principal." | |
Write-Host "Copy and paste content of $certPemWithBagAttributesFileName in Azure DevOps service connection certificate textbox." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment