git.iko.soy/typeable/oauth2-proxy
on master help sign in
Move AuthOnly authorize logic to a dedicated method
commit025056cba0a74f32db7148ad0f8fbd27bfb386e1 authorNick Meves <nick.meves@greenhouse.io> dateThu 19 Nov 2020, 20:27 (6 years ago) parent44d83e5
2 files changed+20−8
CHANGELOG.md+2−2 oauthproxy.go+18−6
CHANGELOG.md+2−2
@@ -54,13 +54,13 @@
5454- [#938](https://github.com/oauth2-proxy/oauth2-proxy/pull/938) Cleanup missed provider renaming refactor methods (@NickMeves)
5555- [#816](https://github.com/oauth2-proxy/oauth2-proxy/pull/816) (via [#936](https://github.com/oauth2-proxy/oauth2-proxy/pull/936)) Support non-list group claims (@loafoe)
5656- [#936](https://github.com/oauth2-proxy/oauth2-proxy/pull/936) Refactor OIDC Provider and support groups from Profile URL (@NickMeves)
57+- [#869](https://github.com/oauth2-proxy/oauth2-proxy/pull/869) Streamline provider interface method names and signatures (@NickMeves)
58+- [#849](https://github.com/oauth2-proxy/oauth2-proxy/pull/849) Support group authorization on `oauth2/auth` endpoint via `allowed_group` & `allowed_groups` querystring parameters (@NickMeves)
5759- [#925](https://github.com/oauth2-proxy/oauth2-proxy/pull/925) Fix basic auth legacy header conversion (@JoelSpeed)
5860- [#916](https://github.com/oauth2-proxy/oauth2-proxy/pull/916) Add AlphaOptions struct to prepare for alpha config loading (@JoelSpeed)
5961- [#923](https://github.com/oauth2-proxy/oauth2-proxy/pull/923) Support TLS 1.3 (@aajisaka)
6062- [#918](https://github.com/oauth2-proxy/oauth2-proxy/pull/918) Fix log header output (@JoelSpeed)
6163- [#911](https://github.com/oauth2-proxy/oauth2-proxy/pull/911) Validate provider type on startup.
62−- [#869](https://github.com/oauth2-proxy/oauth2-proxy/pull/869) Streamline provider interface method names and signatures (@NickMeves)
63−- [#849](https://github.com/oauth2-proxy/oauth2-proxy/pull/849) Support group authorization on `oauth2/auth` endpoint via `allowed_group` & `allowed_groups` querystring parameters (@NickMeves)
6464- [#906](https://github.com/oauth2-proxy/oauth2-proxy/pull/906) Set up v6.1.x versioned documentation as default documentation (@JoelSpeed)
6565- [#905](https://github.com/oauth2-proxy/oauth2-proxy/pull/905) Remove v5 legacy sessions support (@NickMeves)
6666- [#904](https://github.com/oauth2-proxy/oauth2-proxy/pull/904) Set `skip-auth-strip-headers` to `true` by default (@NickMeves)
oauthproxy.go+18−6
@@ -926,7 +926,7 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
926926}
927927
928928// AuthOnly checks whether the user is currently logged in (both authentication
929−// and optional authorization via `allowed_groups` querystring).
929+// and optional authorization).
930930func (p *OAuthProxy) AuthOnly(rw http.ResponseWriter, req *http.Request) {
931931 session, err := p.getAuthenticatedSession(rw, req)
932932 if err != nil {
@@ -934,9 +934,9 @@ func (p *OAuthProxy) AuthOnly(rw http.ResponseWriter, req *http.Request) {
934934 return
935935 }
936936
937− // Allow secondary group restrictions based on the `allowed_group` or
938− // `allowed_groups` querystring parameter
939− if !checkAllowedGroups(req, session) {
937+ // Unauthorized cases need to return 403 to prevent infinite redirects with
938+ // subrequest architectures
939+ if !authOnlyAuthorize(req, session) {
940940 http.Error(rw, http.StatusText(http.StatusForbidden), http.StatusForbidden)
941941 return
942942 }
@@ -1024,13 +1024,25 @@ func (p *OAuthProxy) getAuthenticatedSession(rw http.ResponseWriter, req *http.R
10241024 return session, nil
10251025}
10261026
1027−func checkAllowedGroups(req *http.Request, session *sessionsapi.SessionState) bool {
1027+// authOnlyAuthorize handles special authorization logic that is only done
1028+// on the AuthOnly endpoint for use with Nginx subrequest architectures.
1029+func authOnlyAuthorize(req *http.Request, s *sessionsapi.SessionState) bool {
1030+ // Allow secondary group restrictions based on the `allowed_group` or
1031+ // `allowed_groups` querystring parameter
1032+ if !checkAllowedGroups(req, s) {
1033+ return false
1034+ }
1035+
1036+ return true
1037+}
1038+
1039+func checkAllowedGroups(req *http.Request, s *sessionsapi.SessionState) bool {
10281040 allowedGroups := extractAllowedGroups(req)
10291041 if len(allowedGroups) == 0 {
10301042 return true
10311043 }
10321044
1033− for _, group := range session.Groups {
1045+ for _, group := range s.Groups {
10341046 if _, ok := allowedGroups[group]; ok {
10351047 return true
10361048 }