Skip to content

add a check for kcm-socket file when configuring kerberos#1771

Open
omegaji wants to merge 1 commit intocontainers:mainfrom
omegaji:fix-1734
Open

add a check for kcm-socket file when configuring kerberos#1771
omegaji wants to merge 1 commit intocontainers:mainfrom
omegaji:fix-1734

Conversation

@omegaji
Copy link

@omegaji omegaji commented Mar 15, 2026

An attempt to fix: #1734
When configuring kerberos, it should be checked if the corresponding domain socket used for communication with KCM exists or not.

From the man page, they do state that the default path of the socket is /run/.heim_org.h5l.kcm-socket . But they also state that it is configurable through the conf file, by adding a kcm_socket field.

So hopefully checking at that path to see if the socket exists or not should be enough to fix this issue.

As for testing it, I do the same as the reproduction steps mentioned in the issue, instead of doing klist I do kinit which give the error:
kinit: Configuration file does not specify default realm when parsing name <user>. But I think the error is just that I haven't configured the default_realm in my conf file.

And also the default cache isn't KCM in this case as well, it becomes the kernel keyring cache
default_ccache_name = KEYRING:persistent:%{uid}

@omegaji omegaji requested a review from debarshiray as a code owner March 15, 2026 22:22
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Kerberos configuration process by adding a robust check for the KCM socket's presence and validity. This ensures that Kerberos setup only proceeds when the necessary communication channel for credential management is operational, thereby preventing potential configuration failures and improving the overall reliability of Kerberos integration within the application.

Highlights

  • Kerberos Configuration Logic: Introduced a pre-check for the KCM (Kerberos Credential Manager) socket before proceeding with Kerberos configuration, preventing errors when the socket is not available.
  • KCM Socket Detection Utility: Added a new utility function, IsKCMSocketEnabled, which determines the KCM socket path by parsing /etc/krb5.conf or using a default, and then verifies if the socket file exists and is a valid Unix domain socket.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/cmd/initContainer.go
    • Added a call to utils.IsKCMSocketEnabled() to conditionally skip Kerberos configuration if the KCM socket is not enabled.
  • src/pkg/utils/utils.go
    • Imported the bufio package for file scanning.
    • Implemented the IsKCMSocketEnabled function to check for the KCM socket's existence and type, including parsing krb5.conf for a custom socket path.
Activity
  • No specific activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

When configuring kerberos, it was assumed the sssd-kcm service and corresponding socket were active.
Which is not necessarily true, as it can be disabled and not exist.
containers#1771
Signed-off-by: om <omhpurohit@gmail.com>
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 adds a check to see if the KCM socket is enabled before attempting to configure Kerberos. This is a sensible improvement to prevent configuration errors when KCM is not being used. The implementation correctly checks for the socket file, and also attempts to parse /etc/krb5.conf for a custom socket path. However, the configuration file parsing logic is a bit too simplistic and doesn't handle comments, which could lead to incorrect behavior. I've provided a suggestion to make the parsing more robust.

Comment on lines +914 to +927
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if strings.HasPrefix(text, "[") {
insideLibdefaultsSection = text == "[libdefaults]"
continue
}

if insideLibdefaultsSection {
parts := strings.SplitN(text, "=", 2)
if len(parts) == 2 && strings.TrimSpace(parts[0]) == "kcm_socket" {
kcmSocketPath = strings.TrimSpace(parts[1])
}
}
}

Choose a reason for hiding this comment

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

medium

The current parsing logic for /etc/krb5.conf is a bit too simple and doesn't handle comments. According to the krb5.conf man page, lines can contain comments starting with # or ;. The current implementation can fail in a few ways:

  1. A section header with a comment (e.g., [libdefaults] # comment) will not be recognized correctly.
  2. A key-value pair with an inline comment (e.g., kcm_socket = /path/to/socket # comment) will result in the comment being part of the path.

I suggest a more robust parsing loop that handles comments and empty lines correctly, and also properly identifies section headers.

for scanner.Scan() {
			line := scanner.Text()
			// Ignore comments, which can start with '#' or ';'.
			if i := strings.IndexAny(line, "#;"); i != -1 {
				line = line[:i]
			}
			text := strings.TrimSpace(line)
			if text == "" {
				continue
			}

			// Check for section headers like '[libdefaults]'.
			if strings.HasPrefix(text, "[") && strings.HasSuffix(text, "]") {
				sectionName := strings.TrimSpace(text[1 : len(text)-1])
				insideLibdefaultsSection = sectionName == "libdefaults"
				continue
			}

			if insideLibdefaultsSection {
				parts := strings.SplitN(text, "=", 2)
				if len(parts) == 2 && strings.TrimSpace(parts[0]) == "kcm_socket" {
					kcmSocketPath = strings.TrimSpace(parts[1])
				}
			}
		}

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.

Toolbx set KCM credential cache by default

1 participant