Browse Source
Merge pull request #140 from kubespray/secret_from_localhost
Merge pull request #140 from kubespray/secret_from_localhost
generate secrets on deployment machinepull/142/head
Antoine Legrand
8 years ago
19 changed files with 157 additions and 185 deletions
Split View
Diff Options
-
27.travis.yml
-
2README.md
-
31roles/kubernetes/master/tasks/gen_kube_tokens.yml
-
34roles/kubernetes/master/tasks/main.yml
-
3roles/kubernetes/node/meta/main.yml
-
28roles/kubernetes/node/tasks/gen_certs.yml
-
6roles/kubernetes/node/tasks/main.yml
-
50roles/kubernetes/node/tasks/secrets.yml
-
1roles/kubernetes/preinstall/defaults/main.yml
-
0roles/kubernetes/secrets/files/certs/.gitkeep
-
0roles/kubernetes/secrets/files/tokens/.gitkeep
-
4roles/kubernetes/secrets/handlers/main.yml
-
0roles/kubernetes/secrets/scripts/kube-gen-token.sh
-
33roles/kubernetes/secrets/scripts/make-ssl.sh
-
51roles/kubernetes/secrets/tasks/gen_certs.yml
-
30roles/kubernetes/secrets/tasks/gen_tokens.yml
-
41roles/kubernetes/secrets/tasks/main.yml
-
0roles/kubernetes/secrets/templates/openssl.conf.j2
-
1roles/network_plugin/calico/handlers/main.yml
@ -1,31 +0,0 @@ |
|||
--- |
|||
- name: tokens | copy the token gen script |
|||
copy: |
|||
src=kube-gen-token.sh |
|||
dest={{ kube_script_dir }} |
|||
mode=u+x |
|||
when: inventory_hostname == groups['kube-master'][0] |
|||
|
|||
- name: tokens | generate tokens for master components |
|||
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}" |
|||
environment: |
|||
TOKEN_DIR: "{{ kube_token_dir }}" |
|||
with_nested: |
|||
- [ "system:kubectl" ] |
|||
- "{{ groups['kube-master'] }}" |
|||
register: gentoken_master |
|||
changed_when: "'Added' in gentoken_master.stdout" |
|||
when: inventory_hostname == groups['kube-master'][0] |
|||
notify: restart kube-apiserver |
|||
|
|||
- name: tokens | generate tokens for node components |
|||
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}" |
|||
environment: |
|||
TOKEN_DIR: "{{ kube_token_dir }}" |
|||
with_nested: |
|||
- [ 'system:kubelet' ] |
|||
- "{{ groups['kube-node'] }}" |
|||
register: gentoken_node |
|||
changed_when: "'Added' in gentoken_node.stdout" |
|||
when: inventory_hostname == groups['kube-master'][0] |
|||
notify: restart kube-apiserver |
@ -0,0 +1,3 @@ |
|||
--- |
|||
dependencies: |
|||
- role: kubernetes/secrets |
@ -1,28 +0,0 @@ |
|||
--- |
|||
- name: certs | install cert generation script |
|||
copy: |
|||
src=make-ssl.sh |
|||
dest={{ kube_script_dir }} |
|||
mode=0500 |
|||
changed_when: false |
|||
|
|||
- name: certs | write openssl config |
|||
template: |
|||
src: "openssl.conf.j2" |
|||
dest: "{{ kube_config_dir }}/.openssl.conf" |
|||
|
|||
- name: certs | run cert generation script |
|||
shell: > |
|||
{{ kube_script_dir }}/make-ssl.sh |
|||
-f {{ kube_config_dir }}/.openssl.conf |
|||
-g {{ kube_cert_group }} |
|||
-d {{ kube_cert_dir }} |
|||
args: |
|||
creates: "{{ kube_cert_dir }}/apiserver.pem" |
|||
|
|||
- name: certs | check certificate permissions |
|||
file: |
|||
path={{ kube_cert_dir }} |
|||
group={{ kube_cert_group }} |
|||
owner=kube |
|||
recurse=yes |
@ -1,50 +0,0 @@ |
|||
--- |
|||
- name: Secrets | certs | make sure the certificate directory exits |
|||
file: |
|||
path={{ kube_cert_dir }} |
|||
state=directory |
|||
mode=o-rwx |
|||
group={{ kube_cert_group }} |
|||
|
|||
- name: Secrets | tokens | make sure the tokens directory exits |
|||
file: |
|||
path={{ kube_token_dir }} |
|||
state=directory |
|||
mode=o-rwx |
|||
group={{ kube_cert_group }} |
|||
|
|||
- include: gen_certs.yml |
|||
when: inventory_hostname == groups['kube-master'][0] |
|||
|
|||
# Sync certs between nodes |
|||
- name: Secrets | create user |
|||
user: |
|||
name: '{{ansible_user_id}}' |
|||
generate_ssh_key: yes |
|||
delegate_to: "{{ groups['kube-master'][0] }}" |
|||
run_once: yes |
|||
|
|||
- name: Secrets | 'get ssh keypair' |
|||
slurp: path=~/.ssh/id_rsa.pub |
|||
register: public_key |
|||
delegate_to: "{{ groups['kube-master'][0] }}" |
|||
|
|||
- name: Secrets | 'setup keypair on nodes' |
|||
authorized_key: |
|||
user: '{{ansible_user_id}}' |
|||
key: "{{public_key.content|b64decode }}" |
|||
|
|||
- name: Secrets | synchronize certificates for nodes |
|||
synchronize: |
|||
src: "{{ item }}" |
|||
dest: "{{ kube_cert_dir }}" |
|||
recursive: yes |
|||
delete: yes |
|||
rsync_opts: [ '--one-file-system'] |
|||
set_remote_user: false |
|||
with_items: |
|||
- "{{ kube_cert_dir}}/ca.pem" |
|||
- "{{ kube_cert_dir}}/node.pem" |
|||
- "{{ kube_cert_dir}}/node-key.pem" |
|||
delegate_to: "{{ groups['kube-master'][0] }}" |
|||
when: inventory_hostname not in "{{ groups['kube-master'] }}" |
@ -0,0 +1,4 @@ |
|||
--- |
|||
- name: set secret_changed |
|||
set_fact: |
|||
secret_changed: true |
@ -0,0 +1,51 @@ |
|||
--- |
|||
- name: certs | write openssl config |
|||
sudo: False |
|||
local_action: template src="openssl.conf.j2" dest="{{ role_path }}/files/openssl.conf" |
|||
run_once: yes |
|||
|
|||
- name: certs | run cert generation script |
|||
sudo: False |
|||
local_action: shell |
|||
{{ role_path }}/scripts/make-ssl.sh |
|||
-f {{ role_path }}/files/openssl.conf |
|||
-d {{ role_path }}/files/certs/ |
|||
run_once: yes |
|||
|
|||
- name: certs | Copy certs on nodes |
|||
copy: |
|||
src: "certs/{{ item }}" |
|||
dest: "{{ kube_cert_dir }}" |
|||
with_items: |
|||
- ca.pem |
|||
- node.pem |
|||
- node-key.pem |
|||
when: inventory_hostname in "{{ groups['k8s-cluster'] }}" |
|||
|
|||
- name: certs | Copy certs on master |
|||
copy: |
|||
src: "certs/{{ item }}" |
|||
dest: "{{ kube_cert_dir }}" |
|||
with_items: |
|||
- ca-key.pem |
|||
- admin.pem |
|||
- admin-key.pem |
|||
- apiserver-key.pem |
|||
- apiserver.pem |
|||
when: inventory_hostname in "{{ groups['kube-master'] }}" |
|||
|
|||
- name: certs | check certificate permissions |
|||
file: |
|||
path={{ kube_cert_dir }} |
|||
group={{ kube_cert_group }} |
|||
owner=kube |
|||
recurse=yes |
|||
|
|||
- shell: ls {{ kube_cert_dir}}/*key.pem |
|||
register: keyfiles |
|||
|
|||
- name: certs | set permissions on keys |
|||
file: |
|||
path: "{{ item }}" |
|||
mode: 0600 |
|||
with_items: keyfiles.stdout_lines |
@ -0,0 +1,30 @@ |
|||
--- |
|||
- name: tokens | generate tokens for master components |
|||
sudo: False |
|||
local_action: command "{{ role_path }}/scripts/kube-gen-token.sh" "{{ item[0] }}-{{ item[1] }}" |
|||
environment: |
|||
TOKEN_DIR: "{{ role_path }}/files/tokens" |
|||
with_nested: |
|||
- [ "system:kubectl" ] |
|||
- "{{ groups['kube-master'] }}" |
|||
register: gentoken_master |
|||
changed_when: "'Added' in gentoken_master.stdout" |
|||
notify: set secret_changed |
|||
|
|||
- name: tokens | generate tokens for node components |
|||
sudo: False |
|||
local_action: command "{{ role_path }}/scripts/kube-gen-token.sh" "{{ item[0] }}-{{ item[1] }}" |
|||
environment: |
|||
TOKEN_DIR: "{{ role_path }}/files/tokens" |
|||
with_nested: |
|||
- [ 'system:kubelet' ] |
|||
- "{{ groups['kube-node'] }}" |
|||
register: gentoken_node |
|||
changed_when: "'Added' in gentoken_node.stdout" |
|||
notify: set secret_changed |
|||
|
|||
- name: tokens | Copy tokens on master |
|||
copy: |
|||
src: "tokens" |
|||
dest: "/etc/kubernetes" |
|||
when: inventory_hostname in "{{ groups['kube-master'] }}" |
@ -0,0 +1,41 @@ |
|||
--- |
|||
- name: Make sure the certificate directory exits |
|||
file: |
|||
path={{ kube_cert_dir }} |
|||
state=directory |
|||
mode=o-rwx |
|||
group={{ kube_cert_group }} |
|||
|
|||
- name: Make sure the tokens directory exits |
|||
file: |
|||
path={{ kube_token_dir }} |
|||
state=directory |
|||
mode=o-rwx |
|||
group={{ kube_cert_group }} |
|||
|
|||
- name: Make sure the users directory exits |
|||
file: |
|||
path={{ kube_users_dir }} |
|||
state=directory |
|||
mode=o-rwx |
|||
group={{ kube_cert_group }} |
|||
|
|||
- name: Populate users for basic auth in API |
|||
lineinfile: |
|||
dest: "{{ kube_users_dir }}/known_users.csv" |
|||
create: yes |
|||
line: '{{ item.value.pass }},{{ item.key }},{{ item.value.role }}' |
|||
backup: yes |
|||
with_dict: "{{ kube_users }}" |
|||
when: inventory_hostname in "{{ groups['kube-master'] }}" |
|||
notify: set secret_changed |
|||
|
|||
- name: Check if a certificate already exists |
|||
stat: |
|||
path: "{{ kube_cert_dir }}/ca.pem" |
|||
register: kubecert |
|||
|
|||
- include: gen_certs.yml |
|||
when: not kubecert.stat.exists |
|||
|
|||
- include: gen_tokens.yml |
Write
Preview
Loading…
Cancel
Save