Fix lock file regression by appending UID to the lock driectory#22623
Conversation
…and add a test for the new structure.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: medyagh The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/ok-to-test |
|
here is the link to the binary from a PR that I think might fix this issue, do you mind trying it out ? https://storage.googleapis.com/minikube-builds/22623/minikube-linux-amd64 |
There was a problem hiding this comment.
Pull request overview
This pull request fixes a regression introduced in v1.38.0 where multiple users on the same machine couldn't acquire locks due to permission issues with the shared /tmp/minikube-locks directory.
Changes:
- Modified the lock directory naming to include the user's UID (
/tmp/minikube-locks-<UID>) for per-user isolation - Added a test to verify the lock directory structure follows the new naming convention
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/util/lock/lock.go | Updated Acquire() function to append user UID to lock directory name, ensuring each user has their own lock directory |
| pkg/util/lock/lock_test.go | Added TestLockDirectoryStructure() to verify the directory naming convention with UID suffix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nirs
left a comment
There was a problem hiding this comment.
This works, but it will be better keep locks the recommended location for the platform:
| Operating System | Primary Location (User-level) | Specification / Documentation |
|---|---|---|
| Linux | $XDG_RUNTIME_DIR (e.g., /run/user/1000/) |
XDG Base Directory Spec |
| macOS | ~/Library/Application Support/<app>/ |
Apple File System Guide |
| Windows | %LOCALAPPDATA%\<app>\ |
Windows App Data Storage |
that sounds like a good idea ! however I think for a patch for 1.38.1 we should stick to something low risk and more fimilar with what we have Summary: While the suggestion follows OS standards (which is generally good), switching to these paths for lock files introduces significant risks for Minikube's specific use cases (CI, containers, enterprise setups). Analysis: Reliability (The Main Risk): It solves the original "permission denied" and collision issues. |
…s for user isolation and writability.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Instead, we use the SHA1 hash of the user's home directory as a unique identifier. | ||
| // This ensures per-user isolation in shared temporary directories. | ||
| hash := sha1.Sum([]byte(homeDir)) | ||
| return fmt.Sprintf("minikube-locks-windows-%x", hash) |
There was a problem hiding this comment.
The full SHA1 hash (40 hex characters) creates an excessively long directory name that could approach or exceed path length limits on some systems. Consider truncating the hash to a shorter length (e.g., first 16 characters) while still maintaining reasonable collision resistance for typical multi-user scenarios on a single machine. This would make the directory name more manageable while preserving the per-user isolation benefit.
| return fmt.Sprintf("minikube-locks-windows-%x", hash) | |
| hashStr := fmt.Sprintf("%x", hash) | |
| if len(hashStr) > 16 { | |
| hashStr = hashStr[:16] | |
| } | |
| return fmt.Sprintf("minikube-locks-windows-%s", hashStr) |
| if err := os.WriteFile(testFile, []byte("test"), 0600); err != nil { | ||
| t.Errorf("Expected to be able to write to %s: %v", lockDir, err) | ||
| } | ||
| os.Remove(testFile) |
There was a problem hiding this comment.
If WriteFile succeeds but Remove fails, the error from Remove is silently ignored. Consider using defer to ensure cleanup happens, or at minimum log the error if cleanup fails. This prevents test file leakage in the temporary directory.
| os.Remove(testFile) | |
| if err := os.Remove(testFile); err != nil { | |
| t.Logf("failed to remove test file %s: %v", testFile, err) | |
| } |
|
kvm2 driver with docker runtime DetailsTimes for minikube ingress: 16.3s 16.8s 15.7s 16.3s 16.3s Times for minikube start: 36.7s 36.6s 38.0s 36.8s 40.4s docker driver with docker runtime DetailsTimes for minikube start: 20.9s 21.7s 21.0s 17.9s 18.4s Times for minikube ingress: 10.6s 11.6s 10.6s 10.6s 10.6s docker driver with containerd runtime DetailsTimes for minikube start: 19.9s 15.9s 16.8s 17.0s 19.6s Times for minikube ingress: 25.1s 23.1s 25.1s 25.1s 24.1s |
|
@medyagh: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
This does not seem to comply with recommendations for generating temp files/dirs here. The old name and the suggested change is unfortunately guessable. Would it be better to have directory that is created with this golang api. It doesn't even need to have the username in it...something like '/tmp/minikube-${random_val}'? Is there any reason that the directory needs to be the same for each run of the tool? Would it be reasonable to have |
|
And I don't know what the multiple lock files in that directory are for, but it would be possible to name them something more understandable if the directory itself was unique. |
|
Also, the change seems to do what is described on a Fedora machine. I created a /tmp/minikube-locks dir and set the perms to 600. I then started a minikube cluster and saw that the |
The lock files in the directory will be accessed by multiple minikube instances, so we cannot use random names. This is not a directory or temporary data but directory synchronizing multiple processes. Creating the directory is safe since creating a directory is atomic operation. If the directory already exits the call will fail. If 2 minikube instance try to create the directory in the same time one will succeed and the other will with ErrExist. The directory must be created with permissions 0o700 so only the user can access it. When creating a lock file we can use O_CREATE|O_NOFOLLOW to protect forms symlinks attacks. See #22624 for discussion on location of the runtime data. |
I assume that the lock files directory needs to be used for multiple invocations of the minikube binary. If that is true, couldn't minikube store that in the minikube profile config? Is there some problem with having a different dir for each profile?
The problem is that another user could create the directory and prevent my user from running minikube successfully. There are other failure modes that I can think of.
For the test, I created the old name (/tmp/minikube-locks) with 0o600 to make sure that minikube wasn't writing to it with the change. I didn't create the new directory manually. The directory wsa created with 0o700, as expected.
I am less worried about symlink attacks. I am more worried about just making sure that best practices around temp dir creation/usage are followed. Also, using os.mkTempDir will make sure that the proper temp directories are used on different platforms following their conventions. For example, the TMPDIR env var on Linux and using the equivalent appropriate env vars on Windows.
I can also post a summary of this there as well, if that is useful. |
|
I read #22624. That's a really good idea. I made a small comment, but it really sounds like the right direction. |
thanks @wt :) yes a summery would be nice, please feel free to add it to the issue I created so we can tackle it in next minor version (not patch version) |
fixes a regression introduced in v1.38.0 where the shared lock directory
/tmp/minikube-lockswas created with0755permissions. This prevented different users (or CI jobs running as different users) from acquiring locks on the same machine, resulting inHOST_HOME_PERMISSIONerrors.Changes:
/tmp/minikube-locks-1000).TestLockDirectoryStructureto verify the directory naming convention.Fixes HOST_HOME_PERMISSION "unable to acquire lock" in 1.38.0 #22619
fix #22619