Files
podman/pkg/systemd/quadlet/podmancmdline.go
Alexander Larsson 285d6c9ba0 quadlet: Rework uid/gid remapping
Quadlet was doing some custom handling of uid/gid remapping, originating
from pre --userns=auto support, including its own user for getting subuids
which kinda conflicts with the "container" user used for that.

This drops all the old support for id remapping in favour of a new set
of keys that more directly map to the podman run options.

We have essentially 3 modes now:

```
RemapUsers=manual
RemapUid=0:10000:10
RemapUid=10:20000:10
RemapGid=0:10000:10
RemapGid=10:20000:10
```

This maps to --uidmap and --gidmap options.

```
RemapUsers=auto
```

This maps to --userns=auto. But you can additionally specify RemapUid,
RemapGid and RemapUidSize which gets applied as options to the
--userns podman option.

```
RemapUsers=keep-id
```
This maps to --userns=keep-id and only works for user units.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2022-11-21 18:02:19 +01:00

54 lines
1.0 KiB
Go

package quadlet
import (
"fmt"
"sort"
)
/* This is a helper for constructing podman commandlines */
type PodmanCmdline struct {
Args []string
}
func (c *PodmanCmdline) add(args ...string) {
c.Args = append(c.Args, args...)
}
func (c *PodmanCmdline) addf(format string, a ...interface{}) {
c.add(fmt.Sprintf(format, a...))
}
func (c *PodmanCmdline) addKeys(arg string, keys map[string]string) {
ks := make([]string, 0, len(keys))
for k := range keys {
ks = append(ks, k)
}
sort.Strings(ks)
for _, k := range ks {
c.add(arg, fmt.Sprintf("%s=%s", k, keys[k]))
}
}
func (c *PodmanCmdline) addEnv(env map[string]string) {
c.addKeys("--env", env)
}
func (c *PodmanCmdline) addLabels(labels map[string]string) {
c.addKeys("--label", labels)
}
func (c *PodmanCmdline) addAnnotations(annotations map[string]string) {
c.addKeys("--annotation", annotations)
}
func NewPodmanCmdline(args ...string) *PodmanCmdline {
c := &PodmanCmdline{
Args: make([]string, 0),
}
c.add("/usr/bin/podman")
c.add(args...)
return c
}