Skip to content

Commit bc4ec94

Browse files
committed
Fix users on debian and add postinstall reqs
1 parent 6ca1e15 commit bc4ec94

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

packaging/linux/deb/debroot.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,6 @@ func setArtifactCapabilitiesPostInst(w *bytes.Buffer, spec *dalec.Spec, target s
741741
sorted := dalec.SortMapKeys(artifacts)
742742
for _, key := range sorted {
743743
cfg := artifacts[key]
744-
// We use the %cap macro when possible and only use setcap postinstall
745-
// if there is a user/group because chmod clear any capabilities previously set.
746-
if cfg.Group == "" && cfg.User == "" {
747-
continue
748-
}
749744
capString := dalec.CapabilitiesString(cfg.Capabilities)
750745
if capString == "" {
751746
continue

packaging/linux/rpm/template.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,30 @@ func getUserPostRequires(users []dalec.AddUserConfig, groups []dalec.AddGroupCon
181181
return out
182182
}
183183

184+
// We need this because AlmaLinux9 do not have chown/chgrp at install time.
185+
// However, AzureLinux cannot resolve the /usr/bin/chown requirement.
186+
// Thus, we just require coreutils which provides chown/chgrp on all distros hopefully.
187+
func getOwnershipPostRequires(artifacts dalec.Artifacts) string {
188+
out := "Requires(post): coreutils\n"
189+
for _, cfg := range artifacts.Binaries {
190+
if cfg.User != "" || cfg.Group != "" {
191+
return out
192+
}
193+
}
194+
for _, cfg := range artifacts.Libs {
195+
if cfg.User != "" || cfg.Group != "" {
196+
return out
197+
}
198+
}
199+
for _, cfg := range artifacts.Libexec {
200+
if cfg.User != "" || cfg.Group != "" {
201+
return out
202+
}
203+
}
204+
205+
return ""
206+
}
207+
184208
func (w *specWrapper) Requires() fmt.Stringer {
185209
b := &strings.Builder{}
186210

@@ -192,6 +216,7 @@ func (w *specWrapper) Requires() fmt.Stringer {
192216
// package names... something to consider as we expand functionality.
193217
b.WriteString(getSystemdRequires(artifacts.Systemd))
194218
b.WriteString(getUserPostRequires(artifacts.Users, artifacts.Groups))
219+
b.WriteString(getOwnershipPostRequires(artifacts))
195220

196221
deps := w.GetPackageDeps(w.Target)
197222
buildDeps := deps.GetBuild()

test/linux_target_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3915,13 +3915,16 @@ func testArtifactCapabilities(ctx context.Context, t *testing.T, testConfig test
39153915
rpmTarget := dalec.Target{
39163916
Dependencies: &dalec.PackageDependencies{
39173917
Runtime: map[string]dalec.PackageConstraints{
3918-
"libcap": {},
3918+
"coreutils": {},
3919+
"libcap": {},
39193920
},
39203921
Build: map[string]dalec.PackageConstraints{
3921-
"libcap": {},
3922+
"coreutils": {},
3923+
"libcap": {},
39223924
},
39233925
Test: map[string]dalec.PackageConstraints{
39243926
"coreutils": {},
3927+
"libcap": {},
39253928
},
39263929
},
39273930
}
@@ -4012,7 +4015,7 @@ echo "This is a third test binary"
40124015
},
40134016
},
40144017
"/tmp/ping3": {
4015-
Name: "ping3",
4018+
Name: "ping3",
40164019
Group: "testgroup",
40174020
Capabilities: []dalec.ArtifactCapability{
40184021
{
@@ -4047,6 +4050,7 @@ echo "This is a third test binary"
40474050
"focal": debTarget,
40484051
"jammy": debTarget,
40494052
"noble": debTarget,
4053+
"trixie": debTarget,
40504054
},
40514055
Tests: []*dalec.TestSpec{
40524056
{
@@ -4055,13 +4059,19 @@ echo "This is a third test binary"
40554059
{
40564060
Command: "getcap /usr/bin/ping",
40574061
Stdout: dalec.CheckOutput{
4058-
Equals: "/usr/bin/ping cap_net_admin=eip cap_net_raw+ep \n",
4062+
// Different distros list capabilities different ways
4063+
Contains: []string{
4064+
"/usr/bin/ping", "cap_net_admin", "eip", "cap_net_raw", "ep",
4065+
},
40594066
},
40604067
},
40614068
{
40624069
Command: "getcap /usr/bin/ping2",
40634070
Stdout: dalec.CheckOutput{
4064-
Equals: "/usr/bin/ping2 cap_net_raw=ep\n",
4071+
// Different distros list capabilities different ways
4072+
Contains: []string{
4073+
"/usr/bin/ping2", "cap_net_raw", "ep",
4074+
},
40654075
},
40664076
},
40674077
{
@@ -4073,13 +4083,16 @@ echo "This is a third test binary"
40734083
{
40744084
Command: "getcap /usr/bin/ping3",
40754085
Stdout: dalec.CheckOutput{
4076-
Equals: "/usr/bin/ping3 cap_net_bind_service=ep\n",
4086+
// Different distros list capabilities different ways
4087+
Contains: []string{
4088+
"/usr/bin/ping3", "cap_net_bind_service", "ep",
4089+
},
40774090
},
40784091
},
40794092
{
40804093
Command: "stat -c '%G' /usr/bin/ping3",
40814094
Stdout: dalec.CheckOutput{
4082-
Equals: "testgroup\n",
4095+
Contains: []string{"testgroup\n"},
40834096
},
40844097
},
40854098
},

0 commit comments

Comments
 (0)