Debian Codegraph @

test/integration/targets/become_su/tasks/main.yml

raw
1 - name: create unprivileged user pair
2 include_role:
3 name: setup_become_user_pair
4 public: true # this exports target_user_name, target_user_password, intermediate_user_name
5 vars:
6 intermediate_user_groups: "{{ 'staff,admin' if ansible_os_family == 'Darwin' else omit }}" # this works, but requires a TTY; disabled MacOS su testing in CI for now via aliases
7
8 - name: deploy su shim
9 copy:
10 src: sushim.sh
11 dest: /tmp/sushim.sh
12 mode: a+rx
13
14 - name: ensure su is setuid on Alpine
15 file:
16 path: /bin/su
17 mode: +s
18 when: ansible_os_family == 'Alpine'
19
20 - name: test su scenarios where a password prompt must be encountered
21 vars:
22 ansible_become: yes
23 ansible_become_method: su
24 ansible_become_exe: /tmp/sushim.sh
25 ansible_become_flags: --intermediate-user {{ intermediate_user_name | quote }} # the default plugin flags are empty
26 ansible_become_user: "{{ target_user_name }}"
27 ansible_become_password: "{{ target_user_password }}"
28 block:
29 - name: basic success check
30 raw: whoami
31 register: success
32 # NOTE: The ssh connection plugin does not properly strip noise from raw stdout, unlike the local connection plugin.
33 # Once that is fixed, this can be changed to a comparison against stdout, not stdout_lines[-1].
34 failed_when: success.stdout_lines[-1] != target_user_name
35
36 - name: validate that a password prompt is being used
37 vars:
38 ansible_become_password: BOGUSPASS
39 raw: exit 99
40 ignore_errors: yes
41 register: bogus_password
42
43 - assert:
44 that:
45 - | # account for different failure behavior between local and ssh
46 bogus_password.msg is contains "Incorrect su password" or
47 bogus_password.msg is contains "Premature end of stream waiting for become success." or
48 (bogus_password.stdout | default('')) is contains "Sorry"
49
50 - name: test wrong su prompt expected
51 raw: echo hi mom from $(whoami)
52 register: wrong_su_prompt
53 vars:
54 ansible_su_prompt_l10n: NOT_A_VALID_PROMPT
55 ansible_local_become_success_timeout: 3 # actual become success timeout
56 ansible_ssh_timeout: 3 # connection timeout, which results in an N+2 second select timeout
57 ignore_unreachable: yes
58
59 - assert:
60 that:
61 - wrong_su_prompt is unreachable
62 - ansible_connection != "local" or wrong_su_prompt.msg is contains "Timed out waiting for become success or become password prompt"
63 - ansible_connection != "ssh" or wrong_su_prompt.msg is contains "waiting for privilege escalation prompt"
64
65 # The bug from issue https://github.com/ansible/ansible/issues/86458 presents itself only on local connections
66 # and only when the password is entered interactively using -K/--ask-become-pass.
67 - name: Test different locale
68 when: ansible_os_family == 'RedHat' and ansible_connection == 'local'
69 block:
70 - import_role:
71 name: setup_pexpect
72
73 - name: install language pack and pexpect
74 dnf:
75 name:
76 - langpacks-uk
77 - glibc-langpack-uk
78 state: present
79
80 - name: verify language pack is enabled
81 command: locale -a
82 register: installed_languages
83
84 - assert:
85 that: "'uk_UA.utf8' in installed_languages.stdout"
86
87 - name: test su prompt basic success with alternate language on local connection
88 expect:
89 command: "ansible -m command -a whoami localhost -b --become-method su -K"
90 responses:
91 BECOME password:
92 - "{{ target_user_password }}"
93 environment:
94 LC_ALL: uk_UA.utf8
95 ANSIBLE_BECOME_USER: "{{ target_user_name }}"
96 ANSIBLE_BECOME_EXE: /tmp/sushim.sh
97 ANSIBLE_BECOME_FLAGS: --intermediate-user {{ intermediate_user_name | quote }}
98 # protect our target user password
99 no_log: true
100 always:
101 - name: remove language pack
102 dnf:
103 name:
104 - langpacks-uk
105 - glibc-langpack-uk
106 state: absent