Skip to content

Commit

Permalink
Add larger test which uses more attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Radovan Sroka <[email protected]>
  • Loading branch information
radosroka committed May 20, 2024
1 parent 2fd26b1 commit 449e34e
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/multiple_sudoers_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
cmnd_alias:
- name: PING
commands:
- /bin/ping
- /usr/bin/ping
user_alias:
- name: PINGERS
users:
Expand Down
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
- name: Ensure /etc/sudoers is configured
template:
src: sudoers.j2
dest: "{{ item.path }}"
dest: "{{ item.path }}"
owner: root
group: root
mode: 0440
Expand Down
11 changes: 11 additions & 0 deletions tests/files/tests_large_configuration_pingers.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Ansible managed
#
# system_role:sudo


# Default override specifications
Defaults: PINGERS !requiretty
Defaults> root !set_logname
Defaults@ host1, host2 !requiretty, !requiretty
Defaults! /usr/bin/ls !requiretty
10 changes: 10 additions & 0 deletions tests/files/tests_large_configuration_root.ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Ansible managed
#
# system_role:sudo

# Default specifications
Defaults syslog=auth

# Default override specifications
Defaults> root !set_logname
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Ansible managed
#
# system_role:sudo

# Default specifications
Defaults !visiblepw
Expand All @@ -16,10 +17,26 @@ Defaults env_keep += "LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETAR
Defaults env_keep += "LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL"
Defaults env_keep += "LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"

# Alias specifications
## Command Aliases
Cmnd_Alias PING = /usr/bin/ping
## Host Aliases
Host_Alias HOST = myhost
## Runas Aliases
Runas_Alias RUNAS = username
## User Aliases
User_Alias PINGERS = username

# User specifications
root ALL=(ALL) ALL
%wheel ALL=(ALL) ALL

# Default override specifications
Defaults: PINGERS !requiretty
Defaults> root !set_logname
Defaults@ host1, host2 !requiretty, !requiretty
Defaults! /usr/bin/cd !requiretty

# Includes
## Include directories
#includedir /etc/sudoers.d
2 changes: 1 addition & 1 deletion tests/files/tests_multiple_sudoers_sudoers.ok
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Defaults env_keep += "LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"

# Alias specifications
## Command Aliases
Cmnd_Alias PING = /bin/ping
Cmnd_Alias PING = /usr/bin/ping



Expand Down
230 changes: 230 additions & 0 deletions tests/tests_large_configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
---
- name: Basic test for Sudo
hosts: all
tasks:
- name: Run tests
block:
- name: Run the role
include_role:
name: linux-system-roles.sudo
vars:
sudo_rewrite_default_sudoers_file: true
sudo_remove_unauthorized_included_files: true
sudo_sudoers_files:
- path: /etc/sudoers
defaults:
- "!visiblepw"
- always_set_home
- match_group_by_gid
- always_query_group_plugin
- env_reset
- secure_path:
- /sbin
- /bin
- /usr/sbin
- /usr/bin
- env_keep:
- COLORS
- DISPLAY
- HOSTNAME
- HISTSIZE
- KDEDIR
- LS_COLORS
- MAIL
- PS1
- PS2
- QTDIR
- USERNAME
- LANG
- LC_ADDRESS
- LC_CTYPE
- LC_COLLATE
- LC_IDENTIFICATION
- LC_MEASUREMENT
- LC_MESSAGES
- LC_MONETARY
- LC_NAME
- LC_NUMERIC
- LC_PAPER
- LC_TELEPHONE
- LC_TIME
- LC_ALL
- LANGUAGE
- LINGUAS
- _XKB_CHARSET
- XAUTHORITY
user_specifications:
- users:
- root
hosts:
- ALL
operators:
- ALL
commands:
- ALL
- users:
- "%wheel"
hosts:
- ALL
operators:
- ALL
commands:
- ALL
- type: user
defaults:
- "!requiretty"
users:
- PINGERS
- type: runas
defaults:
- "!set_logname"
operators:
- root
- type: host
defaults:
- "!requiretty"
- "!set_logname"
hosts:
- host1
- host2
- type: command
defaults:
- "!requiretty"
commands:
- /usr/bin/cd
include_directories:
- /etc/sudoers.d
aliases:
cmnd_alias:
- name: PING
commands:
- /usr/bin/ping
host_alias:
- name: HOST
hosts:
- myhost
user_alias:
- name: PINGERS
users:
- username
runas_alias:
- name: RUNAS
users:
- username
- path: /etc/sudoers.d/pingers
user_specifications:
- type: user
defaults:
- "!requiretty"
users:
- PINGERS
- type: runas
defaults:
- "!set_logname"
operators:
- root
- type: host
defaults:
- "!requiretty"
- "!requiretty"
hosts:
- host1
- host2
- type: command
defaults:
- "!requiretty"
commands:
- /usr/bin/ls
- path: /etc/sudoers.d/root
defaults:
- syslog=auth
user_specifications:
- type: runas
defaults:
- "!set_logname"
operators:
- root

- name: Create temp test directory
tempfile:
path: /var/tmp
prefix: sudo_
state: directory
register: __sudo_tmpdir

- name: Backup sudoers
copy:
src: /etc/sudoers
dest: "{{ __sudo_tmpdir.path }}/sudoers"
owner: root
group: root
mode: 0644
remote_src: true

- name: Backup sudoers.d
copy:
src: /etc/sudoers.d
dest: "{{ __sudo_tmpdir.path }}/sudoers.d"
owner: root
group: root
mode: 0644
remote_src: true

- name: Get stat of tests/files/test_large_configuration_sudoers.ok
delegate_to: localhost
stat:
path: files/test_large_configuration_sudoers.ok
checksum_algorithm: sha256
register: sudoers_ok

# sha256sum ./files/test_large_configuration_sudoers.ok
- name: Check sudoers
command: >-
echo "{{ sudoers.ok.stat.checksum }} /etc/sudoers" | sha256sum --check
- name: Get stat of tests/files/test_large_configuration_pingers.ok
delegate_to: localhost
stat:
path: files/test_large_configuration_pingers.ok
checksum_algorithm: sha256
register: pingers_ok

# sha256sum ./files/test_large_configuration_pingers.ok
- name: Check pingers
command: >-
echo "{{ pingers.ok.stat.checksum }} /etc/sudoers.d/pingers" | sha256sum --check
- name: Get stat of tests/files/test_large_configuration_root.ok
delegate_to: localhost
stat:
path: files/test_large_configuration_root.ok
checksum_algorithm: sha256
register: root_ok

# sha256sum ./files/test_large_configuration_root.ok
- name: Check root
command: >-
echo "{{ sudoers.ok.stat.checksum }} /etc/sudoers.d/root" | sha256sum --check
- name: Restore sudoers
copy:
src: "{{ __sudo_tmpdir.path }}/sudoers"
dest: /etc/sudoers
owner: root
group: root
mode: 0644
remote_src: true

- name: Restore sudoers.d
copy:
src: "{{ __sudo_tmpdir.path }}/sudoers.d"
dest: /etc/sudoers.d
owner: root
group: root
mode: 0644
remote_src: true

- name: Clean up temp directory
file:
path: "{{ __sudo_tmpdir.path }}"
state: absent
2 changes: 1 addition & 1 deletion tests/tests_multiple_sudoers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
cmnd_alias:
- name: PING
commands:
- /bin/ping
- /usr/bin/ping
user_alias:
- name: PINGERS
users:
Expand Down

0 comments on commit 449e34e

Please sign in to comment.