Azure / Azure/azure-cli

Download a certificate as PEM and check its fingerprint in openssl does not include private key

Open
#13,703 2 comments 0 reactions 2 assignees Claimed by @evelyn-ys View on GitHub
act-identity-squad feature-request KeyVault
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

The guidance on this page unfortunately is misleading and does not include an example of how to download a Key Vault cert to use for authentication. The example included in this doc. is not formatted correctly:

`az keyvault certificate download --vault-name vault -n cert-name -f cert.pem && \
openssl x509 -in cert.pem -inform PEM -noout -sha1 -fingerprint`

If we attempt to pass the cert that downloads in with the above commands during authentication it fails.

However after research we've been able to find that there is an issue with this method as documented here: https://github.com/Azure/azure-cli/issues/7404

The solution that has allowed for authentication with a downloaded Key Vault cert via CLI is the following:
```az login```

#creates service principal and key vault certificate
```
az ad sp create-for-rbac --name $spname --keyvault $vaultname --cert $cert --create-cert
```

#downloads key vault certificate with private key
```
az keyvault secret download --vault-name $vaultname --name $cert --encoding base64 --file $cert.pfx
```

#exports .pfx to .pem (To sign in withb a certificate, it must be availale locally as a PEM or DER file, in ASCII format. When using a PEM file, the PRIVATE KEY and CERTIFICATE must be appended together within the file.)

#when the below command prompts for import password hit **enter** no password input required
```
openssl pkcs12 -in $cert.pfx --clcerts -nodes -out $cert.pem
```

Still working on how to not prompt for the import password and pass in a variable instead... :)

#test authentication with new service principal and key vault cert
```
az login --service-principal --username $spname --tenant $tenantid --password $cert.pem
```
---

Maybe it is assumed that users will know the below steps to convert to .pfx then back to .pem however it would be helpful if we update the doc with these steps for the above scenario.

#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: a9c661d7-bf43-5354-015e-3859f30a42a2
* Version Independent ID: fa69e552-5904-ce97-d02c-915c819bdde1
* Content: [az keyvault certificate](https://docs.microsoft.com/en-us/cli/azure/keyvault/certificate?view=azure-cli-latest#az-keyvault-certificate-download)
* Content Source: [src/azure-cli/azure/cli/command_modules/keyvault/_help.py](https://github.com/Azure/azure-cli/blob/dev/src/azure-cli/azure/cli/command_modules/keyvault/_help.py)
* Service: **key-vault**
* GitHub Login: @rloutlaw
* Microsoft Alias: **routlaw**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.