From 0a09a6e6f247729457d15480f8d2b9bb0b89ae5e Mon Sep 17 00:00:00 2001 From: elijah Date: Mon, 29 Aug 2016 22:55:41 -0700 Subject: Updated (very out of date) docs and README.md --- docs/en/guide/keys-and-certificates/index.html | 480 +++++++++++++++++++++++++ 1 file changed, 480 insertions(+) create mode 100644 docs/en/guide/keys-and-certificates/index.html (limited to 'docs/en/guide/keys-and-certificates') diff --git a/docs/en/guide/keys-and-certificates/index.html b/docs/en/guide/keys-and-certificates/index.html new file mode 100644 index 00000000..4775de5a --- /dev/null +++ b/docs/en/guide/keys-and-certificates/index.html @@ -0,0 +1,480 @@ + + + + +Keys and Certificates - LEAP Platform Documentation + + + + + + + + +
+
+

Keys and Certificates

+ +
Working with SSH keys, secrets, and X.509 certificates.
+
+
+ + +

Working with SSH

+ +

Whenever the leap command needs to push changes to a node or gather information from a node, it tunnels this command over SSH. Another way to put this: the security of your servers rests entirely on SSH. Because of this, it is important that you understand how leap uses SSH.

+ +

SSH related files

+ +

Assuming your provider directory is called ‘provider’:

+ +
    +
  • provider/nodes/crow/crow_ssh.pub – The public SSH host key for node ‘crow’.
  • +
  • provider/users/alice/alice_ssh.pub – The public SSH user key for user ‘alice’. Anyone with the private key that corresponds to this public key will have root access to all nodes.
  • +
  • provider/files/ssh/known_hosts – An autogenerated known_hosts, built from combining provider/nodes/*/*_ssh.pub. You must not edit this file directly. If you need to change it, remove or change one of the files that is used to generate known_hosts and then run leap compile.
  • +
  • provider/files/ssh/authorized_keys – An autogenerated list of all the user SSH keys with root access to the notes. It is created from provider/users/*/*_ssh.pub. You must not edit this file directly. If you need to change it, remove or change one of the files that is used to generate authorized_keys and then run leap compile.
  • +
+ + +

All of these files should be committed to source control.

+ +

If you rename, remove, or add a node with leap node [mv|add|rm] the SSH key files and the known_hosts file will get properly updated.

+ +

SSH and local nodes

+ +

Local nodes are run as Vagrant virtual machines. The leap command handles SSH slightly differently for these nodes.

+ +

Basically, all the SSH security is turned off for local nodes. Since local nodes only exist for a short time on your computer and can’t be reached from the internet, this is not a problem.

+ +

Specifically, for local nodes:

+ +
    +
  1. known_hosts is never updated with local node keys, since the SSH public key of a local node is different for each user.
  2. +
  3. leap entirely skips the checking of host keys when connecting with a local node.
  4. +
  5. leap adds the public Vagrant SSH key to the list of SSH keys for a user. The public Vagrant SSH key is a shared and insecure key that has root access to most Vagrant virtual machines.
  6. +
+ + +

To upgrade a SSH host key

+ +

Most servers will have more than one SSH host key. Sometimes, the server will have a better SSH host key than the one you have on file. In order to upgrade to the better SSH host key, simply re-run the init command:

+ +
workstation$ leap node init NODE_NAME
+
+ +

This will prompt you if you want to upgrade the SSH host key, but only if leap thinks that an upgrade is advisable.

+ +

When SSH host key changes

+ +

If the host key for a node has changed, you will get an error “WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED”.

+ +

To fix this, you need to remove the file files/nodes/stompy/stompy_ssh.pub and run leap node init stompy, where the node’s name is ‘stompy’. Only do this if you are ABSOLUTELY CERTAIN that the node’s SSH host key has changed.

+ +

Changing the SSH port

+ +

Suppose you have a node blinky that has SSH listening on port 22 and you want to make it port 2200.

+ +

First, modify the configuration for blinky to specify the variable ssh.port as 2200. Usually, this is done in common.json or in a tag file.

+ +

For example, you could put this in tags/production.json:

+ +
{
+  "ssh": {
+    "port": 2200
+  }
+}
+
+ +

Run leap compile and open hiera/blinky.yaml to confirm that ssh.port is set to 2200. The port number must be specified as a number, not a string (no quotes).

