Skip to content

Commit

Permalink
fix: auth callback timeout was incorrectly set to session expiration.…
Browse files Browse the repository at this point in the history
… Now is 10 minutes.
  • Loading branch information
clambin committed Sep 1, 2024
1 parent 547d522 commit 1c01b0b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- perf
- refactor

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches-ignore:
- main
- perf
- refactor

jobs:
test:
Expand Down
5 changes: 2 additions & 3 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"golang.org/x/sync/errgroup"
"log/slog"
"net/http"
"time"
)

func Run(ctx context.Context, cfg configuration.Configuration, registry prometheus.Registerer, version string, logger *slog.Logger) error {
Expand All @@ -23,7 +22,7 @@ func Run(ctx context.Context, cfg configuration.Configuration, registry promethe

metrics := server.NewMetrics("traefik_simple_auth", "", prometheus.Labels{"provider": cfg.Provider})
registry.MustRegister(metrics)
sessionStore := sessions.New(cfg.SessionCookieName, cfg.Secret, cfg.TTL)
sessionStore := sessions.New(cfg.SessionCookieName, cfg.Secret, cfg.SessionExpiration)
stateStore := makeStateStore(cfg.CacheConfiguration)
s := server.New(ctx, sessionStore, stateStore, cfg, metrics, logger)

Expand Down Expand Up @@ -77,6 +76,6 @@ func makeStateStore(cfg configuration.CacheConfiguration) state.States {
return state.States{
Cache: backend,
Namespace: "github.com/clambin/traefik-simple-auth",
TTL: 5 * time.Minute,
TTL: cfg.TTL,
}
}
6 changes: 4 additions & 2 deletions internal/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
addr = flag.String("addr", ":8080", "The address to listen on for HTTP requests")
promAddr = flag.String("prom", ":9090", "The address to listen on for Prometheus scrape requests")
sessionCookieName = flag.String("session-cookie-name", "_traefik_simple_auth", "The cookie name to use for authentication")
expiry = flag.Duration("expiry", 30*24*time.Hour, "How long a session remains valid")
sessionExpiration = flag.Duration("expiry", 30*24*time.Hour, "How long a session remains valid")
authPrefix = flag.String("auth-prefix", "auth", "prefix to construct the authRedirect URL from the domain")
domainsString = flag.String("domains", "", "Comma-separated list of domains to allow access")
users = flag.String("users", "", "Comma-separated list of usernames to allow access")
Expand Down Expand Up @@ -46,6 +46,7 @@ type Configuration struct {
ClientID string
ClientSecret string
AuthPrefix string
SessionExpiration time.Duration
CacheConfiguration
}

Expand Down Expand Up @@ -79,9 +80,10 @@ func GetConfiguration() (Configuration, error) {
ClientID: *clientId,
ClientSecret: *clientSecret,
AuthPrefix: *authPrefix,
SessionExpiration: *sessionExpiration,
CacheConfiguration: CacheConfiguration{
Backend: *cacheBackend,
TTL: *expiry,
TTL: 10 * time.Minute,
MemcachedConfiguration: MemcachedConfiguration{
Addr: *cacheMemcachedAddr,
},
Expand Down
3 changes: 2 additions & 1 deletion internal/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ func TestGetConfiguration(t *testing.T) {
Addr: ":8080",
PromAddr: ":9090",
SessionCookieName: "_traefik_simple_auth",
SessionExpiration: 30 * 24 * time.Hour,
CacheConfiguration: CacheConfiguration{
Backend: "memory",
TTL: 30 * 24 * time.Hour,
TTL: 10 * time.Minute,
},
Secret: []byte("secret\n"),
Provider: "google",
Expand Down

0 comments on commit 1c01b0b

Please # to comment.