Tutorial

How To Secure Your CoreOS Cluster with TLS/SSL and Firewall Rules

How To Secure Your CoreOS Cluster with TLS/SSL and Firewall Rules

Introduction

If you are planning to run a CoreOS cluster in a network environment outside of your control, such as within a shared datacenter or across the public internet, you may have noticed that etcd communicates by making unencrypted HTTP requests. It’s possible to mitigate the risks of that behavior by configuring an IPTables firewall on each node in the cluster, but a complete solution would ideally use an encrypted transport layer.

Fortunately, etcd supports peer-to-peer TLS/SSL connections, so that each member of a cluster is authenticated and all communication is encrypted. In this guide, we’ll begin by provisioning a simple cluster with three members, then configure HTTPS endpoints and a basic firewall on each machine.

Prerequisites

This guide builds heavily on concepts discussed in this introduction to CoreOS system components and this guide to setting up a CoreOS cluster on DigitalOcean.

You should be familiar with the basics of etcd, fleetctl, cloud-config files, and generating a discovery URL.

In order to create and access the machines in your cluster, you’ll need an SSH public key associated with your DigitalOcean account. For detailed information about using SSH keys with DigitalOcean, see here.

If you want to use the DigitalOcean API to create your CoreOS machines, refer to this tutorial for information on how to generate and use a Personal Access Token with write permissions. Use of the API is optional, but may save you time in the long run, particularly if you anticipate building larger clusters.

Generate a New Discovery URL

Retrieve a new discovery URL from discovery.etcd.io, either by visiting https://discovery.etcd.io/new?size=3 in your browser and copying the URL displayed, or by using curl from the terminal on your local machine:

  1. curl -w "\n" "https://discovery.etcd.io/new?size=3"

Save the returned URL; we’ll use it in our cloud-config shortly.

Write a Cloud-Config File Including HTTPS Configuration

We’ll start by writing a cloud-config. The cloud-config will be supplied as user data when initializing each server, defining important configuration details for the cluster. This file will be long, but shouldn’t wind up much more complicated than the version in the basic cluster guide. We’ll tell fleet explicitly to use HTTPS endpoints, enable a service called iptables-restore for our firewall, and write out configuration files telling etcd and fleet where to find SSL certificates.

Open a terminal on your local machine, make sure you’re in your home directory, and use nano (or your favorite text editor) to create and open ~/cloud-config.yml:

  1. cd ~
  2. nano cloud-config.yml

Paste the following, then change https://discovery.etcd.io/token in the etcd2 section to the discovery URL you claimed in the last section.

You can also remove the iptables-restore section, if you don’t want to enable a firewall.

Be careful with indentation when pasting. The cloud-config is written in YAML, which is sensitive to whitespace. See comments within the file for info on specific lines, then we’ll go over some important sections in greater detail.

~/cloud-config.yml
#cloud-config

coreos:
  etcd2:
    # generate a new token for each unique cluster from https://discovery.etcd.io/new:
    discovery: https://discovery.etcd.io/token
    # multi-region deployments, multi-cloud deployments, and Droplets without
    # private networking need to use $public_ipv4:
    advertise-client-urls: https://$private_ipv4:2379,https://$private_ipv4:4001
    initial-advertise-peer-urls: https://$private_ipv4:2380
    # listen on the official ports 2379, 2380 and one legacy port 4001:
    listen-client-urls: https://0.0.0.0:2379,https://0.0.0.0:4001
    listen-peer-urls: https://$private_ipv4:2380
  fleet:
    # fleet defaults to plain HTTP - explicitly tell it to use HTTPS on port 4001:
    etcd_servers: https://$private_ipv4:4001
    public-ip: $private_ipv4   # used for fleetctl ssh command
  units:
    - name: etcd2.service
      command: start
    - name: fleet.service
      command: start
    # enable and start iptables-restore
    - name: iptables-restore.service
      enable: true
      command: start
