Skip to content

Commit 6ba7b1e

Browse files
committed
fix: Set stricter permissions on created directories
* Changed directory creation permissions from 0755 to 0750. * Restricted read and execute access for users other than the owner and group. * Applied the permission change in sample pipeline generation, globbing tests, and SCM utility functions. * Improved the default security posture for created directories. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent f0e3411 commit 6ba7b1e

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

pkg/cmd/tknpac/generate/generate.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (o *Opts) samplePipeline(recreateTemplate bool) error {
195195
}
196196

197197
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
198-
if err := os.MkdirAll(dirPath, 0o755); err != nil {
198+
if err := os.MkdirAll(dirPath, 0o750); err != nil {
199199
return err
200200
}
201201
fmt.Fprintf(o.IOStreams.Out, "%s Directory %s has been created.\n",
@@ -226,8 +226,7 @@ func (o *Opts) samplePipeline(recreateTemplate bool) error {
226226
return err
227227
}
228228

229-
//nolint: gosec
230-
err = os.WriteFile(fpath, tmpl.Bytes(), 0o644)
229+
err = os.WriteFile(fpath, tmpl.Bytes(), 0o600)
231230
if err != nil {
232231
return fmt.Errorf("cannot write template to %s: %w", fpath, err)
233232
}

pkg/cmd/tknpac/info/globbing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestGlobbing(t *testing.T) {
6767
tmpdir := fs.NewDir(t, t.Name())
6868
defer tmpdir.Remove()
6969
for _, file := range tt.files {
70-
assert.NilError(t, os.MkdirAll(filepath.Dir(filepath.Join(tmpdir.Path(), file)), 0o755))
70+
assert.NilError(t, os.MkdirAll(filepath.Dir(filepath.Join(tmpdir.Path(), file)), 0o750))
7171
f, err := os.Create(filepath.Join(tmpdir.Path(), file))
7272
assert.NilError(t, err)
7373
_, _ = f.WriteString("")

test/pkg/scm/scm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func PushFilesToRefGit(t *testing.T, opts *Opts, entries map[string]string) stri
106106
assert.NilError(t, err)
107107

108108
for filename, content := range entries {
109-
assert.NilError(t, os.MkdirAll(filepath.Dir(filename), 0o755))
109+
assert.NilError(t, os.MkdirAll(filepath.Dir(filename), 0o750))
110110
// write content to filename
111111
assert.NilError(t, os.WriteFile(filename, []byte(content), 0o600))
112112
}

0 commit comments

Comments
 (0)