Skip to content

Commit 625fb88

Browse files
peterficationpjbgf
andcommitted
Reduce file permission
As suggested by @pjbgf Co-authored-by: Paulo Gomes <paulo.gomes.uk@gmail.com> Co-authored-by: Paulo Gomes <paulo.gomes.uk@gmail.com> Signed-off-by: Peter Gundel <mail@petergundel.de>
1 parent 0949d0a commit 625fb88

File tree

9 files changed

+30
-30
lines changed

9 files changed

+30
-30
lines changed

controllers/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (s Storage) SetHostname(URL string) string {
112112
// MkdirAll calls os.MkdirAll for the given v1beta1.Artifact base dir.
113113
func (s *Storage) MkdirAll(artifact sourcev1.Artifact) error {
114114
dir := filepath.Dir(s.LocalPath(artifact))
115-
return os.MkdirAll(dir, 0o777)
115+
return os.MkdirAll(dir, 0o770)
116116
}
117117

118118
// RemoveAll calls os.RemoveAll for the given v1beta1.Artifact base dir.
@@ -432,7 +432,7 @@ func (s *Storage) Archive(artifact *sourcev1.Artifact, dir string, filter Archiv
432432
return err
433433
}
434434

435-
if err := os.Chmod(tmpName, 0o644); err != nil {
435+
if err := os.Chmod(tmpName, 0o640); err != nil {
436436
return err
437437
}
438438

controllers/storage_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestStorage_Archive(t *testing.T) {
136136
}
137137
for name, b := range files {
138138
absPath := filepath.Join(dir, name)
139-
if err = os.MkdirAll(filepath.Dir(absPath), 0o755); err != nil {
139+
if err = os.MkdirAll(filepath.Dir(absPath), 0o750); err != nil {
140140
return
141141
}
142142
f, err := os.Create(absPath)

internal/fs/fs_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ func TestRenameWithFallback(t *testing.T) {
4242
}
4343

4444
srcpath = filepath.Join(dir, "a")
45-
if err = os.MkdirAll(srcpath, 0o777); err != nil {
45+
if err = os.MkdirAll(srcpath, 0o770); err != nil {
4646
t.Fatal(err)
4747
}
4848

4949
dstpath := filepath.Join(dir, "b")
50-
if err = os.MkdirAll(dstpath, 0o777); err != nil {
50+
if err = os.MkdirAll(dstpath, 0o770); err != nil {
5151
t.Fatal(err)
5252
}
5353

@@ -64,7 +64,7 @@ func TestCopyDir(t *testing.T) {
6464
defer os.RemoveAll(dir)
6565

6666
srcdir := filepath.Join(dir, "src")
67-
if err := os.MkdirAll(srcdir, 0o755); err != nil {
67+
if err := os.MkdirAll(srcdir, 0o750); err != nil {
6868
t.Fatal(err)
6969
}
7070

@@ -81,7 +81,7 @@ func TestCopyDir(t *testing.T) {
8181
for i, file := range files {
8282
fn := filepath.Join(srcdir, file.path)
8383
dn := filepath.Dir(fn)
84-
if err = os.MkdirAll(dn, 0o755); err != nil {
84+
if err = os.MkdirAll(dn, 0o750); err != nil {
8585
t.Fatal(err)
8686
}
8787

@@ -151,7 +151,7 @@ func TestCopyDirFail_SrcInaccessible(t *testing.T) {
151151

152152
cleanup := setupInaccessibleDir(t, func(dir string) error {
153153
srcdir = filepath.Join(dir, "src")
154-
return os.MkdirAll(srcdir, 0o755)
154+
return os.MkdirAll(srcdir, 0o750)
155155
})
156156
defer cleanup()
157157

@@ -184,7 +184,7 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) {
184184
defer os.RemoveAll(dir)
185185

186186
srcdir = filepath.Join(dir, "src")
187-
if err = os.MkdirAll(srcdir, 0o755); err != nil {
187+
if err = os.MkdirAll(srcdir, 0o750); err != nil {
188188
t.Fatal(err)
189189
}
190190

@@ -235,12 +235,12 @@ func TestCopyDirFail_DstExists(t *testing.T) {
235235
defer os.RemoveAll(dir)
236236

237237
srcdir = filepath.Join(dir, "src")
238-
if err = os.MkdirAll(srcdir, 0o755); err != nil {
238+
if err = os.MkdirAll(srcdir, 0o750); err != nil {
239239
t.Fatal(err)
240240
}
241241

242242
dstdir = filepath.Join(dir, "dst")
243-
if err = os.MkdirAll(dstdir, 0o755); err != nil {
243+
if err = os.MkdirAll(dstdir, 0o750); err != nil {
244244
t.Fatal(err)
245245
}
246246

@@ -273,7 +273,7 @@ func TestCopyDirFailOpen(t *testing.T) {
273273
defer os.RemoveAll(dir)
274274

275275
srcdir = filepath.Join(dir, "src")
276-
if err = os.MkdirAll(srcdir, 0o755); err != nil {
276+
if err = os.MkdirAll(srcdir, 0o750); err != nil {
277277
t.Fatal(err)
278278
}
279279

@@ -285,7 +285,7 @@ func TestCopyDirFailOpen(t *testing.T) {
285285
srcf.Close()
286286

287287
// setup source file so that it cannot be read
288-
if err = os.Chmod(srcfn, 0o222); err != nil {
288+
if err = os.Chmod(srcfn, 0o220); err != nil {
289289
t.Fatal(err)
290290
}
291291

@@ -419,11 +419,11 @@ func TestCopyFileLongFilePath(t *testing.T) {
419419
}
420420

421421
fullPath := filepath.Join(dir, dirName, string(os.PathSeparator))
422-
if err := os.MkdirAll(fullPath, 0o755); err != nil && !os.IsExist(err) {
422+
if err := os.MkdirAll(fullPath, 0o750); err != nil && !os.IsExist(err) {
423423
t.Fatalf("%+v", fmt.Errorf("unable to create temp directory: %s", fullPath))
424424
}
425425

426-
err = os.WriteFile(fullPath+"src", []byte(nil), 0o644)
426+
err = os.WriteFile(fullPath+"src", []byte(nil), 0o640)
427427
if err != nil {
428428
t.Fatalf("%+v", err)
429429
}
@@ -460,7 +460,7 @@ func TestCopyFileFail(t *testing.T) {
460460

461461
cleanup := setupInaccessibleDir(t, func(dir string) error {
462462
dstdir = filepath.Join(dir, "dir")
463-
return os.Mkdir(dstdir, 0o777)
463+
return os.Mkdir(dstdir, 0o770)
464464
})
465465
defer cleanup()
466466

@@ -493,15 +493,15 @@ func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
493493
subdir := filepath.Join(dir, "dir")
494494

495495
cleanup := func() {
496-
if err := os.Chmod(subdir, 0o777); err != nil {
496+
if err := os.Chmod(subdir, 0o770); err != nil {
497497
t.Error(err)
498498
}
499499
if err := os.RemoveAll(dir); err != nil {
500500
t.Error(err)
501501
}
502502
}
503503

504-
if err := os.Mkdir(subdir, 0o777); err != nil {
504+
if err := os.Mkdir(subdir, 0o770); err != nil {
505505
cleanup()
506506
t.Fatal(err)
507507
return nil
@@ -513,7 +513,7 @@ func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
513513
return nil
514514
}
515515

516-
if err := os.Chmod(subdir, 0o666); err != nil {
516+
if err := os.Chmod(subdir, 0o660); err != nil {
517517
cleanup()
518518
t.Fatal(err)
519519
return nil
@@ -532,7 +532,7 @@ func TestIsDir(t *testing.T) {
532532

533533
cleanup := setupInaccessibleDir(t, func(dir string) error {
534534
dn = filepath.Join(dir, "dir")
535-
return os.Mkdir(dn, 0o777)
535+
return os.Mkdir(dn, 0o770)
536536
})
537537
defer cleanup()
538538

@@ -575,7 +575,7 @@ func TestIsSymlink(t *testing.T) {
575575
defer os.RemoveAll(dir)
576576

577577
dirPath := filepath.Join(dir, "directory")
578-
if err = os.MkdirAll(dirPath, 0o777); err != nil {
578+
if err = os.MkdirAll(dirPath, 0o770); err != nil {
579579
t.Fatal(err)
580580
}
581581

internal/helm/chart/builder_local_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ fullnameOverride: "full-foo-name-override"`),
201201
// Write value file in the base dir.
202202
for _, f := range tt.valuesFiles {
203203
vPath := filepath.Join(localRef.WorkDir, f.Name)
204-
g.Expect(os.WriteFile(vPath, f.Data, 0o644)).ToNot(HaveOccurred())
204+
g.Expect(os.WriteFile(vPath, f.Data, 0o640)).ToNot(HaveOccurred())
205205
}
206206

207207
// Write chart dependencies in the base dir.
@@ -336,7 +336,7 @@ func Test_mergeFileValues(t *testing.T) {
336336
defer os.RemoveAll(baseDir)
337337

338338
for _, f := range tt.files {
339-
g.Expect(os.WriteFile(filepath.Join(baseDir, f.Name), f.Data, 0o644)).To(Succeed())
339+
g.Expect(os.WriteFile(filepath.Join(baseDir, f.Name), f.Data, 0o640)).To(Succeed())
340340
}
341341

342342
got, err := mergeFileValues(baseDir, tt.paths)

internal/helm/chart/metadata_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func TestLoadChartMetadataFromDir(t *testing.T) {
140140
copy.Copy("../testdata/charts/helmchart", tmpDir)
141141
bigRequirementsFile := filepath.Join(tmpDir, "requirements.yaml")
142142
data := make([]byte, helm.MaxChartFileSize+10)
143-
g.Expect(os.WriteFile(bigRequirementsFile, data, 0o644)).ToNot(HaveOccurred())
143+
g.Expect(os.WriteFile(bigRequirementsFile, data, 0o640)).ToNot(HaveOccurred())
144144

145145
tests := []struct {
146146
name string
@@ -205,7 +205,7 @@ func TestLoadChartMetadataFromArchive(t *testing.T) {
205205
defer os.RemoveAll(tmpDir)
206206
bigArchiveFile := filepath.Join(tmpDir, "chart.tgz")
207207
data := make([]byte, helm.MaxChartSize+10)
208-
g.Expect(os.WriteFile(bigArchiveFile, data, 0o644)).ToNot(HaveOccurred())
208+
g.Expect(os.WriteFile(bigArchiveFile, data, 0o640)).ToNot(HaveOccurred())
209209

210210
tests := []struct {
211211
name string

internal/helm/repository/chart_repository_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func TestChartRepository_LoadIndexFromFile(t *testing.T) {
363363
defer os.RemoveAll(tmpDir)
364364
bigIndexFile := filepath.Join(tmpDir, "index.yaml")
365365
data := make([]byte, helm.MaxIndexSize+10)
366-
g.Expect(os.WriteFile(bigIndexFile, data, 0o644)).ToNot(HaveOccurred())
366+
g.Expect(os.WriteFile(bigIndexFile, data, 0o640)).ToNot(HaveOccurred())
367367

368368
tests := []struct {
369369
name string

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func mustInitStorage(path string, storageAdvAddr string, artifactRetentionTTL ti
299299
if path == "" {
300300
p, _ := os.Getwd()
301301
path = filepath.Join(p, "bin")
302-
os.MkdirAll(path, 0o777)
302+
os.MkdirAll(path, 0o770)
303303
}
304304

305305
storage, err := controllers.NewStorage(path, storageAdvAddr, artifactRetentionTTL, artifactRetentionRecords)

pkg/sourceignore/sourceignore_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ func TestLoadExcludePatterns(t *testing.T) {
209209
"a/b/.sourceignore": "subdir.txt",
210210
}
211211
for n, c := range files {
212-
if err = os.MkdirAll(filepath.Join(tmpDir, filepath.Dir(n)), 0o755); err != nil {
212+
if err = os.MkdirAll(filepath.Join(tmpDir, filepath.Dir(n)), 0o750); err != nil {
213213
t.Fatal(err)
214214
}
215-
if err = os.WriteFile(filepath.Join(tmpDir, n), []byte(c), 0o644); err != nil {
215+
if err = os.WriteFile(filepath.Join(tmpDir, n), []byte(c), 0o640); err != nil {
216216
t.Fatal(err)
217217
}
218218
}

tests/fuzz/gitrepository_fuzzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func createRandomFiles(f *fuzz.ConsumeFuzzer, fs billy.Filesystem, wt *git.Workt
494494
return errors.New("Dir contains '..'")
495495
}
496496

497-
err = fs.MkdirAll(dirPath, 0o777)
497+
err = fs.MkdirAll(dirPath, 0o770)
498498
if err != nil {
499499
return errors.New("Could not create the subDir")
500500
}

0 commit comments

Comments
 (0)