Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updated config file permission requirements for windows (#9666) #9732

Merged
merged 4 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have an equivalent test for windows?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Slack:

I actually did try to create windows only tests but I just couldn't manage to set the permission properly with golang it just won't set it to something other than 0444 or 0666

lgtm. :-)


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