write_files:
  # tell etcd2 and fleet where our certificates are going to live:
  - path: /run/systemd/system/etcd2.service.d/30-certificates.conf
    permissions: 0644
    content: |
      [Service]
      # client environment variables
      Environment=ETCD_CA_FILE=/home/core/ca.pem
      Environment=ETCD_CERT_FILE=/home/core/coreos.pem
      Environment=ETCD_KEY_FILE=/home/core/coreos-key.pem
      # peer environment variables
      Environment=ETCD_PEER_CA_FILE=/home/core/ca.pem
      Environment=ETCD_PEER_CERT_FILE=/home/core/coreos.pem
      Environment=ETCD_PEER_KEY_FILE=/home/core/coreos-key.pem
  - path: /run/systemd/system/fleet.service.d/30-certificates.conf
    permissions: 0644
    content: |
      [Service]
      # client auth certs
      Environment=FLEET_ETCD_CAFILE=/home/core/ca.pem
      Environment=FLEET_ETCD_CERTFILE=/home/core/coreos.pem
      Environment=FLEET_ETCD_KEYFILE=/home/core/coreos-key.pem

As an optional step, you can paste your cloud-config into the official CoreOS Cloud Config Validator and press Validate Cloud-Config.

Save the file and exit. In nano, you can accomplish this with Ctrl-X to exit, y to confirm writing the file, and Enter to confirm the filename to save.

Let’s look at a handful of specific blocks from cloud-init.yml. First, the fleet values:

  fleet:
    # fleet defaults to plain HTTP - explicitly tell it to use HTTPS:
    etcd_servers: https://$private_ipv4:4001
    public-ip: $private_ipv4   # used for fleetctl ssh command

Notice that etcd_servers is set to an https URL. For plain HTTP operation, this value doesn’t need to be set. Without explicit configuration, however, HTTPS will fail. ($private_ipv4 is a variable understood by the CoreOS initialization process, not one you need to change.)

Next we come to the write_files block. Values are broken into a filesystem path, permissions mask, and content, which contains the desired contents of a file. Here, we specify that systemd unit files for the etcd2 and fleet services should set up environment variables pointing to the TLS/SSL certificates we’ll be generating:

write_files:
  # tell etcd2 and fleet where our certificates are going to live:
  - path: /run/systemd/system/etcd2.service.d/30-certificates.conf
    permissions: 0644
    content: |
      [Service]
      # client environment variables
      Environment=ETCD_CA_FILE=/home/core/ca.pem
      ...
  - path: /run/systemd/system/fleet.service.d/30-certificates.conf
    permissions: 0644
    content: |
      [Service]
      # client auth certs
      Environment=FLEET_ETCD_CAFILE=/home/core/ca.pem
      ...

While we tell the services where to find certificate files, we can’t yet provide the files themselves. In order to that, we’ll need to know the private IP address of each CoreOS machine, which is only available once the machines have been created.

Note: On CoreOS Droplets, the contents of cloud-config cannot be changed after the Droplet is created, and the file is re-executed on every boot. You should avoid using the write-files section for any configuration you plan to modify after your cluster is built, since it will be reset the next time the Droplet starts up.

Provision Droplets

Now that we have a cloud-config.yml defined, we’ll use it to provision each member of the cluster. On DigitalOcean, there are two basic approaches we can take: Via the web-based Control Panel, or making calls to the DigitalOcean API using cURL from the command line.

Using the DigitalOcean Control Panel

Create three new CoreOS Droplets within the same datacenter region. Make sure to check Private Networking and Enable User Data each time.

  • coreos-1
  • coreos-2
  • coreos-3

In the User Data field, paste the contents of cloud-config.yml from above, making sure you’ve inserted your discovery URL in the discovery field near the top of the file.

Using the DigitalOcean API

As an alternative approach which may save repetitive pasting into fields, we can write a short Bash script which uses curl to request a new Droplet from the DigitalOcean API with our cloud-config, and invoke it once for each Droplet. Open a new file called makecoreos.sh with nano (or your text editor of choice):

  1. cd ~
  2. nano makecoreos.sh

