Fix upgrades for certs from non-rbac to rbac

This commit is contained in:
Matthew Mosesohn 2017-08-17 10:34:40 +03:00
parent 270af1f718
commit 20652eb8ad
3 changed files with 52 additions and 12 deletions

View file

@ -80,7 +80,9 @@ gen_key_and_cert() {
openssl x509 -req -in ${name}.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out ${name}.pem -days 3650 -extensions v3_req -extfile ${CONFIG} > /dev/null 2>&1 openssl x509 -req -in ${name}.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out ${name}.pem -days 3650 -extensions v3_req -extfile ${CONFIG} > /dev/null 2>&1
} }
if [ ! -e "$SSLDIR/ca-key.pem" ]; then # Admins
if [ -n "$MASTERS" ]; then
# If any host requires new certs, just regenerate all master certs
# kube-apiserver # kube-apiserver
gen_key_and_cert "apiserver" "/CN=kube-apiserver" gen_key_and_cert "apiserver" "/CN=kube-apiserver"
cat ca.pem >> apiserver.pem cat ca.pem >> apiserver.pem
@ -88,10 +90,7 @@ if [ ! -e "$SSLDIR/ca-key.pem" ]; then
gen_key_and_cert "kube-scheduler" "/CN=system:kube-scheduler" gen_key_and_cert "kube-scheduler" "/CN=system:kube-scheduler"
# kube-controller-manager # kube-controller-manager
gen_key_and_cert "kube-controller-manager" "/CN=system:kube-controller-manager" gen_key_and_cert "kube-controller-manager" "/CN=system:kube-controller-manager"
fi
# Admins
if [ -n "$MASTERS" ]; then
for host in $MASTERS; do for host in $MASTERS; do
cn="${host%%.*}" cn="${host%%.*}"
# admin # admin

View file

