Skip to content

[release-4.13] fix: use syscall.Chmod to correctly handle setgid/setuid/sticky bits in mountPermissions#1110

Merged
k8s-ci-robot merged 4 commits intokubernetes-csi:release-4.13from
k8s-infra-cherrypick-robot:cherry-pick-1106-to-release-4.13
Apr 20, 2026
Merged

[release-4.13] fix: use syscall.Chmod to correctly handle setgid/setuid/sticky bits in mountPermissions#1110
k8s-ci-robot merged 4 commits intokubernetes-csi:release-4.13from
k8s-infra-cherrypick-robot:cherry-pick-1106-to-release-4.13

Conversation

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

This is an automated cherry-pick of #1106

/assign andyzhangx

Fix mountPermissions to correctly apply setgid, setuid, and sticky bits (e.g. 02770) by using syscall.Chmod instead of os.Chmod.

andyzhangx and others added 4 commits April 20, 2026 01:19
…in mountPermissions

os.Chmod with os.FileMode does not correctly map Unix setgid (02000),
setuid (04000), or sticky (01000) bits because Go os.FileMode uses
different bit positions for these flags. For example, mountPermissions
of 02770 (setgid + rwxrwx) would only apply 0770 via os.Chmod,
silently dropping the setgid bit.

Switch to syscall.Chmod which takes raw Unix mode bits directly.
Also use chmodIfPermissionMismatch in CreateVolume for consistency,
and use 0777 for MkdirAll in NodePublishVolume since the subsequent
chmodIfPermissionMismatch handles the actual permission setting.

Ref 940
…n mask, add special-bit tests

- Split syscall.Chmod into platform-specific files (chmod_unix.go, chmod_windows.go)
  with build tags to avoid breaking Windows builds
- Fix permission comparison mask in chmodIfPermissionMismatch to include
  setuid/setgid/sticky bits, not just os.ModePerm (0777)
- Add fileModeToUnixMode helper to correctly convert raw Unix mode values
  to Go's os.FileMode representation
- Add unit tests for special bits (02770, 01777, 04755) in chmod_unix_test.go
@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 20, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 20, 2026
Copy link
Copy Markdown
Member

@andyzhangx andyzhangx left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 20, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx, k8s-infra-cherrypick-robot

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 20, 2026
@k8s-ci-robot k8s-ci-robot merged commit a4b306b into kubernetes-csi:release-4.13 Apr 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants