From 4209f1cbfd157d90417dc5cd3047deff735ba9e2 Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Thu, 12 Oct 2017 13:32:54 +0100 Subject: [PATCH] Security fixes for etcd (#1778) * Security fixes for etcd * Use certs when querying etcd --- roles/etcd/handlers/main.yml | 2 ++ roles/etcd/tasks/configure.yml | 13 ++++++++++--- roles/etcd/templates/etcd.env.j2 | 3 +++ roles/network_plugin/calico/tasks/main.yml | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/roles/etcd/handlers/main.yml b/roles/etcd/handlers/main.yml index 2575c25a4..d4af7f049 100644 --- a/roles/etcd/handlers/main.yml +++ b/roles/etcd/handlers/main.yml @@ -21,6 +21,8 @@ - name: wait for etcd up uri: url: "https://{% if is_etcd_master %}{{ etcd_address }}{% else %}127.0.0.1{% endif %}:2379/health" + client_cert: "{{ etcd_cert_dir}}/admin-{{ groups['etcd'][0] }}.pem" + client_key: "{{ etcd_cert_dir }}/admin-{{ groups['etcd'][0] }}-key.pem" validate_certs: no register: result until: result.status is defined and result.status == 200 diff --git a/roles/etcd/tasks/configure.yml b/roles/etcd/tasks/configure.yml index 5f8756e71..2764e388b 100644 --- a/roles/etcd/tasks/configure.yml +++ b/roles/etcd/tasks/configure.yml @@ -5,12 +5,11 @@ ignore_errors: true changed_when: false check_mode: no - when: is_etcd_master tags: - facts - name: Configure | Add member to the cluster if it is not there - when: is_etcd_master and etcd_member_in_cluster.rc != 0 and etcd_cluster_is_healthy.rc == 0 + when: etcd_member_in_cluster.rc != 0 and etcd_cluster_is_healthy.rc == 0 shell: "{{ bin_dir }}/etcdctl --peers={{ etcd_access_addresses }} member add {{ etcd_member_name }} {{ etcd_peer_url }}" - name: Install etcd launch script @@ -27,5 +26,13 @@ src: "etcd-{{ etcd_deployment_type }}.service.j2" dest: /etc/systemd/system/etcd.service backup: yes - when: is_etcd_master notify: restart etcd + +- name: Confugure | Set etcd data dir permissions + file: + path: "{{ etcd_data_dir }}" + owner: etcd + group: etcd + mode: 0700 + state: directory + recurse: yes diff --git a/roles/etcd/templates/etcd.env.j2 b/roles/etcd/templates/etcd.env.j2 index 00ac5d844..3056ff82b 100644 --- a/roles/etcd/templates/etcd.env.j2 +++ b/roles/etcd/templates/etcd.env.j2 @@ -1,4 +1,5 @@ ETCD_DATA_DIR={{ etcd_data_dir }} +ETCD_WAL_DIR={{ etcd_data_dir }}/member/wal ETCD_ADVERTISE_CLIENT_URLS={{ etcd_client_url }} ETCD_INITIAL_ADVERTISE_PEER_URLS={{ etcd_peer_url }} ETCD_INITIAL_CLUSTER_STATE={% if etcd_cluster_is_healthy.rc != 0 | bool %}new{% else %}existing{% endif %} @@ -22,3 +23,5 @@ ETCD_PEER_TRUSTED_CA_FILE={{ etcd_cert_dir }}/ca.pem ETCD_PEER_CERT_FILE={{ etcd_cert_dir }}/member-{{ inventory_hostname }}.pem ETCD_PEER_KEY_FILE={{ etcd_cert_dir }}/member-{{ inventory_hostname }}-key.pem ETCD_PEER_CLIENT_CERT_AUTH=true +ETCD_CLIENT_CERT_AUTH=true + diff --git a/roles/network_plugin/calico/tasks/main.yml b/roles/network_plugin/calico/tasks/main.yml index 3889e801c..873a4698b 100644 --- a/roles/network_plugin/calico/tasks/main.yml +++ b/roles/network_plugin/calico/tasks/main.yml @@ -81,6 +81,8 @@ - name: Calico | wait for etcd uri: url: https://localhost:2379/health + client_cert: "{{ etcd_cert_dir}}/admin-{{ groups['etcd'][0] }}.pem" + client_key: "{{ etcd_cert_dir }}/admin-{{ groups['etcd'][0] }}-key.pem" validate_certs: no register: result until: result.status == 200 or result.status == 401