Skip to content
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

Support follow parameter for authorized_keys #19

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible/roles/authorized_keys/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
comment: '{{ item.comment | d(omit) }}'
path: '{{ item.path | d(omit) }}'
exclusive: '{{ item.exclusive | d(omit) }}'
follow: '{{ item.follow | d(omit) }}'
loop: '{{ lookup("template", "lookup/authorized_keys__identities.j2") | from_yaml }}'
loop_control:
label: '{{ {"identity": item.identity,
Expand Down
6 changes: 6 additions & 0 deletions ansible/roles/root_account/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ root_account__combined_authorized_keys: '{{ root_account__authorized_keys
# to the existing keys on the ``root`` account.
root_account__authorized_keys_exclusive: False

# ]]]
# .. envvar:: root_account__authorized_keys_follow [[[
#
# If ``True``, follow symlinks instead of replacing the file.
root_account__authorized_keys_follow: False

# ]]]
# .. envvar:: root_account__authorized_keys_state [[[
#
Expand Down
4 changes: 2 additions & 2 deletions ansible/roles/root_account/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
exclusive: '{{ root_account__authorized_keys_exclusive|bool }}'
state: 'present'
user: 'root'
when: root_account__enabled|bool and root_account__combined_authorized_keys|d() and
root_account__authorized_keys_state != 'absent'
follow: '{{ root_account__authorized_keys_follow | bool }}'
when: root_account__enabled|bool and root_account__authorized_keys_state != 'absent'
urscale marked this conversation as resolved.
Show resolved Hide resolved

- name: Remove /root/.ssh/authorized_keys file if requested
file:
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/system_users/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
state: 'present'
user: '{{ (item.prefix | d(system_users__prefix)) + item.name }}'
exclusive: '{{ item.sshkeys_exclusive | d(omit) }}'
follow: '{{ item.sshkeys_follow | d(omit) }}'
loop: '{{ system_users__combined_accounts | debops.debops.parse_kv_items }}'
loop_control:
label: '{{ {"name": (item.prefix | d(system_users__prefix)) + item.name,
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/users/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
state: 'present'
user: '{{ item.name }}'
exclusive: '{{ item.sshkeys_exclusive | d(omit) }}'
follow: '{{ item.sshkeys_follow | d(omit) }}'
loop: '{{ users__combined_accounts | debops.debops.parse_kv_items }}'
loop_control:
label: '{{ {"name": item.name,
Expand Down
4 changes: 4 additions & 0 deletions docs/ansible/roles/authorized_keys/defaults-detailed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ Each list entry is a YAML dictionary with specific parameters:
this option can break idempotency if multiple entries with the same
``name`` parameter are used.

``follow``
Optional, boolean. If defined and ``True``, the role will follow symlinks to
the :file:`authorized_keys` file instead of replacing them.

``home``
Optional, boolean. If not specified or ``False``, the SSH keys will be
managed in the :file:`/etc/ssh/authorized_keys/` directory, with custom
Expand Down
4 changes: 4 additions & 0 deletions docs/ansible/roles/system_users/defaults-detailed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ Parameters related to public SSH keys
``~/.ssh/authorized_keys`` file that are not specified in the ``sshkeys``
parameter.

``sshkeys_follow``
Optional, boolean. If ``True``, the role will follow symlinks to the user's
``~/.ssh/authorized_keys`` file instead of replacing them.

``sshkeys_state``
Optional. If not specified or ``present``, the SSH keys will be set on the
user's account. If ``absent``, the ``~/.ssh/authorized_keys`` file will be
Expand Down
4 changes: 4 additions & 0 deletions docs/ansible/roles/users/defaults-detailed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ Parameters related to public SSH keys
``~/.ssh/authorized_keys`` file that are not specified in the ``sshkeys``
parameter.

``sshkeys_follow``
Optional, boolean. If ``True``, the role will follow symlinks to the user's
``~/.ssh/authorized_keys`` file instead of replacing them.

``sshkeys_state``
Optional. If not specified or ``present``, the SSH keys will be set on the
user's account. If ``absent``, the ``~/.ssh/authorized_keys`` file will be
Expand Down
Loading