Paste and save the following script, adjusting the region and size fields as-desired for your cluster (the defaults of nyc3 and 512mb are fine for demonstration purposes, but you may want a different region or bigger Droplets for real-world projects):

~/makecoreos.sh
#!/usr/bin/env bash

# A basic Droplet create request.
curl -X POST "https://api.digitalocean.com/v2/droplets" \
     -d'{"name":"'"$1"'","region":"nyc3","size":"512mb","private_networking":true,"image":"coreos-stable","user_data":
"'"$(cat ~/cloud-config.yml)"'",
         "ssh_keys":[ "'$DO_SSH_KEY_FINGERPRINT'" ]}' \
     -H "Authorization: Bearer $TOKEN" \
     -H "Content-Type: application/json"

Now, let’s set the environment variables $DO_SSH_KEY_FINGERPRINT and $TOKEN to the fingerprint of an SSH key associated with your DigitalOcean account and your API Personal Access Token, respectively.

For information about getting a Personal Access Token and using the API, refer to this tutorial.

In order to find the fingerprint of a key associated with your account, check the Security section of your account settings, under SSH Keys. It will be in the form of a public key fingerprint, something like 43:51:43:a1:b5:fc:8b:b7:0a:3a:a9:b1:0f:66:73:a8.

We use export here so that child processes of the shell, like makecoreos.sh, will be able to access the variables. Both must be set in the current shell any time the script is used, or the API call will fail:

  1. export DO_SSH_KEY_FINGERPRINT="ssh_key_fingerprint"
  2. export TOKEN="your_personal_access_token"

Note: If you’ve just generated a Personal Access Token for the API, remember to keep it handy and secure. There’s no way to retrieve it after it’s shown to you on first creation, and anyone with the token can control your DigitalOcean account.

Once we’ve set environment variables for each of the required credentials, we can run the script to create each desired Droplet. makecoreos.sh uses its first parameter to fill out the name field in its call to the API:

  1. bash makecoreos.sh coreos-1
  2. bash makecoreos.sh coreos-2
  3. bash makecoreos.sh coreos-3

You should see JSON output describing each new Droplet, and all three should appear in your list of Droplets in the Control Panel. It may take a few seconds for them to finish booting.

Log in to coreos-1

Whether you used the Control Panel or the API, you should now have three running Droplets. Now is a good time to make note of their public and private IPs, which are available by clicking on an individual Droplet in the Control Panel, then clicking on the Settings link. The private IP address of each Droplet will be needed when generating certificates and configuring a firewall.

Let’s test a Droplet. Make sure that your SSH key is added to your local SSH agent:

  1. eval $(ssh-agent)
  2. ssh-add

Find the public IP address of coreos-1 in the DigitalOcean Control Panel, and connect with SSH agent forwarding turned on:

  1. ssh -A core@coreos-1_public_ip

On first login to any member of the cluster, we are likely to receive an error message from systemd:

Output
CoreOS stable (766.5.0) Failed Units: 1 iptables-restore.service

This indicates that the firewall hasn’t yet been configured. For now, it’s safe to ignore this message. (If you elected not to enable the firewall in your cloud-config, you won’t see an error message. You can always enable the iptables-restore service later.)

Before we worry about the firewall, let’s get the etcd2 instances on each member of the cluster talking to one another.

Use CFSSL to Generate Self-Signed Certificates

CFSSL is a toolkit for working with TLS/SSL certificates, published by CloudFlare. At the time of this writing, it’s the CoreOS maintainers’ chosen tool for generating self-signed certificates, in preference to OpenSSL and the now-deprecated etcd-ca.

Install CFSSL on Your Local Machine

CFSSL requires a working Go installation to install from source. See this guide to installing Go.

Make sure your $GOPATH is set correctly and added to your $PATH, then use go get to install the cfssl commands:

  1. export GOPATH=~/gocode
  2. export PATH=$PATH:$GOPATH/bin
  3. go get -u github.com/cloudflare/cfssl/cmd/cfssl
  4. go get -u github.com/cloudflare/cfssl/...

