Skip to content

Commit dd03f1a

Browse files
committed
Quadlet - Error when units define User, Group, or DynamicUser in Service group
Fixes: #26543 Signed-off-by: Evan Miller <miller.evan815@gmail.com>
1 parent 5d48c0b commit dd03f1a

12 files changed

+69
-0
lines changed

docs/source/markdown/podman-systemd.unit.5.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ session gets started. For unit files placed in subdirectories within
7878
/etc/containers/systemd/user/${UID}/ and the other user unit search paths,
7979
Quadlet will recursively search and run the unit files present in these subdirectories.
8080

81+
Note that Quadlet units do not support running as a non-root user by defining the
82+
[User, Group](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#User=),
83+
or [DynamicUser](https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#DynamicUser=)
84+
systemd options. If you want to run a rootless Quadlet, you will need to create the user
85+
and add the unit file to one of the above rootless unit search paths.
86+
8187
Note: When a Quadlet is starting, Podman often pulls or builds one more container images which may take a considerable amount of time.
8288
Systemd defaults service start time to 90 seconds, or fails the service. Pre-pulling the image or extending
8389
the systemd timeout time for the service using the *TimeoutStartSec* Service option can fix the problem.

pkg/systemd/quadlet/quadlet.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ const (
186186
KeyYaml = "Yaml"
187187
)
188188

189+
// Unsupported keys in the Service group. Defined here so we can error when they are found
190+
var UnsupportedServiceKeys = [...]string{"User", "Group", "DynamicUser"}
191+
189192
type UnitInfo struct {
190193
// The name of the generated systemd service unit
191194
ServiceName string
@@ -2245,6 +2248,14 @@ func initServiceUnitFile(quadletUnitFile *parser.UnitFile, isUser bool, unitsInf
22452248
return nil, nil, err
22462249
}
22472250

2251+
// These Service keys cannot be used in a Quadlet unit
2252+
for _, key := range UnsupportedServiceKeys {
2253+
_, hasKey := quadletUnitFile.Lookup(ServiceGroup, key)
2254+
if hasKey {
2255+
return nil, nil, fmt.Errorf("using key %s in the Service group is not supported", key)
2256+
}
2257+
}
2258+
22482259
service := quadletUnitFile.Dup()
22492260
service.Filename = unitInfo.ServiceFileName()
22502261

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key DynamicUser in the Service group is not supported"
3+
[Service]
4+
DynamicUser=foobar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key DynamicUser in the Service group is not supported"
3+
[Service]
4+
DynamicUser=foobar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key DynamicUser in the Service group is not supported"
3+
[Service]
4+
DynamicUser=foobar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key DynamicUser in the Service group is not supported"
3+
[Service]
4+
DynamicUser=foobar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key DynamicUser in the Service group is not supported"
3+
[Service]
4+
DynamicUser=foobar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key DynamicUser in the Service group is not supported"
3+
[Service]
4+
DynamicUser=foobar
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key DynamicUser in the Service group is not supported"
3+
[Service]
4+
DynamicUser=foobar
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## assert-failed
2+
## assert-stderr-contains "using key Group in the Service group is not supported"
3+
[Container]
4+
Group=1000 # This is fine
5+
6+
[Service]
7+
Group=1000 # This isn't

0 commit comments

Comments
 (0)