github.com/flant/helm@v2.8.1+incompatible/docs/tiller_ssl.md (about) 1 # Using SSL Between Helm and Tiller 2 3 This document explains how to create strong SSL/TLS connections between Helm and 4 Tiller. The emphasis here is on creating an internal CA, and using both the 5 cryptographic and identity functions of SSL. 6 7 > Support for TLS-based auth was introduced in Helm 2.3.0 8 9 Configuring SSL is considered an advanced topic, and knowledge of Helm and Tiller 10 is assumed. 11 12 ## Overview 13 14 The Tiller authentication model uses client-side SSL certificates. Tiller itself 15 verifies these certificates using a certificate authority. Likewise, the client 16 also verifies Tiller's identity by certificate authority. 17 18 There are numerous possible configurations for setting up certificates and authorities, 19 but the method we cover here will work for most situations. 20 21 > As of Helm 2.7.2, Tiller _requires_ that the client certificate be validated 22 > by its CA. In prior versions, Tiller used a weaker validation strategy that 23 > allowed self-signed certificates. 24 25 In this guide, we will show how to: 26 27 - Create a private CA that is used to issue certificates for Tiller clients and 28 servers. 29 - Create a certificate for Tiller 30 - Create a certificate for the Helm client 31 - Create a Tiller instance that uses the certificate 32 - Configure the Helm client to use the CA and client-side certificate 33 34 By the end of this guide, you should have a Tiller instance running that will 35 only accept connections from clients who can be authenticated by SSL certificate. 36 37 ## Generating Certificate Authorities and Certificates 38 39 One way to generate SSL CAs is via the `openssl` command line tool. There are many 40 guides and best practices documents available online. This explanation is focused 41 on getting ready within a small amount of time. For production configurations, 42 we urge readers to read [the official documentation](https://www.openssl.org) and 43 consult other resources. 44 45 ### Generate a Certificate Authority 46 47 The simplest way to generate a certificate authority is to run two commands: 48 49 ```console 50 $ openssl genrsa -out ./ca.key.pem 4096 51 $ openssl req -key ca.key.pem -new -x509 -days 7300 -sha256 -out ca.cert.pem -extensions v3_ca 52 Enter pass phrase for ca.key.pem: 53 You are about to be asked to enter information that will be incorporated 54 into your certificate request. 55 What you are about to enter is what is called a Distinguished Name or a DN. 56 There are quite a few fields but you can leave some blank 57 For some fields there will be a default value, 58 If you enter '.', the field will be left blank. 59 ----- 60 Country Name (2 letter code) [AU]:US 61 State or Province Name (full name) [Some-State]:CO 62 Locality Name (eg, city) []:Boulder 63 Organization Name (eg, company) [Internet Widgits Pty Ltd]:tiller 64 Organizational Unit Name (eg, section) []: 65 Common Name (e.g. server FQDN or YOUR name) []:tiller 66 Email Address []:tiller@example.com 67 ``` 68 69 Note that the data input above is _sample data_. You should customize to your own 70 specifications. 71 72 The above will generate both a secret key and a CA. Note that these two files are 73 very important. The key in particular should be handled with particular care. 74 75 Often, you will want to generate an intermediate signing key. For the sake of brevity, 76 we will be signing keys with our root CA. 77 78 ### Generating Certificates 79 80 We will be generating two certificates, each representing a type of certificate: 81 82 - One certificate is for Tiller. You will want one of these _per tiller host_ that 83 you run. 84 - One certificate is for the user. You will want one of these _per helm user_. 85 86 Since the commands to generate these are the same, we'll be creating both at the 87 same time. The names will indicate their target. 88 89 First, the Tiller key: 90 91 ```console 92 $ openssl genrsa -out ./tiller.key.pem 4096 93 Generating RSA private key, 4096 bit long modulus 94 ..........................................................................................................................................................................................................................................................................................................................++ 95 ............................................................................++ 96 e is 65537 (0x10001) 97 Enter pass phrase for ./tiller.key.pem: 98 Verifying - Enter pass phrase for ./tiller.key.pem: 99 ``` 100 101 Next, generate the Helm client's key: 102 103 ```console 104 $ openssl genrsa -out ./helm.key.pem 4096 105 Generating RSA private key, 4096 bit long modulus 106 .....++ 107 ......................................................................................................................................................................................++ 108 e is 65537 (0x10001) 109 Enter pass phrase for ./helm.key.pem: 110 Verifying - Enter pass phrase for ./helm.key.pem: 111 ``` 112 113 Again, for production use you will generate one client certificate for each user. 114 115 Next we need to create certificates from these keys. For each certificate, this is 116 a two-step process of creating a CSR, and then creating the certificate. 117 118 ```console 119 $ openssl req -key tiller.key.pem -new -sha256 -out tiller.csr.pem 120 Enter pass phrase for tiller.key.pem: 121 You are about to be asked to enter information that will be incorporated 122 into your certificate request. 123 What you are about to enter is what is called a Distinguished Name or a DN. 124 There are quite a few fields but you can leave some blank 125 For some fields there will be a default value, 126 If you enter '.', the field will be left blank. 127 ----- 128 Country Name (2 letter code) [AU]:US 129 State or Province Name (full name) [Some-State]:CO 130 Locality Name (eg, city) []:Boulder 131 Organization Name (eg, company) [Internet Widgits Pty Ltd]:Tiller Server 132 Organizational Unit Name (eg, section) []: 133 Common Name (e.g. server FQDN or YOUR name) []:tiller-server 134 Email Address []: 135 136 Please enter the following 'extra' attributes 137 to be sent with your certificate request 138 A challenge password []: 139 An optional company name []: 140 ``` 141 142 And we repeat this step for the Helm client certificate: 143 144 ```console 145 $ openssl req -key helm.key.pem -new -sha256 -out helm.csr.pem 146 # Answer the questions with your client user's info 147 ``` 148 149 (In rare cases, we've had to add the `-nodes` flag when generating the request.) 150 151 Now we sign each of these CSRs with the CA certificate we created: 152 153 ```console 154 $ openssl x509 -req -CA ca.cert.pem -CAkey ca.key.pem -CAcreateserial -in tiller.csr.pem -out tiller.cert.pem 155 Signature ok 156 subject=/C=US/ST=CO/L=Boulder/O=Tiller Server/CN=tiller-server 157 Getting CA Private Key 158 Enter pass phrase for ca.key.pem: 159 ``` 160 161 And again for the client certificate: 162 163 ```console 164 $ openssl x509 -req -CA ca.cert.pem -CAkey ca.key.pem -CAcreateserial -in helm.csr.pem -out helm.cert.pem 165 ``` 166 167 At this point, the important files for us are these: 168 169 ``` 170 # The CA. Make sure the key is kept secret. 171 ca.cert.pem 172 ca.key.pem 173 # The Helm client files 174 helm.cert.pem 175 helm.key.pem 176 # The Tiller server files. 177 tiller.cert.pem 178 tiller.key.pem 179 ``` 180 181 Now we're ready to move on to the next steps. 182 183 ## Creating a Custom Tiller Installation 184 185 Helm includes full support for creating a deployment configured for SSL. By specifying 186 a few flags, the `helm init` command can create a new Tiller installation complete 187 with all of our SSL configuration. 188 189 To take a look at what this will generate, run this command: 190 191 ```console 192 $ helm init --dry-run --debug --tiller-tls --tiller-tls-cert ./tiller.cert.pem --tiller-tls-key ./tiller.key.pem --tiller-tls-verify --tls-ca-cert ca.cert.pem 193 ``` 194 195 The output will show you a Deployment, a Secret, and a Service. Your SSL information 196 will be preloaded into the Secret, which the Deployment will mount to pods as they 197 start up. 198 199 If you want to customize the manifest, you can save that output to a file and then 200 use `kubectl create` to load it into your cluster. 201 202 > We strongly recommend enabling RBAC on your cluster and adding [service accounts](rbac.md) 203 > with RBACS. 204 205 Otherwise, you can remove the `--dry-run` and `--debug` flags. We also recommend 206 putting Tiller in a non-system namespace (`--tiller-namespace=something`) and enable 207 a service account (`--service-account=somename`). But for this example we will stay 208 with the basics: 209 210 ```console 211 $ helm init --tiller-tls --tiller-tls-cert ./tiller.cert.pem --tiller-tls-key ./tiller.key.pem --tiller-tls-verify --tls-ca-cert ca.cert.pem 212 ``` 213 214 In a minute or two it should be ready. We can check Tiller like this: 215 216 ```console 217 $ kubectl -n kube-system get deployment 218 NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE 219 ... other stuff 220 tiller-deploy 1 1 1 1 2m 221 ``` 222 223 If there is a problem, you may want to use `kubectl get pods -n kube-system` to 224 find out what went wrong. With the SSL/TLS support, the most common problems all 225 have to do with improperly generated TLS certificates or accidentally swapping the 226 cert and the key. 227 228 At this point, you should get a _failure_ when you run basic Helm commands: 229 230 ```console 231 $ helm ls 232 Error: transport is closing 233 ``` 234 235 This is because your Helm client does not have the correct certificate to authenticate 236 to Tiller. 237 238 ## Configuring the Helm Client 239 240 The Tiller server is now running with TLS protection. It's time to configure the 241 Helm client to also perform TLS operations. 242 243 For a quick test, we can specify our configuration manually. We'll run a normal 244 Helm command (`helm ls`), but with SSL/TLS enabled. 245 246 ```console 247 helm ls --tls --tls-ca-cert ca.cert.pem --tls-cert helm.cert.pem --tls-key helm.key.pem 248 ``` 249 250 This configuration sends our client-side certificate to establish identity, uses 251 the client key for encryption, and uses the CA certificate to validate the remote 252 Tiller's identity. 253 254 Typing a line that that is cumbersome, though. The shortcut is to move the key, 255 cert, and CA into `$HELM_HOME`: 256 257 ```console 258 $ cp ca.cert.pem $(helm home)/ca.pem 259 $ cp helm.cert.pem $(helm home)/cert.pem 260 $ cp helm.key.pem $(helm home)/key.pem 261 ``` 262 263 With this, you can simply run `helm ls --tls` to enable TLS. 264 265 ### Troubleshooting 266 267 *Running a command, I get `Error: transport is closing`* 268 269 This is almost always due to a configuration error in which the client is missing 270 a certificate (`--tls-cert`) or the certificate is bad. 271 272 *I'm using a certificate, but get `Error: remote error: tls: bad certificate`* 273 274 This means that Tiller's CA cannot verify your certificate. In the examples above, 275 we used a single CA to generate both the client and server certificates. In these 276 examples, the CA has _signed_ the client's certificate. We then load that CA 277 up to Tiller. So when the client certificate is sent to the server, Tiller 278 checks the client certificate against the CA. 279 280 *If I use `--tls-verify` on the client, I get `Error: x509: certificate is valid for tiller-server, not localhost`* 281 282 If you plan to use `--tls-verify` on the client, you will need to make sure that 283 the host name that Helm connects to matches the host name on the certificate. In 284 some cases this is awkward, since Helm will connect over localhost, or the FQDN is 285 not available for public resolution. 286 287 ## References 288 289 https://github.com/denji/golang-tls 290 https://www.openssl.org/docs/ 291 https://jamielinux.com/docs/openssl-certificate-authority/sign-server-and-client-certificates.html