Skip to content

Commit e44bd03

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 <[email protected]>
1 parent 76ee3de commit e44bd03

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

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_t /bin/pwd, /usr/bin/cd
3737

3838
# Default override specifications
3939
Defaults: PINGERS !requiretty

tests/tests_large_configuration.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@
7171
- ALL
7272
operators:
7373
- ALL
74+
selinux_type:
75+
- sysadm_t
76+
selinux_role:
77+
- sysadm_t
7478
commands:
75-
- ALL
79+
- /bin/pwd
80+
- /usr/bin/cd
7681
default_overrides:
7782
- type: user
7883
defaults:

0 commit comments

Comments
 (0)