Skip to content

Conversation

@ningmingxiao
Copy link
Contributor

@ningmingxiao ningmingxiao commented Dec 6, 2025

@ningmingxiao ningmingxiao force-pushed the selinux_support branch 7 times, most recently from d69b7e0 to 2eaa687 Compare December 6, 2025 15:21
@ningmingxiao ningmingxiao changed the title feature:support selinux use --security-opt label=xxx feature:support selinux Dec 6, 2025
@ningmingxiao ningmingxiao changed the title feature:support selinux feature: support selinux Dec 6, 2025

func TestRunSelinuxWithSecurityOpt(t *testing.T) {
require.Not(nerdtest.NoSelinux)
base := testutil.NewBase(t)
Copy link
Member

@AkihiroSuda AkihiroSuda Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspectCmd := base.Cmd("inspect", testContainer, "--format", "{{.State.Pid}}")
inspectRes := inspectCmd.Run()
pid := strings.TrimSpace(inspectRes.Stdout())
cmd := exec.Command("ps", "-Z", pid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just read /proc/PID/attr/* without using ps -Z

defer func() {
base.Cmd("rm", "-f", testContainer)
}()
inspectCmd := base.Cmd("inspect", testContainer, "--format", "{{.State.Pid}}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nerdctl container inspect, not nerdctl inspect

DNSOpts []string `toml:"dns_opts,omitempty"`
DNSSearch []string `toml:"dns_search,omitempty"`
DisableHCSystemd bool `toml:"disable_hc_systemd"`
SexlinuxEnabled bool `toml:"selinux_enabled"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

require.Not(nerdtest.NoSelinux)
base := testutil.NewBase(t)
testContainer := testutil.Identifier(t)
base.Cmd("--selinux-enabled", "run", "--name", testContainer, "-d", testutil.AlpineImage, "sleep", "infinity").AssertOK()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For docker target, this has to be skipped, or executed with a custom daemon config

require.Not(nerdtest.NoSelinux)
base := testutil.NewBase(t)
testContainer := testutil.Identifier(t)
base.Cmd("run", "--name", testContainer, "-d", "--security-opt", "label=type:container_t", testutil.AlpineImage, "sleep", "infinity").AssertOK()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need --selinux-enabled?

}
}

func TestRunSelinux(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not really useful without :z and :Z mounts

if err != nil {
output := strings.TrimSpace(string(stdout))
if strings.Contains(output, "container_t") {
t.Fatal(fmt.Errorf("expect label container_t but get %s", output))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uniqueness of the MCS categories have to be checked too?

- :nerd_face: `--host-gateway-ip`: IP address that the special 'host-gateway' string in --add-host resolves to. It has no effect without setting --add-host
- Default: the IP address of the host
- :nerd_face: `--userns-remap=<username>:<groupname>`: Support idmapping of containers. This options is only supported on rootful linux for container create and run if a user name and optionally group name is passed, it does idmapping based on the uidmap and gidmap ranges specified in /etc/subuid and /etc/subgid respectively. Note: `--userns-remap` is not supported for building containers. Nerdctl Build doesn't support userns-remap feature. (format: <name|uid>[:<group|gid>])
- :nerd_face: `--selinux-enabled`: Enable selinux support
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkihiroSuda AkihiroSuda added this to the v2.3.0 milestone Dec 8, 2025
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
@ningmingxiao ningmingxiao marked this pull request as draft December 9, 2025 01:52
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.

2 participants