As an alternative approach, pre-built binaries can be retrieved from pkg.cfssl.org. First make sure that ~/bin exists and is in your path:

  1. mkdir -p ~/bin
  2. export PATH=$PATH:~/bin

Then use curl to retrieve the latest versions of cfssl and cfssljson for your platform:

  1. curl -s -L -o ~/bin/cfssl https://pkg.cfssl.org/R1.1/cfssl_linux-amd64
  2. curl -s -L -o ~/bin/cfssljson https://pkg.cfssl.org/R1.1/cfssljson_linux-amd64

Make sure the cfssl binaries are executable:

  1. chmod +x ~/bin/cfssl
  2. chmod +x ~/bin/cfssljson

Generate a Certificate Authority

Now that the cfssl commands are installed, we can use them to generate a custom Certificate Authority which we’ll use to sign certificates for each of our CoreOS machines. Let’s start by making and entering a fresh directory to stash these files in:

  1. mkdir ~/coreos_certs
  2. cd ~/coreos_certs

Now, create and open ca-config.json in nano (or your favorite text editor):

  1. nano ca-config.json

Paste and save the following, which configures how cfssl will do signing:

~/coreos_certs/ca-config.json
{
    "signing": {
        "default": {
            "expiry": "43800h"
        },
        "profiles": {
            "client-server": {
                "expiry": "43800h",
                "usages": [
                    "signing",
                    "key encipherment",
                    "server auth",
                    "client auth"
                ]
            }
        }
    }
}

Of note here are the expiry, currently set to 43800 hours (or 5 years), and the client-server profile, which includes both server auth and client auth usages. We need both of these for peer-to-peer TLS.

Next, create and open ca-csr.json.

  1. nano ca-csr.json

Paste the following, adjusting CN and the names array as desired for your location and organization. It’s safe to use fictional values for the hosts entry as well as place and organization names:

~/coreos_certs/ca-csr.json
{
    "CN": "My Fake CA",
    "hosts": [
        "example.net",
        "www.example.net"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "US",
            "L": "CO",
            "O": "My Company",
            "ST": "Lyons",
            "OU": "Some Org Unit"
        }
    ]
}

If you want to compare these with default values for ca-config.json and ca-csr.json, you can print defaults with cfssl. For ca-config.json, use:

  1. cfssl print-defaults config

For ca-csr.json, use:

  1. cfssl print-defaults csr

With ca-csr.json and ca-config.json in place, generate the Certificate Authority:

  1. cfssl gencert -initca ca-csr.json | cfssljson -bare ca -

Generate and Sign Certificates for CoreOS Machines

Now that we have a Certificate Authority, we can write defaults for a CoreOS machine:

Create and open coreos-1.json:

  1. nano coreos-1.json

Paste and save the following, adjusting it for the private IP address of coreos-1 (visible in the DigitalOcean Control Panel by clicking on an individual Droplet):

~/coreos_certs/coreos-1.json
{
    "CN": "coreos-1",
    "hosts": [
        "coreos-1",
        "coreos-1.local",
        "127.0.0.1",
        "coreos-1_private_ip"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "US",
            "L": "Lyons",
            "ST": "Colorado"
        }
    ]
}

The most important parts are CN, which should be your hostname, and the hosts array, which must contain all of:

  • your local hostname(s)
  • 127.0.0.1
  • the CoreOS machine’s private IP address (not its public-facing IP)

These will be added to the resulting certificate as subjectAltNames. etcd connections (including to the local loopback device at 127.0.0.1) require the certificate to have a SAN matching the connecting hostname.

You can also change the names array to reflect your location, if desired. Again, it’s safe to use fictional values for placenames.

Repeat this process for each remaining machine, creating a matching coreos-2.json and coreos-3.json with the appropriate hosts entries.

Note: If you’d like to take a look at default values for coreos-1.json, you can use cfssl:

  1. cfssl print-defaults csr

