@@ -1402,6 +1402,8 @@ pub struct IsolationSpecInput<'a> {
14021402 pub supervisor_bin : Option < & ' a Path > ,
14031403 pub tls_secrets : Option < & ' a [ String ; 3 ] > ,
14041404 pub identity : & ' a openshell_isolation_interface:: contract:: ResolvedWorkloadIdentity ,
1405+ /// Whether this workload is created by a rootless Podman service.
1406+ pub rootless : bool ,
14051407}
14061408
14071409pub struct IsolationSpecs {
@@ -1439,19 +1441,44 @@ pub fn build_isolation_specs(
14391441 . iter ( )
14401442 . filter_map ( |entry| entry. split_once ( '=' ) . map ( |( key, _) | key. to_string ( ) ) )
14411443 . collect ( ) ;
1442- workload. command = vec ! [
1443- "--bootstrap" . into( ) ,
1444- crate :: isolation:: BOOTSTRAP_PATH . into( ) ,
1445- ] ;
1446- workload. user . clone_from ( & user) ;
1447- workload. groups = input
1448- . identity
1449- . supplementary_gids
1450- . iter ( )
1451- . map ( ToString :: to_string)
1452- . collect ( ) ;
1453- workload. cap_drop = vec ! [ "ALL" . into( ) ] ;
1454- workload. cap_add . clear ( ) ;
1444+ if input. rootless {
1445+ // Podman's archive endpoint writes named-volume contents with the
1446+ // rootless gateway user's host ownership. In a remapped user namespace,
1447+ // that is container root rather than the resolved workload UID. Start
1448+ // the trusted runtime as namespace root only long enough to chown the
1449+ // empty workspace and irreversibly drop to the resolved identity before
1450+ // it reads bootstrap material or accepts a control connection.
1451+ workload. command = vec ! [
1452+ "launch-capability-free" . into( ) ,
1453+ input. identity. uid. to_string( ) ,
1454+ input. identity. gid. to_string( ) ,
1455+ crate :: isolation:: BOOTSTRAP_PATH . into( ) ,
1456+ driver_mounts:: DEFAULT_WORKSPACE_ROOT . into( ) ,
1457+ ] ;
1458+ workload. user = "0:0" . into ( ) ;
1459+ workload. groups . clear ( ) ;
1460+ workload. cap_drop = vec ! [ "ALL" . into( ) ] ;
1461+ workload. cap_add = vec ! [
1462+ "CHOWN" . into( ) ,
1463+ "SETGID" . into( ) ,
1464+ "SETUID" . into( ) ,
1465+ "SETPCAP" . into( ) ,
1466+ ] ;
1467+ } else {
1468+ workload. command = vec ! [
1469+ "--bootstrap" . into( ) ,
1470+ crate :: isolation:: BOOTSTRAP_PATH . into( ) ,
1471+ ] ;
1472+ workload. user . clone_from ( & user) ;
1473+ workload. groups = input
1474+ . identity
1475+ . supplementary_gids
1476+ . iter ( )
1477+ . map ( ToString :: to_string)
1478+ . collect ( ) ;
1479+ workload. cap_drop = vec ! [ "ALL" . into( ) ] ;
1480+ workload. cap_add . clear ( ) ;
1481+ }
14551482 workload. apparmor_profile = input
14561483 . config
14571484 . app_armor_profile
@@ -1740,16 +1767,33 @@ mod tests {
17401767 supervisor_bin : None ,
17411768 tls_secrets : None ,
17421769 identity : & identity,
1770+ rootless : true ,
17431771 } )
17441772 . unwrap ( ) ;
17451773 for spec in [ & specs. workload , & specs. supervisor ] {
1746- assert_eq ! ( spec. user, "1000:1001" ) ;
1747- assert_eq ! ( spec. groups, vec![ "2000" ] ) ;
17481774 assert_eq ! ( spec. cap_drop, vec![ "ALL" ] ) ;
1749- assert ! ( spec. cap_add. is_empty( ) ) ;
17501775 assert ! ( spec. seccomp_profile_path. is_empty( ) ) ;
17511776 assert ! ( spec. no_new_privileges) ;
17521777 }
1778+ assert_eq ! ( specs. workload. user, "0:0" ) ;
1779+ assert ! ( specs. workload. groups. is_empty( ) ) ;
1780+ assert_eq ! (
1781+ specs. workload. cap_add,
1782+ vec![ "CHOWN" , "SETGID" , "SETUID" , "SETPCAP" ]
1783+ ) ;
1784+ assert_eq ! (
1785+ specs. workload. command,
1786+ vec![
1787+ "launch-capability-free" ,
1788+ "1000" ,
1789+ "1001" ,
1790+ crate :: isolation:: BOOTSTRAP_PATH ,
1791+ driver_mounts:: DEFAULT_WORKSPACE_ROOT ,
1792+ ]
1793+ ) ;
1794+ assert_eq ! ( specs. supervisor. user, "1000:1001" ) ;
1795+ assert_eq ! ( specs. supervisor. groups, vec![ "2000" ] ) ;
1796+ assert ! ( specs. supervisor. cap_add. is_empty( ) ) ;
17531797 assert_eq ! ( specs. workload. netns. nsmode, "none" ) ;
17541798 assert_eq ! (
17551799 specs
0 commit comments