Conversation
Two functions edited /etc/sudoers in place with no validation: enable_sudo_without_password ran 'sed -i.bak' against the %sudo line, and pass_http_thru_sudo appended an env_keep Defaults line via 'sudo tee -a'. A syntax error introduced by either -- a sed pattern that matches unexpectedly on a future Ubuntu, a partially written append -- makes sudo refuse to run at all, and the .bak is then only recoverable from a root shell or recovery boot. Write both rules to /etc/sudoers.d/ instead, via a helper that: - confirms /etc/sudoers actually has an includedir directive - runs 'visudo -cf' on the candidate file and aborts if it fails - installs with 'install -m 0440 -o root -g root', which is atomic This is also idempotent by construction, replacing the grep-based guards. Verified both generated snippets parse with visudo -cf. Machines provisioned by an earlier version keep the inline edits in /etc/sudoers; the drop-ins are equivalent, so those lines can be removed by hand with visudo. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The new helper’s includedir detection regex is incorrect/too strict, and the drop-in installation path should avoid non-atomic overwrites to prevent partial sudoers files if interrupted.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens sudo configuration changes in setup by moving from in-place edits of /etc/sudoers to validated drop-in files under /etc/sudoers.d, reducing the risk of locking sudo out due to syntax errors or partial writes.
Changes:
- Added
_install_sudoers_snippethelper to validate generated sudoers content withvisudo -cfbefore installing. - Updated
enable_sudo_without_passwordto install a%sudo ... NOPASSWD:SETENVrule via a managed drop-in. - Updated
pass_http_thru_sudoto install anenv_keepDefaults rule via a managed drop-in.
File summaries
| File | Description |
|---|---|
| setup | Replaces direct /etc/sudoers edits with validated, managed sudoers drop-ins. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+185
to
+186
| if ! sudo grep -qE '^[@#]includedir[[:space:]]+/etc/sudoers.d' /etc/sudoers; then | ||
| die "/etc/sudoers does not include /etc/sudoers.d; refusing to edit sudoers" |
Comment on lines
+199
to
+200
| sudo install -o root -g root -m 0440 "$tmp" "/etc/sudoers.d/$name" | ||
| rm -f "$tmp" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two functions edited /etc/sudoers in place with no validation:
enable_sudo_without_password ran 'sed -i.bak' against the %sudo line,
and pass_http_thru_sudo appended an env_keep Defaults line via
'sudo tee -a'. A syntax error introduced by either -- a sed pattern
that matches unexpectedly on a future Ubuntu, a partially written
append -- makes sudo refuse to run at all, and the .bak is then only
recoverable from a root shell or recovery boot.
Write both rules to /etc/sudoers.d/ instead, via a helper that:
This is also idempotent by construction, replacing the grep-based
guards. Verified both generated snippets parse with visudo -cf.
Machines provisioned by an earlier version keep the inline edits in
/etc/sudoers; the drop-ins are equivalent, so those lines can be
removed by hand with visudo.
🤖 Generated with Claude Code