-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pick: Add initial support for libsubid
Pick and adapt apptainer/apptainer#2433 Original description: This commit adds support for remote access to /etc/subuid and /etc/subgid mappings from ldap services using libsubid. Requires shadow-utils + libsubid. Code ported from podman / container storage. Signed-off-by: Andrew E. Bruno <[email protected]>
- Loading branch information
Showing
14 changed files
with
257 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ run: | |
- apparmor | ||
- e2e_test | ||
- fakeroot_engine | ||
- libsubid | ||
- seccomp | ||
- selinux | ||
- singularity_engine | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ The following have contributed code and/or documentation to this repository. | |
- Alexander Grund <[email protected]> | ||
- Amanda Duffy <[email protected]> | ||
- Ana Guerrero Lopez <[email protected]> | ||
- Andrew Bruno <[email protected]> | ||
- Ángel Bejarano <[email protected]> | ||
- Apuã Paquola <[email protected]> | ||
- Aron Öfjörð Jóhannesson <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
//go:build linux && cgo && libsubid | ||
// +build linux,cgo,libsubid | ||
|
||
// Portions of this code was adopted from github.com/containers/storage | ||
// Copyright (C) The Linux Foundation and its contributors. | ||
// Original source released under: Apache 2.0 license | ||
// See: https://github.com/containers/storage/blob/main/pkg/idtools/idtools_supported.go | ||
// | ||
// Copyright (c) Contributors to the Apptainer project, established as | ||
// Apptainer a Series of LF Projects LLC. | ||
// Copyright (c) 2019-2025, Sylabs Inc. All rights reserved. | ||
// This software is licensed under a 3-clause BSD license. Please consult the | ||
// LICENSE.md file distributed with the sources of this project regarding your | ||
// rights to use or distribute this software. | ||
|
||
package fakeroot | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"unsafe" | ||
|
||
"github.com/sylabs/singularity/v4/internal/pkg/util/user" | ||
) | ||
|
||
/* | ||
#cgo LDFLAGS: -l subid | ||
#include <shadow/subid.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
struct subid_range singularity_get_range(struct subid_range *ranges, int i) | ||
{ | ||
return ranges[i]; | ||
} | ||
#if !defined(SUBID_ABI_MAJOR) || (SUBID_ABI_MAJOR < 4) | ||
# define subid_get_uid_ranges get_subuid_ranges | ||
# define subid_get_gid_ranges get_subgid_ranges | ||
#endif | ||
*/ | ||
import "C" | ||
|
||
func readSubid(user *user.User, isUser bool) ([]*Entry, error) { | ||
ret := make([]*Entry, 0) | ||
uidstr := fmt.Sprintf("%d", user.UID) | ||
|
||
if user.Name == "ALL" { | ||
return nil, errors.New("username ALL not supported") | ||
} | ||
|
||
cUsername := C.CString(user.Name) | ||
defer C.free(unsafe.Pointer(cUsername)) | ||
|
||
cuidstr := C.CString(uidstr) | ||
defer C.free(unsafe.Pointer(cuidstr)) | ||
|
||
var nRanges C.int | ||
var cRanges *C.struct_subid_range | ||
if isUser { | ||
nRanges = C.subid_get_uid_ranges(cUsername, &cRanges) | ||
if nRanges <= 0 { | ||
nRanges = C.subid_get_uid_ranges(cuidstr, &cRanges) | ||
} | ||
} else { | ||
nRanges = C.subid_get_gid_ranges(cUsername, &cRanges) | ||
if nRanges <= 0 { | ||
nRanges = C.subid_get_gid_ranges(cuidstr, &cRanges) | ||
} | ||
} | ||
if nRanges < 0 { | ||
return nil, errors.New("cannot read subids") | ||
} | ||
defer C.free(unsafe.Pointer(cRanges)) | ||
|
||
for i := 0; i < int(nRanges); i++ { | ||
r := C.singularity_get_range(cRanges, C.int(i)) | ||
line := fmt.Sprintf("%d:%d:%d", user.UID, r.start, r.count) | ||
ret = append( | ||
ret, | ||
&Entry{ | ||
UID: user.UID, | ||
Start: uint32(r.start), | ||
Count: uint32(r.count), | ||
disabled: false, | ||
line: line, | ||
}) | ||
} | ||
return ret, nil | ||
} | ||
|
||
func readSubuid(user *user.User) ([]*Entry, error) { | ||
return readSubid(user, true) | ||
} | ||
|
||
func readSubgid(user *user.User) ([]*Entry, error) { | ||
return readSubid(user, false) | ||
} | ||
|
||
func (c *Config) getMappingEntries(user *user.User) ([]*Entry, error) { | ||
entries := make([]*Entry, 0) | ||
for _, entry := range c.entries { | ||
if entry.UID == user.UID { | ||
entries = append(entries, entry) | ||
} | ||
} | ||
|
||
var subidEntries []*Entry | ||
var err error | ||
if strings.Contains(c.file.Name(), "gid") { | ||
subidEntries, err = readSubgid(user) | ||
} else { | ||
subidEntries, err = readSubuid(user) | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return append(entries, subidEntries...), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build !linux || !libsubid || !cgo | ||
// +build !linux !libsubid !cgo | ||
|
||
// Copyright (c) Contributors to the Apptainer project, established as | ||
// Apptainer a Series of LF Projects LLC. | ||
// Copyright (c) 2019-2025, Sylabs Inc. All rights reserved. | ||
// This software is licensed under a 3-clause BSD license. Please consult the | ||
// LICENSE.md file distributed with the sources of this project regarding your | ||
// rights to use or distribute this software. | ||
|
||
package fakeroot | ||
|
||
import ( | ||
"github.com/sylabs/singularity/v4/internal/pkg/util/user" | ||
) | ||
|
||
func (c *Config) getMappingEntries(user *user.User) ([]*Entry, error) { | ||
entries := make([]*Entry, 0) | ||
for _, entry := range c.entries { | ||
if entry.UID == user.UID { | ||
entries = append(entries, entry) | ||
} | ||
} | ||
|
||
return entries, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/bin/sh - | ||
# Copyright (c) 2019-2024, Sylabs Inc. All rights reserved. | ||
# Copyright (c) 2019-2025, Sylabs Inc. All rights reserved. | ||
# Copyright (c) 2015-2018, Yannick Cote <[email protected]>. All rights reserved. | ||
# Copyright (c) Contributors to the Apptainer project, established as | ||
# Apptainer a Series of LF Projects LLC. | ||
|
@@ -62,6 +62,7 @@ with_conmon=1 | |
with_squashfuse=1 | ||
with_suid=1 | ||
with_seccomp_check=1 | ||
with_libsubid=1 | ||
|
||
builddir= | ||
prefix= | ||
|
@@ -117,6 +118,7 @@ usage_args () { | |
echo | ||
echo " Singularity options:" | ||
echo " --without-suid do not install SUID binary (linux only)" | ||
echo " --without-libsubid do not compile libsubid support even if available (linux only)" | ||
echo " --without-network do not compile/install network plugins (linux only)" | ||
echo " --without-seccomp do not compile/install seccomp support (linux only)" | ||
echo | ||
|
@@ -376,6 +378,8 @@ while [ $# -ne 0 ]; do | |
verbose=1; shift;; | ||
--without-suid) | ||
with_suid=0; shift;; | ||
--without-libsubid) | ||
with_libsubid=0; shift;; | ||
--without-network) | ||
with_network=0; shift;; | ||
--without-seccomp) | ||
|
@@ -783,6 +787,11 @@ if [ "$appsec" = "1" ]; then | |
cat $makeit_fragsdir/go_appsec_opts.mk >> $makeit_makefile | ||
fi | ||
|
||
if [ "$libsubid" = "1" ]; then | ||
drawline $makeit_fragsdir/go_libsubid_opts.mk | ||
cat $makeit_fragsdir/go_libsubid_opts.mk >> $makeit_makefile | ||
fi | ||
|
||
if [ "$build_runtime" = "1" ]; then | ||
drawline $makeit_fragsdir/go_runtime_opts.mk | ||
cat $makeit_fragsdir/go_runtime_opts.mk >> $makeit_makefile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GO_TAGS += libsubid | ||
GO_TAGS_SUID += libsubid |