Skip to content

Skips loadDir(child) if user has no permissions on parent, or parent does not exist. #3397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cmattoon
Copy link
Contributor

This suppresses a potentially-confusing error (#3241) when the k9s user doesn't have access to one of the XDG_DATA_DIRS.

The current behavior attempts to look for k9s/plugins inside each directory in XDG_DATA_DIRS and reports a permission denied error on a non-existent subdirectory because the user has no permission to open the parent.

This fix opens the parent directory first and simply logs a warning if there's an issue, avoiding the failed loadDir(child) call and Loading plugins failed! error when we expect it to fail because of issues with the parent.

Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@cmattoon Good catch!

@@ -73,6 +73,23 @@ func (p Plugins) Load(path string, loadExtra bool) error {
// Load from XDG dirs
const k9sPluginsDir = "k9s/plugins"
for _, dir := range append(xdg.DataDirs, xdg.DataHome, xdg.ConfigHome) {
// Try to access the XDG directory. If it's not accessible, either because
Copy link
Owner

Choose a reason for hiding this comment

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

I think this only solves the issue at the top level but what if we have a/b/c where user has rights to a but not b?
Perhaps best to add a helper to check existence and rights during the recursive descent and catch all potential issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I considered this myself, and can definitely write a helper function to be more robust, but figured I'd send the smallest fix first.

I limited it to the top level only to prevent XDG-related (i.e., not k9s-related) errors since the issue suggested the user had no idea or intention of storing k9s files there. If they really did want to store k9s files there, I think the right fix would be for them to fix their permissions.

If the user had /xdg/k9s (with XDG_DATA_DIRS=/xdg) and they had access to /xdg but not /xdg/k9s, they'd get the normal error message - but it would be ignored if k9s is missing (current loadDirs functionality) or the user didn't have permissions to /xdg itself (new).

@derailed derailed added bug Something isn't working needs-tlc Pr needs additional updates labels Jun 15, 2025
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-tlc Pr needs additional updates stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants