Skip to content

Commit 8c193c8

Browse files
committed
fix: update permissions for logging directories in /var
Fixes #9630 Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com> (cherry picked from commit 7f3aaa2)
1 parent 5044a41 commit 8c193c8

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -887,20 +887,58 @@ func SetupVarDirectory(runtime.Sequence, any) (runtime.TaskExecutionFunc, string
887887
return err
888888
}
889889

890-
for _, p := range []string{"/var/log/audit", "/var/log/containers", "/var/log/pods", "/var/lib/kubelet", "/var/run/lock", constants.SeccompProfilesDirectory} {
891-
if err := os.MkdirAll(p, 0o700); err != nil {
890+
for _, dir := range []struct {
891+
Path string
892+
Mode os.FileMode
893+
UID, GID int
894+
}{
895+
{
896+
Path: "/var/log",
897+
Mode: 0o755,
898+
},
899+
{
900+
Path: "/var/log/audit",
901+
Mode: 0o700,
902+
},
903+
{
904+
Path: "/var/log/containers",
905+
Mode: 0o755,
906+
},
907+
{
908+
Path: "/var/log/pods",
909+
Mode: 0o755,
910+
},
911+
{
912+
Path: "/var/lib/kubelet",
913+
Mode: 0o700,
914+
},
915+
{
916+
Path: "/var/run/lock",
917+
Mode: 0o755,
918+
},
919+
{
920+
Path: constants.SeccompProfilesDirectory,
921+
Mode: 0o700,
922+
},
923+
{
924+
Path: constants.KubernetesAuditLogDir,
925+
Mode: 0o700,
926+
UID: constants.KubernetesAPIServerRunUser,
927+
GID: constants.KubernetesAPIServerRunGroup,
928+
},
929+
} {
930+
if err := os.MkdirAll(dir.Path, dir.Mode); err != nil {
892931
return err
893932
}
894-
}
895933

896-
// Handle Kubernetes directories which need different ownership
897-
for _, p := range []string{constants.KubernetesAuditLogDir} {
898-
if err := os.MkdirAll(p, 0o700); err != nil {
934+
if err := os.Chmod(dir.Path, dir.Mode); err != nil {
899935
return err
900936
}
901937

902-
if err := os.Chown(p, constants.KubernetesAPIServerRunUser, constants.KubernetesAPIServerRunGroup); err != nil {
903-
return fmt.Errorf("failed to chown %s: %w", p, err)
938+
if dir.UID != 0 || dir.GID != 0 {
939+
if err := os.Chown(dir.Path, dir.UID, dir.GID); err != nil {
940+
return err
941+
}
904942
}
905943
}
906944

0 commit comments

Comments
 (0)