Skip to content

Conversation

@afbase
Copy link

@afbase afbase commented Jul 30, 2025

relates to moby/profiles#2

Historical Context

In Late December 2015, it was decided to exclude the add_key, keyctl, and request_key syscalls in the new default seccomp profile in the moby project. The rationale was that these syscalls for the Kernel Key Retention and Kernel Key Requesting were not user namespaced.

In January 2016, @jessfraz wrote about the newly released default seccomp profile. Jess also contributed to incorporating seccomp profiles into kubernetes later that year.

In 2019, @dhowells and @thejh worked on these syscalls to respect user namespace boundaries.

For containters/common, the PR #421 added keyctl syscall but not the related add_key or request_key syscalls.

Why These Syscalls Are Now Safe

The original 2015 security concerns have been addressed through specific kernel code changes that ensure proper user namespace isolation. Here are some examples:

1. Namespace-Aware Keyring Access

The add_key syscall now operates within the caller's user namespace context through lookup_user_key():

/* find the target keyring (which must be writable) */
keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_NEED_WRITE);

This function ensures containers can only access keyrings that exist within their namespace boundary, preventing cross-namespace key access.

2. Namespace Validation for Key Operations

Key ownership changes are validated within the caller's namespace via keyctl_chown_key:

uid = make_kuid(current_user_ns(), user);
gid = make_kgid(current_user_ns(), group);
ret = -EINVAL;
if ((user != (uid_t) -1) && !uid_valid(uid))
    goto error;

3. Namespace-Aware Request Key Operations

The request_key syscall properly handles namespace translation during userspace callouts in request_key.c:

/* record the UID and GID */
sprintf(uid_str, "%d", from_kuid(&init_user_ns, cred->fsuid));
sprintf(gid_str, "%d", from_kgid(&init_user_ns, cred->fsgid));

Summary by Sourcery

Enable add_key and request_key syscalls in the default seccomp profile now that kernel keyring operations respect user namespace boundaries.

Enhancements:

  • Allow the add_key syscall in the default seccomp profile
  • Allow the request_key syscall in the default seccomp profile

Signed-off-by: Clinton Bowen <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Jul 30, 2025

Reviewer's Guide

This PR updates the default seccomp profile to include the add_key and request_key syscalls, reflecting recent kernel improvements that enforce user‐namespace isolation for keyring operations.

File-Level Changes

Change Details Files
Include add_key and request_key in seccomp.json profile
  • Added add_key syscall entry
  • Added request_key syscall entry
pkg/seccomp/seccomp.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @afbase - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 30, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: afbase, sourcery-ai[bot]
Once this PR has been reviewed and has the lgtm label, please assign giuseppe for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Luap99 Luap99 changed the title add add_key and request_key seccomp: add add_key and request_key Jul 30, 2025
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

The json file is generated from the code so you must add them in the go code and the generate the file.

@giuseppe PTAL
Even if they respect the user namesapce boundary root containers by default do not run in a new user namespace so this would enable access the main system keyring of the host for them?

@giuseppe
Copy link
Member

same concern as @Luap99, wouldn't this allow containers that run without a new user namespace to get access to these syscalls?

@afbase
Copy link
Author

afbase commented Jul 31, 2025

Even if they respect the user namesapce boundary root containers by default do not run in a new user namespace so this would enable access the main system keyring of the host for them?

@Luap99 and @giuseppe this is a great point for which I didn't consider. To enable this for any configuration, we would have to require some additional UID/GID measure - especially in the root container case. 🤦🏾

I feel a little embarrassed but am very glad you both raised this point. Notably so that @giuseppe wrote about the k8s user namespace isolation blog post that could be a good measure to manage this issue and potentially allow for the use of these syscalls in the k8s scenario.

I am going to go ahead and close this. Thank you!

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.

3 participants