Generate self-signed certificates | Flatcar Container Linux
Generate self-signed certificates
If you build Flatcar Container Linux cluster on top of public networks it is recommended to enable encryption for Flatcar Container Linux services to prevent traffic interception and man-in-the-middle attacks. For these purposes you have to use Certificate Authority (CA), private keys and certificates signed by CA. Let’s use
cfssl
and walk through the whole process to create all these components.
NOTE: We will use basic procedure here. If your configuration requires advanced security options, please refer to official
cfssl
documentation.
Download cfssl
CloudFlare’s distributes
cfssl
source code on github page and binaries on
cfssl website
.
Our documentation assumes that you will run
cfssl
on your local x86_64 Linux host.
Certificate types which are used inside Flatcar Container Linux
client certificate is used to authenticate client by server. For example etcdctl, etcd proxy, or docker clients.
server certificate is used by server and verified by client for server identity. For example docker server or kube-apiserver.
peer certificate is used by etcd cluster members as they communicate with each other in both ways.
Configure CA options
Now we can configure signing options inside ca-config.json config file. Default options contain following preconfigured fields:
profiles: www with server auth (TLS Web Server Authentication) X509 V3 extension and client with client auth (TLS Web Client Authentication) X509 V3 extension.
expiry: with 8760h default value (or 365 days)
For compliance let’s rename www profile into server, create additional peer profile with both server auth and client auth extensions, and set expiry to 43800h (5 years):
You can also modify ca-csr.json Certificate Signing Request (CSR):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{"CN":"My own CA","key":{"algo":"rsa","size":2048},"names":[{"C":"US","L":"CA","O":"My Company Name","ST":"San Francisco","OU":"Org Unit 1","OU":"Org Unit 2"}]}
And generate CA with defined options:
1
cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
You’ll get following files:
1
2
3
ca-key.pem
ca.csr
ca.pem
Please keep ca-key.pem file in safe. This key allows to create any kind of certificates within your CA.
*.csr files are not used in our example.
Generate server certificate
1
cfssl print-defaults csr > server.json
Most important values for server certificate are Common Name (CN) and hosts. We have to substitute them, for example:
Don’t put your ca-key.pem into a Butane Config when untrusted workloads are running on the machine that could access the instance metadata, it is recommended to store it in safe place. This key allows to generate as much certificates as possible.
Keep key files in safe. Don’t forget to set proper file permissions, i.e. chmod 0600 server-key.pem.
Certificates in this TLDR example have both server auth and client auth X509 V3 extensions and you can use them with servers and clients’ authentication.
You are free to generate keys and certificates for wildcard * address as well. They will work on any machine. It will simplify certificates routine but increase security risks.