Skip to content

KRB5: let 'krb5_child' tolerate missing cap-set-id #8312

Merged
pbrezina merged 1 commit into
SSSD:masterfrom
alexey-tikhonov:krb5-child-setid
Jan 5, 2026
Merged

KRB5: let 'krb5_child' tolerate missing cap-set-id #8312
pbrezina merged 1 commit into
SSSD:masterfrom
alexey-tikhonov:krb5-child-setid

Conversation

@alexey-tikhonov

@alexey-tikhonov alexey-tikhonov commented Dec 19, 2025

Copy link
Copy Markdown
Member

If CAP_SETUID and/or CAP_SETGID are missing, 'krb5_child' will
skip operation that require those capabilities, namely any manipulations
with user ccache.

:packaging:This update makes it possible to not grant CAP_SETUID and CAP_SETGID
to 'krb5_child' binary in a situation where it is not required to store acquired
TGT after user authentication. Taking into account that it is already possible
to avoid using CAP_DAC_READ_SEARCH if keytab is readable by SSSD service user,
and usage of 'selinux_child' isn't always required, this allows to build a setup
with completely privilege-less SSSD to serve certain use cases. In particular,
this might be used to build a container running SSSD on OCP with a restricted
profile.

@alexey-tikhonov alexey-tikhonov added the no-backport This should go to target branch only. label Dec 19, 2025
gemini-code-assist[bot]

This comment was marked as outdated.

@alexey-tikhonov
alexey-tikhonov force-pushed the krb5-child-setid branch 2 times, most recently from 92a0aaf to e8f7c10 Compare December 20, 2025 10:36
@alexey-tikhonov alexey-tikhonov changed the title KRB5: make sure empty ccache is created under proper euid KRB5: let 'krb5_child' tolerate missing cap-set-id Dec 20, 2025
@alexey-tikhonov

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request aims to make krb5_child tolerant of missing CAP_SETUID and CAP_SETGID capabilities, which is a valuable enhancement for running SSSD in restricted environments like containers. The approach of using a flag to guard capability-dependent operations is sound. However, my review identified two critical issues. First, the logic for checking capabilities and setting credentials can lead to a partial and inconsistent credential state for the process. Second, a recurring bug in error handling paths causes the child process to exit without responding to the parent, leading to timeouts. I have provided code suggestions to address both of these critical problems.

