Skip to content

Commit b9abab2

Browse files
committed
fix: review comments
1 parent 3fd5627 commit b9abab2

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎internal/model/config.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewDefaultConfiguration() *Config {
2424
SessionMaxLifetime: 0, // disabled
2525
LoginTimeout: 300, // 5 minutes
2626
LoginMaxRetries: 3,
27-
ACLS: ACLSConfig{
27+
ACLs: ACLsConfig{
2828
Policy: "allow",
2929
},
3030
},
@@ -117,7 +117,7 @@ type AuthConfig struct {
117117
LoginTimeout int `description:"Login timeout in seconds." yaml:"loginTimeout"`
118118
LoginMaxRetries int `description:"Maximum login retries." yaml:"loginMaxRetries"`
119119
TrustedProxies []string `description:"Comma-separated list of trusted proxy addresses." yaml:"trustedProxies"`
120-
ACLS ACLSConfig `description:"ACLs configuration." yaml:"acls"`
120+
ACLs ACLsConfig `description:"ACLs configuration." yaml:"acls"`
121121
}
122122

123123
type UserAttributes struct {
@@ -227,8 +227,8 @@ type OIDCClientConfig struct {
227227
Name string `description:"Client name in UI." yaml:"name"`
228228
}
229229

230-
type ACLSConfig struct {
231-
Policy string `description:"ACL policy for allow-by-default or deny-by-defaut, available options are allow and deny default is allow." yaml:"policy"`
230+
type ACLsConfig struct {
231+
Policy string `description:"ACL policy for allow-by-default or deny-by-default, available options are allow and deny, default is allow." yaml:"policy"`
232232
}
233233

234234
// ACLs

‎internal/service/access_controls_service.go‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ type AccessControlPolicy string
1313

1414
const (
1515
PolicyAllow AccessControlPolicy = "allow"
16-
PolicyBlock AccessControlPolicy = "block"
16+
PolicyDeny AccessControlPolicy = "deny"
1717
)
1818

1919
func accessControlPolicyFromString(s string) (AccessControlPolicy, bool) {
2020
switch strings.ToLower(s) {
2121
case "allow":
2222
return PolicyAllow, true
23-
case "block":
24-
return PolicyBlock, true
23+
case "deny":
24+
return PolicyDeny, true
2525
default:
26-
return "", false
26+
return PolicyAllow, false
2727
}
2828
}
2929

@@ -49,17 +49,16 @@ func NewAccessControlsService(
4949
labelProvider: labelProvider,
5050
}
5151

52-
policy, ok := accessControlPolicyFromString(config.Auth.ACLS.Policy)
52+
policy, ok := accessControlPolicyFromString(config.Auth.ACLs.Policy)
5353

5454
if !ok {
55-
log.App.Warn().Str("policy", config.Auth.ACLS.Policy).Msg("Invalid ACL policy in config, defaulting to 'allow'")
56-
service.policy = PolicyAllow
55+
log.App.Warn().Str("policy", config.Auth.ACLs.Policy).Msg("Invalid ACL policy in config, defaulting to 'allow'")
5756
}
5857

5958
if policy == PolicyAllow {
6059
log.App.Debug().Msg("Using 'allow' ACL policy: access to apps will be allowed by default unless explicitly blocked")
6160
} else {
62-
log.App.Debug().Msg("Using 'block' ACL policy: access to apps will be blocked by default unless explicitly allowed")
61+
log.App.Debug().Msg("Using 'deny' ACL policy: access to apps will be blocked by default unless explicitly allowed")
6362
}
6463

6564
service.policy = policy
@@ -121,7 +120,7 @@ func (service *AccessControlsService) IsUserAllowed(context model.UserContext, a
121120
}
122121

123122
service.log.App.Debug().Msg("Checking users allow list")
124-
return utils.CheckFilter(acls.Users.Allow, context.GetUsername())
123+
return service.policyResult(utils.CheckFilter(acls.Users.Allow, context.GetUsername()))
125124
}
126125

127126
func (service *AccessControlsService) IsInOAuthGroup(context model.UserContext, acls *model.App) bool {
@@ -211,8 +210,8 @@ func (service *AccessControlsService) IsIPAllowed(ip string, acls *model.App) bo
211210
}
212211

213212
// Merge the global and app IP filter
214-
blockedIps := append(service.config.Auth.IP.Block, acls.IP.Block...)
215-
allowedIPs := append(service.config.Auth.IP.Allow, acls.IP.Allow...)
213+
blockedIps := append(acls.IP.Block, service.config.Auth.IP.Block...)
214+
allowedIPs := append(acls.IP.Allow, service.config.Auth.IP.Allow...)
216215

217216
for _, blocked := range blockedIps {
218217
res, err := utils.FilterIP(blocked, ip)

‎internal/test/test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ func CreateTestConfigs(t *testing.T) (model.Config, model.RuntimeConfig) {
4040
SessionExpiry: 10,
4141
LoginTimeout: 10,
4242
LoginMaxRetries: 3,
43+
ACLs: model.ACLsConfig{
44+
Policy: "allow",
45+
},
4346
},
4447
Database: model.DatabaseConfig{
4548
Path: filepath.Join(tempDir, "test.db"),

0 commit comments

Comments
 (0)