Skip to content

feat/OIDC auth - #93

Open
matthiasbaldi wants to merge 3 commits into
cloudlena:mainfrom
fidentity:feat/oidc-auth
Open

matthiasbaldi wants to merge 3 commits into
cloudlena:mainfrom
fidentity:feat/oidc-auth

Conversation

@matthiasbaldi

Copy link
Copy Markdown
Contributor

This Pullrequest enables the s3Manager to get protected directly with its own security layer via OIDC.
Maybe it would be further expandable as the issue #3 asks for. Currently for our usecase for SSO.

In this PR are includes one feature and one change - I could split if you wish:

  • feat: OIDC login and all required settings for a successful OIDC integration
  • change: Allow to give the BUCKET_NAME a list instead only a single bucket name, this would allow to filter a list of buckets afterwards instead to show many "unauthorized" buckets which you could list but not access.

@cloudlena cloudlena left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the big PR, @matthiasbaldi! I left some comments.

Comment thread main.go Outdated
viper.SetDefault("PORT", "8080")
viper.SetDefault("TIMEOUT", 600)
viper.SetDefault("AUTH_PROVIDER", auth.ProviderNone)
viper.SetDefault("AUTH_ANONYMOUS_ROLE", "viewer")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default should be "writer". Both the README ("defaults to writer, which is the historical behaviour") and the doc comment on Config.AnonymousRole ("It is RoleWriter by default … exactly as before authentication existed") say so.

As written, an existing install upgrading with no auth env vars set and the default ALLOW_DELETE=true gets RoleViewer on every request: effectiveOptions clears AllowDelete so the delete UI disappears, and auth.RequireRole(auth.RoleWriter) returns 403 for create-bucket, upload/create-object, bulk-delete, delete-object, delete-bucket and put-policy. The app silently becomes read-only with no configuration change.


// Authenticate grants every request the same identity.
func (a *anonymous) Authenticate(_ http.ResponseWriter, _ *http.Request) (*Identity, bool) {
return a.identity, true

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AUTH_ANONYMOUS_ROLE=none doesn't actually deny access. This always returns (identity, true), and no read route carries a RequireRole(RoleViewer) guard — only the mutating routes are guarded.

So an operator who sets AUTH_ANONYMOUS_ROLE=none to lock the app down (reasonable, given RoleNone is documented as "no access at all" and OIDC_DEFAULT_ROLE=none "denies access") still gets a fully browsable, fully downloadable app — only writes are blocked. Either reject none for the anonymous provider at start-up, or guard the read routes with RequireRole(RoleViewer).

func effectiveOptions(ctx context.Context, opts Options) Options {
isWriter := auth.RoleFrom(ctx) >= auth.RoleWriter

opts.AllowDelete = opts.AllowDelete && isWriter

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only AllowDelete is narrowed here, but the templates render the other write affordances unconditionally: "Upload files" (bucket.html.tmpl:368), "Upload folder" (374), "Create folder" (381) and the bucket-policy save, plus "Create bucket" (buckets.html.tmpl:55, 65).

A RoleViewer user therefore sees all of them, and each click hits a writer(...)-guarded route and pops a 403 toast. The design note added to CLAUDE.md says every capability is ANDed with the role, but only this one is — a CanWrite/AllowCreate flag threaded into both page data structs and the templates is still missing.

Comment thread internal/app/s3manager/auth/session.go Outdated
}

return &sessionStore{
store: sessions.NewCookieStore(key, key),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SESSION_MAX_AGE is never enforced server side. sessions.NewCookieStore sets each securecookie codec's max age to 86400*30 (30 days), and the code only ever assigns session.Options — store.MaxAge(...) is never called.

So the MaxAge in cookieOptions is just a browser cookie attribute: a session cookie lifted out of a browser (or replayed by a tool that ignores cookie expiry) is still accepted for 30 days even with the 8 h default, and a SESSION_MAX_AGE above 30 days silently stops working at day 30. Same applies to the 10-minute loginMaxAge on the login-state cookie.

Comment thread internal/app/s3manager/auth/session.go Outdated
keySubject: identity.Subject,
keyName: identity.Name,
keyEmail: identity.Email,
keyGroups: identity.Groups,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest dropping keyGroups. Identity.Groups is never read after login — only a.role(...) uses it, at callback time, before the session is saved.

Meanwhile securecookie's maxLength is 4096, so a user in a large directory (a few hundred AD/Keycloak groups) makes session.Save return errEncodedValueTooLong; saveIdentity propagates it and handleCallback answers 500 "Login failed: error opening session". Removing the claim removes the failure mode at no cost.

Comment thread internal/app/s3manager/auth/oidc.go Outdated
func (a *oidcAuthenticator) RegisterRoutes(router *mux.Router) {
router.HandleFunc(LoginPath, a.handleLogin).Methods(http.MethodGet)
router.HandleFunc(CallbackPath, a.handleCallback).Methods(http.MethodGet)
router.HandleFunc(LogoutPath, a.handleLogout).Methods(http.MethodGet, http.MethodPost)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logout accepts GET and is rendered as a plain <a href> (layout.html.tmpl:171), which makes it CSRF-able: any third-party page — or a link prefetcher / corporate link scanner — can log the user out with <img src="https://s3manager.example.com/auth/logout">.

Restricting handleLogout to POST and making the template a small form closes it.

@cloudlena
cloudlena force-pushed the main branch 2 times, most recently from 17fe30b to f0627ba Compare September 24, 2026 17:15
matthiasbaldi and others added 3 commits October 21, 2026 17:23
Adds an optional authentication layer in front of the web app,
independent of the S3 credentials used against the storage backend:

- internal/app/s3manager/auth: Authenticator extension point, with
  NewAnonymous (AUTH_PROVIDER=none, default) and an OIDC implementation
  using coreos/go-oidc and x/oauth2 (authorization code flow + PKCE +
  nonce). The resulting Identity lives in an encrypted, HttpOnly,
  SameSite=Lax session cookie so the app stays stateless.
- permissions.go: effectiveOptions ANDs each capability with the
  caller's role and never assigns from it, so a role can only narrow
  the deployer's configured Options, never grant beyond them. Routes a
  deployment disables (e.g. ALLOW_DELETE=false) are not registered at
  all, regardless of any role.
- main.go / layout.html.tmpl: wires the middleware and login/logout
  routes, and adds a user chip plus logout link next to the existing
  instance switcher.

Also extends BUCKET_NAME to accept a comma-separated list of buckets,
in addition to a single name, for deployments that need to expose more
than one bucket through the same instance. This stays a display filter
only, as it already was upstream.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
A leading backslash such as /\evil.example is not caught by the
existing // check, but some browsers normalize it to a protocol
relative URL and follow it off-site.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- Default AUTH_ANONYMOUS_ROLE to writer so upgrades keep full access
- Refuse AUTH_ANONYMOUS_ROLE=none at start-up and require at least the
  viewer role on every app route
- Hide create, upload and policy-save actions from viewers
- Enforce SESSION_MAX_AGE and the login-state max age server side
- Keep groups out of the session cookie
- Accept logout only via POST and render it as a form

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants