Skip to content

Commit 72adc40

Browse files
committed
fix: preserve SELinux label for atomic writes
1 parent 2a77230 commit 72adc40

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/containerservice/armcontainerservice/v8 v8.3.0-beta.2
1010
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/hybridcompute/armhybridcompute v1.2.0
1111
github.com/Azure/kubelogin v0.2.15
12-
github.com/Azure/unbounded v0.1.20-rc.4
12+
github.com/Azure/unbounded v0.1.20-rc.4.0.20260707043133-59e1ae4179f5
1313
github.com/google/renameio/v2 v2.0.2
1414
github.com/google/uuid v1.6.0
1515
github.com/spf13/cobra v1.10.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ github.com/Azure/kubelogin v0.2.15 h1:oJqD8Dvput3rO/xZgMTU+hBrcgg0BfQGPCNHJ2dEmy
3838
github.com/Azure/kubelogin v0.2.15/go.mod h1:RwJS8TzSHTVQhfIZA4HLS79QGfvIp0ocIVLT5oHS/ls=
3939
github.com/Azure/unbounded v0.1.20-rc.4 h1:ftzpSuL1Zl+hiFyXovC8wr9gTS2JIuUdYeIVlMY7+BQ=
4040
github.com/Azure/unbounded v0.1.20-rc.4/go.mod h1:WnWLk0Y+Hwnj6MSMGa3YkSXG75y6JS1ek+UyNzAb9d0=
41+
github.com/Azure/unbounded v0.1.20-rc.4.0.20260707043133-59e1ae4179f5 h1:+X4Yjfr/PFAFmUw7KUvg5fL+X100uI9g6rUZP6PjE6w=
42+
github.com/Azure/unbounded v0.1.20-rc.4.0.20260707043133-59e1ae4179f5/go.mod h1:WnWLk0Y+Hwnj6MSMGa3YkSXG75y6JS1ek+UyNzAb9d0=
4143
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM=
4244
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1/go.mod h1:tCcJZ0uHAmvjsVYzEFivsRTN00oz5BEsRgQHu5JZ9WE=
4345
github.com/AzureAD/microsoft-authentication-library-for-go v1.7.2 h1:RHK7bS+HQMslb1sZpAokUt+zTVmue0hKSs2C791hhzU=

pkg/utils/utilio/io.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ func InstallFile(filename string, r io.Reader, perm os.FileMode) error {
2424

2525
// InstallFileWithLimitedSize streams content to local file with limited size and specified permissions.
2626
// It ensures that the target directory exists and handles the file writing atomically.
27+
// The temp file is created in the same directory as the destination to preserve the
28+
// correct SELinux label (avoiding the user_tmp_t label from /tmp).
2729
//
2830
// NOTE: we assume the filename is trusted and cleaned without path traversal characters.
2931
func InstallFileWithLimitedSize(filename string, r io.Reader, perm os.FileMode, maxBytes int64) error {
@@ -34,7 +36,7 @@ func InstallFileWithLimitedSize(filename string, r io.Reader, perm os.FileMode,
3436
return err
3537
}
3638

37-
pf, err := renameio.NewPendingFile(filename, renameio.WithPermissions(perm))
39+
pf, err := renameio.NewPendingFile(filename, renameio.WithPermissions(perm), renameio.WithTempDir(filepath.Dir(filename)))
3840
if err != nil {
3941
return err
4042
}
@@ -57,12 +59,14 @@ func InstallFileWithLimitedSize(filename string, r io.Reader, perm os.FileMode,
5759

5860
// WriteFile writes the provided content to a local file with specified permissions.
5961
// It ensures that the target directory exists and handles the file writing atomically.
62+
// The temp file is created in the same directory as the destination to preserve the
63+
// correct SELinux label (avoiding the user_tmp_t label from /tmp).
6064
//
6165
// NOTE: we assume the filename is trusted and cleaned without path traversal characters.
6266
func WriteFile(filename string, content []byte, perm os.FileMode) error {
6367
if err := os.MkdirAll(filepath.Dir(filename), 0750); err != nil {
6468
return err
6569
}
6670

67-
return renameio.WriteFile(filename, content, perm)
71+
return renameio.WriteFile(filename, content, perm, renameio.WithTempDir(filepath.Dir(filename)))
6872
}

0 commit comments

Comments
 (0)