Skip to content

Commit 326504b

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Support running without root privileges"
2 parents b4733da + 7fd3f6b commit 326504b

File tree

12 files changed

+138
-25
lines changed

12 files changed

+138
-25
lines changed

ansible/inventory/group_vars/all/globals

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ kayobe_ansible_setup_filter: "{{ omit }}"
7070
# Gather subset to apply to the setup module when gathering facts. Default is
7171
# to not specify a gather subset.
7272
kayobe_ansible_setup_gather_subset: "{{ omit }}"
73+
74+
# Whether or not we should try and escalate privileges on the control host.
75+
# This allows us to install packages and create arbitrary directories that our
76+
# user would not normally have permission to create. Default is true.
77+
kayobe_control_host_become: true

ansible/inventory/group_vars/all/kolla

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ kolla_ansible_group: kolla
496496
# Ansible.
497497
kolla_ansible_become: false
498498

499+
# Whether to use privilege escalation for operations on the control host.
500+
# Default is {{ kayobe_control_host_become }}.
501+
kolla_ansible_control_host_become: "{{ kayobe_control_host_become | bool }}"
502+
499503
# Whether to create a user account, configure passwordless sudo and authorise
500504
# an SSH key for Kolla Ansible. Default is 'true'.
501505
kolla_ansible_create_user: true

ansible/kolla-ansible.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
- import_role:
8787
name: kolla-ansible
8888
vars:
89+
kolla_ansible_control_host_become: "{{ kayobe_control_host_become | bool }}"
8990
kolla_ansible_install_epel: "{{ dnf_install_epel }}"
9091
kolla_external_fqdn_cert: "{{ kolla_config_path }}/certificates/haproxy.pem"
9192
kolla_internal_fqdn_cert: "{{ kolla_config_path }}/certificates/haproxy-internal.pem"

ansible/roles/bootstrap/tasks/main.yml

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,49 @@
11
---
2+
- block:
3+
- name: Testing privilege escalation
4+
raw: "true"
5+
become: true
6+
failed_when: false
7+
changed_when: false
8+
register: privilege_escalation_result
9+
10+
- name: Assert that we can escalate privileges
11+
assert:
12+
that:
13+
- privilege_escalation_result is success
14+
- '"password is required" not in privilege_escalation_result.stderr'
15+
fail_msg: >-
16+
Could not escalate privileges. You can either: set kayobe_control_host_become: true,
17+
set ansible_become_password, or set up passwordless sudo.
18+
when: kayobe_control_host_become | bool
19+
220
- name: Include OS family-specific variables
321
include_vars: "{{ ansible_facts.os_family }}.yml"
422

5-
- name: Ensure required packages are installed
6-
package:
7-
name: "{{ bootstrap_package_dependencies }}"
8-
state: present
9-
cache_valid_time: "{{ apt_cache_valid_time if ansible_facts.os_family == 'Debian' else omit }}"
10-
update_cache: "{{ True if ansible_facts.os_family == 'Debian' else omit }}"
11-
become: True
23+
- name: Gather the package facts
24+
ansible.builtin.package_facts:
25+
manager: auto
26+
27+
- block:
28+
- name: Assert that all packages are installed if not using privilege escalation
29+
assert:
30+
that: missing_packages is falsy
31+
fail_msg: >-
32+
The following packages are missing from your system: {{ missing_packages | join(', ') }} and
33+
privilege escalation is disabled. Please get your system administator to install these packages
34+
or enable kayobe_control_host_become.
35+
when: not kayobe_control_host_become | bool
36+
37+
- name: Ensure required packages are installed
38+
package:
39+
name: "{{ bootstrap_package_dependencies }}"
40+
state: present
41+
cache_valid_time: "{{ apt_cache_valid_time if ansible_facts.os_family == 'Debian' else omit }}"
42+
update_cache: "{{ True if ansible_facts.os_family == 'Debian' else omit }}"
43+
become: True
44+
when: missing_packages is truthy
45+
vars:
46+
missing_packages: "{{ bootstrap_package_dependencies | difference(ansible_facts.packages.keys()) }}"
1247

1348
- name: Check whether an SSH key exists
1449
stat:
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
# List of package dependencies to install.
3+
# NOTE(wszusmki): meta packages are not supported in this list since we cannot
4+
# determine if they are installed via ansible facts.
35
bootstrap_package_dependencies:
46
- git
5-
- vim
7+
- vim-enhanced

ansible/roles/kolla-ansible/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ kolla_ansible_group: kolla
7777
# Ansible.
7878
kolla_ansible_become: false
7979

80+
# Whether to use privilege escalation for operations on the control host.
81+
kolla_ansible_control_host_become: true
82+
8083
###############################################################################
8184
# Kolla-ansible inventory configuration.
8285

ansible/roles/kolla-ansible/tasks/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
owner: "{{ ansible_facts.user_uid }}"
3434
group: "{{ ansible_facts.user_gid }}"
3535
mode: 0750
36-
become: True
36+
become: "{{ kolla_ansible_control_host_become | bool }}"
3737
with_items:
3838
- "{{ kolla_config_path }}"
3939
- "{{ kolla_seed_inventory_path }}"

ansible/roles/kolla-ansible/tasks/install.yml

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,65 @@
22
- name: Include OS family-specific variables
33
include_vars: "{{ ansible_facts.os_family }}.yml"
44

