Skip to content

Add user to sudo group in container setup script#6

Open
sreeragh-s wants to merge 1 commit intotinkerhub:mainfrom
sreeragh-s:main
Open

Add user to sudo group in container setup script#6
sreeragh-s wants to merge 1 commit intotinkerhub:mainfrom
sreeragh-s:main

Conversation

@sreeragh-s
Copy link
Copy Markdown

@sreeragh-s sreeragh-s commented Apr 12, 2026

Summary by CodeRabbit

  • New Features
    • SSH users in containers now automatically receive sudo privileges upon creation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 12, 2026

📝 Walkthrough

Walkthrough

The container initialization script now grants sudo group membership to SSH-configured users. A single line executing usermod -aG sudo {user} was added after user creation to extend administrative privileges to the configured SSH user accounts.

Changes

Cohort / File(s) Summary
Container SSH User Configuration
scripts/containers.sh
Added usermod -aG sudo {user} command to grant sudo group membership to SSH-enabled container users.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A single line hops into place,
Sudo powers now embrace,
SSH users gain their right,
Administrative might!
One small change, containers bright!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add user to sudo group in container setup script' accurately and concisely describes the main change: adding a user to the sudo group in the container setup script.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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 the current code and only fix it if needed.

Inline comments:
In `@scripts/containers.sh`:
- Line 86: The script currently always runs the command `usermod -aG sudo
{user}`, granting sudo to every SSH user; change this to be conditional on an
explicit per-user opt-in (e.g., `sudo: true` in containers.yml) so sudo is only
granted when requested. Update the logic that renders/iterates users in the
script to read the privilege flag from the user record (or an exported variable
for that user) and wrap the `usermod -aG sudo {user}` call in an if-check (only
execute when that user's sudo flag is true); ensure the check uses the same user
identifier used elsewhere in the script so you modify only the `usermod -aG sudo
{user}` execution path.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 132431b3-6c70-49da-bc7b-c9d9b55a30d6

📥 Commits

Reviewing files that changed from the base of the PR and between 3523da2 and 40c054e.

📒 Files selected for processing (1)
  • scripts/containers.sh

setup_cmd = f'''
set -e
id -u {user} >/dev/null 2>&1 || useradd -m -s /bin/bash {user}
usermod -aG sudo {user}
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

Gate sudo membership behind explicit config instead of granting it by default.

Line 86 unconditionally elevates every SSH user to sudo. Since containers/containers.yml does not define a privilege field, this silently broadens admin access for all configured accounts. Make sudo opt-in (e.g., sudo: true) and only run usermod when explicitly requested.

Suggested change
@@
-    setup_cmd = f'''
+    allow_sudo = bool(c.get('sudo', False))
+    setup_cmd = f'''
 set -e
 id -u {user} >/dev/null 2>&1 || useradd -m -s /bin/bash {user}
-usermod -aG sudo {user}
+{"usermod -aG sudo " + user if allow_sudo else ""}
 mkdir -p /home/{user}/.ssh
 printf '%s\\n' '{key}' > /home/{user}/.ssh/authorized_keys
 chmod 700 /home/{user}/.ssh
 chmod 600 /home/{user}/.ssh/authorized_keys
 chown -R {user}:{user} /home/{user}/.ssh
 '''
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/containers.sh` at line 86, The script currently always runs the
command `usermod -aG sudo {user}`, granting sudo to every SSH user; change this
to be conditional on an explicit per-user opt-in (e.g., `sudo: true` in
containers.yml) so sudo is only granted when requested. Update the logic that
renders/iterates users in the script to read the privilege flag from the user
record (or an exported variable for that user) and wrap the `usermod -aG sudo
{user}` call in an if-check (only execute when that user's sudo flag is true);
ensure the check uses the same user identifier used elsewhere in the script so
you modify only the `usermod -aG sudo {user}` execution path.

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.

1 participant