middleware

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

admin_audit.go — a generic, unopinionated admin-mutation audit seam (companion to the extension.go org/auth seams).

State-changing admin routes (e.g. the agent patterns/services clears, shadow/detect clears, and the manual service / attribution-override mutations) call RecordAdminAudit after they succeed OR when they reject a request. OSS ships NO hook, so every call is a community-mode no-op and an untouched OSS binary behaves exactly as before — there is no audit backend in the open-core tree. An external wrapper (the enterprise build) registers a hook that writes the event into its append-only, per-org audit trail.

The hook is handed the request ctx (not a pre-extracted actor/org) so the implementation can derive the operator identity and tenant the way it authenticates requests — OSS has no concept of an SSO principal or a tenant, so resolving those belongs entirely to the wrapper.

Registration is process-wide and expected to happen once at boot, before the server starts accepting connections.

extension.go — generic, unopinionated extension seams (X2-T3).

These are registration hooks the OSS server exposes so an external module (the enterprise build, or any third-party wrapper) can attach behaviour WITHOUT the OSS tree depending on it. Nothing here is enterprise-specific: the defaults are community-mode no-ops, so an untouched OSS binary behaves exactly as before.

Two seams:

  • Org injection — a request-context org id, resolved per request and defaulting to storage.DefaultOrgID ("default"). Single-tenant OSS never sees it; a multi-tenant wrapper registers a resolver that reads the org from a header/token.
  • Auth slot — a settable middleware that runs on the API surface ahead of the OSS gateway-secret checks. OSS registers none (the slot is a pass-through); a wrapper registers SSO/JWT enforcement. A registered handler may call MarkAuthorized to tell the OSS gateway-secret guards the request is already authenticated by an alternative credential (e.g. an SSO session), so one enterprise credential can unlock both the data plane and the admin surfaces.

Registration is process-wide and expected to happen once at boot, before the server starts accepting connections.

Index

Constants

View Source
const (
	// AdminAuditSuccess — the mutation completed.
	AdminAuditSuccess = "success"
	// AdminAuditDenied — the mutation was rejected (validation, precondition,
	// conflict, or a gate).
	AdminAuditDenied = "denied"
)

Admin-audit outcome strings. A destructive admin action records exactly one of these; they mirror the wrapper's audit-result vocabulary without the OSS tree depending on it.

View Source
const AuthorizedContextKey = "versus.authorized"

AuthorizedContextKey is the fiber Locals key a registered auth handler (see SetAuthMiddleware) sets to mark a request as already authenticated by an alternative credential — e.g. an enterprise SSO session. The OSS gateway-secret guards honour this flag and skip the X-Gateway-Secret check when it is set, so a single enterprise credential can unlock both the data plane and the admin surfaces.

View Source
const OrgContextKey = "versus.org_id"

OrgContextKey is the fiber Locals key under which the resolved org id is stored for the lifetime of a request.

Variables

This section is empty.

Functions

func AuthMiddleware added in v1.4.4

func AuthMiddleware() fiber.Handler

AuthMiddleware returns the registered auth handler, or a no-op pass-through when none is registered (community mode).

func Logger

func Logger() fiber.Handler

func MarkAuthorized added in v1.4.4

func MarkAuthorized(c *fiber.Ctx)

MarkAuthorized records that the current request was authenticated upstream by a registered auth handler. Community OSS never calls this, so the gateway-secret guards behave exactly as before.

func OrgFromContext added in v1.4.4

func OrgFromContext(c *fiber.Ctx) string

OrgFromContext returns the org id stamped on the request by OrgInjector, or storage.DefaultOrgID when none was set.

func OrgInjector added in v1.4.4

func OrgInjector() fiber.Handler

OrgInjector returns middleware that stamps the resolved org id onto the request context. With no resolver registered (or a resolver that returns ""), every request is scoped to storage.DefaultOrgID, which is invisible to single-tenant OSS users.

func RecordAdminAudit added in v1.4.7

func RecordAdminAudit(c *fiber.Ctx, action, target, result string)

RecordAdminAudit emits one admin-mutation audit event to the registered hook. With no hook registered (community mode) it is a no-op, so an OSS binary is byte-inert. Callers pass a freshly built, non-secret target string.

func RequestAuthorized added in v1.4.4

func RequestAuthorized(c *fiber.Ctx) bool

RequestAuthorized reports whether a prior auth handler marked this request authorized. It defaults to false (community mode), leaving the OSS gateway-secret checks unchanged.

func SetAdminAuditHook added in v1.4.7

func SetAdminAuditHook(h AdminAuditHook)

SetAdminAuditHook registers the hook invoked for every state-changing admin action. OSS ships none (the slot is a no-op). Passing nil clears it (back to the community no-op). Call at boot.

func SetAuthMiddleware added in v1.4.4

func SetAuthMiddleware(h fiber.Handler)

SetAuthMiddleware registers an extra auth handler that runs on the API surface ahead of the OSS gateway-secret checks. OSS ships none. Passing nil clears the slot (back to the community pass-through). Call at boot.

func SetOrgResolver added in v1.4.4

func SetOrgResolver(r OrgResolver)

SetOrgResolver registers the function used to resolve an org id from a request. OSS ships none, so every request resolves to the default org. Passing nil clears it. Call at boot.

Types

type AdminAuditEvent added in v1.4.7

type AdminAuditEvent struct {
	Action string
	Target string
	Result string
}

AdminAuditEvent describes one state-changing admin action for the audit seam. Action is a stable, namespaced verb (e.g. "agent.patterns.cleared"); Target is the non-secret object acted upon (a service name, override id, or a reset summary); Result is one of the AdminAudit* outcome strings.

type AdminAuditHook added in v1.4.7

type AdminAuditHook func(c *fiber.Ctx, ev AdminAuditEvent)

AdminAuditHook records one admin mutation. It receives the request ctx so an implementation can derive the actor, org and request provenance. OSS ships none (community no-op).

type OrgResolver added in v1.4.4

type OrgResolver func(c *fiber.Ctx) string

OrgResolver extracts the org id for a request. Returning "" means "no explicit org" and falls back to storage.DefaultOrgID.

Jump to

Keyboard shortcuts

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