Skip to content

Conversation

@richm
Copy link
Contributor

@richm richm commented Jul 8, 2025

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

Summary by Sourcery

Fix whitespace and value formatting in the sudoers Jinja template for TYPE, ROLE, PRIVS, and LIMITPRIVS; add tests to cover selinux_type and selinux_role and refresh fixtures.

Bug Fixes:

  • Correct rendering of TYPE and ROLE as single values with a leading space instead of comma-separated lists.
  • Remove extraneous spaces in Solaris PRIVS and LIMITPRIVS filters by joining without added spaces.

Tests:

  • Add selinux_type and selinux_role entries and specific commands to the large configuration tests.
  • Refresh the expected sudoers output fixture to validate the updated formatting.

@richm richm requested a review from spetrosi as a code owner July 8, 2025 22:28
@sourcery-ai
Copy link

sourcery-ai bot commented Jul 8, 2025

Reviewer's Guide

Fixes whitespace and value formatting for TYPE, ROLE, and Solaris privilege entries in the sudoers Jinja template by enforcing single-string output and adjusts associated tests to validate these changes.

Class diagram for spec data structure changes in sudoers template

classDiagram
    class spec {
        operators : list[string]
        selinux_type : string | list[string]
        selinux_role : string | list[string]
        solaris_privs : list[string]
        solaris_limitprivs : list[string]
        tags : list[string]
    }
    %% Note: The handling of selinux_type and selinux_role now ensures single string output in the template, even if the input is a list.
Loading

File-Level Changes

Change Details Files
Refactor Jinja2 templating for selinux and Solaris privilege formatting
  • Removed whitespace control modifiers in conditional blocks to maintain a single leading space
  • Replaced join(", ") with a conditional expression for selinux_type and selinux_role to enforce single-string output
  • Adjusted join delimiter for solaris_privs and solaris_limitprivs to use "," without spaces
templates/sudoers.j2
Update tests to cover selinux_type, selinux_role, and refined command entries
  • Added selinux_type and selinux_role fields to the large-configuration test
  • Replaced a generic ALL command with specific binaries in the test commands list
  • Updated the expected sudoers output file to reflect the new formatting rules
tests/tests_large_configuration.yml
tests/files/tests_large_configuration_sudoers.ok

Possibly linked issues

  • #0: The PR corrects the whitespace and formatting for SELinux TYPE and ROLE tags in the sudoers template, fixing the issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @richm - I've reviewed your changes - here's some feedback:

  • Consider using the built-in Jinja2 first filter (e.g. {{ spec.selinux_type | first }}) instead of manually indexing into the list.
  • The mix of {%- and {% for whitespace control in your Jinja tags is inconsistent—standardize on one style for readability.
  • Double-check that removing the space in join(",") for solaris_privs/limitprivs still aligns with the expected sudoers file formatting conventions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using the built-in Jinja2 `first` filter (e.g. `{{ spec.selinux_type | first }}`) instead of manually indexing into the list.
- The mix of `{%-` and `{%` for whitespace control in your Jinja tags is inconsistent—standardize on one style for readability.
- Double-check that removing the space in `join(",")` for solaris_privs/limitprivs still aligns with the expected sudoers file formatting conventions.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@76ee3de). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #65   +/-   ##
=======================================
  Coverage        ?   52.31%           
=======================================
  Files           ?        1           
  Lines           ?      346           
  Branches        ?        0           
=======================================
  Hits            ?      181           
  Misses          ?      165           
  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.

@richm
Copy link
Contributor Author

richm commented Jul 8, 2025

[citest]

@richm
Copy link
Contributor Author

richm commented Jul 8, 2025

Fixes #64

Copy link
Contributor

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this! @kraker validated this in #64 (comment)

{%- if spec.selinux_type is defined and spec.selinux_type | length > 0 -%}
TYPE={{ spec.selinux_type | join(", ") }}
{%- if spec.selinux_type is defined and spec.selinux_type | length > 0 %}
TYPE={{ spec.selinux_type if spec.selinux_type is string else spec.selinux_type[0] }}
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit weird that we entirely ignore all but the first list entries -- I suppose this should have been a single value all along? But that's water under the bridge now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a bit weird that we entirely ignore all but the first list entries -- I suppose this should have been a single value all along?

That's what I understand according to https://www.sudo.ws/docs/man/1.8.15/sudoers.man/#Quick_guide_to_EBNF - it should have been a single value all along - perhaps @radosroka can confirm.

…e 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>
@richm
Copy link
Contributor Author

richm commented Jul 9, 2025

[citest]

@richm
Copy link
Contributor Author

richm commented Jul 9, 2025

also note that we cannot actually test the solaris options because 1) linux visudo -cf does not like those options and 2) we do not have CI testing on solaris

@richm richm merged commit e419831 into linux-system-roles:main Jul 9, 2025
36 checks passed
@richm richm deleted the issue-64 branch July 9, 2025 16:47
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