@@ -75,10 +75,11 @@ type AuthService struct {
7575 runtime model.RuntimeConfig
7676 context context.Context
7777
78- ldap * LdapService
79- queries repository.Store
80- oauthBroker * OAuthBrokerService
81- tailscale * TailscaleService
78+ ldap * LdapService
79+ queries repository.Store
80+ oauthBroker * OAuthBrokerService
81+ tailscale * TailscaleService
82+ policyEngine * PolicyEngine
8283
8384 loginAttempts map [string ]* LoginAttempt
8485 ldapGroupsCache map [string ]* LdapGroupsCache
@@ -101,6 +102,7 @@ func NewAuthService(
101102 queries repository.Store ,
102103 oauthBroker * OAuthBrokerService ,
103104 tailscale * TailscaleService ,
105+ policy * PolicyEngine ,
104106) * AuthService {
105107 service := & AuthService {
106108 log : log ,
@@ -114,6 +116,7 @@ func NewAuthService(
114116 queries : queries ,
115117 oauthBroker : oauthBroker ,
116118 tailscale : tailscale ,
119+ policyEngine : policy ,
117120 }
118121
119122 wg .Go (service .CleanupOAuthSessionsRoutine )
@@ -285,18 +288,27 @@ func (auth *AuthService) RecordLoginAttempt(identifier string, success bool) {
285288 }
286289}
287290
291+ // We could also directly access the policyEngine.effectToAccess but
292+ // I believe it's better to use the exported functions instead
288293func (auth * AuthService ) IsEmailWhitelisted (provider string , email string ) bool {
289- whitelist := auth .runtime .OAuthWhitelist
290- if providerConfig , ok := auth .runtime .OAuthProviders [provider ]; ok && len (providerConfig .Whitelist ) > 0 {
291- whitelist = providerConfig .Whitelist
292- }
293-
294- match , err := utils .CheckFilter (strings .Join (whitelist , "," ), email )
295- if err != nil {
296- auth .log .App .Warn ().Err (err ).Str ("provider" , provider ).Str ("email" , email ).Msg ("Invalid email filter pattern" )
297- return false
298- }
299- return match
294+ return auth .policyEngine .EvaluateFunc (func () Effect {
295+ whitelist := auth .runtime .OAuthWhitelist
296+ if providerConfig , ok := auth .runtime .OAuthProviders [provider ]; ok && len (providerConfig .Whitelist ) > 0 {
297+ whitelist = providerConfig .Whitelist
298+ }
299+ match , err := utils .CheckFilter (strings .Join (whitelist , "," ), email )
300+ if err != nil {
301+ if err == utils .ErrFilterEmpty {
302+ return EffectAbstain
303+ }
304+ auth .log .App .Error ().Err (err ).Str ("email" , email ).Msg ("Failed to evaluate email whitelist filter, defaulting to deny" )
305+ return EffectDeny
306+ }
307+ if match {
308+ return EffectAllow
309+ }
310+ return EffectDeny
311+ })
300312}
301313
302314func (auth * AuthService ) CreateSession (ctx context.Context , data repository.Session ) (* http.Cookie , error ) {
0 commit comments