5-
- name: Ensure EPEL repo is installed
6-
package:
7-
name: epel-release
8-
state: present
9-
become: True
5+
- name: Gather the package facts
6+
ansible.builtin.package_facts:
7+
manager: auto
8+
9+
- block:
10+
- name: Assert that epel-release package is installed if not using privilege escalation
11+
assert:
12+
that: "'epel-release' in ansible_facts.packages.keys()"
13+
fail_msg: >-
14+
The following packages are missing from your system: epel-release and
15+
privilege escalation is disabled. Please get your system administator
16+
to install these packages or enable kolla_ansible_control_host_become.
17+
when:
18+
- not kolla_ansible_control_host_become | bool
19+
20+
- name: Ensure EPEL repo is installed
21+
package:
22+
name: epel-release
23+
state: present
24+
become: True
25+
when: "'epel-release' not in ansible_facts.packages.keys()"
1026
vars:
1127
ansible_python_interpreter: /usr/bin/python3
1228
when:
1329
- ansible_facts.os_family == 'RedHat'
1430
- kolla_ansible_install_epel | bool
1531

16-
- name: Ensure required packages are installed
17-
package:
18-
# NOTE(mgoddard): select non-empty packages.
19-
name: "{{ kolla_ansible_package_dependencies | select | list }}"
20-
state: present
21-
cache_valid_time: "{{ apt_cache_valid_time if ansible_facts.os_family == 'Debian' else omit }}"
22-
update_cache: "{{ True if ansible_facts.os_family == 'Debian' else omit }}"
32+
- block:
33+
- name: Assert that all packages are installed if not using privilege escalation
34+
assert:
35+
that: missing_packages is falsy
36+
fail_msg: >-
37+
The following packages are missing from your system:
38+
{{ missing_packages | join(', ') }} and privilege escalation is disabled. Please get
39+
your system administator to install these packages or enable
40+
kolla_ansible_control_host_become.
41+
when: not kolla_ansible_control_host_become | bool
42+
43+
- name: Ensure required packages are installed
44+
package:
45+
name: "{{ packages }}"
46+
state: present
47+
cache_valid_time: "{{ apt_cache_valid_time if ansible_facts.os_family == 'Debian' else omit }}"
48+
update_cache: "{{ True if ansible_facts.os_family == 'Debian' else omit }}"
49+
become: True
50+
when: missing_packages is truthy
2351
vars:
52+
# NOTE(mgoddard): select non-empty packages.
2453
ansible_python_interpreter: /usr/bin/python3
25-
become: True
54+
packages: "{{ kolla_ansible_package_dependencies | select | list }}"
55+
missing_packages: "{{ packages | difference(ansible_facts.packages.keys()) }}"
2656

2757
- name: Ensure source code checkout parent directory exists
2858
file:
2959
path: "{{ kolla_ansible_source_path | dirname }}"
3060
state: directory
3161
owner: "{{ ansible_facts.user_uid }}"
3262
group: "{{ ansible_facts.user_gid }}"
33-
become: True
63+
become: "{{ kolla_ansible_control_host_become | bool }}"
3464
when: kolla_ansible_ctl_install_type == 'source'
3565

3666
- name: Ensure Kolla Ansible source code checkout exists
@@ -44,7 +74,7 @@
4474
file:
4575
path: "{{ kolla_ansible_venv }}"
4676
state: absent
47-
become: True
77+
become: "{{ kolla_ansible_control_host_become | bool }}"
4878
when:
4979
- kolla_ansible_venv is not none
5080
- (kolla_ansible_venv ~ '/bin/python') | realpath != kolla_ansible_venv_python | realpath
@@ -55,7 +85,7 @@
5585
state: directory
5686
owner: "{{ ansible_facts.user_uid }}"
5787
group: "{{ ansible_facts.user_gid }}"
58-
become: True
88+
become: "{{ kolla_ansible_control_host_become | bool }}"
5989
when: kolla_ansible_venv is not none
6090

6191
- name: Ensure the latest version of pip is installed

doc/source/usage.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,19 @@ which can be used to improve visibility into changes that would be made on
8383
target systems. The Kayobe CLI supports the ``--check`` argument, and since
8484
11.0.0, the ``--diff`` argument. Note that these modes are not always
8585
guaranteed to work, when some tasks are dependent on earlier ones.
86+
87+
Avoiding privilege escalation on the control host
88+
-------------------------------------------------
89+
90+
.. note::
91+
92+
This means that kayobe will not be able to install OS packages or use paths
93+
that are not writable for your user.
94+
95+
It is possible to avoid privilege escalation on the control host. To use this feature set
96+
the following config option:
97+
98+
.. code-block:: yaml
99+
:caption: ``$KAYOBE_CONFIG_PATH/globals.yml``
100+
101+
kayobe_control_host_become: false

etc/kayobe/globals.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
# equivalent to a value of 100.
6969
#kayobe_max_fail_percentage:
7070

71+
# Whether or not we should try and escalate privileges on the control host.
72+
# This allows us to install packages and create arbitrary directories that our
73+
# user would not normally have permission to create. Default is true.
74+
#kayobe_control_host_become:
75+
7176
###############################################################################
7277
# Dummy variable to allow Ansible to accept this file.
7378
workaround_ansible_issue_8743: yes

0 commit comments

Comments
 (0)