Comment thread src/providers/krb5/krb5_child.c Outdated
Comment thread src/providers/krb5/krb5_child.c Outdated
Comment on lines +4420 to +4423
if (!krb5_child_has_setid_cap) {
ret = KRB5_CC_NOTFOUND;
goto done;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The goto done; statement here will cause the child process to exit without sending a response to the parent process. The parent process will then time out waiting for a response. The error code should be sent back to the parent. This can be fixed by using break; to exit the switch statement, which will then allow k5c_send_data() to be called. This issue also exists in other error paths in this function, such as the offline check for SSS_CMD_RENEW.

        if (!krb5_child_has_setid_cap) {
            ret = KRB5_CC_NOTFOUND;
            break;
        }

@alexey-tikhonov alexey-tikhonov Dec 20, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The same is done in case if (offline)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Imo, having exit(error_code) is enough.

@alexey-tikhonov alexey-tikhonov added the coverity Trigger a coverity scan label Dec 22, 2025
@alexey-tikhonov

Copy link
Copy Markdown
Member Author

Note: Covscan is green.

@alexey-tikhonov

Copy link
Copy Markdown
Member Author

As for testing:

@alexey-tikhonov
alexey-tikhonov marked this pull request as ready for review December 22, 2025 10:34
@alexey-tikhonov alexey-tikhonov removed the coverity Trigger a coverity scan label Dec 22, 2025
Comment thread src/providers/krb5/krb5_child.c Outdated
@alexey-tikhonov

Copy link
Copy Markdown
Member Author

/gemini review

@alexey-tikhonov alexey-tikhonov added the coverity Trigger a coverity scan label Dec 23, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

The pull request aims to make krb5_child tolerate missing CAP_SETUID and CAP_SETGID capabilities, which is useful for running SSSD in restricted environments like containers. The changes correctly add checks for these capabilities and skip operations that require them, such as manipulating user ccache.

However, I've found a couple of critical issues. One is a potential use of an uninitialized variable in an offline authentication scenario without capabilities. The other is an incorrect use of goto done instead of break in the SSS_CMD_RENEW command handler, which would cause the child process to exit without sending a response. These issues need to be addressed to ensure the correctness and stability of the changes.

Comment on lines +4395 to +4397
if (kr->krb5_child_has_setid_caps) {
ret = create_empty_ccache(kr);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The ret variable is not assigned a value if offline is true and kr->krb5_child_has_setid_caps is false. This leads to k5c_send_data() being called with an uninitialized variable, which is undefined behavior.

When no capabilities are present, no ccache is created, but the authentication should still be considered successful in an offline scenario. You should initialize ret to EOK in this case.

            if (kr->krb5_child_has_setid_caps) {
                ret = create_empty_ccache(kr);
            } else {
                ret = EOK;
            }

@alexey-tikhonov alexey-tikhonov Dec 23, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ret is known to be EOK at this point.

Comment thread src/providers/krb5/krb5_child.c

@sumit-bose sumit-bose 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.

Hi,

thank you for the updates, ACK.

bye,
Sumit

@alexey-tikhonov

Copy link
Copy Markdown
Member Author

Note: Covscan is still green.

@alexey-tikhonov alexey-tikhonov added Waiting for review and removed coverity Trigger a coverity scan labels Dec 23, 2025
@pbrezina pbrezina self-assigned this Jan 5, 2026
@pbrezina

pbrezina commented Jan 5, 2026

Copy link
Copy Markdown
Member

PR CI failure is not related.

If CAP_SETUID and/or CAP_SETGID are missing, 'krb5_child' will
skip operation that require those capabilities, namely any manipulations
with user ccache.

:packaging:This update makes it possible to not grant CAP_SETUID and CAP_SETGID
to 'krb5_child' binary in a situation where it is not required to store acquired
TGT after user authentication. Taking into account that it is already possible
to avoid using CAP_DAC_READ_SEARCH if keytab is readable by SSSD service user,
and usage of 'selinux_child' isn't always required, this allows to build a setup
with completely privilege-less SSSD to serve certain use cases. In particular,
this might be used to build a container running SSSD on OCP with a restricted
profile.

Reviewed-by: Pavel Březina <[email protected]>
Reviewed-by: Sumit Bose <[email protected]>
@sssd-bot

sssd-bot commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

The pull request was accepted by @pbrezina with the following PR CI status:


🟢 CodeFactor (success)
🟢 CodeQL (success)
🟢 osh-diff-scan:fedora-rawhide-x86_64:upstream (success)
🟢 rpm-build:centos-stream-10-x86_64:upstream (success)
🟢 rpm-build:fedora-42-x86_64:upstream (success)
🟢 rpm-build:fedora-43-x86_64:upstream (success)
🟢 rpm-build:fedora-rawhide-x86_64:upstream (success)
🟢 Analyze (target) / cppcheck (success)
🟢 Build / freebsd (success)
🟢 Build / make-distcheck (success)
🟢 ci / intgcheck (centos-10) (success)
🟢 ci / intgcheck (fedora-42) (success)
🟢 ci / intgcheck (fedora-43) (success)
🟢 ci / intgcheck (fedora-44) (success)
🟢 ci / prepare (success)
🟢 ci / system (centos-10) (success)
🟢 ci / system (fedora-42) (success)
🟢 ci / system (fedora-43) (success)
🔴 ci / system (fedora-44) (failure)
➖ Coverity scan / coverity (skipped)
🟢 Static code analysis / codeql (success)
🟢 Static code analysis / pre-commit (success)
🟢 Static code analysis / python-system-tests (success)


There are unsuccessful or unfinished checks. Make sure that the failures are not related to this pull request before merging.

@pbrezina
pbrezina merged commit d9ab8a8 into SSSD:master Jan 5, 2026
11 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Accepted no-backport This should go to target branch only. Waiting for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants