Skip to content

Commit df88bed

Browse files
authored
fix(podman): support rootless user namespace configurations (NVIDIA#3527)
* test(podman): cover user namespace configurations Signed-off-by: Evan Lezar <elezar@nvidia.com> * fix(podman): support keep-id runtime groups Signed-off-by: Evan Lezar <elezar@nvidia.com> refactor(podman): generalize keep-id group handling Signed-off-by: Evan Lezar <elezar@nvidia.com> * ci(podman): run driver integration tests Signed-off-by: Evan Lezar <elezar@nvidia.com> --------- Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent 84960e7 commit df88bed

21 files changed

Lines changed: 1126 additions & 18 deletions

File tree

‎.github/workflows/branch-e2e.yml‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,21 @@ jobs:
247247
]
248248
249249
# Run driver-specific integration tests:
250-
# TODO: This should be added as soon as we have driver-specific tests enabled in tmachine.
251-
# driver-specific:
252-
# needs: prepare-integration
253-
# permissions:
254-
# actions: read
255-
# contents: read
256-
# packages: read
257-
# uses: ./.github/workflows/integration-runner.yml
258-
# with:
259-
# category: driver-specific
260-
# source-sha: ${{ needs.prepare-integration.outputs.source_sha }}
261-
# integration-inputs-artifact-id: ${{ needs.prepare-integration.outputs.integration_inputs_artifact_id }}
262-
# test-matrix: >-
263-
# [
264-
# ]
250+
driver-specific-integration:
251+
needs: prepare-integration
252+
permissions:
253+
actions: read
254+
contents: read
255+
packages: read
256+
uses: ./.github/workflows/integration-runner.yml
257+
with:
258+
category: driver-specific
259+
source-sha: ${{ needs.prepare-integration.outputs.source_sha }}
260+
integration-inputs-artifact-id: ${{ needs.prepare-integration.outputs.integration_inputs_artifact_id }}
261+
test-matrix: >-
262+
[
263+
{"environment":"fedora-podman-rootless","installer":"binaries","testsuite":"driver-podman"}
264+
]
265265
266266
docker-e2e:
267267
needs: [pr_metadata, build-binaries, build-images]
@@ -451,6 +451,7 @@ jobs:
451451
- pr_metadata
452452
- conformance-integration
453453
- feature-specific-integration
454+
- driver-specific-integration
454455
- docker-e2e
455456
- vm-e2e
456457
- docker-external-driver-e2e

‎crates/openshell-driver-podman/src/driver.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,9 @@ impl PodmanComputeDriver {
11591159
&workload_id,
11601160
&uuid::Uuid::new_v4().to_string(),
11611161
&identity,
1162+
crate::isolation::userns_preserves_host_groups(
1163+
self.config.userns.as_deref(),
1164+
),
11621165
child_env,
11631166
&launch_authentication,
11641167
)?;
@@ -1501,6 +1504,7 @@ impl PodmanComputeDriver {
15011504
&container_id,
15021505
generation.as_str(),
15031506
&restart_metadata.workload_identity,
1507+
crate::isolation::userns_preserves_host_groups(self.config.userns.as_deref()),
15041508
restart_metadata.child_env,
15051509
&launch_authentication,
15061510
)?;

