apple / apple/container

[Bug]: `usermod -aG docker $USER` has no effect in `container machine`

Open
#2,108 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
49.9k
Forks
1.8k
Avg merge
1d 20h
Merged PRs (30d)
22

Description

### I have done the following

- [x] I have searched the existing issues
- [x] If possible, I've reproduced the issue using the 'main' branch of this project

### Steps to reproduce

Create a container machine.
Add user to a group using `usermod -aG `.

Reopen shell using `container machine run`.
Groups of the user is not updated.

### Problem description

This is because `sbin.machine/init -s` (which is invoked on `machine run`) just spawns the shell, not running user login procedures.

Appending `-l` to the shell command doesn't solve this issue.

To fix this, we need to
1. Run `exec su -l "$USER"` in `sbin.machine/init` instead of just running `exec "${USER_SHELL:-${SHELL}}"`
2. Update `MachineRun.swift` to run `sbin.machine/init` process as root to avoid prompting password for `su -l`
3. Pass username as $USER env variable

Related to #1991

### Environment

```markdown
- OS:
- Xcode:
- Container:
```

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the group update with `container machine run`, then read `sbin.machine/init` and `MachineRun.swift` around the shell launch and process privileges. The change is complete when a user added with `usermod -aG` sees the updated groups after reopening the shell, without an `su -l` password prompt.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell, swift
Domain
cli, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.