Problem
When using the remote backend in Terraform to execute runs on a Terraform Enterprise instance that uses a custom Certificate Authority (CA), client commands such as terraform login fail with one of the following errors:
x509: certificate signed by unknown authority
x509: certificate is not trusted
Cause
When Terraform Enterprise is configured with a custom CA, any client connecting to it must also trust that CA to validate the SSL/TLS certificate chain. When you use the Terraform CLI, the machine running the terraform command must have the Terraform Enterprise CA certificate installed in its operating system's trust store.
Solutions
To resolve this issue, you must add the Terraform Enterprise CA certificate to the trust store of the client machine where you run terraform commands. The procedure varies depending on the operating system.
First, you must obtain the CA certificate from your Terraform Enterprise instance. You can export the PEM-formatted CA certificate with the following command on the Terraform Enterprise instance.
Replicated
replicatedctl app-config export --template '{{.ca_certs.Value}}' > tfe-ca.pemFlexible Deployment Options (FDO) Docker/Podman
cp /path/to/certs_dir/cert.pem tfe-ca.pemAfter you have the tfe-ca.pem file, follow the instructions for your operating system.
Solution 1: Configure the Windows Trust Store
-
Convert the PEM-formatted CA certificate to the PFX format using OpenSSL.
openssl pkcs12 -export -in tfe-ca.pem -out tfe-ca.pfx
- Transfer the
tfe-ca.pfxfile to the client machine. - Click Start, type
mmc, and press Enter. - Click Yes to start the Microsoft Management Console.
- Select File > Add/Remove Snap-in.
- Under Available snap-ins, select Certificates and click Add.
- Select Computer account, then click Next.
- Click Finish, then click OK.
- Expand Certificates, right-click Trusted Root Certification Authorities, and select All Tasks > Import.
- Click Next.
- Click Browse, select your
tfe-ca.pfxcertificate file, and click Open. - Click Next, Next, then Finish.
- When the "import was successful" message appears, click OK.
- Select File > Save, then Save again.
- Close the Microsoft Management Console.
Solution 2: Configure the macOS Keychain
-
Convert the PEM-formatted CA certificate to the DER format (
.cer) using OpenSSL.openssl x509 -inform PEM -in tfe-ca.pem -outform DER -out tfe-ca.cer
- Transfer the
tfe-ca.cerfile to the client machine (e.g., to the~/Downloadsfolder). - Open the Terminal application.
-
Run the following command to add the certificate to the system keychain. This example assumes the file is named
tfe-ca.cer.sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/Downloads/tfe-ca.cer
- Enter your password when prompted and press Return.
- Close the Terminal.
Solution 3: Configure the Linux Trust Store
Note: This procedure assumes the Linux distribution uses ca-certificates, which includes supported distributions like Red Hat-based and Debian-based systems.
- Transfer the PEM-formatted CA certificate (
tfe-ca.pem) to the client machine (e.g., to the~/Downloadsfolder). - Open a command-line terminal.
-
Copy the CA certificate to the trust store source directory. This example renames the file to
tfe-ca.crtfor clarity.sudo cp ~/Downloads/tfe-ca.pem /etc/pki/ca-trust/source/anchors/tfe-ca.crt
-
Update the system's CA trust store.
sudo update-ca-trust
After completing these steps, Terraform CLI commands should connect to Terraform Enterprise without certificate errors.
Additional Information
For more information on how to download the Terraform Enterprise CA certificate, refer to the guide on Tracing SSL certificate chain issues in Terraform Enterprise.