‎crates/openshell-driver-podman/src/isolation.rs‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use openshell_core::proto::compute::v1::DriverSandbox;
1313
use openshell_isolation_interface::contract::{
1414
OuterFenceGuarantee, OuterFenceGuarantees, ResolvedWorkloadIdentity,
1515
};
16+
use openshell_sandbox_backend::ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM;
1617
use openshell_sandbox_backend::boundary_protocol::{
1718
BoundaryConfig, BoundaryListener, GatewayVerificationKey, SandboxRuntimeDescriptor,
1819
SandboxTlsClientConfig, SandboxTlsServerConfig, SandboxTransport,
@@ -70,6 +71,12 @@ pub fn channel_volume_name(id: &str) -> String {
7071
format!("openshell-channel-{id}")
7172
}
7273

74+
/// `keep-id` may retain the gateway user's supplementary groups in the
75+
/// container. Other user-namespace modes, including `auto`, do not.
76+
pub fn userns_preserves_host_groups(userns: Option<&str>) -> bool {
77+
userns.is_some_and(|mode| mode.split(':').next() == Some("keep-id"))
78+
}
79+
7380
fn invalid(error: impl std::fmt::Display) -> ComputeDriverError {
7481
ComputeDriverError::Precondition(error.to_string())
7582
}
@@ -195,19 +202,26 @@ pub fn bootstrap_archives(
195202
container_id: &str,
196203
generation: &str,
197204
identity: &ResolvedWorkloadIdentity,
205+
allow_extra_supplementary_groups: bool,
198206
child_env: HashMap<String, String>,
199207
launch_authentication: &openshell_core::jwt::SandboxLaunchAuthentication,
200208
) -> Result<BootstrapArchives, ComputeDriverError> {
201209
launch_authentication.validate().map_err(invalid)?;
202210
let session_id = launch_authentication.supervisor.session_id;
203211
let tls = generate_sandbox_tls_material(session_id).map_err(invalid)?;
204-
let resource_claims = BTreeMap::from([
212+
let mut resource_claims = BTreeMap::from([
205213
("podman.container_id".into(), container_id.into()),
206214
(
207215
"podman.image_identity".into(),
208216
identity.resource_digest.clone(),
209217
),
210218
]);
219+
if allow_extra_supplementary_groups {
220+
resource_claims.insert(
221+
ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM.into(),
222+
"true".into(),
223+
);
224+
}
211225
let runtime_generation = launch_authentication
212226
.supervisor
213227
.runtime_generation
@@ -496,6 +510,7 @@ mod tests {
496510
"container",
497511
"generation-1",
498512
&identity,
513+
false,
499514
child_env.clone(),
500515
&authentication,
501516
)
@@ -541,6 +556,11 @@ mod tests {
541556
.outer_fence
542557
.validate(&runtime_descriptor.generation)
543558
.unwrap();
559+
assert!(
560+
!config
561+
.resource_claims
562+
.contains_key(ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM)
563+
);
544564
let restart_metadata: RestartMetadata = serde_json::from_slice(
545565
supervisor
546566
.get(&PathBuf::from(
@@ -558,4 +578,15 @@ mod tests {
558578
.any(|window| window == b"PRIVATE KEY")
559579
);
560580
}
581+
582+
#[test]
583+
fn keep_id_is_the_only_userns_mode_that_preserves_host_groups() {
584+
assert!(userns_preserves_host_groups(Some("keep-id")));
585+
assert!(userns_preserves_host_groups(Some(
586+
"keep-id:uid=1000,gid=1000"
587+
)));
588+
assert!(!userns_preserves_host_groups(Some("auto")));
589+
assert!(!userns_preserves_host_groups(Some("private")));
590+
assert!(!userns_preserves_host_groups(None));
591+
}
561592
}

‎crates/openshell-sandbox-backend/src/lib.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ pub const BACKEND_NAME: &str = "openshell-sandbox";
2121
/// Resource claim set by compute drivers when the workload requests GPU access.
2222
pub const GPU_RESOURCE_CLAIM: &str = "openshell.gpu";
2323

24+
/// Resource claim set when the runtime may retain supplementary groups in
25+
/// addition to the image-derived workload identity.
26+
pub const ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM: &str =
27+
"openshell.identity.allow_extra_supplementary_groups";
28+
2429
/// Memory-backed parent used for supervisor CA material.
2530
pub const SUPERVISOR_CA_RUNTIME_ROOT: &str = "/run/openshell-supervisor-ca";
2631

‎crates/openshell-sandbox/src/boundary_server.rs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ mod linux {
3939
BoundaryConfirmation, BoundaryExec, BoundaryLoopbackConnector, BoundaryProcess,
4040
BoundaryTerminal, ExecSession, LoopbackTarget, ResolvedWorkloadIdentity,
4141
};
42-
use openshell_sandbox_backend::GPU_RESOURCE_CLAIM;
4342
use openshell_sandbox_backend::mediation::{
4443
self, DnsQueryWire, MediationFrame, MediationFrameKind,
4544
};
@@ -53,6 +52,9 @@ mod linux {
5352
SandboxConnectionId, SandboxConnectionRegistry, SandboxProtocolAuthenticator,
5453
SandboxProtocolPrincipal,
5554
};
55+
use openshell_sandbox_backend::{
56+
ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM, GPU_RESOURCE_CLAIM,
57+
};
5658
use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
5759
use tokio_stream::wrappers::ReceiverStream;
5860

@@ -389,6 +391,10 @@ mod linux {
389391
.resource_claims
390392
.get(GPU_RESOURCE_CLAIM)
391393
.is_some_and(|value| value == "true")
394+
|| config
395+
.resource_claims
396+
.get(ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM)
397+
.is_some_and(|value| value == "true")
392398
}
393399

394400
fn supplementary_groups_match(actual: &[u32], expected: &[u32], allow_extra: bool) -> bool {
@@ -3834,6 +3840,33 @@ mod linux {
38343840
assert!(!supplementary_groups_match(&[44, 992], &[1001], true));
38353841
}
38363842

3843+
#[test]
3844+
fn generic_identity_claim_allows_runtime_supplementary_groups() {
3845+
let config = BoundaryConfig {
3846+
boundary_id: "sandbox-1".to_string(),
3847+
generation: "generation-1".to_string(),
3848+
session_id: test_session_id(),
3849+
session_rotation: openshell_core::jwt::SessionRotation::new(1)
3850+
.expect("session rotation"),
3851+
auth_epoch: CredentialEpoch::new(1).expect("auth epoch"),
3852+
gateway_id: "test-gateway".to_string(),
3853+
verification_keys: vec![],
3854+
listener: BoundaryListenerConfig::Vsock {
3855+
control_port: 5500,
3856+
tls: placeholder_server_tls(),
3857+
},
3858+
resource_claims: std::collections::BTreeMap::from([(
3859+
ALLOW_EXTRA_SUPPLEMENTARY_GROUPS_RESOURCE_CLAIM.to_string(),
3860+
"true".to_string(),
3861+
)]),
3862+
resource_claim_files: std::collections::BTreeMap::new(),
3863+
workload_identity: test_workload_identity(),
3864+
outer_fence: test_outer_fence(),
3865+
child_env: std::collections::HashMap::new(),
3866+
};
3867+
assert!(allows_runtime_supplementary_groups(&config));
3868+
}
3869+
38373870
#[test]
38383871
fn control_connection_slots_bound_authenticated_sessions() {
38393872
let active = Arc::new(AtomicUsize::new(MAX_CONTROL_CONNECTIONS - 1));
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
- name: Capture the default rootless Podman user-namespace mapping
6+
hosts: all
7+
gather_facts: false
8+
vars:
9+
podman_reference_image: "{{ openshell_podman_reference_image }}"
10+
podman_reference_uid_map: /var/lib/openshell-test-inputs/podman/reference-uid-map
11+
tasks:
12+
- name: Wait for SSH
13+
ansible.builtin.wait_for_connection:
14+
15+
- name: Read OpenShell gateway service user
16+
become: true
17+
ansible.builtin.command:
18+
argv:
19+
- systemctl
20+
- show
21+
- openshell-gateway.service
22+
- --property
23+
- User
24+
- --value
25+
changed_when: false
26+
register: openshell_gateway_service_user
27+
28+
- name: Require the rootless Podman gateway user
29+
ansible.builtin.assert:
30+
that:
31+
- openshell_gateway_service_user.stdout == "tmachine"
32+
fail_msg: >-
33+
The Podman default-userns suite requires a rootless Podman gateway
34+
running as tmachine, not {{ openshell_gateway_service_user.stdout | default("unknown") }}
35+
36+
- name: Read OpenShell gateway configuration
37+
become: true
38+
ansible.builtin.slurp:
39+
src: /etc/openshell/gateway.toml
40+
register: openshell_gateway_config
41+
42+
- name: Require unconfigured Podman user namespaces
43+
ansible.builtin.assert:
44+
that:
45+
- >-
46+
(openshell_gateway_config.content | b64decode)
47+
is not regex('(?m)^\\s*(userns|uidmap|gidmap)\\s*=')
48+
fail_msg: >-
49+
The Podman default-userns suite requires gateway.toml to omit userns,
50+
uidmap, and gidmap.
51+
52+
- name: Resolve tmachine UID
53+
ansible.builtin.command:
54+
argv:
55+
- id
56+
- -u
57+
- tmachine
58+
changed_when: false
59+
register: tmachine_uid
60+
61+
- name: Create Podman test-input directory
62+
become: true
63+
ansible.builtin.file:
64+
path: "{{ podman_reference_uid_map | dirname }}"
65+
state: directory
66+
owner: tmachine
67+
group: tmachine
68+
mode: "0700"
69+
70+
- name: Pull the Podman reference image
71+
become: true
72+
become_user: tmachine
73+
ansible.builtin.command:
74+
argv: [podman, pull, "{{ podman_reference_image }}"]
75+
environment:
76+
HOME: /home/tmachine
77+
XDG_RUNTIME_DIR: "/run/user/{{ tmachine_uid.stdout }}"
78+
changed_when: false
79+
80+
- name: Capture direct Podman default UID mapping
81+
become: true
82+
become_user: tmachine
83+
ansible.builtin.command:
84+
argv:
85+
- podman
86+
- run
87+
- --rm
88+
- --pull
89+
- never
90+
- --entrypoint
91+
- /bin/cat
92+
- "{{ podman_reference_image }}"
93+
- /proc/self/uid_map
94+
environment:
95+
HOME: /home/tmachine
96+
XDG_RUNTIME_DIR: "/run/user/{{ tmachine_uid.stdout }}"
97+
changed_when: false
98+
register: podman_default_uid_map
99+
100+
- name: Require a direct Podman UID mapping
101+
ansible.builtin.assert:
102+
that:
103+
- podman_default_uid_map.stdout | trim | length > 0
104+
fail_msg: Direct rootless Podman reference container returned no UID mapping
105+
106+
- name: Store direct Podman default UID mapping
107+
become: true
108+
ansible.builtin.copy:
109+
content: "{{ podman_default_uid_map.stdout | trim }}\n"
110+
dest: "{{ podman_reference_uid_map }}"
111+
owner: tmachine
112+
group: tmachine
113+
mode: "0600"

0 commit comments

Comments
 (0)