2017-09-26 09:38:58 +00:00
|
|
|
---
|
2017-10-02 12:14:50 +00:00
|
|
|
- name: Rotate Tokens | Get default token name
|
|
|
|
shell: "{{ bin_dir }}/kubectl get secrets -o custom-columns=name:{.metadata.name} --no-headers | grep -m1 default-token"
|
|
|
|
register: default_token
|
2017-11-06 13:51:07 +00:00
|
|
|
changed_when: false
|
2017-10-02 12:14:50 +00:00
|
|
|
|
|
|
|
- name: Rotate Tokens | Get default token data
|
|
|
|
command: "{{ bin_dir }}/kubectl get secrets {{ default_token.stdout }} -ojson"
|
|
|
|
register: default_token_data
|
2017-11-06 13:51:07 +00:00
|
|
|
changed_when: false
|
2017-10-02 12:14:50 +00:00
|
|
|
|
2017-09-27 13:49:20 +00:00
|
|
|
- name: Rotate Tokens | Test if default certificate is expired
|
2017-10-02 12:14:50 +00:00
|
|
|
uri:
|
|
|
|
url: https://{{ kube_apiserver_ip }}/api/v1/nodes
|
|
|
|
method: GET
|
|
|
|
return_content: no
|
|
|
|
validate_certs: no
|
|
|
|
headers:
|
|
|
|
Authorization: "Bearer {{ (default_token_data.stdout|from_json)['data']['token']|b64decode }}"
|
2017-09-27 13:49:20 +00:00
|
|
|
register: check_secret
|
2017-10-02 12:14:50 +00:00
|
|
|
failed_when: false
|
2017-09-27 13:49:20 +00:00
|
|
|
|
|
|
|
- name: Rotate Tokens | Determine if certificate is expired
|
|
|
|
set_fact:
|
2017-10-02 12:14:50 +00:00
|
|
|
needs_rotation: '{{ check_secret.status not in [200, 403] }}'
|
2017-09-27 13:49:20 +00:00
|
|
|
|
2017-09-27 13:47:47 +00:00
|
|
|
# FIXME(mattymo): Exclude built in secrets that were automatically rotated,
|
|
|
|
# instead of filtering manually
|
2017-09-26 09:38:58 +00:00
|
|
|
- name: Rotate Tokens | Get all serviceaccount tokens to expire
|
|
|
|
shell: >-
|
|
|
|
{{ bin_dir }}/kubectl get secrets --all-namespaces
|
|
|
|
-o 'jsonpath={range .items[*]}{"\n"}{.metadata.namespace}{" "}{.metadata.name}{" "}{.type}{end}'
|
|
|
|
| grep kubernetes.io/service-account-token
|
|
|
|
| egrep 'default-token|kube-proxy|kube-dns|dnsmasq|netchecker|weave|calico|canal|flannel|dashboard|cluster-proportional-autoscaler|efk|tiller'
|
|
|
|
register: tokens_to_delete
|
2017-09-27 13:49:20 +00:00
|
|
|
when: needs_rotation
|
2017-09-26 09:38:58 +00:00
|
|
|
|
|
|
|
- name: Rotate Tokens | Delete expired tokens
|
|
|
|
command: "{{ bin_dir }}/kubectl delete secrets -n {{ item.split(' ')[0] }} {{ item.split(' ')[1] }}"
|
|
|
|
with_items: "{{ tokens_to_delete.stdout_lines }}"
|
2017-09-27 13:49:20 +00:00
|
|
|
when: needs_rotation
|
2017-09-26 09:38:58 +00:00
|
|
|
|
|
|
|
- name: Rotate Tokens | Delete pods in system namespace
|
|
|
|
command: "{{ bin_dir }}/kubectl delete pods -n {{ system_namespace }} --all"
|
2017-09-27 13:49:20 +00:00
|
|
|
when: needs_rotation
|