Skip to content

Commit 18daa6e

Browse files
chrnormjpbelleau
andauthored
Revert "update file permissions to read/write (#751)" (#755)
Fixes the permissions issue in the latest Granted release. --------- Co-authored-by: James Belleau <[email protected]>
1 parent 286a999 commit 18daa6e

File tree

8 files changed

+22
-57
lines changed

8 files changed

+22
-57
lines changed

pkg/accessrequest/role.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ import (
1414
"github.com/common-fate/granted/pkg/config"
1515
)
1616

17-
const (
18-
// permission for user to read/write.
19-
USER_READ_WRITE_PERM = 0644
20-
)
21-
2217
type Role struct {
2318
Account string `json:"account"`
2419
Role string `json:"role"`
@@ -51,7 +46,7 @@ func (r Role) Save() error {
5146
}
5247

5348
file := filepath.Join(configFolder, "latest-role")
54-
return os.WriteFile(file, roleBytes, USER_READ_WRITE_PERM)
49+
return os.WriteFile(file, roleBytes, 0644)
5550
}
5651

5752
func LatestRole() (*Role, error) {
@@ -96,7 +91,7 @@ func (p Profile) Save() error {
9691
}
9792

9893
file := filepath.Join(configFolder, "latest-profile")
99-
return os.WriteFile(file, profileBytes, USER_READ_WRITE_PERM)
94+
return os.WriteFile(file, profileBytes, 0644)
10095
}
10196

10297
func LatestProfile() (*Profile, error) {

pkg/cfaws/ssotoken.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ import (
1515
"github.com/common-fate/granted/pkg/securestorage"
1616
)
1717

18-
const (
19-
// permission for user to read/write.
20-
USER_READ_WRITE_PERM = 0644
21-
)
22-
2318
type SSOPlainTextOut struct {
2419
AccessToken string `json:"accessToken"`
2520
ExpiresAt string `json:"expiresAt"`
@@ -93,13 +88,13 @@ func dumpTokenFile(jsonToken []byte, key string) error {
9388
}
9489

9590
if _, err := os.Stat(path); os.IsNotExist(err) {
96-
err := os.MkdirAll(path, USER_READ_WRITE_PERM)
91+
err := os.MkdirAll(path, 0700)
9792
if err != nil {
9893
return fmt.Errorf("unable to create sso cache directory with err: %s", err)
9994
}
10095
}
10196

102-
err = os.WriteFile(filepath.Join(path, key), jsonToken, USER_READ_WRITE_PERM)
97+
err = os.WriteFile(filepath.Join(path, key), jsonToken, 0600)
10398
if err != nil {
10499
return err
105100
}

pkg/config/config.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,6 @@ import (
1717
"github.com/common-fate/granted/internal/build"
1818
)
1919

20-
const (
21-
// permission for user to read/write.
22-
USER_READ_WRITE_PERM = 0644
23-
)
24-
25-
const (
26-
// permission for user to read/write.
27-
USER_READ_WRITE_EXECUTE_PERM = 0700
28-
)
29-
3020
type BrowserLaunchTemplate struct {
3121
// UseForkProcess specifies whether to use forkprocess to launch the browser.
3222
//
@@ -152,7 +142,7 @@ func SetupConfigFolder() error {
152142
return err
153143
}
154144
if _, err := os.Stat(grantedFolder); os.IsNotExist(err) {
155-
err := os.Mkdir(grantedFolder, USER_READ_WRITE_PERM)
145+
err := os.Mkdir(grantedFolder, 0700)
156146
if err != nil {
157147
return err
158148
}
@@ -168,14 +158,14 @@ func SetupZSHAutoCompleteFolderAssume() (string, error) {
168158
}
169159
zshPath := path.Join(grantedFolder, "zsh_autocomplete")
170160
if _, err := os.Stat(zshPath); os.IsNotExist(err) {
171-
err := os.Mkdir(zshPath, USER_READ_WRITE_EXECUTE_PERM)
161+
err := os.Mkdir(zshPath, 0700)
172162
if err != nil {
173163
return "", err
174164
}
175165
}
176166
zshPath = path.Join(zshPath, build.AssumeScriptName())
177167
if _, err := os.Stat(zshPath); os.IsNotExist(err) {
178-
err := os.Mkdir(zshPath, USER_READ_WRITE_EXECUTE_PERM)
168+
err := os.Mkdir(zshPath, 0700)
179169
if err != nil {
180170
return "", err
181171
}
@@ -191,14 +181,14 @@ func SetupZSHAutoCompleteFolderGranted() (string, error) {
191181
}
192182
zshPath := path.Join(grantedFolder, "zsh_autocomplete")
193183
if _, err := os.Stat(zshPath); os.IsNotExist(err) {
194-
err := os.Mkdir(zshPath, USER_READ_WRITE_EXECUTE_PERM)
184+
err := os.Mkdir(zshPath, 0700)
195185
if err != nil {
196186
return "", err
197187
}
198188
}
199189
zshPath = path.Join(zshPath, build.GrantedBinaryName())
200190
if _, err := os.Stat(zshPath); os.IsNotExist(err) {
201-
err := os.Mkdir(zshPath, USER_READ_WRITE_EXECUTE_PERM)
191+
err := os.Mkdir(zshPath, 0700)
202192
if err != nil {
203193
return "", err
204194
}
@@ -284,7 +274,7 @@ func Load() (*Config, error) {
284274
return nil, err
285275
}
286276

287-
file, err := os.OpenFile(configFilePath, os.O_RDWR|os.O_CREATE, USER_READ_WRITE_PERM)
277+
file, err := os.OpenFile(configFilePath, os.O_RDWR|os.O_CREATE, 0600)
288278
if err != nil {
289279
return nil, err
290280
}
@@ -306,7 +296,7 @@ func (c *Config) Save() error {
306296
return err
307297
}
308298

309-
file, err := os.OpenFile(configFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, USER_READ_WRITE_PERM)
299+
file, err := os.OpenFile(configFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
310300
if err != nil {
311301
return err
312302
}

pkg/frecency/frecency.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ import (
1111
"github.com/common-fate/granted/pkg/config"
1212
)
1313

14-
const (
15-
// permission for user to read/write.
16-
USER_READ_WRITE_PERM = 0644
17-
)
18-
1914
// change these to play with the weights
2015
// values between 0 and 1
2116
// 0 will exclude the metric all together from the ordering
@@ -75,14 +70,14 @@ func Load(fecencyStoreKey string) (*FrecencyStore, error) {
7570

7671
// check if the providers file exists
7772
if _, err = os.Stat(c.path); os.IsNotExist(err) {
78-
err := os.MkdirAll(configFolder, USER_READ_WRITE_PERM)
73+
err := os.MkdirAll(configFolder, 0700)
7974
if err != nil {
8075
return nil, err
8176
}
8277
return &c, nil
8378
}
8479

85-
file, err := os.OpenFile(c.path, os.O_RDWR|os.O_CREATE, USER_READ_WRITE_PERM)
80+
file, err := os.OpenFile(c.path, os.O_RDWR|os.O_CREATE, 0600)
8681
if err != nil {
8782
return nil, err
8883
}
@@ -191,7 +186,7 @@ func (store *FrecencyStore) save() error {
191186
// store.Entries = store.Entries[0 : len(store.Entries)-1]
192187
// }
193188

194-
file, err := os.OpenFile(store.path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, USER_READ_WRITE_PERM)
189+
file, err := os.OpenFile(store.path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
195190
if err != nil {
196191
return err
197192
}

pkg/granted/exp/request/request.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ import (
3838
"gopkg.in/ini.v1"
3939
)
4040

41-
const (
42-
// permission for user to read/write.
43-
USER_READ_WRITE_PERM = 0644
44-
)
45-
4641
var Command = cli.Command{
4742
Name: "request",
4843
Usage: "Request access to a role",
@@ -731,7 +726,7 @@ func updateCachedAccessRule(ctx context.Context, opts updateCacheOpts) error {
731726
return err
732727
}
733728

734-
err = os.WriteFile(filename, ruleBytes, USER_READ_WRITE_PERM)
729+
err = os.WriteFile(filename, ruleBytes, 0644)
735730
if err != nil {
736731
return err
737732
}

pkg/granted/registry/add.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import (
1515
"github.com/urfave/cli/v2"
1616
)
1717

18+
const (
19+
// permission for user to read/write/execute.
20+
USER_READ_WRITE_PERM = 0700
21+
)
22+
1823
var AddCommand = cli.Command{
1924
Name: "add",
2025
Description: "Add a Profile Registry that you want to sync with aws config file",

pkg/granted/registry/ini.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ import (
1010
"gopkg.in/ini.v1"
1111
)
1212

13-
const (
14-
// permission for user to read/write.
15-
USER_READ_WRITE_PERM = 0644
16-
)
17-
1813
// Find the ~/.aws/config absolute path based on OS.
1914
func getDefaultAWSConfigLocation() (string, error) {
2015
h, err := os.UserHomeDir()

pkg/shells/file.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import (
66
"strings"
77
)
88

9-
const (
10-
// permission for user to read/write.
11-
USER_READ_WRITE_PERM = 0644
12-
)
13-
149
// AppendLine writes a line to a file if it does not already exist
1510
func AppendLine(file string, line string) error {
1611
b, err := os.ReadFile(file)
@@ -24,7 +19,7 @@ func AppendLine(file string, line string) error {
2419
}
2520

2621
// open the file for writing
27-
out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY, USER_READ_WRITE_PERM)
22+
out, err := os.OpenFile(file, os.O_APPEND|os.O_WRONLY, 0644)
2823
if err != nil {
2924
return err
3025
}
@@ -78,7 +73,7 @@ func RemoveLine(file string, lineToRemove string) error {
7873
}
7974

8075
output := strings.Join(ignored, "\n")
81-
err = os.WriteFile(file, []byte(output), USER_READ_WRITE_PERM)
76+
err = os.WriteFile(file, []byte(output), 0644)
8277
if err != nil {
8378
return err
8479
}

0 commit comments

Comments
 (0)