-
Notifications
You must be signed in to change notification settings - Fork 34
Generate and persist hostkeys for ondemand and login nodes #525
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a1e5bd7
Reworked persist_hostkeys role to use common set of persistent keys f…
wtripp180901 fa028f9
removed unnescessary caas config
wtripp180901 001c459
updated docs
wtripp180901 4652c34
typo
wtripp180901 f021167
comment update
wtripp180901 895f302
Merge branch 'main' into feat/hostkey-secrets
wtripp180901 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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
# persist_hostkeys | ||
|
||
Save hostkeys to persistent storage and restore them after a rebuild/reimage. | ||
Idempotently generates a persistent set of hostkeys and restores them after a rebuild/reimage. | ||
|
||
Add hosts to the `persist_hostkeys` group to enable. | ||
|
||
This role has no variables but hosts in this group must have `appliances_state_dir` | ||
defined as a directory they can write to on persistent storage. | ||
Add hosts to the `persist_hostkeys` group to enable. All hosts in group will share the same set hostkeys. |
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,2 @@ | ||
persist_hostkeys_state_server: "{{ groups['control'] | first }}" | ||
persist_hostkeys_state_dir: "{{ hostvars[persist_hostkeys_state_server]['appliances_state_dir'] }}/hostkeys" |
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 |
---|---|---|
@@ -1,33 +1,46 @@ | ||
--- | ||
|
||
- name: Ensure hostkeys directory exists on persistent storage | ||
file: | ||
path: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: 0600 | ||
- name: Generate persistent hostkeys in state directory | ||
delegate_to: "{{ persist_hostkeys_state_server }}" | ||
block: | ||
- name: Ensure hostkeys directory exists on persistent storage | ||
file: | ||
path: "{{ persist_hostkeys_state_dir }}" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: 0600 | ||
|
||
- name: Copy hostkeys from persistent storage | ||
# won't fail if no keys are in persistent storage | ||
copy: | ||
src: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}/" | ||
dest: /etc/ssh/ | ||
remote_src: true | ||
- name: Check for existing hostkeys | ||
find: | ||
paths: "{{ persist_hostkeys_state_dir }}/" | ||
register: _files_found | ||
|
||
- name: Generate hostkeys | ||
when: _files_found.matched == 0 | ||
shell: | ||
cmd: | | ||
mkdir -p {{ persist_hostkeys_state_dir }}/etc/ssh | ||
ssh-keygen -A -N \"\" -f {{ persist_hostkeys_state_dir }} | ||
wtripp180901 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mv {{ persist_hostkeys_state_dir }}/etc/ssh/* {{ persist_hostkeys_state_dir }} | ||
rm -rf {{ persist_hostkeys_state_dir }}/etc/ssh | ||
|
||
- name: Get created key names | ||
find: | ||
path: "{{ persist_hostkeys_state_dir }}/" | ||
register: _find_ssh_keys | ||
|
||
- name: Find hostkeys | ||
find: | ||
path: /etc/ssh/ | ||
patterns: ssh_host_*_key* | ||
register: _find_ssh_keys | ||
- name: Create in-memory copies of keys | ||
ansible.builtin.slurp: | ||
src: "{{ item.path }}" | ||
loop: "{{ _find_ssh_keys.files }}" | ||
register: _slurp_keys | ||
|
||
- name: Persist hostkeys | ||
- name: Copy keys to hosts | ||
no_log: true | ||
copy: | ||
dest: "{{ appliances_state_dir }}/hostkeys/{{ inventory_hostname }}/" | ||
src: "{{ item }}" | ||
remote_src: true | ||
mode: preserve | ||
loop: "{{ _find_ssh_keys.files | map(attribute='path') }}" | ||
content: "{{ item.content | b64decode }}" | ||
dest: "/etc/ssh/{{ item.source | regex_search('[^/]+$') }}" | ||
loop: "{{ _slurp_keys.results }}" | ||
|
||
- meta: reset_connection | ||
|
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
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 |
---|---|---|
|
@@ -14,6 +14,3 @@ compute | |
|
||
[podman:children] | ||
zenith | ||
|
||
[persist_hostkeys:children] | ||
openondemand |
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
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
Oops, something went wrong.
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.