{"id":28566775,"url":"https://github.com/gruntwork-io/private-tls-cert","last_synced_at":"2025-06-10T15:38:41.191Z","repository":{"id":51686768,"uuid":"100378434","full_name":"gruntwork-io/private-tls-cert","owner":"gruntwork-io","description":"A simple Terraform module to generate self-signed TLS certificates for private use","archived":false,"fork":false,"pushed_at":"2021-03-30T15:52:47.000Z","size":8,"stargazers_count":40,"open_issues_count":0,"forks_count":46,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-05-01T11:28:23.044Z","etag":null,"topics":["devops","ssl","ssl-certificates","terraform","tls","tls-certificate"],"latest_commit_sha":null,"homepage":"https://www.gruntwork.io/","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gruntwork-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2017-08-15T13:08:46.000Z","updated_at":"2024-04-16T08:09:38.000Z","dependencies_parsed_at":"2022-08-23T00:40:44.817Z","dependency_job_id":null,"html_url":"https://github.com/gruntwork-io/private-tls-cert","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fprivate-tls-cert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fprivate-tls-cert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fprivate-tls-cert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fprivate-tls-cert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gruntwork-io","download_url":"https://codeload.github.com/gruntwork-io/private-tls-cert/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gruntwork-io%2Fprivate-tls-cert/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259104001,"owners_count":22805782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","ssl","ssl-certificates","terraform","tls","tls-certificate"],"created_at":"2025-06-10T15:38:39.554Z","updated_at":"2025-06-10T15:38:41.164Z","avatar_url":"https://github.com/gruntwork-io.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Private TLS Cert\n\nThis repository contains a [Terraform](https://www.terraform.io/) module that can be used to generate self-signed TLS\ncertificate. To be more accurate, the module generates the following:\n\n* A Certificate Authority (CA) public key \n* The public and private keys of a TLS certificate signed by the CA\n\nThis TLS certificate is meant to be used with **private** services, such as a web service used only within your \ncompany. For publicly-accessible services, especially services you access through a web browser, you should NOT use \nthis module, and instead get certificates from a commercial Certificate Authority, such as \n[Let's Encrypt](https://letsencrypt.org/).\n\nIf you're unfamiliar with how TLS certificates work, check out the [Background section](#background).\n\n\n\n\n## Quick start\n\n*Note: This Terraform module uses bash commands in a `local-exec` provisioner to copy the generate certificates to\nfiles, so currently, it will only work on Linux, Unix, and OS X.*\n\n1. `git clone` this repo to your computer and go into the `modules/generate-cert` folder.\n\n1. Open `vars.tf` and fill in the variables that do not have a default.\n\n1. DO NOT configure Terraform remote state storage for this code. You do NOT want to store the state files as they \n   will contain the private keys for the certificates.\n\n1. Run `terraform init`.\n\n1. Run `terraform apply`. The output will show you the paths to the generated files:\n\n    ```\n    Outputs:\n    \n    ca_public_key_file_path = ca.key.pem\n    private_key_file_path = my-app.key.pem\n    public_key_file_path = my-app.crt.pem\n    ```\n    \n1. Delete your local Terraform state:\n\n    ```\n    rm -rf terraform.tfstate*\n    ```\n\n   The Terraform state will contain the private keys for the certificates, so it's important to clean it up!\n\nYou can now use the TLS certs with your applications! To inspect a certificate, you can use OpenSSL:\n\n```\nopenssl x509 -inform pem -noout -text -in my-app.crt.pem\n```\n\n\n\n\n## Background\n\n\n### How TLS/SSL Works\n\nThe industry-standard way to add encryption for data in motion is to use TLS (the successor to SSL). There are many \nexamples online explaining how TLS works, but here are the basics:\n\n- Some entity decides to be a \"Certificate Authority\" (\"CA\") meaning it will issue TLS certificates to websites or \n  other services\n\n- An entity becomes a Certificate Authority by creating a public/private key pair and publishing the public portion \n  (typically known as the \"CA Cert\"). The private key is kept under the tightest possible security since anyone who \n  possesses it could issue TLS certificates as if they were this Certificate Authority!\n\n- In fact, the consequences of a CA's private key being compromised are so disastrous that CA's typically create an \n  \"intermediate\" CA keypair with their \"root\" CA key, and only issue TLS certificates with the intermediate key.\n\n- Your client (e.g. a web browser) can decide to trust this newly created Certificate Authority by including its CA \n  Cert (the CA's public key) when making an outbound request to a service that uses the TLS certificate.\n\n- When CAs issue a TLS certificate (\"TLS cert\") to a service, they again create a public/private keypair, but this time \n  the public key is \"signed\" by the CA. That public key is what you view when you click on the lock icon in a web \n  browser and what a service \"advertises\" to any clients such as web browsers to declare who it is. When we say that \n  the CA signed a public key, we mean that, cryptographically, any possessor of the CA Cert can validate that this same \n  CA issued this particular public key.\n\n- The public key is more generally known as the TLS cert.\n\n- The private key created by the CA must be kept secret by the service since the possessor of the private key can \n  \"prove\" they are whoever the TLS cert (public key) claims to be as part of the TLS protocol.\n\n- How does that \"proof\" work? Well, your web browser will attempt to validate the TLS cert in two ways:\n  - First, it will ensure this public key (TLS cert) is in fact signed by a CA it trusts.\n  - Second, using the TLS protocol, your browser will encrypt a message with the public key (TLS cert) that only the\n    possessor of the corresponding private key can decrypt. In this manner, your browser will be able to come up with a\n    symmetric encryption key it can use to encrypt all traffic for just that one web session.\n\n- Now your client/browser has:\n  - declared which CA it will trust\n  - verified that the service it's connecting to possesses a certificate issued by a CA it trusts\n  - used that service's public key (TLS cert) to establish a secure session\n\n\n### Commercial or Public Certificate Authorities\n\nFor public services like banks, healthcare, and the like, it makes sense to use a \"Commercial CA\" like Verisign, Thawte,\nor Digicert, or better yet a widely trusted but free service like [Let's Encrypt](https://letsencrypt.org/). That's \nbecause every web browser comes pre-configured with a set of CA's that it trusts. This means the client connecting to \nthe bank doesn't have to know anything about CA's at all. Instead, their web browser is configured to trust the CA that \nhappened to issue the bank's certificate.\n\nConnecting securely to private services is similar to connecting to your bank's website over TLS, with one primary \ndifference: **We want total control over the CA.**\n\nImagine if we used a commercial CA to issue our private TLS certificate and that commercial or public CA--which we \ndon't control--were compromised. Now the attackers of that commercial or public CA could impersonate our private server. \nAnd indeed, [it](https://www.theguardian.com/technology/2011/sep/05/diginotar-certificate-hack-cyberwar) [has](\nhttps://www.schneier.com/blog/archives/2012/02/verisign_hacked.html) [happened](\nhttp://www.infoworld.com/article/2623707/hacking/the-real-security-issue-behind-the-comodo-hack.html)\nmultiple times.\n\n\n### How We'll Generate a TLS Cert for Private Services\n\nOne option is to be very selective about choosing a commercial CA, but to what benefit? What we want instead is \nassurance that our private service really was launched by people we trust. Those same people--let's call them our \n\"operators\"--can become their *own* CA and generate their *own* TLS certificate for the private service.\n\nSure, no one else in the world will trust this CA, but we don't care because we only need our organization to trust \nthis CA.\n\nSo here's our strategy for issuing a TLS Cert for a private service:\n\n1. **Create our own CA.**\n   - If a client wishes to trust our CA, they need only reference this CA public key.\n   - We'll deal with the private key in a moment.\n  \n1. **Using our CA, issue a TLS Certificate for our private service.**\n   - Create a public/private key pair for the private service, and have the CA sign the public key.\n   - This means anyone who trusts the CA will trust that the possessor of the private key that corresponds to this public \n    key is who they claim to be.\n   - We will be extremely careful with the TLS private key since anyone who obtains it can impersonate our private \n    service! For this reason, we recommend immediately encrypting the private key with \n    [KMS](https://aws.amazon.com/kms/).\n    \n1. **Freely advertise our CA's public key to all internal services.**\n   - Any service that wishes to connect securely to our private service will need our CA's public key so it can declare \n    that it trusts this CA, and thereby the TLS cert it issued to the private service.\n    \n1. **Throw away the CA private key.**\n   - By erasing a CA private key it's impossible for the CA to be compromised, because there's no private key to steal!\n   - Future certs can be generated with a new CA.\n\n\n\n\n## License\n\nThis code is released under the MIT License. See [LICENSE.txt](/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgruntwork-io%2Fprivate-tls-cert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgruntwork-io%2Fprivate-tls-cert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgruntwork-io%2Fprivate-tls-cert/lists"}