Skip to content

Commit

Permalink
feat: default policy 2fa
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyu committed Mar 12, 2024
1 parent 46db207 commit b031bcd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion internal/authorization/ts_app_authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,39 @@ func (t *TsAuthorizer) getAppRules(position int, app *application.Application,
}
}

// hardcode vault /server policy
if app.Spec.Name == "vault" {
if policy, ok := policies["vault"]; !ok {
policies["vault"] = &application.ApplicationSettingsPolicy{
DefaultPolicy: userAuth.appDefaultPolicy.String(),
SubPolicies: []*application.ApplicationSettingsSubPolicy{
{
URI: "/server/*",
Policy: OneFactor.String(),
},
},
OneTime: false,
Duration: -1,
}
} else {
found := false
for _, sp := range policy.SubPolicies {
if sp.URI == "/server/*" {
sp.Policy = OneFactor.String()
found = true
}
}

if !found {
policy.SubPolicies = append(policy.SubPolicies, &application.ApplicationSettingsSubPolicy{
URI: "/server/*",
Policy: OneFactor.String(),
})
}
}

} // end if vault

customDomainData, customDomainExists := app.Spec.Settings[application.ApplicationSettingsCustomDomainKey]
customDomain := make(map[string]*application.ApplicationCustomDomain)
if customDomainExists {
Expand Down Expand Up @@ -540,7 +573,7 @@ func (t *TsAuthorizer) newUserAuthorizer(user string) *userAuthorizer {
return &userAuthorizer{
defaultPolicy: Denied,
desktopPolicy: TwoFactor,
appDefaultPolicy: OneFactor,
appDefaultPolicy: TwoFactor,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func upsertResourceAuthLevelInSession(ctx *middlewares.AutheliaCtx, parsedURI *u
}

if rule == nil {
ctx.Logger.Debugf("Get match rule froom session for the URL %s", parsedURI.String())
ctx.Logger.Debugf("Get match rule from session for the URL %s", parsedURI.String())

session.ResourceAuthenticationLevels = append(session.ResourceAuthenticationLevels,
&sess.ResourceAuthenticationLevel{
Expand Down

0 comments on commit b031bcd

Please sign in to comment.