github.com/ghodss/etcd@v0.3.1-0.20140417172404-cc329bfa55cb/Documentation/security.md (about)

     1  # Reading and Writing over HTTPS
     2  
     3  ## Transport Security with HTTPS
     4  
     5  Etcd supports SSL/TLS and client cert authentication for clients to server, as well as server to server communication.
     6  
     7  First, you need to have a CA cert `clientCA.crt` and signed key pair `client.crt`, `client.key`.
     8  This site has a good reference for how to generate self-signed key pairs:
     9  http://www.g-loaded.eu/2005/11/10/be-your-own-ca/
    10  Or you could use [etcd-ca](https://github.com/coreos/etcd-ca) to generate certs and keys.
    11  
    12  For testing you can use the certificates in the `fixtures/ca` directory.
    13  
    14  Let's configure etcd to use this keypair:
    15  
    16  ```sh
    17  ./etcd -f -name machine0 -data-dir machine0 -cert-file=./fixtures/ca/server.crt -key-file=./fixtures/ca/server.key.insecure
    18  ```
    19  
    20  There are a few new options we're using:
    21  
    22  * `-f` - forces a new machine configuration, even if an existing configuration is found. (WARNING: data loss!)
    23  * `-cert-file` and `-key-file` specify the location of the cert and key files to be used for for transport layer security between the client and server.
    24  
    25  You can now test the configuration using HTTPS:
    26  
    27  ```sh
    28  curl --cacert ./fixtures/ca/server-chain.pem https://127.0.0.1:4001/v2/keys/foo -XPUT -d value=bar -v
    29  ```
    30  
    31  You should be able to see the handshake succeed.
    32  
    33  **OSX 10.9+ Users**: curl 7.30.0 on OSX 10.9+ doesn't understand certificates passed in on the command line.
    34  Instead you must import the dummy ca.crt directly into the keychain or add the `-k` flag to curl to ignore errors.
    35  If you want to test without the `-k` flag run `open ./fixtures/ca/ca.crt` and follow the prompts.
    36  Please remove this certificate after you are done testing!
    37  If you know of a workaround let us know.
    38  
    39  ```
    40  ...
    41  SSLv3, TLS handshake, Finished (20):
    42  ...
    43  ```
    44  
    45  And also the response from the etcd server:
    46  
    47  ```json
    48  {
    49      "action": "set",
    50      "key": "/foo",
    51      "modifiedIndex": 3,
    52      "value": "bar"
    53  }
    54  ```
    55  
    56  
    57  ## Authentication with HTTPS Client Certificates
    58  
    59  We can also do authentication using CA certs.
    60  The clients will provide their cert to the server and the server will check whether the cert is signed by the CA and decide whether to serve the request.
    61  
    62  ```sh
    63  ./etcd -f -name machine0 -data-dir machine0 -ca-file=./fixtures/ca/ca.crt -cert-file=./fixtures/ca/server.crt -key-file=./fixtures/ca/server.key.insecure
    64  ```
    65  
    66  ```-ca-file``` is the path to the CA cert.
    67  
    68  Try the same request to this server:
    69  
    70  ```sh
    71  curl --cacert ./fixtures/ca/server-chain.pem https://127.0.0.1:4001/v2/keys/foo -XPUT -d value=bar -v
    72  ```
    73  
    74  The request should be rejected by the server.
    75  
    76  ```
    77  ...
    78  routines:SSL3_READ_BYTES:sslv3 alert bad certificate
    79  ...
    80  ```
    81  
    82  We need to give the CA signed cert to the server.
    83  
    84  ```sh
    85  curl --key ./fixtures/ca/server2.key.insecure --cert ./fixtures/ca/server2.crt --cacert ./fixtures/ca/server-chain.pem -L https://127.0.0.1:4001/v2/keys/foo -XPUT -d value=bar -v
    86  ```
    87  
    88  You should able to see:
    89  
    90  ```
    91  ...
    92  SSLv3, TLS handshake, CERT verify (15):
    93  ...
    94  TLS handshake, Finished (20)
    95  ```
    96  
    97  And also the response from the server:
    98  
    99  ```json
   100  {
   101      "action": "set",
   102      "node": {
   103          "createdIndex": 12,
   104          "key": "/foo",
   105          "modifiedIndex": 12,
   106          "value": "bar"
   107      }
   108  }
   109  ```
   110  
   111  ### Why SSLv3 alert handshake failure when using SSL client auth?
   112  
   113  The `crypto/tls` package of `golang` checks the key usage of the certificate public key before using it.
   114  To use the certificate public key to do client auth, we need to add `clientAuth` to `Extended Key Usage` when creating the certificate public key.
   115  
   116  Here is how to do it:
   117  
   118  Add the following section to your openssl.cnf:
   119  
   120  ```
   121  [ ssl_client ]
   122  ...
   123    extendedKeyUsage = clientAuth
   124  ...
   125  ```
   126  
   127  When creating the cert be sure to reference it in the `-extensions` flag:
   128  
   129  ```
   130  openssl ca -config openssl.cnf -policy policy_anything -extensions ssl_client -out certs/machine.crt -infiles machine.csr
   131  ```