Skip to content

Commit 4a41b3c

Browse files
committed
Fix rootless container spawning
It turns out that Arch Linux does not come with `/etc/{subuid,subgid}` files by default, unlike most Linux distributions. They must be present and configured correctly in order to work, and also the `--rootless` global runtime flag should be dropped from `crun`. This makes the `config.json` generated by `umoci` work without the `crun spec --rootless` hotfix we had until now, and it also finally fixes the errors seen in `crun start <id>`! This commit also adds a new "Troubleshooting" section to the `README.md` which documents the creation/configuration of the `/etc/{subuid,subgid}` files for this program, if they don't come ready with your particular Linux distribution by default.
1 parent 42a675f commit 4a41b3c

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,45 @@ TODO
6565
dependencies for `#![no_std]` alternatives, or rewriting certain functionality
6666
ourselves with adequate tests.
6767
* TODO: Add more as we go along...
68+
69+
## Troubleshooting
70+
71+
This container engine leverages [rootless containers] for increased security,
72+
convenience, and flexibility. Like other rootless container engines, e.g.
73+
[rootless Podman], there are several Linux kernel features that must be
74+
available for this engine to run:
75+
76+
[rootless containers]: https://rootlesscontaine.rs/
77+
[rootless Podman]: https://github.com/containers/podman/blob/master/rootless.md
78+
79+
### 1) System must have `/etc/subuid` and `/etc/subguid`
80+
81+
> Required for _container creation_
82+
83+
If you see an error like this when starting containers:
84+
85+
```text
86+
writing file `/proc/7109/gid_map`: Invalid argument
87+
setresuid(0): Invalid argument
88+
```
89+
90+
then it is possible that your Linux distribution may not come with `/etc/subuid`
91+
and/or `etc/subgid` files, or perhaps they are configured incorrectly. For
92+
example, Arch Linux's version of `shadow` does not come with either file by
93+
default.
94+
95+
If neither `/etc/subuid` nor `/etc/subgid` exist, you can create them like so:
96+
97+
```bash
98+
USERNAME=$(whoami) # Alternatively, use a user group that you belong to.
99+
echo "$USERNAME:165536-169631" | sudo tee /etc/subuid /etc/subgid
100+
```
101+
102+
On the other hand, if both `/etc/subuid` and `/etc/subgid` exist, but your user
103+
or member group is missing, you can dedicate a range of sub-UIDs and GIDs to
104+
yourself for use with `light-containerd`:
105+
106+
```bash
107+
USERNAME=$(whoami) # Alternatively, use a user group that you belong to.
108+
sudo usermod --add-subuids 165536-169631 --add-subgids 165536-169631 "$USERNAME"
109+
```

src/container.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ impl Container {
5151
.args(&["--cuuid", &uuid_str])
5252
.args(&["--name", &id])
5353
.args(&["--runtime", RUNTIME_BIN])
54-
.args(&["--runtime-arg", "--rootless=true"])
5554
.args(&["--bundle", bundle_dir])
5655
.args(&["--exit-dir", exits_dir])
5756
.args(&["--log-path", log_file])
@@ -145,7 +144,10 @@ impl Container {
145144

146145
impl Drop for Container {
147146
fn drop(&mut self) {
148-
unsafe { libc::kill(self.pid, libc::SIGKILL) };
147+
std::process::Command::new(RUNTIME_BIN)
148+
.args(&["delete", "--force", &self.id])
149+
.status()
150+
.ok();
149151
}
150152
}
151153

src/image.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use tokio::process::Command;
1010

1111
const SKOPEO_BIN: &str = "skopeo";
1212
const UMOCI_BIN: &str = "umoci";
13-
const CRUN_BIN: &str = "crun";
1413

1514
/// Represents a fetched OCI image.
1615
#[derive(Debug)]
@@ -113,28 +112,6 @@ impl OciBundle {
113112
));
114113
}
115114

116-
// Replace rootless `config.json` generated by `umoci` because it doesn't work properly.
117-
tokio::fs::remove_file(bundle_dir.join("config.json")).await?;
118-
119-
// This configuration file works properly on rootless systems, according to my testing.
120-
let mut gen_rootless_spec_cmd = Command::new(CRUN_BIN);
121-
let output = gen_rootless_spec_cmd
122-
.stdout(Stdio::piped())
123-
.stderr(Stdio::piped())
124-
.args(&["spec", "--rootless"])
125-
.current_dir(&bundle_dir)
126-
.output()
127-
.await?;
128-
129-
if !output.status.success() {
130-
let stderr = String::from_utf8(output.stderr)?;
131-
return Err(anyhow!(
132-
"failed to generate rootless spec, `{:?}` returned non-zero exit status: [{}]",
133-
gen_rootless_spec_cmd,
134-
stderr
135-
));
136-
}
137-
138115
// Create the `exits` subdirectory so it can be used by `conmon` later.
139116
tokio::fs::create_dir(&exits_dir).await?;
140117

0 commit comments

Comments
 (0)