Skip to content

nixos/wrappers: verify that capabilities strings are valid - #502310

Merged
GrimmTheShrimp merged 4 commits into
NixOS:staging-nixosfrom
amarshall:capabilities-check
Aug 9, 2026
Merged

GrimmTheShrimp merged 4 commits into
NixOS:staging-nixosfrom
amarshall:capabilities-check

Conversation

@amarshall

@amarshall amarshall commented Mar 22, 2026 •

Copy link
Copy Markdown
Member

See individual commits for details and elaboration. Fixes #398934.

Not sure the best name for the pkg, or if it would be better inlined in the module (possibly with writeCBin? though don’t think one can add flags with that…).

Things done

nix-build -A nixosTests.wrappers, including manually changing one of the wrapper defs in the test to have a broken capabilities string.

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

github-actions[bot]

This comment was marked as outdated.

@nixpkgs-ci nixpkgs-ci Bot added 8.has: package (new) This PR adds a new package 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. labels Mar 22, 2026
@amarshall
amarshall marked this pull request as draft March 23, 2026 01:06
@amarshall
amarshall changed the base branch from master to staging-nixos March 23, 2026 01:07
@nixpkgs-ci nixpkgs-ci Bot closed this Mar 23, 2026
@amarshall
amarshall marked this pull request as ready for review March 23, 2026 01:07
@nixpkgs-ci nixpkgs-ci Bot reopened this Mar 23, 2026
@nixpkgs-ci nixpkgs-ci Bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Mar 23, 2026
@nixpkgs-ci nixpkgs-ci Bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Apr 24, 2026
@nixpkgs-ci nixpkgs-ci Bot added 2.status: merge conflict This PR has merge conflicts with the target branch and removed 2.status: merge conflict This PR has merge conflicts with the target branch labels May 29, 2026
@amarshall
amarshall requested review from aviallon and nikstur July 23, 2026 02:12
@amarshall
amarshall force-pushed the capabilities-check branch 2 times, most recently from 8b1ecfe to 04ab390 Compare July 23, 2026 02:25
@nixpkgs-ci nixpkgs-ci Bot added the 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. label Jul 23, 2026

@aviallon aviallon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I love the idea, but, I believe having original source code inside nixpkgs directly is quite uncommon.

Usually, you'd write the program in a dedicated project (which may be adopted by nix-community), and then you package it, and wire it up.

@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

No, its not uncommon for original code to exist within nixpkgs if it is small and maintainable enough, especially if the utility outside nixos is basically zero.

@amarshall
amarshall force-pushed the capabilities-check branch 2 times, most recently from 277c883 to f4b8e82 Compare July 27, 2026 01:12
@nixpkgs-ci
nixpkgs-ci Bot requested a review from ck3d July 27, 2026 01:21
@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

also failing CI because it wants __structuredAttrs = true; strictDeps = true; in the libcap-text-verifier package

@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

As to general approach: We use setcap from libcap, so using libcap to validate our capability names seems appropriate.

Alternatively we could attempt to use libcap_ng with its python bindings (#546283), but that has some subtle differences in how it does cap naming (it omits the cap_ prefix) and also needs splitting off the + suffixes before you are able to call capng.capng_name_to_capability. So having python instead of C is likely not worth the added fragility, and having a dedicated small C program using libcap is appropriate here imo.

@amarshall
amarshall force-pushed the capabilities-check branch from f4b8e82 to 83c5ce0 Compare July 27, 2026 12:38
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. and removed 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. labels Jul 27, 2026
@amarshall
amarshall force-pushed the capabilities-check branch from 83c5ce0 to 9f2dd23 Compare July 27, 2026 12:58
@amarshall

Copy link
Copy Markdown
Member Author

libcap_ng would be nice to avoid C, but agree that the extra complexity of the integration layer is probably not worth it, especially since this C program is quite simple anyway.

I do notice that the regular wrapper C src and drv is vendored next to the NixOS module…curious if you think that would be better than exposing in pkgs?

@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

Tbh, exposing libcap-text-verifier in nixpkgs (rather than nixos in-place) seems nicer to me. That allows easier testing of cross-compiling etc.

@GrimmTheShrimp GrimmTheShrimp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One nit and one small issue (i should have tested my suggestions better), then i am happy

These are likely to differ for many folks, and running these checks
should be quite fast (`runCommandLocal` docs suggest anything less than
one second should use local).
@amarshall
amarshall force-pushed the capabilities-check branch from 9f2dd23 to 9d504a2 Compare August 8, 2026 11:23
This will be used by the `security.wrappers` NixOS module.
Without this, an invalid capabilities string would cause the activation
script to fail completely, meaning all wrappers would be missing. This
causes unix_chkpwd to be missing, and thus all logins to fail.

See NixOS#398934.
@amarshall
amarshall force-pushed the capabilities-check branch from 9d504a2 to 6b93582 Compare August 8, 2026 11:28
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. and removed 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. labels Aug 8, 2026

@GrimmTheShrimp GrimmTheShrimp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pkgsLLVM.libcap-text-verifier fails because sqlite is broken, not your problem.
Other than that, all the tests i ran on all my stuff seem to indicate this is fine.

###### wrappers consistency checks
system.checks = lib.singleton (
pkgs.runCommand "ensure-all-wrappers-paths-exist"
pkgs.runCommandLocal "ensure-all-wrappers-paths-exist"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually, one last comment: the name of this drv is nonsensical now

@GrimmTheShrimp

Copy link
Copy Markdown
Contributor

Other than that, this seems to work perfectly:

Checking that Nix store paths of all wrapped programs exist... OK
Checking that all capabilities of all wrapped programs are valid... cap_from_text: Invalid argument
FAIL
The capability cap_foobar+ep is invalid!
Please, check the value of `security.wrappers."garbage".capabilities`.

Ty :)

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Aug 8, 2026
@GrimmTheShrimp
GrimmTheShrimp added this pull request to the merge queue Aug 9, 2026
Merged via the queue into NixOS:staging-nixos with commit 3ecdde1 Aug 9, 2026
29 checks passed
@amarshall
amarshall deleted the capabilities-check branch August 10, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: package (new) This PR adds a new package 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants