client

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package client is the shared "is this caller the platform superadmin" AdminAuthorizer implementation, used by org, identity, registry and the gateway's superadmin guard. One HTTP round trip (call authz's POST /internal/authz/effective-access/can with scope "global" and the platform-superadmin feature key/role, forward the caller's raw bearer verbatim, fail closed on anything but a well-formed 200 envelope) behind thin package-local adapters (AdminAuthorizer's method signature names each package's own AuthContext type, so Go structural typing can't share the interface itself across packages; the HTTP logic is what's shared).

Index

Constants

View Source
const (
	AdminFeatureKey   = "auth.platform_administration.access"
	AdminRequiredRole = "kiban-superadmin"
)

AdminFeatureKey / AdminRequiredRole — every admin guard in the platform asks authz the identical question.

View Source
const CompanyAdminRole = "admin"

CompanyAdminRole is the company-scope role an administrator of a company holds: the base model's `company:<id>#admin` relation, the same tuple the grants route calls the admin relation.

Variables

View Source
var ErrAuthorizationUnavailable = errors.New("authz client: authorization is unavailable")

ErrAuthorizationUnavailable is the fail-closed sentinel every caller of Can must treat as deny (never allow) — Can itself never returns a bare bool with a nil error meaning uncertainty; a non-nil error always means exactly this.

Functions

This section is empty.

Types

type AdminAuthorizer

type AdminAuthorizer struct {
	// contains filtered or unexported fields
}

AdminAuthorizer calls authz's effective-access/can endpoint to answer "does the bearer belong to the platform superadmin". It is deliberately NOT itself org.AdminAuthorizer or identity.AdminAuthorizer (those interfaces name package-local AuthContext types) — each package wraps this in a one-method adapter, see internal/org/adminauthz.go and internal/identity/adminauthz.go.

func New

func New(baseURL string, httpClient *http.Client) *AdminAuthorizer

New builds an AdminAuthorizer against authz's base URL (e.g. "http://authz:8140" in compose, "http://127.0.0.1:8140" for a host-run process). A nil httpClient gets a bounded-timeout default (same 5s every other internal client in this codebase uses).

func (*AdminAuthorizer) Can

func (a *AdminAuthorizer) Can(ctx context.Context, rawBearer, action string) (bool, error)

Can reports whether rawBearer belongs to the platform superadmin. Fail-closed: everything Decide fails on, plus any response that isn't an explicit ALLOWED envelope, returns (false, ErrAuthorizationUnavailable) — never a bare "false, nil" a caller could mistake for a confident deny.

func (*AdminAuthorizer) Decide

func (a *AdminAuthorizer) Decide(ctx context.Context, rawBearer, action, correlationID string) (Decision, error)

Decide asks authz's effective-access/can whether rawBearer (the inbound request's untouched "Authorization: Bearer ..." header value) belongs to the platform superadmin, per authz's live effective-access decision (decision.ScopeGlobal — subject lookup, Keycloak-enabled, lifecycle, then a platform-role match against AdminRequiredRole; see internal/authz/decision/evaluate.go). action is carried through only for the caller's own audit trail — it plays no role in the decision itself. correlationID, when non-empty, is forwarded in the body and as x-correlation-id.

Fail-closed: an empty bearer, any transport/decode failure, or any non-200 status returns ErrAuthorizationUnavailable (never a fabricated allow). Non-200 covers authz's own DEPENDENCY_UNAVAILABLE => 503 mapping (internal/authz/http.go's writeDecision) along with every other transport-level failure (401, 500, ...).

func (*AdminAuthorizer) DecideInCompany added in v0.1.1

func (a *AdminAuthorizer) DecideInCompany(ctx context.Context, rawBearer, action, companyID, correlationID string) (Decision, error)

DecideInCompany asks authz whether the bearer may perform action in companyID as the superadmin OR as an administrator of that company: one company-scope decision with the platform-operator exception on and RequiredCompanyRole = CompanyAdminRole. A superadmin passes without membership; anyone else must be an active member holding the admin relation.

func (*AdminAuthorizer) DecideMemberInCompany added in v0.1.1

func (a *AdminAuthorizer) DecideMemberInCompany(ctx context.Context, rawBearer, action, companyID, correlationID string) (Decision, error)

DecideMemberInCompany is DecideInCompany without the role: the superadmin, or any active, unblocked member of the company. The read guard for a company's own facts.

type Decision

type Decision struct {
	Allowed bool
	Reason  string
}

Decision is authz's own answer, exactly as decoded from a well-formed 200 envelope. Allowed is authoritative only together with Reason == "ALLOWED" (see Can); a false Allowed carries the decision's reason code so a caller that distinguishes a confirmed denial from uncertainty (the gateway's 403-vs-503) can inspect it.

func (Decision) Denied

func (d Decision) Denied() bool

Denied reports a CONFIRMED denial: authz answered, and the reason is one it produces for "this bearer is not the platform superadmin". A caller that distinguishes 403 from 503 treats exactly this as the 403; everything that is neither Denied nor an ALLOWED envelope stays uncertain (fail-closed 503).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL