Skip to content
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

PodMounter: Add group read access to credentials if Pod is not root #388

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

Conversation

yerzhan7
Copy link
Contributor

Issue: #108

Description

  • Problem: If fsGroup security context is applied on Mountpoint Pod and it's not run as default root user (0), then currently Mountpoint Pod fails to read credentials that are provided by CSI Driver Node Pod.
  • Solution: Adding group read permissions to credentials folder/files if parent folder has non-zero gid.
  • Implementation:
    • Added logic to check gid of parent folder in Mount() method
    • Added new CredentialDirPerm and CredentialFilePerm fields to credential's ProvideContext
    • Use these fields when creating credential files/directory
  • Manual Testing: Successfully validated this fix in personal ROSA cluster.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@yerzhan7 yerzhan7 requested a review from a team as a code owner February 23, 2025 22:00
Copy link
Contributor

@unexge unexge left a comment

Choose a reason for hiding this comment

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

Left some small comments, but overall it looks good to me. Thanks @yerzhan7!

@@ -36,24 +36,28 @@ const targetDirPerm = fs.FileMode(0755)
// This is mainly exposed for testing, in production platform-native function (`mountSyscallDefault`) will be used.
type mountSyscall func(target string, args mountpoint.Args) (fd int, err error)

type fileGroupID func(path string) (gid uint32, err error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this is only exposed for testing, and I feel like it would be cleaner if we just change the gid of the parent directory in our tests to test different cases via os.Chown.

@@ -37,3 +45,18 @@ func ReplaceFile(destPath string, sourcePath string, perm fs.FileMode) error {

return nil
}

// FileGroupID returns gid of the file or directory.
func FileGroupID(path string) (gid uint32, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a public function, it would be nice to add some tests for this function in file_test.go.

Comment on lines +12 to +15
FileMode600 = fs.FileMode(0600) // User: read/write, Group: none, Others: none
FileMode640 = fs.FileMode(0640) // User: read/write, Group: read-only, Others: none
FileMode700 = fs.FileMode(0700) // User: full access, Group: none, Others: none
FileMode750 = fs.FileMode(0750) // User: full access, Group: read/execute only, Others: none
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like it'd be nicer if we name these constants after their permissions, something like:

Suggested change
FileMode600 = fs.FileMode(0600) // User: read/write, Group: none, Others: none
FileMode640 = fs.FileMode(0640) // User: read/write, Group: read-only, Others: none
FileMode700 = fs.FileMode(0700) // User: full access, Group: none, Others: none
FileMode750 = fs.FileMode(0750) // User: full access, Group: read/execute only, Others: none
FileModeUserReadWrite = fs.FileMode(0600) // User: read/write, Group: none, Others: none
FileModeUserGroupReadWrite = fs.FileMode(0640) // User: read/write, Group: read-only, Others: none
FileModeUserFull = fs.FileMode(0700) // User: full access, Group: none, Others: none
FileModeUserFullGroupRead = fs.FileMode(0750) // User: full access, Group: read/execute only, Others: none

Though, feel free to change them if you can come up with better names :)

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.

2 participants