Files
versitygw/iamapi/router.go
T
niksis02 658c37907d feat: add OIDC endpoint relaxations for private/isolated networks
Closes #2364

`AssumeRoleWithWebIdentity` only ever trusted an `OIDC` provider reachable over verified `https`, at a publicly routable address, on the implicit `:443`. That posture is right for an internet-facing IdP but rejects every address an internal one can have, so a `SPIFFE/SPIRE` OIDC discovery provider in the same cluster — or as a sidecar in the same pod — could never be registered, let alone verified against, and no setting could express "this private address is the IdP".

Two opt-in flags on `versitygw iam`, both off by default:

`--oidc-allow-private-endpoints`
Permit a provider `Url` resolving to a loopback/private/link-local address, and an explicit port. Transport is unchanged: still `https`, still fully verified (a self-signed in-cluster cert is trusted the way AWS documents, through `ThumbprintList`).

`--oidc-allow-insecure-transport`
Additionally permit plaintext `http` provider URLs, discovery/JWKS endpoints and redirects, and drop TLS verification (`thumbprint` pinning included) for `https` ones.

Both apply uniformly to the thumbprint auto-fetch at `CreateOpenIDConnectProvider` time and to the discovery-document plus `JWKS` fetch at `AssumeRoleWithWebIdentity` time. Neither weakens anything past the endpoint: signature verification, issuer matching, audience and trust policy evaluation are untouched, and the DNS-resolve-once/dial-the-resolved-IP shape stays in place so a rebind still cannot redirect a connection.

An `http` provider keeps its scheme in its stored `Url`, `ARN` and `iss` matching, rather than being stripped like an `https` one — otherwise `"http://host"` and `"https://host"` would collapse onto a single ARN and storage key and each could satisfy the other's trust policy. It also stores an empty `ThumbprintList` rather than failing: a plaintext provider presents no certificate to thumbprint.

Helm: `iamServer.oidc.{allowPrivateEndpoints,allowInsecureTransport}`, alongside `disableThumbprintAutofetch` moved into the same block (the flat `iamServer.disableOidcThumbprintAutofetch` stays honored). Chart `0.4.1 -> 0.4.2`.

The WebUI's create-provider form no longer rejects `http` URLs and ports client-side; it cannot see the service's settings, so those two rules are left to the server, whose error surfaces as a toast like any other.
2026-09-08 16:30:37 +04:00

177 lines
6.2 KiB
Go

// Copyright 2026 Versity Software
// This file is licensed under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package iamapi
import (
"net/http"
"github.com/gofiber/fiber/v3"
"github.com/versity/versitygw/iamapi/iamerr"
"github.com/versity/versitygw/iamapi/internal/iammiddleware"
"github.com/versity/versitygw/iamapi/internal/iamutil"
"github.com/versity/versitygw/iamapi/storage"
"github.com/versity/versitygw/internal/sigv4auth"
)
const (
iamAPIVersion = "2010-05-08"
stsAPIVersion = "2011-06-15"
noVersionSpecified = "NO_VERSION_SPECIFIED"
productURL = "https://www.versity.com/products/versitygw/"
actionAssumeRoleWithWebIdentity = "AssumeRoleWithWebIdentity"
)
// stsActions are routed through this same IAM endpoint but, being real STS
// actions, are versioned against stsAPIVersion rather than iamAPIVersion —
// and (see response.go's ProcessController) render under STS's own XML
// namespace rather than IAM's.
var stsActions = map[string]bool{
"AssumeRoleWithWebIdentity": true,
"GetCallerIdentity": true,
}
var unknownOperationBody = []byte("<UnknownOperationException/>\n")
type IAMApiRouter struct {
app *fiber.App
store storage.Storer
Ctrl IAMApiController
actions map[string]ActionHandler
rootCreds *RootCredentials
// oidc is threaded into the controller and the policy middleware, both
// of which validate caller-supplied OIDC provider URLs
oidc OIDCConfig
}
func (r *IAMApiRouter) Init() {
r.Ctrl = NewController(r.store, r.oidc)
r.actions = map[string]ActionHandler{
// User CRUD
"CreateUser": r.Ctrl.CreateUser,
"DeleteUser": r.Ctrl.DeleteUser,
"GetUser": r.Ctrl.GetUser,
"ListUsers": r.Ctrl.ListUsers,
"UpdateUser": r.Ctrl.UpdateUser,
// User Tagging
"TagUser": r.Ctrl.TagUser,
"UntagUser": r.Ctrl.UntagUser,
"ListUserTags": r.Ctrl.ListUserTags,
// User Access Key CRUD
"CreateAccessKey": r.Ctrl.CreateAccessKey,
"UpdateAccessKey": r.Ctrl.UpdateAccessKey,
"DeleteAccessKey": r.Ctrl.DeleteAccessKey,
"GetAccessKeyLastUsed": r.Ctrl.GetAccessKeyLastUsed,
"ListAccessKeys": r.Ctrl.ListAccessKeys,
// User Inline Policy CRUD
"PutUserPolicy": r.Ctrl.PutUserPolicy,
"GetUserPolicy": r.Ctrl.GetUserPolicy,
"DeleteUserPolicy": r.Ctrl.DeleteUserPolicy,
"ListUserPolicies": r.Ctrl.ListUserPolicies,
// Role CRUD
"CreateRole": r.Ctrl.CreateRole,
"GetRole": r.Ctrl.GetRole,
"ListRoles": r.Ctrl.ListRoles,
"DeleteRole": r.Ctrl.DeleteRole,
"UpdateAssumeRolePolicy": r.Ctrl.UpdateAssumeRolePolicy,
// Role Tagging
"TagRole": r.Ctrl.TagRole,
"UntagRole": r.Ctrl.UntagRole,
"ListRoleTags": r.Ctrl.ListRoleTags,
// Role Inline Policy CRUD
"PutRolePolicy": r.Ctrl.PutRolePolicy,
"GetRolePolicy": r.Ctrl.GetRolePolicy,
"DeleteRolePolicy": r.Ctrl.DeleteRolePolicy,
"ListRolePolicies": r.Ctrl.ListRolePolicies,
// OIDC Provider CRUD
"CreateOpenIDConnectProvider": r.Ctrl.CreateOpenIDConnectProvider,
"GetOpenIDConnectProvider": r.Ctrl.GetOpenIDConnectProvider,
"ListOpenIDConnectProviders": r.Ctrl.ListOpenIDConnectProviders,
"DeleteOpenIDConnectProvider": r.Ctrl.DeleteOpenIDConnectProvider,
"AddClientIDToOpenIDConnectProvider": r.Ctrl.AddClientIDToOpenIDConnectProvider,
"RemoveClientIDFromOpenIDConnectProvider": r.Ctrl.RemoveClientIDFromOpenIDConnectProvider,
"UpdateOpenIDConnectProviderThumbprint": r.Ctrl.UpdateOpenIDConnectProviderThumbprint,
// OIDC Provider Tagging
"TagOpenIDConnectProvider": r.Ctrl.TagOpenIDConnectProvider,
"UntagOpenIDConnectProvider": r.Ctrl.UntagOpenIDConnectProvider,
"ListOpenIDConnectProviderTags": r.Ctrl.ListOpenIDConnectProviderTags,
// STS actions (routed through this same endpoint; see stsActions)
"AssumeRoleWithWebIdentity": r.Ctrl.AssumeRoleWithWebIdentity,
"GetCallerIdentity": r.Ctrl.GetCallerIdentity,
}
iamRoute := ProcessHandlers(r.routeAction,
iammiddleware.VerifyIAMAuth(sigv4auth.ServiceIAM, r.rootCreds, r.store),
iammiddleware.VerifyIAMPolicy(r.store, r.oidc.endpointPolicy()),
)
stsAuthRoute := ProcessHandlers(r.routeAction,
iammiddleware.VerifyIAMAuth(sigv4auth.ServiceSTS, r.rootCreds, r.store),
)
stsOpenRoute := ProcessHandlers(r.routeAction)
dispatch := func(ctx fiber.Ctx) error {
action, _ := iamutil.RequestParam(ctx, "Action")
switch {
case action == actionAssumeRoleWithWebIdentity:
return stsOpenRoute(ctx)
case stsActions[action]:
return stsAuthRoute(ctx)
default:
return iamRoute(ctx)
}
}
r.app.Get("/*", iamutil.MatchQueryOrFormArgs("Action"), dispatch)
r.app.Post("/*", iamutil.MatchQueryOrFormArgs("Action"), dispatch)
r.app.All("/", r.redirectRoot)
r.app.All("*", r.unknownOperation)
}
func (r *IAMApiRouter) routeAction(ctx fiber.Ctx) (*Response, error) {
action, _ := iamutil.RequestParam(ctx, "Action")
version, versionSpecified := iamutil.RequestParam(ctx, "Version")
if !versionSpecified {
version = noVersionSpecified
}
expectedVersion := iamAPIVersion
if stsActions[action] {
expectedVersion = stsAPIVersion
}
if version != expectedVersion {
return &Response{}, iamerr.InvalidAction(action, version)
}
handler, ok := r.actions[action]
if !ok {
return &Response{}, iamerr.InvalidAction(action, version)
}
return handler(ctx)
}
func (r *IAMApiRouter) redirectRoot(ctx fiber.Ctx) error {
iammiddleware.EnsureRequestID(ctx)
ctx.Set(fiber.HeaderLocation, productURL)
ctx.Status(http.StatusFound)
return nil
}
func (r *IAMApiRouter) unknownOperation(ctx fiber.Ctx) error {
iammiddleware.EnsureRequestID(ctx)
return ctx.Status(http.StatusNotFound).Send(unknownOperationBody)
}