Skip to content

Conversation

@Stevenjin8
Copy link
Contributor

What this PR does / why we need it:

This allows for setting capabilities for binaries in artifacts. This is helpful in contexts that do not allow for privilege escalation.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):
Fixes #

Special notes for your reviewer:

Copilot AI review requested due to automatic review settings October 24, 2025 14:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for setting POSIX capabilities on artifacts in Dalec package specifications. This feature enables binaries to have specific Linux capabilities (like cap_net_raw) without requiring privilege escalation, which is useful in restricted security contexts.

Key changes:

  • Added Capabilities field to ArtifactConfig struct for specifying capability strings
  • Implemented capability setting in both RPM and DEB packaging backends using setcap commands
  • Added integration test verifying capability setting works end-to-end

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
artifacts.go Added Capabilities field to ArtifactConfig struct with documentation
docs/spec.schema.json Updated JSON schema to include the new capabilities field
packaging/linux/rpm/template.go Implemented getArtifactCapabilities() to generate setcap commands in RPM %post scriptlet
packaging/linux/deb/debroot.go Implemented setArtifactCapabilitiesPostInst() to generate setcap commands in DEB postinst script
test/linux_target_test.go Added testArtifactCapabilities integration test that verifies capability setting on a binary

apply(artifacts.ConfigFiles, ConfigFilesPath)
apply(artifacts.Manpages, filepath.Join(ManpagesPath, spec.Name))
apply(artifacts.Headers, HeadersPath)
apply(artifacts.Licenses, filepath.Join(LicensesPath, spec.Name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think copilot is right about not needing to set something like "capabilities" on non-binaries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a little weird, but you could say the same thing about making files here executable, and that's perfectly allowed. So it seems inconsistent to be able to make a license or manpage executable, but not give it any capabilities

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a fair point

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make the argument the other way around though, caps are only relevant to actual binaries while permissions are relevant to everything. Up to you, I don't feel strongly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The undocumented macro for RPM just lands in the files section. I think this is ok, document that it isn;t supported?

@Stevenjin8 Stevenjin8 requested a review from MorrisLaw October 24, 2025 15:19
@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch 2 times, most recently from c2896eb to 9776fc9 Compare October 24, 2025 15:40
}
resolved := cfg.ResolveName(key)
p := filepath.Join(root, cfg.SubPath, resolved)
fmt.Fprintf(w, "setcap %s \"$DESTDIR%s\"\n", cfg.Capabilities, p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this with the RPM macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see other comment

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch 2 times, most recently from 331e0ac to 63a5a68 Compare October 28, 2025 17:51
@Stevenjin8 Stevenjin8 requested a review from cpuguy83 October 31, 2025 19:10
@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch from 226d13c to ef7af3a Compare November 3, 2025 17:53
artifacts.go Outdated
// Group is the group name that should own the artifact
Group string `yaml:"group,omitempty" json:"group,omitempty"`
// Capabilities is the list of POSIX capabilities to set on the artifact
Capabilities []ArtifactCapability `yaml:"capabilities,omitempty" json:"capabilities,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: LinuxCapabilities

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear I fixed this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpuguy83 fixed. Sorry about that.

@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch from 5596177 to 2b546b7 Compare November 4, 2025 18:25
@Stevenjin8 Stevenjin8 requested a review from cpuguy83 November 6, 2025 04:15
@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch from a310dee to dbcc92c Compare November 6, 2025 04:38
@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch from 049ba54 to 2b88f81 Compare November 25, 2025 20:54
@cpuguy83
Copy link
Collaborator

Needs a go generate ./...

Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Stevenjin8 and others added 16 commits November 25, 2025 20:37
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Steven Jin <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
Signed-off-by: Steven Jin Xuan <[email protected]>
@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch from 429459e to d4a7096 Compare November 26, 2025 01:37
@Stevenjin8
Copy link
Contributor Author

@cpuguy83 I rebased, but 2373892 is the first new commit.

Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be missing the last change to swtich to linux_capabilities

@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch from fc7be1e to 350425a Compare November 26, 2025 19:05
@Stevenjin8 Stevenjin8 requested a review from cpuguy83 November 26, 2025 19:18
Signed-off-by: Steven Jin Xuan <[email protected]>
@Stevenjin8 Stevenjin8 force-pushed the feature/artifact-caps branch from d2dbb2e to f70fba5 Compare November 26, 2025 19:33
@cpuguy83 cpuguy83 merged commit 6e30f3f into project-dalec:main Nov 26, 2025
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants