Skip to content

Commit

Permalink
Merge branch 'k3a-extra' of github.com:k3a/traefik-forward-auth into …
Browse files Browse the repository at this point in the history
…v3.0.0
  • Loading branch information
jr0d committed May 24, 2020
2 parents e0a1ddf + 78e279f commit 7e8ab37
Show file tree
Hide file tree
Showing 18 changed files with 924 additions and 553 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This is a partial rewrite to support generic OIDC Providers that provide [OpenID

[`noelcatt/traefik-forward-auth`](https://github.com/noelcatt/traefik-forward-auth) and [`funkypenguin/traefik-forward-auth`](https://github.com/funkypenguin/traefik-forward-auth) also made [`thomseddon/traefik-forward-auth`](https://github.com/thomseddon/traefik-forward-auth) apply to generic OIDC, but they are now based on an older version which does not support rules and also require the UserInfo endpoint to be supported.

This version optionally implements RBAC within Kuberbetes by using `ClusterRole` and `ClusterRoleBinding`. It extends from the original Kubernetes usage as it also allows specifying full URLs (including a scheme and domain) within `nonResourceURLs` attribute of `ClusterRole`. And unlike the original behavior, `*` wildcard character matches within one path component only. There is a special globstar `**` to match within multiple paths (inspired by Bash, Python and JS libraries).

The raw id-token received from OIDC provider can optionally be passed upstream via a custom header.

## Differences to the original

The instructions for [`thomseddon/traefik-forward-auth`](https://github.com/thomseddon/traefik-forward-auth) are useful, keeping in mind that this version:
Expand All @@ -19,3 +23,10 @@ The instructions for [`thomseddon/traefik-forward-auth`](https://github.com/thom
- Returns 401 rather than redirect to OIDC Login if an unauthenticated request is not for HTML (e.g. AJAX calls, images).
- Sends a username cookie as well
- If `auth-host` is set and `cookie-domains` is not set, traefik-forward-auth will redirect any requests using other hostnames to `auth-host`. Set `auth-host` to the OIDC redirect host to ensure that use of the IP or other DNS names will be redirected and get a suitable cookie.

## Upgrading from 2.x version to 3.0 (Breaking Changes):

- config `session-key` (`SESSION_KEY` env) is now called `encryption-key` (`ENCRYPTION_KEY` env) and is `REQUIRED`
- config `groups-session-name` (`GROUPS_SESSION_NAME`) is deprecated as both email and groups are part of the single cookie `cookie-name` (`COOKIE_NAME` env)
- character `*` in existing RBAC rules now works within one path component only, so a single `*` has to be replaced with `**` to match the previous behavior (whether to use `*` or `**` is up to the person writing those rules)

28 changes: 13 additions & 15 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"fmt"
"net/http"
"time"
"os"

"github.com/gorilla/sessions"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

Expand All @@ -15,7 +15,11 @@ import (
// Main
func main() {
// Parse options
config := internal.NewGlobalConfig()
config, err := internal.NewConfig(nil)
if err != nil {
fmt.Printf("%+v\n", err)
os.Exit(1)
}

// Setup logger
log := logger.NewDefaultLogger(config.LogLevel, config.LogFormat)
Expand All @@ -24,7 +28,9 @@ func main() {
config.Validate()

// Query the OIDC provider
config.SetOidcProvider()
if err := config.LoadOIDCProviderConfiguration(); err != nil {
log.Fatalln(err.Error())
}

// Get clientset for Authorizers
var clientset kubernetes.Interface
Expand All @@ -37,24 +43,16 @@ func main() {
if err != nil {
log.Fatalf("error getting kubernetes client: %v", err)
}
} else {
clientset = nil
}

// Prepare cookie session store (first key is for auth, the second one for encryption)
cookieStore := sessions.NewCookieStore(config.Secret, []byte(config.SessionKey))
cookieStore.Options.MaxAge = int(config.Lifetime / time.Second)
cookieStore.Options.HttpOnly = true
cookieStore.Options.Secure = !config.InsecureCookie

// Build server
server := internal.NewServer(cookieStore, clientset)
server := internal.NewServer(config, clientset)

// Attach router to default server
http.HandleFunc("/", server.RootHandler)

// Start
log.Debugf("Starting with options: %s", config)
log.Info("Listening on :4181")
log.Debugf("starting with options: %s", config)
log.Info("listening on :4181")
log.Info(http.ListenAndServe(":4181", nil))
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/gogo/protobuf v1.3.1 // indirect
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/sessions v1.2.0
github.com/gorilla/securecookie v1.1.1
github.com/gravitational/trace v0.0.0-20190409171327-f30095ced5ff // indirect
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/json-iterator/go v1.1.8 // indirect
Expand All @@ -38,7 +38,6 @@ require (
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
gopkg.in/square/go-jose.v2 v2.3.1 // indirect
gopkg.in/yaml.v2 v2.2.4
gotest.tools v2.2.0+incompatible
k8s.io/api v0.17.0
k8s.io/apimachinery v0.17.0
k8s.io/client-go v11.0.0+incompatible
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gravitational/trace v0.0.0-20190409171327-f30095ced5ff h1:xL/fJdlTJL6R/6Qk2tPu3EP1NsXgap9hXLvxKH0Ytko=
github.com/gravitational/trace v0.0.0-20190409171327-f30095ced5ff/go.mod h1:RvdOUHE4SHqR3oXlFFKnGzms8a5dugHygGw1bqDstYI=
github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
Expand Down Expand Up @@ -251,8 +249,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20191219150132-17cfeff5d095 h1:FrhAejQ5P6ZoV9nl5X9sqSNYd13yKAHEDP0fBnklKFw=
Expand Down
Loading

0 comments on commit 7e8ab37

Please sign in to comment.