Merge pull request #20395 from rhatdan/quadlet

Allow systemd specifiers in User and Group Quadlet keys
This commit is contained in:
openshift-ci[bot] 2023-10-19 09:28:12 +00:00 committed by GitHub
commit c2e1debe8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 13 deletions

View File

@ -617,18 +617,8 @@ func ConvertContainer(container *parser.UnitFile, names map[string]string, isUse
podman.add("--read-only-tmpfs=false")
}
hasUser := container.HasKey(ContainerGroup, KeyUser)
hasGroup := container.HasKey(ContainerGroup, KeyGroup)
if hasUser || hasGroup {
uid := container.LookupUint32(ContainerGroup, KeyUser, 0)
gid := container.LookupUint32(ContainerGroup, KeyGroup, 0)
podman.add("--user")
if hasGroup {
podman.addf("%d:%d", uid, gid)
} else {
podman.addf("%d", uid)
}
if err := handleUser(container, ContainerGroup, podman); err != nil {
return nil, err
}
if workdir, exists := container.Lookup(ContainerGroup, KeyWorkingDir); exists {
@ -1231,6 +1221,30 @@ func ConvertImage(image *parser.UnitFile) (*parser.UnitFile, string, error) {
return service, imageName, nil
}
func handleUser(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline) error {
user, hasUser := unitFile.Lookup(groupName, KeyUser)
okUser := hasUser && len(user) > 0
group, hasGroup := unitFile.Lookup(groupName, KeyGroup)
okGroup := hasGroup && len(group) > 0
if !okUser {
if okGroup {
return fmt.Errorf("invalid Group set without User")
}
return nil
}
if !okGroup {
podman.add("--user", user)
return nil
}
podman.addf("--user=%s:%s", user, group)
return nil
}
func handleUserRemap(unitFile *parser.UnitFile, groupName string, podman *PodmanCmdline, isUser, supportManual bool) error {
// ignore Remap keys if UserNS is set
if userns, ok := unitFile.Lookup(groupName, KeyUserNS); ok && len(userns) > 0 {

View File

@ -0,0 +1,6 @@
## assert-failed
## assert-stderr-contains "Group set without User"
[Container]
Image=localhost/imagename
Group=foobar

View File

@ -1,5 +1,5 @@
## assert-podman-final-args localhost/imagename
## assert-podman-args "--user" "998:999"
## assert-podman-args "--user=998:999"
[Container]
Image=localhost/imagename

View File

@ -0,0 +1,6 @@
## assert-podman-final-args localhost/imagename
## assert-podman-args "--user=%U:%G"
[Container]
Image=localhost/imagename
User=%U:%G

View File

@ -0,0 +1,7 @@
## assert-podman-final-args localhost/imagename
## assert-podman-args "--user=%U:%G"
[Container]
Image=localhost/imagename
User=%U
Group=%G