2024-08-11 17:22:35 +02:00
# Users
To run containers securely; in an environment with fewer privileges, a user is necessary.
## Wheel
2024-08-11 22:44:17 +02:00
Before creating the user, install `doas` . To be able to "do as" root when it is required:
2024-08-11 17:22:35 +02:00
```
# apk add doas
```
2024-10-07 21:03:01 +02:00
Configure `doas` through `/etc/doas.d/wheel.conf` :
2024-08-11 17:22:35 +02:00
```
permit persist :wheel as root
```
## Adding a user
2024-08-11 22:44:17 +02:00
A user can be added in Alpine Linux with the `setup-user` script. Here we can specify the name, groups and more:
2024-08-11 17:22:35 +02:00
```
2024-08-11 22:44:17 +02:00
# setup-user -g wheel <username>
2024-08-11 17:22:35 +02:00
# passwd <username>
```
2024-08-11 22:39:30 +02:00
You may have to change the shell of the user in `/etc/passwd` from `/sbin/nologin` to a shell from `/etc/shells` . Alpine Linux comes with `/bin/ash` by default:
```
< username > :x:1234:1234:< Full Name > :/home/< username > :/bin/< shell >
```
2024-08-11 17:22:35 +02:00
If you have checked that `doas` works with the user then you can lock the root account because it imposes security risks if it is kept open. This can be done with:
```
# passwd -l root
```
and editing `/etc/passwd` to change the login shell from `/bin/ash` to `/sbin/nologin` :
```
root:x:0:0:root:/root:/sbin/nologin
```
## User services
2024-08-12 14:19:14 +02:00
The user will have its own service manager, for the management of user containers and other user services. As service manager `runsvdir` from `runit` will be used. Therefore install
2024-08-11 22:39:30 +02:00
```
# apk add runit
```
2024-08-12 14:19:14 +02:00
Create `/etc/init.d/runsvdir-user` , which will be the openrc-script for the service manager of the user.
2024-08-11 22:39:30 +02:00
```
#!/sbin/openrc-run
user="${RC_SVCNAME##*.}"
svdir="/home/${user}/.local/service"
pidfile="/run/runsvdir-user.${user}.pid"
command="/usr/bin/runsvdir"
command_args="$svdir"
command_user="$user"
command_background=true
depend()
{
2024-08-12 14:19:14 +02:00
after network-online
2024-08-11 22:39:30 +02:00
}
```
Make `/etc/init.d/runsvdir-user` an executable
```
# chmod +x /etc/init.d/runsvdir-user
```
Link the user to `/etc/init.d/runsvdir-user`
```
# ln -s /etc/init.d/runsvdir-user /etc/init.d/runsvdir-user.<username>
```
2024-08-12 14:19:14 +02:00
Finally, add the service to the default runlevel
2024-08-11 22:39:30 +02:00
```
2024-08-12 14:19:14 +02:00
# rc-update add runsvdir-user.<username> default
2024-08-11 22:39:30 +02:00
```
2024-08-12 14:19:14 +02:00
> This process can of course be repeated for several users.