Now, for each CoreOS machine, generate a signed certificate and upload it to the correct machine:

  1. cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client-server coreos-1.json | cfssljson -bare coreos
  2. chmod 0644 coreos-key.pem
  3. scp ca.pem coreos-key.pem coreos.pem core@coreos-1_public_ip:

This will create three files (ca.pem, coreos-key.pem, and coreos.pem), make sure permissions are correct on the keyfile, and copy them via scp to core’s home directory on coreos-1.

Repeat this process for each of the remaining machines, keeping in mind that each invocation of the command will overwrite the previous set of certificate files:

  1. cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client-server coreos-2.json | cfssljson -bare coreos
  2. chmod 0644 coreos-key.pem
  3. scp ca.pem coreos-key.pem coreos.pem core@coreos-2_public_ip:
  1. cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client-server coreos-3.json | cfssljson -bare coreos
  2. chmod 0644 coreos-key.pem
  3. scp ca.pem coreos-key.pem coreos.pem core@coreos-3_public_ip:

Check etcd2 Functionality on coreos-1

With certificates in place, we should be able to run fleetctl on coreos-1. First, log in via SSH:

  1. ssh -A core@coreos-1_public_ip

Next, try listing all the machines in the cluster:

  1. fleetctl list-machines

You should see an identifier for each machine listed along with its private IP address:

Output
MACHINE IP METADATA 7cb57440... 10.132.130.187 - d91381d4... 10.132.87.87 - eeb8726f... 10.132.32.222 -

If fleetctl hangs indefinitely, it may be necessary to restart the cluster. Exit to your local machine:

  1. exit

Use SSH to send reboot commands to each CoreOS machine:

  1. ssh core@coreos-1_public_ip 'sudo reboot'
  2. ssh core@coreos-2_public_ip 'sudo reboot'
  3. ssh core@coreos-3_public_ip 'sudo reboot'

Wait a few moments, re-connect to coreos-1, and try fleetctl again.

Configure an IPTables Firewall on Cluster Members

With certificates in place, it should be impossible for other machines on the local network to control your cluster or extract values from etcd2. Nevertheless, it’s a good idea to reduce the available attack surface if possible. In order to limit our network exposure, we can add some simple firewall rules to each machine, blocking most local network traffic from sources other than peers in the cluster.

Remember that, if we enabled the iptables-restore service in cloud-config, we’ll see a systemd error message when first logging in to a CoreOS machine:

Output
CoreOS stable (766.5.0) Failed Units: 1 iptables-restore.service

This lets us know that, although the service is enabled, iptables-restore failed to load correctly. We can diagnose this by using systemctl:

  1. systemctl status -l iptables-restore
