File tree 7 files changed +85
-3
lines changed
7 files changed +85
-3
lines changed Original file line number Diff line number Diff line change @@ -13,12 +13,14 @@ Release Summary
13
13
14
14
| Release Date: 2023-03-09
15
15
| Initial release of the password_prompt role
16
+ | Initial release of the sudo_by_ssh_agent role
16
17
17
18
18
19
Major Changes
19
20
-------------
20
21
21
22
- prompt_password - initial commit
23
+ - sudo_by_ssh_agent - initial commit
22
24
23
25
v1.0.2
24
26
======
Original file line number Diff line number Diff line change @@ -11,11 +11,15 @@ This Ansible collection contains roles for general use.
11
11
Roles:
12
12
13
13
- ` huyz.general.add_to_config_file ` ([ README] ( https://github.com/huyz/ansible-collection-huyz-general/blob/master/roles/add_to_config_file/README.md ) )
14
- - Function: Safely insert a block into one or more shell config files
15
- - Use case: Mainly intended to be re-used by other roles
14
+ - Function: Safely insert a block into one or more shell config files.
15
+ - Use case: Mainly intended to be re-used by other roles.
16
16
- ` huyz.general.prompt_password ` ([ README] ( https://github.com/huyz/ansible-collection-huyz-general/blob/master/roles/prompt_password/README.md ) )
17
17
- Function: Prompts for the ` ansible_password ` if not defined.
18
- - Use case: Avoid the need to call ` ansible-playbook ` with ` --ask-pass ` and ` --ask-become-pass `
18
+ - Use case: Avoid the need to call ` ansible-playbook ` with ` --ask-pass ` and ` --ask-become-pass ` .
19
+ - ` huyz.general.sudo_by_ssh_agent ` ([ README] ( https://github.com/huyz/ansible-collection-huyz-general/blob/master/roles/sudo_by_ssh_agent/README.md ) )
20
+ - Function: Configures sudo to use the ` libpam-ssh-agent-auth ` package and
21
+ authorize the provided ssh key.
22
+ - Use case: Avoid the need to authenticate with a password to run privileged commands.
19
23
20
24
---
21
25
Original file line number Diff line number Diff line change @@ -17,12 +17,16 @@ releases:
17
17
changes :
18
18
major_changes :
19
19
- prompt_password - initial commit
20
+ - sudo_by_ssh_agent - initial commit
20
21
release_summary : ' | Release Date: 2023-03-09
21
22
22
23
| Initial release of the password_prompt role
23
24
25
+ | Initial release of the sudo_by_ssh_agent role
26
+
24
27
'
25
28
fragments :
26
29
- 2023-03-09_prompt_password.yml
30
+ - 2023-03-09_sudo_by_ssh_agent.yml
27
31
- 2023-03-09_v1.0.3_summary.yml
28
32
release_date : ' 2023-03-09'
Original file line number Diff line number Diff line change
1
+ major_changes :
2
+ - sudo_by_ssh_agent - initial commit
Original file line number Diff line number Diff line change 1
1
release_summary : |
2
2
| Release Date: 2023-03-09
3
3
| Initial release of the password_prompt role
4
+ | Initial release of the sudo_by_ssh_agent role
Original file line number Diff line number Diff line change
1
+ # Ansible role: huyz.general.sudo_by_ssh_agent
2
+
3
+ Configures sudo to use the ` libpam-ssh-agent-auth ` package and authorize the
4
+ provided ssh key.
5
+
6
+ ## Installation
7
+
8
+ This repo uses the FQCN convention.
9
+
10
+ Include the collection in the Ansible Galaxy ` requirements.yml ` :
11
+
12
+ ``` shell
13
+ ---
14
+ collections:
15
+ - name: huyz.general
16
+ ```
17
+
18
+ You can then include the role ` huyz.general.sudo_by_ssh_agent ` .
19
+
20
+ ## Example
21
+
22
+ ``` yaml
23
+ - name : Authorize sudo by ssh agent
24
+ ansible.builtin.include_role :
25
+ name : huyz.general.sudo_by_ssh_agent
26
+ vars :
27
+ pub_files_for_sudo : ['~/.ssh/id_ed25519-vip.pub']
28
+ ` ` `
Original file line number Diff line number Diff line change
1
+ # Requires vars:
2
+ # - pub_files_for_sudo: list of full path of the public keys to use for sudo
3
+ ---
4
+ - name : Ensure libpam-ssh-agent-auth package
5
+ ansible.builtin.package :
6
+ name : libpam-ssh-agent-auth
7
+ become : true
8
+
9
+ - name : Add to sudo authorized_keys the content of {{ pub_files_for_sudo }}
10
+ ansible.posix.authorized_key :
11
+ user : root # dummy
12
+ key : " {{ lookup('file', item) }}"
13
+ path : /etc/security/authorized_keys
14
+ manage_dir : false
15
+ become : true
16
+ loop : " {{ pub_files_for_sudo }}"
17
+
18
+ # Per https://www.lorier.net/docs/ssh-agent-sudo.html
19
+ - name : Enable pam_ssh_agent_auth for sudo
20
+ ansible.builtin.blockinfile :
21
+ dest : /etc/pam.d/sudo
22
+ marker : " # {mark} ANSIBLE MANAGED BLOCK: {{ block_id }}"
23
+ insertbefore : " @include common-auth"
24
+ block : |
25
+ # Allow sudo by ssh agent
26
+ auth sufficient pam_ssh_agent_auth.so file=/etc/security/authorized_keys
27
+ vars :
28
+ block_id : sudo_by_ssh_agent
29
+ become : true
30
+
31
+ # Per https://www.lorier.net/docs/ssh-agent-sudo.html
32
+ - name : Preserve SSH_AUTH_SOCK for sudo
33
+ ansible.builtin.blockinfile :
34
+ dest : /etc/sudoers
35
+ marker : " # {mark} ANSIBLE MANAGED BLOCK: {{ block_id }}"
36
+ insertafter : ' #Defaults:%sudo env_keep \+= "SSH_AGENT_PID SSH_AUTH_SOCK"'
37
+ block : |
38
+ Defaults:%sudo env_keep += "SSH_AGENT_PID SSH_AUTH_SOCK"
39
+ vars :
40
+ block_id : sudo_by_ssh_agent
41
+ become : true
You can’t perform that action at this time.
0 commit comments