mirror of
https://github.com/hanzoai/gateway.git
synced 2026-10-30 15:04:44 +00:00
THE LIVE ESCALATION, in the path that ships. `X-User-IsAdmin` is the fleet's PLATFORM-authority header — cloud gates its cross-tenant surfaces on it and the money gates read the bit-field beside it. This edge minted it from claims.IsAdmin, which is IAM's ORG-ROLE bit: an org owner carries it inside their own org. So every org owner reached the fleet as a platform admin. I reported this fixed earlier. It was not. I patched iamauth.InjectIdentity, which has ZERO non-test callers — the shipped KrakenD middleware and the ZAP relay each carried their own inline mint, and both still read the org bit. Two more statements of the same rule, and the one I fixed was the dead one. Fixed where they run: the HTTP edge (auth_middleware.go) now applies edge.Mint, and the relay (gate.go) sets f.IsAdmin — which forward re-emits as X-User-IsAdmin — from PlatformSudo. X-User-IsOrgAdmin is minted for the first time, so org-scoped self-service has its own header to read instead of borrowing platform authority. ONE DECISION. iamauth is DELETED (834 lines) along with the shim over it. What a claim means, which org a request acts in, who pays, which headers get minted — all of it is hanzoai/authz and hanzoai/authz/edge now, and net/http's own header type satisfies edge.Headers, so applying it here is a loop rather than a second implementation. What is left is the part genuinely this deployment's: package token holds the issuer and the AUDIENCE ALLOWLIST (authz.Verify deliberately does not check `aud`, because IAM sets it to the requesting CLIENT), and identity.go holds the money bit vocabulary and the vendor-prefix strip. ONE JWT LIBRARY on the identity path. Verification is golang-jwt/v5, the library IAM SIGNS with, through authz.Verify + the edge's JWKS reader. go-jose is gone from it, and the tests now mint with the same library they verify with — a test signing with a different one is testing a signer the estate does not run. It also makes `kid` mandatory, matching IAM (signClaims always stamps it). THREE HEADERS DROPPED, because IAM never emitted the claims behind them: `roles`, `permissions` and `phone` are absent from the signed claim set and from claims_supported, so the three-shape parsers for the first two read a claim that never arrived, and X-Roles / X-Phone-Number were always empty. All three names STAY in the strip set, so a forged copy still never survives. Removing the permissions parser also closes a latent grant: a token carrying that claim used to be handed the bits it named. The vendor-prefix backstop (X-IAM-*, X-HANZO-*) stays here rather than in the estate's edge, because sweeping prefixes must ENUMERATE header names — which is transport-specific, while edge.Headers is deliberately Get/Set/Del. It is folded into one stripClaimed call with the exact-name strip, because two calls would be an ordering trap that fails silently. Falsified both ways: restoring `if cl.IsAdmin` in edge.Mint turns TestOrgOwnerIsNotAPlatformAdmin and TestAdminOrgMachineGetsNeitherAdminHeader red; granting the admin bit from the org role turns TestOrgAdminNeverMintsPlatformAuthority and TestPermissions_OrgAdminGetsNoAdminBit red. Green on both build tags, including the `legacy` tag production ships. tests/ stays red on the KrakenD fixture suite — verified identical on a stashed tree, so it is not from this change. Co-authored-by: Hanzo Dev <[email protected]>
79 lines
2.6 KiB
Go
79 lines
2.6 KiB
Go
package gin
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/hanzoai/gateway/v2/internal/lura/config"
|
|
"github.com/hanzoai/gateway/v2/internal/lura/logging"
|
|
krakendcors "github.com/hanzoai/gateway/v2/internal/plugin/cors"
|
|
"github.com/hanzoai/gateway/v2/internal/plugin/cors/mux"
|
|
"github.com/rs/cors"
|
|
wrapper "github.com/rs/cors/wrapper/gin"
|
|
)
|
|
|
|
// New returns a gin.HandlerFunc with the CORS configuration provided in the ExtraConfig
|
|
func New(e config.ExtraConfig) gin.HandlerFunc {
|
|
tmp := krakendcors.ConfigGetter(e)
|
|
if tmp == nil {
|
|
return nil
|
|
}
|
|
cfg, ok := tmp.(krakendcors.Config)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
if len(cfg.AllowOrigins) == 0 {
|
|
cfg.AllowOrigins = []string{"*"}
|
|
}
|
|
if len(cfg.AllowHeaders) == 0 {
|
|
cfg.AllowHeaders = []string{"*"}
|
|
}
|
|
// Maintain the old default value to not change behaviour
|
|
// the rs/cors new default is to return a 204
|
|
if cfg.OptionsSuccessStatus == 0 {
|
|
cfg.OptionsSuccessStatus = 200
|
|
}
|
|
|
|
return wrapper.New(cors.Options{
|
|
AllowedOrigins: cfg.AllowOrigins,
|
|
AllowedMethods: cfg.AllowMethods,
|
|
AllowedHeaders: cfg.AllowHeaders,
|
|
ExposedHeaders: cfg.ExposeHeaders,
|
|
AllowCredentials: cfg.AllowCredentials,
|
|
AllowPrivateNetwork: cfg.AllowPrivateNetwork,
|
|
OptionsPassthrough: cfg.OptionsPassthrough,
|
|
OptionsSuccessStatus: cfg.OptionsSuccessStatus,
|
|
MaxAge: int(cfg.MaxAge.Seconds()),
|
|
Debug: cfg.Debug,
|
|
})
|
|
}
|
|
|
|
// RunServer defines the interface of a function used by the KrakenD router to start the service
|
|
type RunServer func(context.Context, config.ServiceConfig, http.Handler) error
|
|
|
|
// NewRunServer returns a RunServer wrapping the injected one with a CORS middleware, so it is called before the
|
|
// actual router checks the URL, method and other details related to selecting the proper handler for the
|
|
// incoming request
|
|
func NewRunServer(next RunServer) RunServer {
|
|
return NewRunServerWithLogger(next, nil)
|
|
}
|
|
|
|
// NewRunServerWithLogger returns a RunServer wrapping the injected one with a CORS middleware, so it is called before the
|
|
// actual router checks the URL, method and other details related to selecting the proper handler for the
|
|
// incoming request
|
|
func NewRunServerWithLogger(next RunServer, l logging.Logger) RunServer {
|
|
if l == nil {
|
|
l = logging.NoOp
|
|
}
|
|
return func(ctx context.Context, cfg config.ServiceConfig, handler http.Handler) error {
|
|
corsMw := mux.NewWithLogger(cfg.ExtraConfig, l)
|
|
if corsMw == nil {
|
|
return next(ctx, cfg, handler)
|
|
}
|
|
l.Debug("[SERVICE: Gin][CORS] Enabled CORS for all requests")
|
|
return next(ctx, cfg, corsMw.Handler(handler))
|
|
}
|
|
}
|