-
Notifications
You must be signed in to change notification settings - Fork 149
fix: enable to use secrets with special characters #961
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,12 +20,29 @@ limitations under the License. | |
package smb | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
mount "k8s.io/mount-utils" | ||
) | ||
|
||
func Mount(m *mount.SafeFormatAndMount, source, target, fsType string, options, sensitiveMountOptions []string, _ string) error { | ||
if len(sensitiveMountOptions) != 0 { | ||
file, err := os.CreateTemp("/tmp/", "*.smb.credentials") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer this file on a ramfs so it wouldn't touch the disk at all. But... at the very minimum, the temp file must have restricted permissions, since /tmp is world-readable on most systems. This needs to be safe in the rare cases that the driver is not run in a container and/or with multiple processes sharing /tmp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johanot , the temp file already has restricted permissions (rw for the user only) because that's how os.CreateTemp() works. See its official docs here: https://pkg.go.dev/os#CreateTemp . I intentionally used "/tmp" instead of ramfs, because the location of ramfs mount may vary depending on environment (at least, I don't know any path that would exist everywhere). But generally I fully agree -- not touching the disk would be better. And "defer os.Remove" will wipe it anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Oh.. Never mind then :)
I guess a rare case exists where the process could get SIGKILL'ed before the deferred function is executed, but.. yeah.
I think I would create a new ramfs for this purpose alone and choose the location myself, e.g. mount at a level below /tmp. However it's easier said than done, iirc, because you'd have to pull in mount-utils only for this pre-mount purpose. If the maintainers here are good with a standard temp file, then I rest my case. |
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, option := range sensitiveMountOptions { | ||
if _, err := file.Write([]byte(fmt.Sprintf("%s\n", option))); err != nil { | ||
return err | ||
} | ||
} | ||
file.Close() | ||
defer os.Remove(file.Name()) | ||
|
||
sensitiveMountOptions = []string{fmt.Sprintf("credentials=%s", file.Name())} | ||
} | ||
return m.MountSensitive(source, target, fsType, options, sensitiveMountOptions) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there could be problem when there is mount process concurrently, is it possible to detect whether there is special chars in secrets first, if yes, then mount with cred file? I think that would be safer since it won't break anything, thanks.