Skip to content

Commit e419831

Browse files
committed
fix: ensure single space before TYPE, ROLE, and correctly format those values
Cause: The recent refactoring for Ansible 2.19 altered the whitespacing before the TYPE and ROLE values. In addition, the TYPE and ROLE values are a single string, not a comma delimited list. We did not have any tests for these values, so we did not catch the error in the refactoring. Consequence: The role would incorrectly format the TYPE and ROLE values. Fix: Use correct Jinja formatting for the TYPE and ROLE values, and the solaris values. Ensure that the TYPE and ROLE values will be a single string. Result: The sudoers file is correctly formatted. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent 76ee3de commit e419831

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,14 @@ You can use a defined `host_alias` name as well as host names.
158158
You can use a defined `runas_alias` name as well as user names.
159159

160160
4. `selinux_role` - Optional selinux role to apply to the specification.
161+
**NOTE** - only a single value is supported. However, due to historical
162+
reasons, the value can be a list - if a list is given, only the first value
163+
is used. Please use a `string` value.
161164

162165
5. `selinux_type` - Optional selinux type to apply to the specification.
166+
**NOTE** - only a single value is supported. However, due to historical
167+
reasons, the value can be a list - if a list is given, only the first value
168+
is used. Please use a `string` value.
163169

164170
6. `solaris_privs` - Optional Solaris privset to apply to the specification.
165171

@@ -192,6 +198,8 @@ sudo_sudoers_files:
192198
- ALL
193199
commands:
194200
- ALL
201+
selinux_role: sysadm_r
202+
selinux_type: sysadm_t
195203
```
196204

197205
#### default_overrides

templates/sudoers.j2

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ Defaults {{ default }}
6464
{%- if spec.operators is defined and spec.operators | length > 0 -%}
6565
({{ spec.operators | join(", ") }})
6666
{%- endif -%}
67-
{%- if spec.selinux_type is defined and spec.selinux_type | length > 0 -%}
68-
TYPE={{ spec.selinux_type | join(", ") }}
67+
{%- if spec.selinux_type is defined and spec.selinux_type | length > 0 %}
68+
TYPE={{ spec.selinux_type if spec.selinux_type is string else spec.selinux_type[0] }}
6969
{%- endif -%}
70-
{%- if spec.selinux_role is defined and spec.selinux_role | length > 0 -%}
71-
ROLE={{ spec.selinux_role | join(", ") }}
70+
{%- if spec.selinux_role is defined and spec.selinux_role | length > 0 %}
71+
ROLE={{ spec.selinux_role if spec.selinux_role is string else spec.selinux_role[0] }}
7272
{%- endif -%}
73-
{%- if spec.solaris_privs is defined and spec.solaris_privs | length > 0 -%}
74-
PRIVS={{ spec.solaris_privs | join(", ") }}
73+
{%- if spec.solaris_privs is defined and spec.solaris_privs | length > 0 %}
74+
PRIVS={{ spec.solaris_privs | join(",") }}
7575
{%- endif -%}
76-
{%- if spec.solaris_limitprivs is defined and spec.solaris_limitprivs | length > 0 -%}
77-
LIMITPRIVS={{ spec.solaris_limitprivs | join(", ") }}
76+
{%- if spec.solaris_limitprivs is defined and spec.solaris_limitprivs | length > 0 %}
77+
LIMITPRIVS={{ spec.solaris_limitprivs | join(",") }}
7878
{%- endif -%}
7979
{%- if spec.tags is defined and spec.tags | length > 0 -%}
8080
{{ spec.tags | join(":") }}:

tests/files/tests_large_configuration_sudoers.ok

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ User_Alias PINGERS = username
3333

3434
# User specifications
3535
root ALL=(ALL) ALL
36-
%wheel ALL=(ALL) ALL
36+
%wheel ALL=(ALL) TYPE=sysadm_t ROLE=sysadm_r /bin/pwd, /usr/bin/cd
3737

3838
# Default override specifications
3939
Defaults: PINGERS !requiretty

tests/tests_large_configuration.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,11 @@
7171
- ALL
7272
operators:
7373
- ALL
74+
selinux_type: sysadm_t
75+
selinux_role: sysadm_r
7476
commands:
75-
- ALL
77+
- /bin/pwd
78+
- /usr/bin/cd
7679
default_overrides:
7780
- type: user
7881
defaults:

0 commit comments

Comments
 (0)