Skip to content

Conversation

@alexey-tikhonov
Copy link
Member

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

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
Member Author

/gemini review

Copy link

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

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 on lines 4420 to 4423
if (!krb5_child_has_setid_cap) {
ret = KRB5_CC_NOTFOUND;
goto done;
}

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;
        }

Copy link
Member Author

@alexey-tikhonov alexey-tikhonov Dec 20, 2025

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
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
Member Author

Note: Covscan is green.

@alexey-tikhonov
Copy link
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
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
Copy link
Member Author

/gemini review

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

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

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);
}

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;
            }

Copy link
Member Author

@alexey-tikhonov alexey-tikhonov Dec 23, 2025

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.

Copy link
Contributor

@sumit-bose sumit-bose left a comment

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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants