Introduction
When utilizing a remote
in Terraform to ensure runs are handled by Terraform Enterprise and a custom Certificate Authority (CA) is used, client commands such as terraform login
that connect to Terraform Enterprise error with x509: certificate
signed by unknown authority
Cause
Due to the way SSL/TLS works, when Terraform Enterprise is configured with a custom Certificate Authority, any connections to it must also trust the CA as well to ensure validity. When utilizing the Terraform CLI, this means that the machine running the terraform
command must also contain the Terraform Enterprise CA in its trust store.
Solution
To ensure network traffic to Terraform Enterprise succeeds SSL/TLS validation, the client machine must add the Terraform Enterprise CA to its trust store of certificates. This trust store is different depending on the host OS. After the store has the new Certificate Authority, the terraform
commands should work as expected.
Windows
- Download the Terraform Enterprise CA certificate in the PFX format to the client machine. To do this, simply export the CA certificates from Terraform Enterprise with
replicatedctl app-config export --template '{{.ca_certs.Value}}' > tfe-certs.pem
(This can be converted from Terraform Enterprise's PEM-formatted CA certificate withopenssl pkcs12 -export -in ca.pem -out ca.pfx
) - Click Start, type
mmc
, and press Enter. - Click Yes, this starts the Microsoft Management Console.
- Select File -> Add/Remove Snap-in.
- Under Available snap-ins, select Certificates. Click Add.
- Select Computer account, then click Next.
- Click Finish, and click OK.
- Expand Certificates, right click Trusted Root Certification Authority, and select All Tasks -> Import.
- Click Next.
- Click Browse, select your root CA certificate from Step 1. Click Open.
- Click Next -> Next -> Finish.
- When the import was successful message is displayed, click OK.
- Select File -> Save -> Save.
- Close the Microsoft Management Console.
Mac OS
- Download the Terraform Enterprise CA certificate in the DER format to the client machine. (This can be converted from Terraform Enterprise's PEM-formatted CA certificate with
openssl x509 -inform PEM -in ca.pem -outform DER -out ca.cer
). In this example, the file is in the Downloads folder. If the certificate is located in a different folder, navigate to this folder in the Terminal before running the command to add the certificate. - Click Launchpad, in the search field, type
terminal
. Click the Terminal icon. - In Terminal, run
cd ~/Downloads
. - Run
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ca.crt
. In this example, the root CA certificate is namedca.crt
. If the certificate has a different file name, be sure to change it in the command before running it. - Type your password and press Return.
- Close the Terminal.
Linux
Note: This assumes the Linux distribution utilizes ca-certificates
as its trust store. This includes all flavors of Linux supported by Terraform Enterprise, including Red Hat-based, Debian-based, and more.
- Download the Terraform Enterprise CA certificate in the DER format to the client machine. (This can be converted from Terraform Enterprise's PEM-formatted CA certificate with
openssl x509 -inform PEM -in ca.pem -outform DER -out ca.cer
). In this example, the file is in the Downloads folder. If the certificate is located in a different folder, change the path before running thecp
command to add the certificate to the trust store. - Open a command-line terminal.
- The CA certificate can be copied into the store with
sudo cp ~/Downloads/ca.crt /etc/pki/ca-trust/source/anchors/tfe-ca.crt
. In this example, the root CA certificate is namedca.crt
and is copied into a file namedtfe-ca.crt
. If the certificate has a different file name or the destination file should be named differently, be sure to change it in the command before running it. - Run
sudo update-ca-trust
.
Additional Information
Please visit this article for more information on how to download the Terraform Enterprise CA certificate: https://support.hashicorp.com/hc/en-us/articles/6631777789971-Tracing-SSL-certificate-chain-issues-in-Terraform-Enterprise