Skip to content

Commit 285f96b

Browse files
committed
PasswordAuthenticator allow_read_by_default -setting
1 parent a4540bc commit 285f96b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

plugins/passwordauthenticator.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type passwordAuthenticator struct {
1212

1313
type passwordSettings struct {
1414
Passwords map[string][]string `yaml:"passwords"`
15+
AllowReadByDefault bool `yaml:"allow_read_by_default"`
1516
}
1617

1718
var settings *passwordSettings
@@ -20,7 +21,10 @@ var DEBUG = false
2021
func getSettings() *passwordSettings {
2122
if settings == nil {
2223
data := core.GetSettingsContents()
24+
2325
s := passwordSettings{}
26+
s.AllowReadByDefault = false
27+
2428
yaml.Unmarshal(*data, &s)
2529
settings = &s
2630
}
@@ -31,13 +35,13 @@ func getSettings() *passwordSettings {
3135
func (ma passwordAuthenticator) GetPermissions(authorization string) auth.Permissions {
3236
d := auth.Permissions{}
3337

38+
s := getSettings()
3439
if authorization == "" {
3540
if DEBUG {
3641
log.Printf("No password provided")
3742
}
3843
} else {
3944
match := false
40-
s := getSettings()
4145
// map is password -> list of channels
4246
for k, v := range s.Passwords {
4347
if k == authorization {
@@ -58,12 +62,13 @@ func (ma passwordAuthenticator) GetPermissions(authorization string) auth.Permis
5862
}
5963
}
6064

61-
// Everyone has READ to all for now
62-
if _, ok := d["*"]; !ok {
63-
d["*"] = &auth.Permission{true, false}
65+
// The default permissions from config
66+
if s.AllowReadByDefault {
67+
if _, ok := d["*"]; !ok {
68+
d["*"] = &auth.Permission{true, false}
69+
}
6470
}
6571

66-
6772
return d
6873
}
6974

settings.example.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ passwords:
1515
- channels.*
1616
- Password2:
1717
- "*"
18+
allow_read_by_default: true
1819
jwt_signing_algorithms:
1920
- HS256
2021
jwt_verification_key: secret

0 commit comments

Comments
 (0)