Output
● iptables-restore.service - Restore iptables firewall rules Loaded: loaded (/usr/lib64/systemd/system/iptables-restore.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Wed 2015-11-25 00:01:24 UTC; 27min ago Process: 689 ExecStart=/sbin/iptables-restore /var/lib/iptables/rules-save (code=exited, status=1/FAILURE) Main PID: 689 (code=exited, status=1/FAILURE) Nov 25 00:01:24 coreos-2 systemd[1]: Starting Restore iptables firewall rules... Nov 25 00:01:24 coreos-2 systemd[1]: iptables-restore.service: Main process exited, code=exited, status=1/FAILURE Nov 25 00:01:24 coreos-2 systemd[1]: Failed to start Restore iptables firewall rules. Nov 25 00:01:24 coreos-2 iptables-restore[689]: Can't open /var/lib/iptables/rules-save: No such file or directory Nov 25 00:01:24 coreos-2 systemd[1]: iptables-restore.service: Unit entered failed state. Nov 25 00:01:24 coreos-2 systemd[1]: iptables-restore.service: Failed with result 'exit-code'.

There’s a lot of information here, but the most useful line is the one containing iptables-restore[689], which is the name of the process systemd attempted to run along with its process id. This is where we’ll often find the actual error output of failed services.

The firewall failed to restore because, while we enabled iptables-restore in cloud-config, we haven’t yet provided it with a file containing our desired rules. We could have done this before we created the Droplets, except that there’s no way to know what IP addresses will be allocated to a Droplet before its creation. Now that we know each private IP, we can write a ruleset.

Open a new file in your editor, paste the following, and replace coreos-1_private_ip, coreos-2_private_ip, and coreos-3_private_ip with the private IP address of each CoreOS machine. You may also need to adjust the section beneath Accept all TCP/IP traffic... to reflect public services you intend to offer from the cluster, although this version should work well for demonstration purposes.

/var/lib/iptables/rules-save
  1. *filter
  2. :INPUT DROP [0:0]
  3. :FORWARD DROP [0:0]
  4. :OUTPUT ACCEPT [0:0]
  5. # Accept all loopback (local) traffic:
  6. -A INPUT -i lo -j ACCEPT
  7. # Accept all traffic on the local network from other members of
  8. # our CoreOS cluster:
  9. -A INPUT -i eth1 -p tcp -s coreos-1_private_ip -j ACCEPT
  10. -A INPUT -i eth1 -p tcp -s coreos-2_private_ip -j ACCEPT
  11. -A INPUT -i eth1 -p tcp -s coreos-3_private_ip -j ACCEPT
  12. # Keep existing connections (like our SSH session) alive:
  13. -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
  14. # Accept all TCP/IP traffic to SSH, HTTP, and HTTPS ports - this should
  15. # be customized for your application:
  16. -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
  17. -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
  18. -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
  19. # Accept pings:
  20. -A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
  21. -A INPUT -p icmp -m icmp --icmp-type 3 -j ACCEPT
  22. -A INPUT -p icmp -m icmp --icmp-type 11 -j ACCEPT
  23. COMMIT

Copy the above to your clipboard, log in to coreos-1, and open rules-save using Vim, the default text editor on CoreOS:

  1. ssh -A core@coreos-1_public_ip
  1. sudo vim /var/lib/iptables/rules-save

Once inside the editor, type :set paste and press Enter to make sure that auto-indentation is turned off, then press i to enter insert mode and paste your firewall rules. Press Esc to leave insert mode and :wq to write the file and quit.

Warning: Make sure there’s a trailing newline on the last line of the file, or IPTables may fail with confusing syntax errors, despite all commands in the file appearing correct.

Finally, make sure that the file has appropriate permissions (read and write for user, read-only for group and world):

  1. sudo chmod 0644 /var/lib/iptables/rules-save

Now we should be ready to try the service again:

  1. sudo systemctl start iptables-restore

If successful, systemctl will exit silently. We can check the status of the firewall in two ways. First, by using systemctl status:

  1. sudo systemctl status -l iptables-restore

And secondly by listing the current iptables rules themselves:

  1. sudo iptables -v -L

We use the -v option to get verbose output, which will let us know what interface a given rule applies to.

Once you’re confident that the firewall on coreos-1 is configured, log out:

  1. exit

Next, repeat this process to install /var/lib/iptables/rules-save on coreos-2 and coreos-3.

Conclusion

In this guide, we’ve defined a basic CoreOS cluster with three members, providing each with a TLS/SSL certificate for authentication and transport security, and used a firewall to block connections from other Droplets on the local data center network. This helps mitigate many of the basic security concerns involved in using CoreOS on a shared network.

From here, you can apply the techniques in the rest of this series on getting started with CoreOS to define and manage services.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


Tutorial Series: Getting Started with CoreOS

CoreOS is a powerful Linux distribution built to make large, scalable deployments on varied infrastructure simple to manage. Based on a build of Chrome OS, CoreOS maintains a lightweight host system and uses Docker containers for all applications. In this series, we will introduce you to the basics of CoreOS, teach you how to set up a CoreOS cluster, and get you started with using docker containers with CoreOS.

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
9 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hey! I’ve tried this multiple times, but somehow it never works. Fleet does not hang, it just can’t talk to etcd. I’ve used both alpha and stable CoreOS, none of them work.

It seems that the error is somewhere in the config, because whenever I try to use etcdctl it gives me the following errors (maybe it’s some certificate-thing?):

Error:  client: etcd cluster is unavailable or misconfigured
error #0: malformed HTTP response "\x15\x03\x01\x00\x02\x02"
error #1: malformed HTTP response "\x15\x03\x01\x00\x02\x02"

Help is much appreciated!

EDIT: I’ve also changed a bit in my cloud-config, since I anticipate that I will be running a multi-region cluster. I am not sure if this is where the fault lies.

EDIT 2: Manually passing in the endpoint to etcdctl (along with cert etc.) works somewhat, it’s just empty.

etcdctl --endpoint=https://127.0.0.1:4001 --ca-file=ca.pem --cert-file=coreos.pem --key-file=coreos-key.pem --no-sync ls

EDIT 3: I solved it! If you want to do it with $public_ipv4, remember to add the public IP to your certificate as well. Don’t know why I forgot that.

Thank you for the excellent article. I had no trouble following the steps and all the commands worked on the first try.

This is a good tutorial. In case folks trying to use it today have problems, there are guides over at coreos.com that are more up to date, and this article will help to customize those instructions for the DigitalOcean environment.

https://coreos.com/os/docs/latest/generate-self-signed-certificates.html https://coreos.com/etcd/docs/latest/etcd-live-http-to-https-migration.html https://coreos.com/etcd/docs/latest/tls-etcd-clients.html

It would be great if you could provide the OpenSSL configuration as well. Its good and all that the CoreOS team has chosen to use CFSSL as their preferred tool for creating certificates, but OpenSSL is a lot more prevalent, available on *nix platforms by default, and is the industry standard for creating keys. You show two different methods for creating Digital Ocean droplets, why not enhance your tutorial for those of us who don’t want to have to install a new compiler to create new tool that does the exact same job of a standard tool that comes bundled with the system.

great article but I think that DO should have scripts that do some part of this for those users who want to knock it out. Sure there is nothing wrong with understanding the tools or the environment but a little help would be appreciated.

Thanks for an excellent article!

Instead of setting the SSL configuration for Fleet and etcd in the write_files section, you can do this directly in each units’ own section. For example,

Environment=ETCD_CERT_FILE=/home/core/coreos.pem

Can be written as:

etcd2:
  ...
  cert_file: /home/core/coreos.pem

This comment has been deleted

    Holy moly. Be very careful of spaces and syntax in the ssl certificate json files. I had a space after one of the IPs (my private IP of course), and it wouldn’t match in etcd.

    As the other commenter mentioned, checking cluster health using this is a great way to check if etcd is working.

    etcdctl --endpoint="https://127.0.0.1:2379/" --cert-file=/home/core/coreos.pem --key-file=/home/core/coreos-key.pem --ca-file=/home/core/ca.pem cluster-health
    
    

    Based on the comments I was able to get etcdctr to query the information I was looking for.

    My question using the defined parameters in this tut how do we go about not passing the keys into the etcdctrl or is that just part of using https. I can’t seem to find any docs that suggest it’s normal.

    For the purpose of figuring this out I have no intention of using public ips, and I’m running alpha 935 on all 3 clusters.

    Works.

    core@coreos-01 ~ $ etcdctl --endpoint="https://127.0.0.1:2379/" --cert-file=/home/core/coreos.pem --key-file=/home/core/coreos-key.pem --ca-file=/home/core/ca.pem cluster-health
    member bb4f3ffa3ba3810 is healthy: got healthy result from https://10.128.7.140:2379
    member 41fde4594c7a5544 is healthy: got healthy result from https://10.128.5.5:2379
    member 4aeeab5914279dd5 is healthy: got healthy result from https://10.128.7.70:2379
    cluster is healthy
    
    core@coreos-01 ~ $ fleetctl list-machines
    MACHINE		IP		METADATA
    55bcd9db...	10.128.7.140	-
    795000ef...	10.128.7.70	-
    c24c2e8b...	10.128.5.5	-
    

    Does not work.

    core@coreos-01 ~ $ etcdctl cluster-health
    cluster may be unhealthy: failed to list members
    Error:  client: etcd cluster is unavailable or misconfigured
    error #0: malformed HTTP response "\x15\x03\x01\x00\x02\x02"
    error #1: malformed HTTP response "\x15\x03\x01\x00\x02\x02"
    

    Clound Config

    scott@scott-u:~/coreos$ cat cloud-config-coreos-01.yml 
    #cloud-config
    
    hostname: 'coreos-01'
    
    coreos:
      etcd2:
        name: 'coreos-01'
        # generate a new token for each unique cluster from https://discovery.etcd.io/new:
        discovery: https://discovery.etcd.io/2bef17b39c1453d3d8467ef8399110e7
        # multi-region deployments, multi-cloud deployments, and Droplets without
        # private networking need to use $public_ipv4:
        advertise-client-urls: https://$private_ipv4:2379,https://$private_ipv4:4001
        initial-advertise-peer-urls: https://$private_ipv4:2380
        # listen on the official ports 2379, 2380 and one legacy port 4001:
        listen-client-urls: https://0.0.0.0:2379,https://0.0.0.0:4001
        listen-peer-urls: https://$private_ipv4:2380
      fleet:
        # fleet defaults to plain HTTP - explicitly tell it to use HTTPS on port 4001:
        etcd_servers: https://$private_ipv4:4001
        public-ip: $private_ipv4   # used for fleetctl ssh command
      units:
        - name: etcd2.service
          command: start
        - name: fleet.service
          command: start
        # enable and start iptables-restore
        - name: iptables-restore.service
          enable: true
          command: start
    write_files:
      # tell etcd2 and fleet where our certificates are going to live:
      - path: /etc/systemd/system/etcd2.service.d/30-certificates.conf
        permissions: 0644
        content: |
          [Service]
          # client environment variables
          Environment=ETCD_CA_FILE=/home/core/ca.pem
          Environment=ETCD_CERT_FILE=/home/core/coreos.pem
          Environment=ETCD_KEY_FILE=/home/core/coreos-key.pem
          # peer environment variables
          Environment=ETCD_PEER_CA_FILE=/home/core/ca.pem
          Environment=ETCD_PEER_CERT_FILE=/home/core/coreos.pem
          Environment=ETCD_PEER_KEY_FILE=/home/core/coreos-key.pem
      - path: /run/systemd/system/fleet.service.d/30-certificates.conf
        permissions: 0644
        content: |
          [Service]
          # client auth certs
          Environment=FLEET_ETCD_CAFILE=/home/core/ca.pem
          Environment=FLEET_ETCD_CERTFILE=/home/core/coreos.pem
          Environment=FLEET_ETCD_KEYFILE=/home/core/coreos-key.pem
    

    30-certs

    core@coreos-01 ~ $ cat /run/systemd/system/etcd2.service.d/30-certificates.conf
    [Service]
    # client environment variables
    Environment=ETCD_CA_FILE=/home/core/ca.pem
    Environment=ETCD_CERT_FILE=/home/core/coreos.pem
    Environment=ETCD_KEY_FILE=/home/core/coreos-key.pem
    # peer environment variables
    Environment=ETCD_PEER_CA_FILE=/home/core/ca.pem
    Environment=ETCD_PEER_CERT_FILE=/home/core/coreos.pem
    Environment=ETCD_PEER_KEY_FILE=/home/core/coreos-key.pem
    
    core@coreos-01 ~ $ cat /run/systemd/system/fleet.service.d/30-certificates.conf 
    [Service]
    # client auth certs
    Environment=FLEET_ETCD_CAFILE=/home/core/ca.pem
    Environment=FLEET_ETCD_CERTFILE=/home/core/coreos.pem
    Environment=FLEET_ETCD_KEYFILE=/home/core/coreos-key.pem 
    

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Join the Tech Talk
    Success! Thank you! Please check your email for further details.

    Please complete your information!

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel