Skip to content

ssh-tpm-agent: keyutils (fixes #505869)#505874

Closed
vorburger wants to merge 1 commit intoNixOS:masterfrom
vorburger:ssh-tpm-agent_keyutils
Closed

ssh-tpm-agent: keyutils (fixes #505869)#505874
vorburger wants to merge 1 commit intoNixOS:masterfrom
vorburger:ssh-tpm-agent_keyutils

Conversation

@vorburger
Copy link
Copy Markdown

Things done

Fixes #505869.

This is my very 1st PR to nixpkgs... let me know if this is cool, or if anything more is needed?

  • 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.

Copilot AI review requested due to automatic review settings April 2, 2026 01:28
Copy link
Copy Markdown
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 addresses nixpkgs issue #505869 by attempting to ensure ssh-tpm-agent can access keyctl (from keyutils) in minimal/non-graphical environments where it may not already be present.

Changes:

  • Add keyutils as an input to the ssh-tpm-agent derivation.
  • Include keyutils in buildInputs alongside openssl.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 24 to 29
vendorHash = "sha256-84ZB1B+RczJS08UToCWvvVfWrD62IQxy0XoBwn+wBkc=";

buildInputs = [
openssl
keyutils
];
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

Adding keyutils to buildInputs alone typically won’t make keyctl available at runtime for ssh-tpm-agent (the Go binary won’t reference the keyutils store path, and systemd/user shells may not have it on PATH). To actually fix the missing keyctl dependency, wrap ssh-tpm-agent (e.g., via makeWrapper + postInstall with --prefix PATH : ${lib.makeBinPath [ keyutils ]}) or otherwise ensure keyutils ends up in the runtime closure and PATH.

Copilot uses AI. Check for mistakes.
@nixpkgs-ci nixpkgs-ci bot requested a review from stigtsp April 2, 2026 01:33
@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: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 12.first-time contribution This PR is the author's first one; please be gentle! labels Apr 2, 2026
@tree-sapii
Copy link
Copy Markdown

Hey! Congrats on your first contrib and fix. I reviewed it and I am not going to listen to what Copilot said, and say that yes including a package in the buildInputs arg of a drv adds them as a runtime dependency, however make sure this 100% by building it and running it from /result/bin as specified in the PR template.

Good stuff!

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Apr 2, 2026
@wishstudio
Copy link
Copy Markdown
Contributor

I think Copilot is correct here. This won't work. The buildInput attribute, as the name suggests, only specifies build dependencies. nix automatically figures out runtime dependencies by searching for store paths in the build result.

You can use the following command to check the dependency of a package.

nix-store --query --references <nix store path>

The result I got for this PR:

[nix-shell:~/.cache/nixpkgs-review/pr-505874/logs]$ nix-store --query --references /nix/store/9g835hzhhb09fv4w11m1lhypb918pjba-ssh-tpm-agent-0.8.0
/nix/store/2ly61i1c0ipwq73w2102lr6px5mlfsjb-iana-etc-20251215
/nix/store/a6kd5v5x97jnyyzbmiild0m1ikn5yfmg-mailcap-2.1.54
/nix/store/jms7zxzm7w1whczwny5m3gkgdjghmi2r-glibc-2.42-51
/nix/store/bga5xf95jaypy385hvxm4h3yxl3m1566-openssl-3.6.1
/nix/store/h15ranlgwagilr6ajd7ich6d896kf9zd-tzdata-2026a

You can read this nixpills article for more information.

@vorburger
Copy link
Copy Markdown
Author

vorburger commented Apr 2, 2026

@wishstudio Thank You, I think I see what you mean. How would I write an (currently expected to be failing) Integration Test in nixpkgs which "runs keyctl on the PATH that package ssh-tpm-agent has at runtime" ?

@vorburger vorburger marked this pull request as draft April 2, 2026 10:30
@tree-sapii
Copy link
Copy Markdown

So after reading the src of go's unix library that ssh-tpm-agent interacts with to to keyctl stuff, I originally thought that it would just link against the keyctl library ( keyctl itself is a syscall ), but if its does really need the binary keyctl, then yes you need to wrap it to set the path.

Make sure to import makeWrapper and keyutils and pass them into buildInputs.
This is what you'd add to the drv:

  postFixup = ''
  wrapProgram $out/bin/ssh-tpm-agent \
    --set PATH ${lib.makeBinPath [
      keyutils
    ]}
  '';

This builds on my system, however I haven't done any tests.

If this is anything to go by, then it works:

nix-store --query --references  /nix/store/4ykvxi8p8z3m4awn0i03jgkyw6q0qvzc-ssh-tpm-agent-0.8.0
/nix/store/2ly61i1c0ipwq73w2102lr6px5mlfsjb-iana-etc-20251215
/nix/store/a6kd5v5x97jnyyzbmiild0m1ikn5yfmg-mailcap-2.1.54
/nix/store/jms7zxzm7w1whczwny5m3gkgdjghmi2r-glibc-2.42-51
/nix/store/bga5xf95jaypy385hvxm4h3yxl3m1566-openssl-3.6.1
/nix/store/h15ranlgwagilr6ajd7ich6d896kf9zd-tzdata-2026a
/nix/store/v8sa6r6q037ihghxfbwzjj4p59v2x0pv-bash-5.3p9
/nix/store/jbsc7gkd508h1wsvfx3l8am18hx3bjc0-keyutils-1.6.3
/nix/store/4ykvxi8p8z3m4awn0i03jgkyw6q0qvzc-ssh-tpm-agent-0.8.0

Copy link
Copy Markdown
Member

@NickCao NickCao left a comment

Choose a reason for hiding this comment

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

I believe that line of code is misleading, if you look into https://github.com/Foxboron/ssh-tpm-agent/tree/e8cd6307ad832c37dc613942cc7298e43694348e/internal/keyring, it's doing syscalls directly, not using the keyctl cli.

@wishstudio
Copy link
Copy Markdown
Contributor

I believe that line of code is misleading, if you look into https://github.com/Foxboron/ssh-tpm-agent/tree/e8cd6307ad832c37dc613942cc7298e43694348e/internal/keyring, it's doing syscalls directly, not using the keyctl cli.

Not an expert in this field. But if you look at the manpage of keyutils:

       The kernel has the ability to upcall to userspace to fabricate new
       keys.  This can be triggered by request_key(), but userspace is
       better off using add_key() instead if it possibly can.

and in kernel doc:

A request proceeds in the following manner:

1. Process A calls request_key() [the userspace syscall calls the kernel interface].

...

4. request_key() then forks and executes /sbin/request-key with a new session keyring that contains a link to auth key V.

So the kernel may call back to the userspace utility when executing the system call.

@NickCao
Copy link
Copy Markdown
Member

NickCao commented Apr 2, 2026

I believe that line of code is misleading, if you look into https://github.com/Foxboron/ssh-tpm-agent/tree/e8cd6307ad832c37dc613942cc7298e43694348e/internal/keyring, it's doing syscalls directly, not using the keyctl cli.

Not an expert in this field. But if you look at the manpage of keyutils:

       The kernel has the ability to upcall to userspace to fabricate new
       keys.  This can be triggered by request_key(), but userspace is
       better off using add_key() instead if it possibly can.

and in kernel doc:

A request proceeds in the following manner:

1. Process A calls request_key() [the userspace syscall calls the kernel interface].

...

4. request_key() then forks and executes /sbin/request-key with a new session keyring that contains a link to auth key V.

So the kernel may call back to the userspace utility when executing the system call.

Yes, but the request-key helper does not come from PATH, See pkgs/os-specific/linux/kernel/request-key-helper.patch

@tree-sapii
Copy link
Copy Markdown

Yet, /run/current-system/sw/bin/request-key doesn't exist on my system and I'm assuming on his too, so the kernel will try to call into userspace and fail and the program interprets that as keyutils don't exist.

@NickCao
Copy link
Copy Markdown
Member

NickCao commented Apr 2, 2026

Yet, /run/current-system/sw/bin/request-key doesn't exist on my system and I'm assuming on his too, so the kernel will try to call into userspace and fail and the program interprets that as keyutils don't exist.

In that case, add environment.systemPackages = with pkgs; [ keyutils ]; to your system configuration.

@wishstudio
Copy link
Copy Markdown
Contributor

Yes, but the request-key helper does not come from PATH, See pkgs/os-specific/linux/kernel/request-key-helper.patch

Nevermind. I misunderstood what you mean.
Anyway, this is an indirect call and I have no idea of the idiomatic way of handling this (or do we handle this at all?).

@tree-sapii
Copy link
Copy Markdown

Yet, /run/current-system/sw/bin/request-key doesn't exist on my system and I'm assuming on his too, so the kernel will try to call into userspace and fail and the program interprets that as keyutils don't exist.

In that case, add environment.systemPackages = with pkgs; [ keyutils ]; to your system configuration.

Then this is the solution. @vorburger, you can create a module for this package that starts up a service as well as adds the keyutils package to systemPackages.

@vorburger
Copy link
Copy Markdown
Author

Then this is the solution. @vorburger, you can create a module for this package that starts up a service as well as adds the keyutils package to systemPackages.

Sounds like a plan! We'll close this?

@tree-sapii
Copy link
Copy Markdown

Then this is the solution. @vorburger, you can create a module for this package that starts up a service as well as adds the keyutils package to systemPackages.

Sounds like a plan! We'll close this?

Sure.

@vorburger vorburger closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.first-time contribution This PR is the author's first one; please be gentle!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ssh-tpm-agent: Missing dependency on keyutils

5 participants