Code Monkey home page Code Monkey logo

ansible-tls-cert's Introduction

TLS Certificate

Installs TLS (SSL) certificates to the target, in one of three ways depending on configuration:

  • Installs your provided TLS certificate, private key, and CA certificate bundle to target system.
  • Deploys a new self-signed certificate + key to target system.
  • Obtains a TLS certificate from Let's Encrypt and configures automated certificate renewal via cron

In either case, automatically creates a "full chain" file (containing certificate + CA bundle, suitable for use with Nginx) as well.

Supports Ubuntu LTS 14+ and CentOS 6+, adding support for other distros would be easy.

Build Status Ansible Galaxy

How to Use

  • If you want to create and deploy a self-signed certificate, don't define anything
  • If you want to Bring Your Own certificate, set the TLS_BYO vars (Ansible will look in "files" directory relative to playbook if you specify a bare filename or relative path.)
  • If you want to use Let's Encrypt, set the TLS_LETSENCRYPT vars

Role Variables

Variable Required Default Choices Comments
TLS_COMMON_NAME no ansible_fqdn The fully qualified domain for the certficate
TLS_BYO_PRIVKEY_SRC no Path to private key on deployer system
TLS_BYO_CERT_SRC no Path to certificate on deployer system
TLS_BYO_CACHAIN_SRC no Path to CA chain on deployer system
TLS_LETSENCRYPT_ENABLE no false true, false Obtain a certificate using Let's Encrypt
TLS_LETSENCRYPT_TLS_SERVICE no Name of service to stop when obtaining certificate and restart upon renewal
TLS_LETSENCRYPT_EMAIL when TLS_LETSENCRYPT_ENABLE Email address to associate with Let's Encrypt certificate

These variables are registered by this role for use in your downstream automations:

Variable Comments
TLS_PRIVKEY_PATH Path to private key on target
TLS_CERT_PATH Path to certificate on target
TLS_CACHAIN_PATH Path to CA chain on target
TLS_FULLCHAIN_PATH Path to fullchain on target

TLS_COMMON_NAME is the Common Name (CN) for the generated certificate, and will also be used to set the Subject Alternate Name (SAN), which indicates the host behind the certificate. A valid example would be 'local.atmo.cloud'. The Chrome browser recently made this field mandatory. If you would like to learn about the history read this SO answer.

* If the deployer provides a certificate, then the certificate's indicated CN (domain) will be used as the base name of the files on the target (e.g. example.com.key, example.com.crt, example.com.cachain.crt, and example.com.fullchain.crt for example.com). If this role creates a self-signed certificate, the files will be named with "selfsigned" as the base name. In either case, setting TLS_DEST_BASENAME overrides this filename.

Caveats / Notices

  • openssl must be available on the deployment host if using this role to deploy a provided certificate, and on the target host if creating+deploying a self-signed certificate. These are likely already true for any modern Linux system.

  • On CentOS, file permissions for the private key are set to owner root and mode 600, because the enclosing /etc/pki/tls/private is permissively visible. (Compare to Ubuntu where the system-wide /etc/ssl/private directory already has restricted permissions.) Beyond that, this role does not do anything with file permissions, like configuring additional users/groups which can read the private key. That is left for the deployer to handle in a playbook. This role also does not configure other services that use the installed certificates.

  • When deploying a certificate with Let's Encrypt, certbot will run in standalone mode. Port 443 must be made available for the standalone server to respond to the ACME challenge. You can provide the name of your service listening on port 443 with TLS_LETSENCRYPT_TLS_SERVICE, and this service will be temporarily stopped when obtaining/renewing the certificate.

Dependencies

None

Example Playbook

If you want to create a self-signed certificate, just call the role with no variables:

- hosts: all
  roles:
    - tls-cert

If you already have a certificate to install:

- hosts: all
  roles:
    - tls-cert
  vars:
    - TLS_BYO_PRIVKEY_SRC: 'example.com.key'
    - TLS_BYO_CERT_SRC: 'example.com.crt'
    - TLS_BYO_CACHAIN_SRC: 'example.com.cachain.crt'

If you want to use Let's Encrypt (example Nginx web server):

- hosts: all
  roles:
    - tls-cert
  vars:
    - TLS_LETSENCRYPT_ENABLE: 'true'
    - TLS_LETSENCRYPT_HTTPS_SERVICE: 'nginx'
    - TLS_LETSENCRYPT_EMAIL: '[email protected]'

License

See license.md

Author Information

Chris Martin Connor Osborn

https://cyverse.org

ansible-tls-cert's People

Contributors

c-mart avatar cdosborn avatar steve-gregory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-tls-cert's Issues

Build option to obtain certificate from Let's Encrypt and set up automatic renewal on target

16:42]  
lenards I might consider looking at the certbot roles
[16:46]  
cmart OK. I think the right answer is to give the new `tls-cert` role a third way to do its job:
1. deploy a provided certificate
2. create and deploy a self-signed certificate
3. obtain a certificate from Let's Encrypt and set up automatic renewal (edited)
[16:47]  
lenards I would agree.
I believe that covers the necessary situations.
[16:48]  
cmart for paths 1 and 2, the role already creates a combined certificate suitable for Nginx. for path 3, it would create such a combined certificate both at initial deploy time, and at each renewal time. (edited)
[16:50]  
actually certbot *already does that for you*
[16:50]  
`/etc/letsencrypt/live/atmo-dev.cyverse.org/fullchain.pem`
[16:50]  
so easy peasy

Also, now that we're potentially deploying certs into a few different directory paths, when the role completes I think it should register variables for the paths to deployed files, so that other automations know where to point to them.

Idempotency check is too weak

In several places (links at the bottom), we use a check like the following:

- name: ...
  command: ...
  args:
    creates: /some/path

The command only runs if /some/path does not exist. This has caused several issues in clank deployments. Most importantly multiple deploys against the same box never result in new self-signed or in the new combined cert. So bug fixes to the cert roles don't result in fixed certs.

Cert creation is really fast (< 10sec). So from clank it makes sense to always create the certs, so that users/devs get fixed certs. If they don't want to create a cert, they just need to set the vars for clank to deploy their existing certs.

However, tests for this role ensure idempotency, that any run after the first results in 0 Changed. if we want to keep this test, we need a more robust check of idempotency.

One option is to move as much of the openssl command into the templated config file the command uses. We can then create the certs whenever this template changes. The keys would be regenerated whenever the parameters of the openssl command change, which is a pretty darn good test of needing to generate a new key.

Another option is to have an override flag: "FORCE_CREATE", which always generates the certs. That way the user can forego the idempotency check if it makes sense (i.e. the clank use case).

1: https://github.com/CyVerse-Ansible/ansible-tls-cert/blob/master/tasks/deploy-selfsigned.yml#L20
2:

creates: "{{ TLS_CERT_DEST_DIR }}/{{ TLS_DEST_BASENAME }}.fullchain.crt"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.