-
Notifications
You must be signed in to change notification settings - Fork 23
Add rekey playbook #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add rekey playbook #796
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e9b0477
Add rekey-hosts.yml playbook
Alex-Welsh c527579
Rekey playbook misc improvements
Alex-Welsh 0123c1f
Change rekey playbook to use existing ssh vars
Alex-Welsh 6931e1c
Rework rekey-hosts.yml playbook
Alex-Welsh 14caeb4
rekey-host.yml remove-key tag
Alex-Welsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
--- | ||
# Playbook to rotate SSH keys across the cloud. By default it will rotate the | ||
# standard keys used by kayobe/kolla-ansible, but it can be configured for any | ||
# keys. | ||
|
||
- name: Rekey hosts | ||
hosts: overcloud,seed,seed-hypervisor,infra-vms | ||
gather_facts: false | ||
vars: | ||
# The existing key is the key that is currently used to access overcloud hosts | ||
existing_private_key_path: "{{ ssh_private_key_path }}" | ||
existing_public_key_path: "{{ ssh_public_key_path }}" | ||
# The new key is the key that will be generated by this playbook | ||
new_private_key_path: "{{ ssh_private_key_path }}" | ||
new_public_key_path: "{{ ssh_public_key_path }}" | ||
new_key_type: "{{ ssh_key_type }}" | ||
# The existing key will locally be moved to deprecated_key_path once it is replaced | ||
deprecated_key_path: ~/old_ssh_key | ||
rekey_users: | ||
- stack | ||
- kolla | ||
rekey_remove_existing_key: false | ||
tasks: | ||
- name: Stat existing private key file | ||
ansible.builtin.stat: | ||
path: "{{ existing_private_key_path }}" | ||
register: stat_result | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Fail when existing private key does not exist | ||
ansible.builtin.fail: | ||
msg: "No existing private key file found. Check existing_private_key_path is set correctly." | ||
when: | ||
- not stat_result.stat.exists | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Stat existing public key file | ||
ansible.builtin.stat: | ||
path: "{{ existing_public_key_path }}" | ||
register: stat_result | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Fail when existing public key does not exist | ||
ansible.builtin.fail: | ||
msg: "No existing public key file found. Check existing_public_key_path is set correctly." | ||
when: | ||
- not stat_result.stat.exists | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Generate a new SSH key | ||
community.crypto.openssh_keypair: | ||
path: "{{ existing_private_key_path }}_new" | ||
type: "{{ new_key_type }}" | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Set new authorized keys | ||
vars: | ||
lookup_path: "{{ existing_private_key_path }}_new.pub" | ||
ansible.posix.authorized_key: | ||
user: "{{ item }}" | ||
state: present | ||
key: "{{ lookup('file', lookup_path) }}" | ||
loop: "{{ rekey_users }}" | ||
become: true | ||
|
||
- name: Locally deprecate existing key (private) | ||
command: "mv {{ existing_private_key_path }} {{ deprecated_key_path }}" | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Locally deprecate existing key (public) | ||
command: "mv {{ existing_public_key_path }} {{ deprecated_key_path }}.pub" | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Locally promote new key (private) | ||
command: "mv {{ existing_private_key_path }}_new {{ new_private_key_path }}" | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Locally promote new key (public) | ||
command: "mv {{ existing_private_key_path }}_new.pub {{ new_public_key_path }}" | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- block: | ||
- name: Stat old key file | ||
ansible.builtin.stat: | ||
path: "{{ deprecated_key_path }}.pub" | ||
register: stat_result | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Fail when deprecated public key does not exist | ||
ansible.builtin.fail: | ||
msg: "No deprecated public key file found. Check deprecated_key_path is set correctly." | ||
when: | ||
- not stat_result.stat.exists | ||
delegate_to: localhost | ||
run_once: true | ||
|
||
- name: Remove old key from hosts | ||
vars: | ||
lookup_path: "{{ deprecated_key_path }}.pub" | ||
ansible.posix.authorized_key: | ||
user: "{{ item }}" | ||
state: absent | ||
key: "{{ lookup('file', lookup_path) }}" | ||
loop: "{{ rekey_users }}" | ||
become: true | ||
tags: remove-key | ||
when: rekey_remove_existing_key | bool | ||
markgoddard marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
features: | ||
- | | ||
Added the ``rekey-hosts.yml`` playbook to automatically rotate the SSH | ||
keys on all hosts. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.