fix: use correct spacing before tags#123
Conversation
Cause: The space before user spec tags was handled incorrectly. Consequence: If you specified selinux_type and selinux_role, there was no space before the tag, and sudo would issue an error trying to parse the generated file. Fix: Ensure the generated sudoers uses correct spacing before the tags. Result: Users can specify selinux_type and selinux_role and have a correctly formatted sudoers. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
📝 WalkthroughWalkthroughThis PR adds SELinux type and role tags support to the sudo role's sudoers template with test coverage. The template's whitespace control was updated for the optional tags block, a test playbook was created to validate the feature, and a golden sudoers file captures the expected output format. ChangesSELinux tags support
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
|
fixes #67 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #123 +/- ##
=======================================
Coverage ? 47.76%
=======================================
Files ? 2
Lines ? 381
Branches ? 0
=======================================
Hits ? 182
Misses ? 199
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/tests_selinux_tags.yml`:
- Around line 6-95: Update tests/tests_selinux_tags.yml to add a negative
assertion and an idempotence run: after the first "Run the role" and the "Check
cloud-init users sudoers include" step, add a task that asserts the malformed
no-space SELinux/tag pattern is absent from the generated file (use
__sudo_test_path = /etc/sudoers.d/90-cloud-init-users and e.g. a grep/assert
task to ensure a pattern like "NOPASSWDunconfined_t" does not exist), then
invoke the same include_tasks used earlier (tasks/run_role_with_clear_facts.yml
with the same vars: sudo_rewrite_default_sudoers_file,
sudo_remove_unauthorized_included_files, sudo_sudoers_files) to perform an
idempotence pass and re-run the existing "Check cloud-init users sudoers
include" (include_tasks: tasks/assert_files_identical.yml with __sudo_ok_path
and __sudo_test_path) to verify no failures or changes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 560cc5af-5b40-4de3-aa33-2f8c72a62273
📒 Files selected for processing (3)
templates/sudoers.j2tests/files/tests_selinux_tags_cloud_init.oktests/tests_selinux_tags.yml
| - name: Run tests | ||
| block: | ||
| - name: Test setup | ||
| include_tasks: tasks/setup.yml | ||
|
|
||
| - name: Run the role | ||
| include_tasks: tasks/run_role_with_clear_facts.yml | ||
| 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 | ||
| - 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 | ||
| include_directories: | ||
| - /etc/sudoers.d | ||
| - path: /etc/sudoers.d/90-cloud-init-users | ||
| user_specifications: | ||
| - users: | ||
| - maintuser | ||
| hosts: | ||
| - ALL | ||
| operators: | ||
| - ALL | ||
| selinux_type: | ||
| - unconfined_t | ||
| selinux_role: | ||
| - unconfined_r | ||
| tags: | ||
| - NOPASSWD | ||
| commands: | ||
| - ALL | ||
|
|
||
| - name: Check cloud-init users sudoers include | ||
| include_tasks: tasks/assert_files_identical.yml | ||
| vars: | ||
| __sudo_ok_path: files/tests_selinux_tags_cloud_init.ok | ||
| __sudo_test_path: /etc/sudoers.d/90-cloud-init-users | ||
|
|
||
| always: | ||
| - name: Test cleanup | ||
| include_tasks: tasks/cleanup.yml |
There was a problem hiding this comment.
Add explicit failure-path and idempotence checks to this test.
This playbook currently validates only the success path once. Please add a negative assertion (e.g., malformed no-space SELinux/tag pattern must be absent) and an idempotence pass (run the same role invocation again and verify no failure/regression).
As per coding guidelines, tests/tests_*.yml: "Tests should verify both success and failure scenarios" and "Tests should be idempotent - running twice should not cause failures".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/tests_selinux_tags.yml` around lines 6 - 95, Update
tests/tests_selinux_tags.yml to add a negative assertion and an idempotence run:
after the first "Run the role" and the "Check cloud-init users sudoers include"
step, add a task that asserts the malformed no-space SELinux/tag pattern is
absent from the generated file (use __sudo_test_path =
/etc/sudoers.d/90-cloud-init-users and e.g. a grep/assert task to ensure a
pattern like "NOPASSWDunconfined_t" does not exist), then invoke the same
include_tasks used earlier (tasks/run_role_with_clear_facts.yml with the same
vars: sudo_rewrite_default_sudoers_file,
sudo_remove_unauthorized_included_files, sudo_sudoers_files) to perform an
idempotence pass and re-run the existing "Check cloud-init users sudoers
include" (include_tasks: tasks/assert_files_identical.yml with __sudo_ok_path
and __sudo_test_path) to verify no failures or changes.
|
[citest] |
Cause: The space before user spec tags was handled incorrectly.
Consequence: If you specified selinux_type and selinux_role, there was no
space before the tag, and sudo would issue an error trying to parse the
generated file.
Fix: Ensure the generated sudoers uses correct spacing before the tags.
Result: Users can specify selinux_type and selinux_role and have a correctly
formatted sudoers.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by CodeRabbit
Changes
Tests