@ -20,7 +20,18 @@
register: kubecert_node register: kubecert_node
with_items: with_items:
- ca.pem - ca.pem
- apiserver.pem
- apiserver-key.pem
- kube-scheduler.pem
- kube-scheduler-key.pem
- kube-controller-manager.pem
- kube-controller-manager-key.pem
- admin-{{ inventory_hostname }}.pem
- admin-{{ inventory_hostname }}-key.pem
- node-{{ inventory_hostname }}.pem
- node-{{ inventory_hostname }}-key.pem - node-{{ inventory_hostname }}-key.pem
- kube-proxy-{{ inventory_hostname }}.pem
- kube-proxy-{{ inventory_hostname }}-key.pem
- name: "Check_certs | Set 'gen_certs' to true" - name: "Check_certs | Set 'gen_certs' to true"
set_fact: set_fact:
@ -29,10 +40,41 @@
run_once: true run_once: true
with_items: >- with_items: >-
['{{ kube_cert_dir }}/ca.pem', ['{{ kube_cert_dir }}/ca.pem',
{% for host in groups['k8s-cluster'] %} '{{ kube_cert_dir }}/apiserver.pem',
'{{ kube_cert_dir }}/node-{{ host }}-key.pem' '{{ kube_cert_dir }}/apiserver-key.pem',
'{{ kube_cert_dir }}/kube-scheduler.pem',
'{{ kube_cert_dir }}/kube-scheduler-key.pem',
'{{ kube_cert_dir }}/kube-controller-manager.pem',
'{{ kube_cert_dir }}/kube-controller-manager-key.pem',
{% for host in groups['kube-master'] %}
'{{ kube_cert_dir }}/admin-{{ host }}.pem'
'{{ kube_cert_dir }}/admin-{{ host }}-key.pem'
{% if not loop.last %}{{','}}{% endif %} {% if not loop.last %}{{','}}{% endif %}
{% endfor %}] {% endfor %}]
{% for host in groups['k8s-cluster'] %}
'{{ kube_cert_dir }}/node-{{ host }}.pem'
'{{ kube_cert_dir }}/node-{{ host }}-key.pem'
'{{ kube_cert_dir }}/kube-proxy-{{ host }}.pem'
'{{ kube_cert_dir }}/kube-proxy-{{ host }}-key.pem'
{% if not loop.last %}{{','}}{% endif %}
{% endfor %}]
- name: "Check_certs | Set 'gen_master_certs' to true"
set_fact:
gen_master_certs: |-
{%- set gen = False -%}
{% set existing_certs = kubecert_master.files|map(attribute='path')|list|sort %}
{% for cert in ['apiserver.pem', 'apiserver-key.pem', 'kube-scheduler.pem',
'kube-scheduler-key.pem', 'kube-controller-manager.pem',
'kube-controller-manager-key.pem'] -%}
{% set cert_file = "%s/%s.pem"|format(kube_cert_dir, cert) %}
{% if not cert_file in existing_certs -%}
{%- set gen = True -%}
{% endif -%}
{% endfor %}
{{ gen }}
run_once: true
- name: "Check_certs | Set 'gen_node_certs' to true" - name: "Check_certs | Set 'gen_node_certs' to true"
set_fact: set_fact:
@ -41,7 +83,8 @@
{% set existing_certs = kubecert_master.files|map(attribute='path')|list|sort %} {% set existing_certs = kubecert_master.files|map(attribute='path')|list|sort %}
{% for host in groups['k8s-cluster'] -%} {% for host in groups['k8s-cluster'] -%}
{% set host_cert = "%s/node-%s-key.pem"|format(kube_cert_dir, host) %} {% set host_cert = "%s/node-%s-key.pem"|format(kube_cert_dir, host) %}
{% if host_cert in existing_certs -%} {% set kube_proxy_cert = "%s/kube-proxy-%s-key.pem"|format(kube_cert_dir, host) %}
{% if host_cert in existing_certs and kube_proxy_cert in existing_certs -%}
"{{ host }}": False, "{{ host }}": False,
{% else -%} {% else -%}
"{{ host }}": True, "{{ host }}": True,
@ -50,7 +93,6 @@
} }
run_once: true run_once: true
- name: "Check_certs | Set 'sync_certs' to true" - name: "Check_certs | Set 'sync_certs' to true"
set_fact: set_fact:
sync_certs: true sync_certs: true
@ -58,8 +100,8 @@
{%- set certs = {'sync': False} -%} {%- set certs = {'sync': False} -%}
{% if gen_node_certs[inventory_hostname] or {% if gen_node_certs[inventory_hostname] or
(not kubecert_node.results[0].stat.exists|default(False)) or (not kubecert_node.results[0].stat.exists|default(False)) or
(not kubecert_node.results[1].stat.exists|default(False)) or (not kubecert_node.results[10].stat.exists|default(False)) or
(kubecert_node.results[1].stat.checksum|default('') != kubecert_master.files|selectattr("path", "equalto", kubecert_node.results[1].stat.path)|map(attribute="checksum")|first|default('')) -%} (kubecert_node.results[10].stat.checksum|default('') != kubecert_master.files|selectattr("path", "equalto", kubecert_node.results[10].stat.path)|map(attribute="checksum")|first|default('')) -%}
{%- set _ = certs.update({'sync': True}) -%} {%- set _ = certs.update({'sync': True}) -%}
{% endif %} {% endif %}
{{ certs.sync }} {{ certs.sync }}

View file

@ -40,7 +40,7 @@
command: "{{ kube_script_dir }}/make-ssl.sh -f {{ kube_config_dir }}/openssl.conf -d {{ kube_cert_dir }}" command: "{{ kube_script_dir }}/make-ssl.sh -f {{ kube_config_dir }}/openssl.conf -d {{ kube_cert_dir }}"
environment: environment:
- MASTERS: "{% for m in groups['kube-master'] %} - MASTERS: "{% for m in groups['kube-master'] %}
{% if gen_node_certs[m]|default(false) %} {% if gen_master_certs|default(false) %}
{{ m }} {{ m }}
{% endif %} {% endif %}
{% endfor %}" {% endfor %}"
@ -72,7 +72,6 @@
'apiserver.pem', 'apiserver.pem',
'apiserver-key.pem', 'apiserver-key.pem',
'kube-scheduler.pem', 'kube-scheduler.pem',
'kube-scheduler-key.pem',
'kube-controller-manager.pem', 'kube-controller-manager.pem',
'kube-controller-manager-key.pem', 'kube-controller-manager-key.pem',
] ]