Getting the contents of a Let's Encrypt certificate
You can save a certificate chain and a private key to use for your own purposes, e.g., when configuring a web server on a VM.
To get the contents of a certificate:
-
In the management console
, select the folder with your certificate. -
Navigate to Certificate Manager.
-
In the row with the certificate, click
and select Export certificate.You can only export certificates with the
Issuedstatus. -
Select one of the export options. The
certificate.pemfile will contain the following data in Base64 encoded text format:-
End-entity certificate and chain: Certificate chain (root and end-user certificates) and private key with standard framing:
-----BEGIN CERTIFICATE----- MIIE5zCCA8+gAwI... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- MIIFFjCCAv6gAwIBAg... -----END CERTIFICATE----- -----BEGIN PRIVATE KEY----- MIIEvgIBADANBgk... -----END PRIVATE KEY----- -
Certificate without private key: Certificate chain (root and end-user certificates):
-----BEGIN CERTIFICATE----- MIIE5zCCA8+gAwI... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- MIIFFjCCAv6gAwIBAg... -----END CERTIFICATE----- -
End-entity certificate:
-----BEGIN CERTIFICATE----- MIIFFjCCAv6gAwIBAg... -----END CERTIFICATE-----` -
Private key only:
-----BEGIN PRIVATE KEY----- MIIEvgIBADANBgk... -----END PRIVATE KEY-----`
-
-
Click Download certificate.
The command will display a certificate chain and a private key and save their contents to the --chain and --key files, respectively.
--id: Certificate ID; make sure you set either the--idor--nameflag.--name: Certificate name; make sure you set either the--idor--nameflag.--chain: File to save the certificate chain to, in PEM format. This is an optional flag.--key: File to save the private key to, in PEM format. This is an optional flag.
yc certificate-manager certificate content \
--id fpqcsmn76v82******** \
--chain certificate_full_chain.pem \
--key private_key.pem
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To get the contents of a custom certificate using Terraform:
-
In the Terraform configuration file, describe the resources you want to create:
data "yandex_cm_certificate_content" "cert_by_id" { certificate_id = "<certificate_ID>" } output "certificate_chain" { value = data.yandex_cm_certificate_content.cert_by_id.certificates } output "certificate_key" { value = data.yandex_cm_certificate_content.cert_by_id.private_key sensitive = true }Where:
data "yandex_cm_certificate_content": Description of the data source for the certificate contents:certificate_id: Certificate ID.
outputsections:certificate_chainoutput variables with the certificate chain and thecertificate_keyprivate key:value: Return value.sensitive: Label data as sensitive.
For more information about the
yandex_cm_certificate_contentdata source properties, see this provider guide. -
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
Terraform will create all the required resources. To check the results, run these commands:
-
Get the certificate chain:
terraform output certificate_chain -
Get the private key value:
terraform output -raw certificate_key
-
To get the certificate contents, use the get REST API method for the CertificateContent resource or the CertificateContentService/Get gRPC API call.
For Let's Encrypt certificates, the exported chain contains your domain's end-user certificate and intermediate certificate. The root certificate is not included because it is already built into the trusted stores of operating systems and browsers. This chain is sufficient to configure web servers, such as Nginx or Apache. If you need the full chain with the root certificate, you can download it from the Let's Encrypt
Note
To read the certificate contents, assign the certificate-manager.certificates.downloader role to the service account.