+ +

Then, you need to deploy this change so that SSH will bind to 2200. You cannot simply run leap deploy blinky because this command will default to using the variable ssh.port which is now 2200 but SSH on the node is still bound to 22.

+ +

So, you manually override the port in the deploy command, using the old port:

+ +
leap deploy --port 22 blinky
+
+ +

Afterwards, SSH on blinky should be listening on port 2200 and you can just run leap deploy blinky from then on.

+ +

Sysadmins with multiple SSH keys

+ +

The command leap add-user --self allows only one SSH key. If you want to specify more than one key for a user, you can do it manually:

+ +
users/userx/userx_ssh.pub
+users/userx/otherkey_ssh.pub
+
+ +

All keys matching ‘userx/*_ssh.pub’ will be usable.

+ +

Removing sysadmin access

+ +

Suppose you want to remove userx from having any further SSH access to the servers. Do this:

+ +
rm -r users/userx
+leap deploy
+
+ +

X.509 Certificates

+ +

Configuration options

+ +

The ca option in provider.json provides settings used when generating CAs and certificates. The defaults are as follows:

+ +
{
+  "ca": {
+    "name": "= global.provider.ca.organization + ' Root CA'",
+    "organization": "= global.provider.name[global.provider.default_language]",
+    "organizational_unit": "= 'https://' + global.provider.domain",
+    "bit_size": 4096,
+    "digest": "SHA256",
+    "life_span": "10y",
+    "server_certificates": {
+      "bit_size": 2048,
+      "digest": "SHA256",
+      "life_span": "1y"
+    },
+    "client_certificates": {
+      "bit_size": 2048,
+      "digest": "SHA256",
+      "life_span": "2m",
+      "limited_prefix": "LIMITED",
+      "unlimited_prefix": "UNLIMITED"
+    }
+  }
+}
+
+ +

You should not need to override these defaults in your own provider.json, but you can if you want to. To see what values are used for your provider, run leap inspect provider.json.

+ +

NOTE: A certificate bit_size greater than 2048 will probably not be recognized by most commercial CAs.

+ +

Certificate Authorities

+ +

There are three x.509 certificate authorities (CA) associated with your provider:

+ +
    +
  1. Commercial CA: It is strongly recommended that you purchase a commercial cert for your primary domain. The goal of platform is to not depend on the commercial CA system, but it does increase security and usability if you purchase a certificate. The cert for the commercial CA must live at files/cert/commercial_ca.crt.
  2. +
  3. Server CA: This is a self-signed CA responsible for signing all the server certificates. The private key lives at files/ca/ca.key and the public cert lives at files/ca/ca.crt. The key is very sensitive information and must be kept private. The public cert is distributed publicly.
  4. +
  5. Client CA: This is a self-signed CA responsible for signing all the client certificates. The private key lives at files/ca/client_ca.key and the public cert lives at files/ca/client_ca.crt. Neither file is distribute publicly. It is not a big deal if the private key for the client CA is compromised, you can just generate a new one and re-deploy.
  6. +
+ + +

To generate both the Server CA and the Client CA, run the command:

+ +
leap cert ca
+
+ +

Server certificates

+ +

Most every server in your service provider will have a x.509 certificate, generated by the leap command using the Server CA. Whenever you modify any settings of a node that might affect it’s certificate (like changing the IP address, hostname, or settings in provider.json), you can magically regenerate all the certs that need to be regenerated with this command:

+ +
leap cert update
+
+ +

Run leap help cert update for notes on usage options.

+ +

Because the server certificates are generated locally on your personal machine, the private key for the Server CA need never be put on any server. It is up to you to keep this file secure.

+ +

Client certificates

+ +

Every leap client gets its own time-limited client certificate. This cert is use to connect to the OpenVPN gateway (and probably other things in the future). It is generated on the fly by the webapp using the Client CA.

+ +

To make this work, the private key of the Client CA is made available to the webapp. This might seem bad, but compromise of the Client CA simply allows the attacker to use the OpenVPN gateways without paying. In the future, we plan to add a command to automatically regenerate the Client CA periodically.

+ +

There are two types of client certificates: limited and unlimited. A client using a limited cert will have its bandwidth limited to the rate specified by provider.service.bandwidth_limit (in Bytes per second). An unlimited cert is given to the user if they authenticate and the user’s service level matches one configured in provider.service.levels without bandwidth limits. Otherwise, the user is given a limited client cert.

+ +

Commercial certificates

+ +

We strongly recommend that you use a commercial signed server certificate for your primary domain (in other words, a certificate with a common name matching whatever you have configured for provider.domain). This provides several benefits:

+ +
    +
  1. When users visit your website, they don’t get a scary notice that something is wrong.
  2. +
  3. When a user runs the LEAP client, selecting your service provider will not cause a warning message.
  4. +
  5. When other providers first discover your provider, they are more likely to trust your provider key if it is fetched over a commercially verified link.
  6. +
+ + +

The LEAP platform is designed so that it assumes you are using a commercial cert for the primary domain of your provider, but all other servers are assumed to use non-commercial certs signed by the Server CA you create.

+ +

To generate a CSR, run:

+ +
leap cert csr
+
+ +

This command will generate the CSR and private key matching provider.domain (you can change the domain with --domain=DOMAIN switch). It also generates a server certificate signed with the Server CA. You should delete this certificate and replace it with a real one once it is created by your commercial CA.

+ +

The related commercial cert files are:

+ +
files/
+  cert/
+    domain.org.crt    # Server certificate for domain.org, obtained by commercial CA.
+    domain.org.csr    # Certificate signing request
+    domain.org.key    # Private key for you certificate
+    commercial_ca.crt # The CA cert obtained from the commercial CA.
+
+ +

The private key file is extremely sensitive and care should be taken with its provenance.

+ +

If your commercial CA has a chained CA cert, you should be OK if you just put the last cert in the chain into the commercial_ca.crt file. This only works if the other CAs in the chain have certs in the debian package ca-certificates, which is the case for almost all CAs.

+ +

If you want to add additional fields to the CSR, like country, city, or locality, you can configure these values in provider.json like so:

+ +
  "ca": {
+    "server_certificates": {
+      "country": "US",
+      "state": "Washington",
+      "locality": "Seattle"
+    }
+  }
+
+ +

If they are not present, the CSR will be created without them.

+ +

Examine Certs

+ +

To see details about the keys and certs you can use leap inspect like so:

+ +
$ leap inspect files/ca/ca.crt
+
+ +

Let’s Encrypt certificate

+ +

LEAP plans to integrate Let’s Encrypt support, so it will be even easier to receive X.509 certificates that are accepted by all browsers. +Until we achieve this, here’s a guide how to do this manually.

+ +

Install the official acme client

+ +

Log in to your webapp node

+ +
server$ git clone https://github.com/certbot/certbot
+server$ cd certbot
+server$ ./certbot-auto --help
+
+ +

Fetch cert

+ +

Stop apache so the letsencrypt client can bind to port 80:

+ +
server$ systemctl stop apache2
+
+ +

Fetch the certs

+ +
server$ ./certbot-auto certonly --standalone --email admin@$(hostname -d) -d $(hostname -d) -d api.$(hostname -d) -d $(hostname -f) -d nicknym.$(hostname -d)
+
+ +

This will put the certs and keys into /etc/letsencrypt/live/DOMAIN/.

+ +

Now, go to your workstation’s provider configuration directory and copy the newly created files from the server to your local config. You will override existing files so please make a backup before proceeding, or use a version control system to track changes.

+ +
workstation$ cd PATH_TO_PROVIDER_CONFIG
+
+ +

Copy the Certificate

+ +
workstation$ scp root@SERVER:/etc/letsencrypt/live/DOMAIN/cert.pem files/cert/dev.pixelated-project.org.crt
+
+ +

Copy the private key

+ +
workstation$ scp root@SERVER:/etc/letsencrypt/live/DOMAIN/privkey.pem files/cert/DOMAIN.key
+
+ +

Copy the CA chain cert

+ +
workstation$ scp root@SERVER:/etc/letsencrypt/live/DOMAIN/fullchain.pem files/cert/commercial_ca.crt
+
+ +

Deploy the certs

+ +

Now you only need to deploy the certs

+ +
workstation$ leap deploy
+
+ +

This will put them into the right locations which are:

+ +
    +
  • /etc/x509/certs/leap_commercial.crt for the certificate
  • +
  • /etc/x509/./keys/leap_commercial.key for the private key
  • +
  • /usr/local/share/ca-certificates/leap_commercial_ca.crt for the CA chain cert.
  • +
+ + +

Start apache2 again

+ +
server$ systemctl start apache2
+
+ +
+
+ + -- cgit v1.2.3 From 811deee9e5b8cc42a3ea424ef873e9d69eb50cba Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 14 Sep 2016 15:09:32 -0700 Subject: updated docs --- docs/en/guide/keys-and-certificates/index.html | 115 +++++++++---------------- 1 file changed, 43 insertions(+), 72 deletions(-) (limited to 'docs/en/guide/keys-and-certificates') diff --git a/docs/en/guide/keys-and-certificates/index.html b/docs/en/guide/keys-and-certificates/index.html index 4775de5a..016a03a7 100644 --- a/docs/en/guide/keys-and-certificates/index.html +++ b/docs/en/guide/keys-and-certificates/index.html @@ -165,7 +165,7 @@ Keys and Certificates - LEAP Platform Documentation Client certificates
  • - Commercial certificates + Signed certificates
  • Examine Certs @@ -173,16 +173,13 @@ Keys and Certificates - LEAP Platform Documentation
  • - Let’s Encrypt certificate + Let’s Encrypt
    1. - Install the official acme client + Creating a certificate
    2. - Fetch cert -
    3. -
    4. - Deploy the certs + Renewing a certificate
  • @@ -351,9 +348,9 @@ leap deploy

    There are two types of client certificates: limited and unlimited. A client using a limited cert will have its bandwidth limited to the rate specified by provider.service.bandwidth_limit (in Bytes per second). An unlimited cert is given to the user if they authenticate and the user’s service level matches one configured in provider.service.levels without bandwidth limits. Otherwise, the user is given a limited client cert.

    -

    Commercial certificates

    +

    Signed certificates

    -

    We strongly recommend that you use a commercial signed server certificate for your primary domain (in other words, a certificate with a common name matching whatever you have configured for provider.domain). This provides several benefits:

    +

    We strongly recommend that the primary domain for your provider has a certificate signed by a “trusted CA” (e.g. A Certificate Authority that is trusted by the web browsers and in the Debian ca-certificates package). This provides several benefits:

    1. When users visit your website, they don’t get a scary notice that something is wrong.
    2. @@ -362,28 +359,38 @@ leap deploy
    -

    The LEAP platform is designed so that it assumes you are using a commercial cert for the primary domain of your provider, but all other servers are assumed to use non-commercial certs signed by the Server CA you create.

    +

    The LEAP platform is designed so that it assumes you are using a certificate signed by a “trusted CA” for the primary domain of your provider, but all other servers are assumed to use certs signed by the Server CA you create.

    To generate a CSR, run:

    -
    leap cert csr
    +
    leap cert csr [DOMAIN]
     
    -

    This command will generate the CSR and private key matching provider.domain (you can change the domain with --domain=DOMAIN switch). It also generates a server certificate signed with the Server CA. You should delete this certificate and replace it with a real one once it is created by your commercial CA.

    +

    This command will generate the CSR and private key matching provider.domain or use DOMAIN. It also generates a server certificate signed with the Server CA. You should delete this certificate and replace it with a real one you get back from a “trusted CA”.

    The related commercial cert files are:

    files/
       cert/
    -    domain.org.crt    # Server certificate for domain.org, obtained by commercial CA.
    -    domain.org.csr    # Certificate signing request
    -    domain.org.key    # Private key for you certificate
    -    commercial_ca.crt # The CA cert obtained from the commercial CA.
    +    domain.org.crt    # Server certificate for domain.org, obtained from
    +                      # the trusted CA (this file is initially signed with
    +                      # the Server CA, but you should replace it).
    +    domain.org.csr    # Certificate signing request (PEM format)
    +    domain.org.key    # Private key for you certificate (PEM format)
    +    commercial_ca.crt # DEPRECATED: The certificate chain obtained from
    +                      # the trusted CA (PEM format)
     

    The private key file is extremely sensitive and care should be taken with its provenance.

    -

    If your commercial CA has a chained CA cert, you should be OK if you just put the last cert in the chain into the commercial_ca.crt file. This only works if the other CAs in the chain have certs in the debian package ca-certificates, which is the case for almost all CAs.

    +

    A few notes on the certificate chain:

    + +
      +
    • A certificate is basically just a key signed by another key. In x.509, the signing key might be signed by yet another key, and so on, all the way to a ‘root’ key. It is the root key that a browser trusts or is in the Debian ca-certificates package. The chain is the set of all the keys from the root to the end certificate.
    • +
    • For TLS, both the server and the client need the full chain from the certificate to the CA’s root.
    • +
    • The full chain should be appended in the file domain.org.crt after the server certificate. The chain can also live in commercial_ca.crt, but this is deprecated.
    • +
    +

    If you want to add additional fields to the CSR, like country, city, or locality, you can configure these values in provider.json like so:

    @@ -405,74 +412,38 @@ leap deploy
    $ leap inspect files/ca/ca.crt
     
    -

    Let’s Encrypt certificate

    - -

    LEAP plans to integrate Let’s Encrypt support, so it will be even easier to receive X.509 certificates that are accepted by all browsers. -Until we achieve this, here’s a guide how to do this manually.

    - -

    Install the official acme client

    - -

    Log in to your webapp node

    - -
    server$ git clone https://github.com/certbot/certbot
    -server$ cd certbot
    -server$ ./certbot-auto --help
    -
    - -

    Fetch cert

    - -

    Stop apache so the letsencrypt client can bind to port 80:

    - -
    server$ systemctl stop apache2
    -
    - -

    Fetch the certs

    +

    Let’s Encrypt

    -
    server$ ./certbot-auto certonly --standalone --email admin@$(hostname -d) -d $(hostname -d) -d api.$(hostname -d) -d $(hostname -f) -d nicknym.$(hostname -d)
    -
    - -

    This will put the certs and keys into /etc/letsencrypt/live/DOMAIN/.

    +

    Let’s Encrypt is a free “trusted CA”. You can obtain signed certificates from Let’s Encrypt very easily using the LEAP command line, so long as you have first set up DNS correctly.

    -

    Now, go to your workstation’s provider configuration directory and copy the newly created files from the server to your local config. You will override existing files so please make a backup before proceeding, or use a version control system to track changes.

    - -
    workstation$ cd PATH_TO_PROVIDER_CONFIG
    -
    +

    Creating a certificate

    -

    Copy the Certificate

    +

    For example:

    -
    workstation$ scp root@SERVER:/etc/letsencrypt/live/DOMAIN/cert.pem files/cert/dev.pixelated-project.org.crt
    +
    workstation$ leap cert register
    +workstation$ leap cert csr demo.bitmask.net
    +workstation$ leap cert renew demo.bitmask.net
    +workstation$ leap deploy
     
    -

    Copy the private key

    +

    Some notes:

    -
    workstation$ scp root@SERVER:/etc/letsencrypt/live/DOMAIN/privkey.pem files/cert/DOMAIN.key
    -
    - -

    Copy the CA chain cert

    +
      +
    1. You only need to run leap cert register once. Registering will save the Let’s Encrypt account key to files/ca/lets-encrypt-account.key. If you delete this file, just run leap cert register again.
    2. +
    3. Let’s Encrypt support requires that you have already platform 0.9 or later.
    4. +
    5. This requires that the DNS records are correct for the domain.
    6. +
    -
    workstation$ scp root@SERVER:/etc/letsencrypt/live/DOMAIN/fullchain.pem files/cert/commercial_ca.crt
    -
    -

    Deploy the certs

    +

    Renewing a certificate

    -

    Now you only need to deploy the certs

    +

    Let’s Encrypt validations are short lived. You will need to renew the certificate at least once every three months. There is no harm in doing it more regularly, however. You can renew your cert every day if you wanted.

    -
    workstation$ leap deploy
    +
    workstation$ leap cert renew demo.bitmask.net
    +workstation$ leap deploy
     
    -

    This will put them into the right locations which are:

    - -
      -
    • /etc/x509/certs/leap_commercial.crt for the certificate
    • -
    • /etc/x509/./keys/leap_commercial.key for the private key
    • -
    • /usr/local/share/ca-certificates/leap_commercial_ca.crt for the CA chain cert.
    • -
    - - -

    Start apache2 again

    - -
    server$ systemctl start apache2
    -
    +

    There is no need to create a new CSR: renewing will reuse the old private key and the old CSR. It is especially important to not create a new CSR if you have advertised public key pins using HPKP.

    -- cgit v1.2.3