Skip to content

Commit f400bf4

Browse files
authored
Use restrictive permissions (0700) for cache directories (#714)
Signed-off-by: Radoslav Dimitrov <radoslav@stacklok.com>
1 parent d2dbc18 commit f400bf4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

metadata/config/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ func (cfg *UpdaterConfig) EnsurePathsExist() error {
8484
}
8585

8686
for _, path := range []string{cfg.LocalMetadataDir, cfg.LocalTargetsDir} {
87-
if err := os.MkdirAll(path, os.ModePerm); err != nil {
87+
// Use 0700 for cache directories: only the owner can read, write, and
88+
// access the directory. This prevents other users on shared systems from
89+
// reading or writing to the TUF cache, which could be a security risk.
90+
// If different permissions are needed, pre-create the directories with
91+
// the desired permissions before calling this function.
92+
if err := os.MkdirAll(path, 0700); err != nil {
8893
return err
8994
}
9095
}

metadata/multirepo/multirepo.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,12 @@ func (cfg *MultiRepoConfig) EnsurePathsExist() error {
351351
return nil
352352
}
353353
for _, path := range []string{cfg.LocalMetadataDir, cfg.LocalTargetsDir} {
354-
err := os.MkdirAll(path, os.ModePerm)
354+
// Use 0700 for cache directories: only the owner can read, write, and
355+
// access the directory. This prevents other users on shared systems from
356+
// reading or writing to the TUF cache, which could be a security risk.
357+
// If different permissions are needed, pre-create the directories with
358+
// the desired permissions before calling this function.
359+
err := os.MkdirAll(path, 0700)
355360
if err != nil {
356361
return err
357362
}

0 commit comments

Comments
 (0)