Skip to content

privilege: normalize the end of the generated sudoers file - #1448

Merged
denisonbarbosa merged 1 commit into
mainfrom
split/privilege-sudoers
Aug 11, 2026
Merged

privilege: normalize the end of the generated sudoers file#1448
denisonbarbosa merged 1 commit into
mainfrom
split/privilege-sudoers

Conversation

@denisonbarbosa

Copy link
Copy Markdown
Member

Split out of #1401 as an unrelated drive-by fix, so it can be reviewed and land on its own.

The generated sudoers file ended with a trailing blank line, and every policy entry appended its own \n whether or not it produced content. Entries yielding an empty sudoers section emitted a stray newline, and the file always finished with one blank line more than needed.

Sections are now collected and joined with a single blank-line separator, so they stay visually separated but the file ends with exactly one newline. Golden files updated accordingly.

Independent of the certificate work — no dependency on the rest of the stack.

The generated sudoers file ended with a trailing blank line, and every
policy entry appended its own "\n" regardless of whether it produced any
content. Entries yielding an empty sudoers section therefore emitted a
stray newline, and the file always finished with one blank line more
than needed.

Collect the non-empty sections and join them with a single blank line
separator instead, so sections stay visually separated but the file ends
with exactly one newline. The golden files are updated accordingly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Normalizes generated sudoers formatting while preserving blank-line separation between policy sections.

Changes:

  • Collects non-empty sudoers sections and joins them consistently.
  • Adds formatting coverage and updates affected golden files.

Reviewed changes

Copilot reviewed 33 out of 33 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/policies/privilege/privilege.go Normalizes sudoers section spacing and final newline.
internal/policies/privilege/privilege_test.go Tests section separation and trailing newline behavior.
internal/policies/testdata/TestApplyPolicies/golden/succeed/etc/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/testdata/TestApplyPolicies/golden/succeed_if_checking_for_backend_online_status_returns_an_error/etc/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/set_client_user_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/set_client_multiple_users_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/set_client_mixed_with_users_and_group_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/set_client_group_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/overwrite_existing_sudoers_file/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/overwrite_existing_polkit_file/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/don't_overwrite_other_existing_files/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/disallow_local_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/disallow_local_admins_with_previous_local_admin_conf_and_set_client_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/disallow_local_admins_and_set_client_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/create_on_new_polkit_version_and_remove_old_file/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/assume_old_polkit_if_cant_read_system_reserved_path/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/allow_local_admins_without_previous_local_admin_conf_and_set_client_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/allow_local_admins_with_previous_local_admin_conf_and_set_client_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/allow_local_admins_with_previous_local_admin_conf_(with_adsys_file)_and_set_client_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
internal/policies/privilege/testdata/TestApplyPolicy/golden/allow_local_admins_with_previous_local_admin_conf_(simple)_and_set_client_admins/sudoers.d/99-adsys-privilege-enforcement Updates normalized golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/refresh_with_one_dangling_symlink_ignores_the_respective_user/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/refresh_with_no_user_connected_updates_machines/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/refresh_some_connected/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/refresh_all_connected/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/machine,_update_old_data/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/machine,_first_time/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/machine,_first_time_with_winbind_backend/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/host_is_offline,_regenerate_machine_from_old_data/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/host_is_offline,_mach_gpos_cache_is_cleared,_with_policies_cache/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/host_is_offline,_get_machine_from_cache_(no_update)/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/does_not_error_when_d-bus_proxy_object_is_not_available/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/does_not_error_when_certmonger_or_cepces_is_not_available/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.
cmd/adsysd/integration_tests/testdata/TestPolicyUpdate/golden/already_up_to_date/sudoers.d/99-adsys-privilege-enforcement Updates integration golden output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@denisonbarbosa
denisonbarbosa merged commit f026ff0 into main Aug 11, 2026
8 of 12 checks passed
@denisonbarbosa
denisonbarbosa deleted the split/privilege-sudoers branch August 11, 2026 11:50
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.

3 participants