Skip to content

Commit

Permalink
fix: updated config file permission requirements for windows (#9732)
Browse files Browse the repository at this point in the history
* fix: reduced config file permission restriction on windows

Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com>

* fix: updated localconfig tests to check error

Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com>
  • Loading branch information
gdsoumya authored and crenshaw-dev committed Jun 21, 2022
1 parent 792e278 commit 211e9f6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
16 changes: 16 additions & 0 deletions util/localconfig/file_perm_unix.go
@@ -0,0 +1,16 @@
//go:build !windows

package localconfig

import (
"fmt"
"os"
)

func getFilePermission(fi os.FileInfo) error {
if fi.Mode().Perm() == 0600 || fi.Mode().Perm() == 0400 {
return nil
}
return fmt.Errorf("config file has incorrect permission flags:%s."+
"change the file permission either to 0400 or 0600.", fi.Mode().Perm().String())
}
16 changes: 16 additions & 0 deletions util/localconfig/file_perm_windows.go
@@ -0,0 +1,16 @@
//go:build windows

package localconfig

import (
"fmt"
"os"
)

func getFilePermission(fi os.FileInfo) error {
if fi.Mode().Perm() == 0666 || fi.Mode().Perm() == 0444 {
return nil
}
return fmt.Errorf("config file has incorrect permission flags:%s."+
"change the file permission either to 0444 or 0666.", fi.Mode().Perm().String())
}
8 changes: 0 additions & 8 deletions util/localconfig/localconfig.go
Expand Up @@ -311,11 +311,3 @@ func GetUsername(subject string) string {
}
return subject
}

func getFilePermission(fi os.FileInfo) error {
if fi.Mode().Perm() == 0600 || fi.Mode().Perm() == 0400 {
return nil
}
return fmt.Errorf("config file has incorrect permission flags:%s."+
"change the file permission either to 0400 or 0600.", fi.Mode().Perm().String())
}
4 changes: 3 additions & 1 deletion util/localconfig/localconfig_test.go
@@ -1,3 +1,5 @@
//go:build !windows

package localconfig

import (
Expand Down Expand Up @@ -83,7 +85,7 @@ func TestFilePermission(t *testing.T) {
if err := getFilePermission(fi); err != nil {
assert.EqualError(t, err, c.expectedError.Error())
} else {
require.Nil(t, err)
require.Nil(t, c.expectedError)
}
})
}
Expand Down

0 comments on commit 211e9f6

Please sign in to comment.