Skip to content

fix: use correct spacing before tags#123

Open
richm wants to merge 1 commit into
linux-system-roles:mainfrom
richm:fix-selinux-contexts
Open

fix: use correct spacing before tags#123
richm wants to merge 1 commit into
linux-system-roles:mainfrom
richm:fix-selinux-contexts

Conversation

@richm
Copy link
Copy Markdown
Contributor

@richm richm commented May 22, 2026

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

    • Updated sudoers template formatting to improve output whitespace handling.
  • Tests

    • Added test coverage for SELinux type and role configurations in sudoers management.

Review Change Stack

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>
@richm richm requested a review from spetrosi as a code owner May 22, 2026 20:29
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

This 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.

Changes

SELinux tags support

Layer / File(s) Summary
Template whitespace control for tags line
templates/sudoers.j2
Updated the Jinja2 conditional that renders the {{ spec.tags | join(":") }}: line to adjust trailing whitespace and newline trimming.
Test playbook and expected output for SELinux tags
tests/tests_selinux_tags.yml, tests/files/tests_selinux_tags_cloud_init.ok
Added test playbook that configures user specifications with unconfined SELinux context and NOPASSWD tags, renders the sudoers output via the role, and asserts it matches the golden file containing the expected maintuser rule format.
🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description Format ⚠️ Warning PR description lacks required template sections. Missing "Enhancement:" or "Feature:", "Reason:", and "Result:" headers required by .github/pull_request_template.md. Reformat PR description to follow template: Enhancement: [what changed], Reason: [why needed], Result: [outcome], plus optional Issue Tracker Tickets section.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'fix: use correct spacing before tags' follows Conventional Commits format with valid 'fix' type and clearly describes the main change in the changeset.
Description check ✅ Passed The PR description provides clear context about the cause, consequence, fix, and result, though it does not follow the provided template structure with sections like 'Enhancement', 'Reason', and 'Result' headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@richm
Copy link
Copy Markdown
Contributor Author

richm commented May 22, 2026

fixes #67

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@36574a0). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 36574a0 and 3d77cd8.

📒 Files selected for processing (3)
  • templates/sudoers.j2
  • tests/files/tests_selinux_tags_cloud_init.ok
  • tests/tests_selinux_tags.yml

Comment on lines +6 to +95
- 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
- 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
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

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.

@richm
Copy link
Copy Markdown
Contributor Author

richm commented May 22, 2026

[citest]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants