authz

package
v0.34.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ObligationKeyRecord is the key the policy engine writes when expressing a
	// session recording obligation. The enforcer reads this key and activates
	// the appropriate recording backends before the session begins.
	ObligationKeyRecord = "record"

	// ObligationRecordNone explicitly disables all session recording.
	ObligationRecordNone = "none"

	// Recording channel name tokens used as comma-separated values of the
	// "record" obligation key.
	ObligationRecordShell       = "shell"
	ObligationRecordExec        = "exec"
	ObligationRecordDirectTCPIP = "direct-tcpip"
	ObligationRecordSFTP        = "sftp"
)
View Source
const (
	// ObligationKeyScopes is the key the policy engine writes to restrict the
	// scopes a newly created token may carry. The value is a JSON-encoded array
	// of scope strings (e.g. ["token:read","workspace:start"]).
	ObligationKeyScopes = "scopes"

	// ObligationKeyExpiresIn is the key the policy engine writes to cap a
	// token's lifetime. The value is a Go duration string (e.g. "720h") or the
	// literal "never" to permit a non-expiring token.
	ObligationKeyExpiresIn = "expires_in"

	// ObligationExpiresInNever is the sentinel value meaning no expiry.
	ObligationExpiresInNever = "never"
)
View Source
const (
	// ObligationKeySudo is the key the policy engine writes when expressing a
	// sudo obligation. The enforcer reads this key and applies the value to the
	// user record before completing onboarding or admin-driven creation.
	ObligationKeySudo = "sudo"

	// ObligationSudoTrue is the obligation value that grants sudo access.
	ObligationSudoTrue = "true"

	// ObligationSudoFalse is the obligation value that explicitly denies sudo access.
	ObligationSudoFalse = "false"
)
View Source
const (
	// ObligationKeyAuthMethods is the key the policy engine writes to indicate
	// which SSH authentication methods are available to the user. The value is
	// a JSON-encoded array of method strings (e.g. ["publickey","password"]).
	ObligationKeyAuthMethods = "auth_methods"
)
View Source
const (
	// ObligationKeyBlueprints is the key the policy engine writes to assign
	// allowed blueprints during onboarding or admin-driven creation. The value
	// is a comma-separated list of blueprint names; "*" grants access to all
	// blueprints.
	ObligationKeyBlueprints = "blueprints"
)
View Source
const (
	// ObligationKeyOrg is the key the policy engine writes to scope a user:list
	// result to a single organization. The value is an organization name.
	ObligationKeyOrg = "org"
)
View Source
const (
	// ObligationKeyPatchPrefix is the prefix the policy engine uses to express
	// blueprint patch obligations for workspace:provision. Each key of the form
	// "patch:<json-pointer>" (RFC 6901) names a location in the blueprint YAML
	// document; the corresponding value is the string to set at that path.
	// Example: "patch:/resources/cpu" → "2000m".
	ObligationKeyPatchPrefix = "patch:"
)
View Source
const (
	// ObligationKeyRoles is the key the policy engine writes to assign roles
	// during onboarding or admin-driven creation. The value is a JSON-encoded
	// array of role name strings.
	ObligationKeyRoles = "roles"
)
View Source
const (
	// ObligationKeyUsername is the key the policy engine writes to scope a
	// session:list result to a single session owner. The value is a username.
	ObligationKeyUsername = "username"
)

Variables

View Source
var (
	// ErrTokenExpired is returned when the token's expiry time has passed.
	ErrTokenExpired = errors.New("jwt: token has expired")

	// ErrTokenInvalidSignature is returned when the token signature does not
	// match the expected signing key.
	ErrTokenInvalidSignature = errors.New("jwt: token signature is invalid")

	// ErrTokenMalformed is returned when the token string is not a valid JWT.
	ErrTokenMalformed = errors.New("jwt: token is malformed")
)

Sentinel errors returned by JWTVerifier.VerifyToken. Use errors.Is to distinguish failure reasons.

Functions

func ApplyProvisionPatches

func ApplyProvisionPatches(bp *models.Blueprint, patches []ProvisionPatch) (*models.Blueprint, error)

ApplyProvisionPatches applies a slice of ProvisionPatch obligations to a Blueprint and returns the modified copy. The blueprint is round-tripped through YAML so that path tokens match yaml struct tag names. Each patch value is YAML-decoded before being written, so "false" becomes bool(false), "2000m" stays as a string, etc. Returns the original pointer unchanged when patches is empty.

func ScopeAllows

func ScopeAllows(scopes []string, action string, satisfied ...ScopeConstraint) bool

ScopeAllows reports whether any scope in the list permits action. satisfied lists the constraints the caller has determined the current request meets (e.g. pass ScopeConstraintSelf when resource.id == subject.username) — the scope layer has no resource awareness of its own, so this is how a caller tells it "self" applies here.

Matching rules (strict):

  • "*" matches any action
  • "prefix:*" matches any action that starts with "prefix:"
  • an exact scope matches only when scope == action
  • a scope with a trailing ":constraint" additionally requires that constraint to be present in satisfied; an unconstrained scope matches regardless of satisfied, so a token holding the broad "user:read:profile" scope still covers its own profile

func ValidateScope

func ValidateScope(s string) error

ValidateScope reports whether s is a well-formed, recognized scope string. A scope is valid when it is:

  • the bare wildcard "*"
  • a known exact action string from the registry
  • a known wildcard prefix followed by ":*"
  • any of the above (except the bare wildcard) followed by ":constraint", provided the "domain:action" prefix accepts a constraint suffix

func ValidateScopes

func ValidateScopes(scopes []string) error

ValidateScopes validates every scope in the slice. Returns the first error encountered, or nil when all scopes are valid. At least one scope is required.

Types

type AuthMethodsObligation added in v0.30.9

type AuthMethodsObligation struct {
	// Methods is the list of authentication methods the policy permits for
	// the user (any of UserAuthMethodPublicKey, UserAuthMethodPassword).
	Methods []UserAuthMethod
}

AuthMethodsObligation is the typed representation of the "auth_methods" obligation key returned by the policy engine in a PolicyResult for user:auth.

func ParseAuthMethodsObligation added in v0.30.9

func ParseAuthMethodsObligation(obligations map[string]string) (AuthMethodsObligation, bool)

ParseAuthMethodsObligation reads the "auth_methods" key from the obligations map. Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set an auth_methods obligation — in that case the enforcer should offer no authentication methods.

type AuthSurface added in v0.32.1

type AuthSurface string

AuthSurface identifies which login surface a user:auth check is evaluating. publickey is only meaningful for AuthSurfaceSSH; AuthSurfaceWeb is password-only in practice, though the contract does not enforce that.

const (
	AuthSurfaceSSH AuthSurface = "ssh"
	AuthSurfaceWeb AuthSurface = "web"
)

type BlueprintsObligation

type BlueprintsObligation struct {
	// Blueprints is the list of blueprint names the policy assigns to the user.
	// An entry of "*" grants access to all blueprints.
	Blueprints []string
}

BlueprintsObligation is the typed representation of the "blueprints" obligation key returned by the policy engine in a PolicyResult for user:onboard or user:create.

func ParseBlueprintsObligation

func ParseBlueprintsObligation(obligations map[string]string) (BlueprintsObligation, bool)

ParseBlueprintsObligation reads the "blueprints" key from the obligations map. The value is a JSON-encoded array of blueprint name strings (e.g. ["bp1","bp2"]). Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set a blueprints obligation — in that case the enforcer should preserve its existing default rather than overwriting it.

type CapabilityCheck added in v0.32.1

type CapabilityCheck struct {
	// Action is the display action label, e.g. "workspace:connect:webshell".
	// Matches the literal action string except for compound actions where the
	// qualifier (connect type, app op, data type, auth surface) is folded in,
	// mirroring the PAT scope convention in scope.go.
	Action string

	// Package is the OPA policy package this action is evaluated under.
	Package string

	// Scope is the PAT token_scopes string that caps this action, in the same
	// "domain:action[:qualifier]" form ScopeAllows expects.
	Scope string

	// SelfOnly marks an action whose contract only makes sense when the
	// subject is the resource itself — user:auth (you can only authenticate
	// as yourself) and user:onboard (onboarding is bootstrapping your own
	// account). Callers building a report for a resource owner other than
	// the subject should skip SelfOnly checks entirely: there is no honest
	// answer to "can Z authenticate as X" for Z != X.
	SelfOnly bool

	// Build constructs the representative EvalRequest for this action from
	// ctx. It may return an error when required data isn't available in
	// ctx — callers should treat that as "unevaluated", not "denied".
	Build func(ctx CapabilityContext) (EvalRequest, error)
}

CapabilityCheck is a self-describing, representative probe for one authz action: enough metadata to build a syntactically valid (if synthetic) EvalRequest for a "what can I do" report, without needing a real resource to exist.

func CapabilityChecks added in v0.32.1

func CapabilityChecks() []CapabilityCheck

CapabilityChecks returns every registered capability probe. The slice is a copy; callers may filter/reorder freely without affecting the registry.

type CapabilityContext added in v0.32.1

type CapabilityContext struct {
	// ResourceOwner is the username whose resources the check is scoped to —
	// workspace/session/ssh owner, or the target user record itself.
	ResourceOwner string

	// IDP and Org are ResourceOwner's real identity source and organization,
	// required by user:onboard, user:auth, and used by user:create/delete.
	// Leave empty when unknown (e.g. ResourceOwner doesn't exist yet) — the
	// affected Build funcs then fail Validate() and the check is reported as
	// unevaluated rather than answered against a fabricated identity.
	IDP, Org string

	// BlueprintName and Blueprint feed workspace:provision. BlueprintName
	// empty means "not supplied" — Build leaves the request's required
	// blueprint context unset on purpose, so Validate() fails and the check
	// comes back unevaluated rather than silently denied.
	BlueprintName string
	Blueprint     *models.Blueprint
}

CapabilityContext carries every synthetic/representative value a capability probe might need to build a syntactically valid EvalRequest without a real resource existing. Not every action uses every field — each CapabilityCheck.Build pulls only what its contract requires.

type EvalRequest

type EvalRequest interface {
	// Validate checks the request against its domain contract. It is called
	// automatically by Build and FromProto, but can be called explicitly if
	// the struct was mutated after construction.
	Validate() error

	// ToProto serializes the typed request into a gRPC EvaluateRequest,
	// attaching the supplied JWT token. Use this on the client side to
	// produce the wire message from the typed, validated struct.
	ToProto(token string) *authzv1.EvaluateRequest
}

EvalRequest is the common interface for every typed policy evaluation request. Each policy domain (ssh, blueprint, ...) provides a concrete implementation.

On the client side, build the concrete type with its With* builder and call ToProto to produce the gRPC message. On the server side, convert the incoming gRPC message with the domain's FromProto function, which validates the contract and returns the typed struct.

type ExpiresInObligation

type ExpiresInObligation struct {
	// Duration is the maximum lifetime of the token. A nil value means the
	// policy permits a non-expiring token (ObligationExpiresInNever).
	Duration *time.Duration
}

ExpiresInObligation is the typed representation of the "expires_in" obligation key returned by the policy engine in a PolicyResult for token:create.

func ParseExpiresInObligation

func ParseExpiresInObligation(obligations map[string]string) (ExpiresInObligation, bool)

ParseExpiresInObligation reads the "expires_in" key from the obligations map. Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set an expires_in obligation. The sentinel "never" yields an obligation with a nil Duration.

type JWTIssuer

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

JWTIssuer creates and signs JWT tokens for authenticated users.

func NewJWTIssuer

func NewJWTIssuer(cfg JWTIssuerConfig) (*JWTIssuer, error)

NewJWTIssuer constructs a JWTIssuer from the provided configuration. Returns an error when the configuration is invalid or keying material cannot be loaded.

func (*JWTIssuer) IssueToken

func (j *JWTIssuer) IssueToken(user *models.User) (claims *UserClaims, signed string, err error)

IssueToken creates a signed JWT string for the given user. The token includes both standard registered claims and k8Shell-specific user attributes as additional claims.

type JWTIssuerConfig

type JWTIssuerConfig struct {
	// Enabled toggles JWT issuance. When false, the issuer is not initialized.
	Enabled bool `yaml:"enabled"`

	// Issuer is the value placed in the "iss" claim.
	Issuer string `yaml:"issuer"`

	// Audience is the value placed in the "aud" claim.
	Audience string `yaml:"audience"`

	// Expiry is the token lifetime (e.g. "1h", "8h", "24h").
	// Defaults to 1 hour when unset.
	Expiry time.Duration `yaml:"expiry"`

	// SigningMethod selects the signing algorithm. Supported values:
	//   hs256 (default) – HMAC-SHA-256, requires SecretKey
	//   rs256            – RSA-SHA-256,  requires PrivateKeyFile
	//   es256            – ECDSA-P256,   requires PrivateKeyFile
	SigningMethod string `yaml:"signingMethod"`

	// SecretKey is the HMAC signing secret (used with hs256).
	SecretKey string `yaml:"secretKey"`

	// PrivateKeyFile is the path to a PEM-encoded RSA or ECDSA private key
	// (used with rs256 / es256).
	PrivateKeyFile string `yaml:"privateKeyFile"`
}

JWTIssuerConfig contains configuration for JWT token issuance.

type JWTVerifier

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

JWTVerifier validates JWT tokens, checking both signature integrity and expiration. It can be used independently from JWTIssuer.

func NewJWTVerifier

func NewJWTVerifier(cfg JWTVerifierConfig) (*JWTVerifier, error)

NewJWTVerifier constructs a JWTVerifier from the provided configuration.

For hs256 SecretKey is used for verification. For rs256 / es256 the verification key is resolved in this order:

  1. PublicKeyFile (if set)
  2. Public key extracted from PrivateKeyFile

func (*JWTVerifier) VerifyToken

func (v *JWTVerifier) VerifyToken(tokenStr string) (*UserClaims, error)

VerifyToken parses and validates tokenStr. It returns the embedded UserClaims on success, or one of the sentinel errors on failure:

  • ErrTokenExpired – token exists but has expired
  • ErrTokenInvalidSignature – signature does not match the key
  • ErrTokenMalformed – string is not a valid JWT
  • any other error – audience/issuer mismatch or internal failure

type JWTVerifierConfig

type JWTVerifierConfig struct {
	// Issuer is the expected "iss" claim value. When set, tokens with a
	// different issuer are rejected.
	Issuer string `yaml:"issuer"`

	// Audience is the expected "aud" claim value. When set, tokens without
	// this audience are rejected.
	Audience string `yaml:"audience"`

	// SigningMethod must match the algorithm used to sign the tokens.
	// Supported values: hs256 (default), rs256, es256.
	SigningMethod string `yaml:"signingMethod"`

	// SecretKey is the HMAC verification secret (used with hs256).
	SecretKey string `yaml:"secretKey"`

	// PublicKey is the PEM-encoded RSA or ECDSA public key as an inline string
	// (used with rs256 / es256). Takes precedence over PublicKeyFile.
	PublicKey string `yaml:"publicKey"`

	// PublicKeyFile is the path to a PEM-encoded RSA or ECDSA public key
	// (used with rs256 / es256). Takes precedence over PrivateKey and PrivateKeyFile.
	PublicKeyFile string `yaml:"publicKeyFile"`

	// PrivateKey is the PEM-encoded RSA or ECDSA private key as an inline string.
	// The public key is extracted from it and used for verification when
	// PublicKey and PublicKeyFile are not set.
	PrivateKey string `yaml:"privateKey"`

	// PrivateKeyFile is the path to a PEM-encoded RSA or ECDSA private key.
	// The public key is extracted from it and used for verification when
	// PublicKey, PublicKeyFile, and PrivateKey are not set.
	PrivateKeyFile string `yaml:"privateKeyFile"`
}

JWTVerifierConfig contains configuration for JWT token verification.

func (JWTVerifierConfig) GetPublicKey

func (c JWTVerifierConfig) GetPublicKey() (string, error)

GetPublicKey returns the PEM-encoded public key for this JWT configuration. Resolution order: PublicKey (inline) → PublicKeyFile → PrivateKey (inline) → PrivateKeyFile.

type OrgObligation added in v0.30.6

type OrgObligation struct {
	// Org is the organization the enforcer should restrict the listing to.
	Org string
}

OrgObligation is the typed representation of the "org" obligation key returned by the policy engine in a PolicyResult for user:list.

func ParseOrgObligation added in v0.30.6

func ParseOrgObligation(obligations map[string]string) (OrgObligation, bool)

ParseOrgObligation reads the "org" key from the obligations map. Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set an org obligation — in that case the enforcer should not scope the listing by organization.

type PolicyInput

type PolicyInput struct {
	Username  string
	Roles     []string
	Package   string
	Action    string
	Resource  PolicyResource
	Context   map[string]string
	Blueprint map[string]any // non-nil for workspace:* actions; decoded from context["blueprint"]

	// CapabilityCheck marks this evaluation as a synthetic "what can I do"
	// probe rather than a real access attempt. It is not set by
	// BuildPolicyInput — since capability_check is a BatchEvaluateRequest-level
	// flag, the caller of BatchEvaluate must propagate it onto each request's
	// PolicyInput after construction. Policy-decision audit logging should
	// record and classify these separately from genuine authorization
	// decisions.
	CapabilityCheck bool
}

PolicyInput is the assembled input to a policy evaluation engine (e.g. OPA). It combines the decoded JWT subject with the validated, normalized fields from the gRPC EvaluateRequest. Construct via BuildPolicyInput.

func BuildPolicyInput

func BuildPolicyInput(req *authzv1.EvaluateRequest) (*PolicyInput, error)

BuildPolicyInput parses the JWT from req, validates the request against the appropriate domain contract, and assembles the PolicyInput for the policy engine. It is the single entry point for all incoming EvaluateRequests on the server side — no per-domain routing is needed at the call site.

type PolicyResource

type PolicyResource struct {
	Type       string
	ID         string
	Attributes map[string]string
}

PolicyResource holds the resource fields for policy evaluation, mirroring the proto Resource message.

type PolicyResult

type PolicyResult struct {
	Allowed     bool
	Reason      string
	Obligations map[string]string
}

PolicyResult holds the outcome of a single policy evaluation.

func PolicyResultFromProto

func PolicyResultFromProto(resp *authzv1.EvaluateResponse) *PolicyResult

PolicyResultFromProto converts a gRPC EvaluateResponse into a PolicyResult.

func (*PolicyResult) ToProto

func (r *PolicyResult) ToProto() *authzv1.EvaluateResponse

ToProto converts a PolicyResult into a gRPC EvaluateResponse.

type ProvisionPatch

type ProvisionPatch struct {
	Path  string // e.g. "/resources/cpu"
	Value string
}

ProvisionPatch is a single blueprint mutation expressed by the policy engine as part of a workspace:provision obligation. Path is a JSON Pointer (RFC 6901) addressing a field in the blueprint YAML document.

func ParseProvisionPatchObligations

func ParseProvisionPatchObligations(obligations map[string]string) []ProvisionPatch

ParseProvisionPatchObligations extracts all patch obligations from the obligations map. Every key with the ObligationKeyPatchPrefix prefix is interpreted as a JSON Pointer path; the map value is the string to write there. Returns nil when no patch obligations are present.

type RecordObligation

type RecordObligation struct {
	Shell       bool
	Exec        bool
	DirectTCPIP bool
	SFTP        bool
}

RecordObligation is the typed representation of the "record" obligation key returned by the policy engine in a PolicyResult for session:start. Each field corresponds to one recording channel; all default to false.

func ParseRecordObligation

func ParseRecordObligation(obligations map[string]string) (RecordObligation, bool)

ParseRecordObligation reads the "record" key from the obligations map. The value is a comma-separated list of channel tokens ("shell", "exec", "direct-tcpip", "sftp"); "none" or an unrecognised value leaves all fields false. Returns (obligation, true) when the key is present, (zero, false) when the policy did not set a record obligation — the enforcer should then apply its configured default (typically no recording).

type RolesObligation

type RolesObligation struct {
	// Roles is the list of roles the policy assigns to the user.
	Roles []models.Role
}

RolesObligation is the typed representation of the "roles" obligation key returned by the policy engine in a PolicyResult for user:onboard or user:create.

func ParseRolesObligation

func ParseRolesObligation(obligations map[string]string) (RolesObligation, bool)

ParseRolesObligation reads the "roles" key from the obligations map. Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set a roles obligation — in that case the enforcer should preserve its existing default rather than overwriting it.

type SSHAction

type SSHAction string

SSHAction is the typed representation of an SSH policy action.

const (
	// SSHActionShell is an interactive PTY session (session channel + shell request).
	SSHActionShell SSHAction = "ssh:shell"

	// SSHActionExec is a non-interactive command execution (session channel + exec request).
	// Also covers SCP.
	SSHActionExec SSHAction = "ssh:exec"

	// SSHActionSFTP is a subsystem "sftp" request on a session channel.
	SSHActionSFTP SSHAction = "ssh:sftp"

	// SSHActionDirectTCPIP is a client-initiated TCP port forward (direct-tcpip channel).
	SSHActionDirectTCPIP SSHAction = "ssh:direct-tcpip"

	// SSHActionDirectStreamlocal is a Unix domain socket forward
	// (direct-streamlocal@openssh.com channel).
	SSHActionDirectStreamlocal SSHAction = "ssh:direct-streamlocal"

	// SSHActionAgentForward is SSH agent forwarding
	// (auth-agent-req@openssh.com session request).
	SSHActionAgentForward SSHAction = "ssh:agent-forward"
)

type SSHContext

type SSHContext struct {
	// PTY is true when a pseudo-terminal was requested (context["pty"] == "true").
	PTY bool

	// Command is the exact command string for ssh:exec channels (context["command"]).
	Command string

	// Host is the destination host for ssh:direct-tcpip channels (context["host"]).
	Host string

	// Port is the destination port for ssh:direct-tcpip channels (context["port"]).
	Port string

	// SocketPath is the Unix socket path for ssh:direct-streamlocal channels
	// (context["socket_path"]).
	SocketPath string

	// AsUser is the Linux user the session runs as inside the workspace
	// (context["as_user"]). Optional; empty means the workspace default user.
	AsUser string
}

SSHContext holds the ambient SSH channel/request attributes supplied by the ssh-proxy in the context map of the EvaluateRequest.

type SSHEvalRequest

type SSHEvalRequest struct {
	Action   SSHAction
	Resource WorkspaceResource
	Context  SSHContext
}

SSHEvalRequest is the validated, typed model for SSH policy evaluation. Use NewSSHEvalRequest to start building, then chain With* methods and call Build to get a validated instance. Use SSHEvalRequestFromProto to convert directly from a gRPC EvaluateRequest.

func NewSSHEvalRequest

func NewSSHEvalRequest(action SSHAction, workspaceID string) *SSHEvalRequest

NewSSHEvalRequest begins building an SSHEvalRequest for the given action and workspace ID. Chain With* methods to supply additional fields, then call Build to validate and obtain the final struct.

func SSHEvalRequestFromProto

func SSHEvalRequestFromProto(req *authzv1.EvaluateRequest) (*SSHEvalRequest, error)

SSHEvalRequestFromProto converts a gRPC EvaluateRequest into a validated SSHEvalRequest. Returns an error if the request does not conform to the SSH policy contract.

func (*SSHEvalRequest) Build

func (r *SSHEvalRequest) Build() (*SSHEvalRequest, error)

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*SSHEvalRequest) ToProto

func (r *SSHEvalRequest) ToProto(token string) *authzv1.EvaluateRequest

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Only non-empty / non-default context fields are included in the context map. Implements EvalRequest.

func (*SSHEvalRequest) Validate

func (r *SSHEvalRequest) Validate() error

Validate checks the request against the SSH policy contract: the action must be recognized, core resource fields must be present, and each action enforces its own required context fields. Implements EvalRequest.

func (*SSHEvalRequest) WithAsUser

func (r *SSHEvalRequest) WithAsUser(user string) *SSHEvalRequest

WithAsUser sets the Linux user the session runs as inside the workspace. Optional for SSHActionShell and SSHActionExec; empty means the workspace default user.

func (*SSHEvalRequest) WithBlueprint

func (r *SSHEvalRequest) WithBlueprint(blueprint string) *SSHEvalRequest

WithBlueprint sets the blueprint name on the resource.

func (*SSHEvalRequest) WithCommand

func (r *SSHEvalRequest) WithCommand(cmd string) *SSHEvalRequest

WithCommand sets the command string; required for SSHActionExec.

func (*SSHEvalRequest) WithHost

func (r *SSHEvalRequest) WithHost(host string) *SSHEvalRequest

WithHost sets the destination host; required for SSHActionDirectTCPIP.

func (*SSHEvalRequest) WithOwner

func (r *SSHEvalRequest) WithOwner(owner string) *SSHEvalRequest

WithOwner sets the workspace owner on the resource.

func (*SSHEvalRequest) WithPTY

func (r *SSHEvalRequest) WithPTY(pty bool) *SSHEvalRequest

WithPTY records whether a pseudo-terminal was requested.

func (*SSHEvalRequest) WithPort

func (r *SSHEvalRequest) WithPort(port string) *SSHEvalRequest

WithPort sets the destination port; required for SSHActionDirectTCPIP.

func (*SSHEvalRequest) WithSocketPath

func (r *SSHEvalRequest) WithSocketPath(path string) *SSHEvalRequest

WithSocketPath sets the Unix socket path; required for SSHActionDirectStreamlocal.

type Scope

type Scope string

Scope is a PAT access token scope string. It is either an exact action string from the registry (e.g. "workspace:list") or a wildcard pattern with "*" as the last segment (e.g. "workspace:connect:*"), optionally narrowed by a trailing constraint (e.g. "user:read:profile:self").

Grammar:

scope      = "*"
           | domain ":" action
           | domain ":" action ":" qualifier
           | domain ":" action ":" qualifier ":" constraint
           | domain ":" action ":" "*"
           | domain ":" action ":" "*" ":" constraint
           | domain ":" "*"

Matching is strict (Option A): a scope without a wildcard matches only its exact action string. To cover all qualifiers of an action, the scope must carry an explicit ":*" suffix (e.g. "workspace:connect:*").

A constraint is an additional, orthogonal condition evaluated against the request rather than the action string — it doesn't change which action the scope matches, only whether the scope applies to this particular request. A plain (unconstrained) scope keeps matching regardless of any constraint state, so a token already holding the broad "user:read:profile" scope is unaffected by a caller also being able to satisfy "self". See ScopeConstraint for the constraint vocabulary and ScopeAllows for how constraint satisfaction is supplied by the caller.

type ScopeConstraint added in v0.33.0

type ScopeConstraint string

ScopeConstraint is the optional 4th segment of a scope string. It narrows a scope to requests that satisfy some condition the scope grammar alone can't express — one the caller must evaluate against the actual request and report back to ScopeAllows (e.g. "is the resource being accessed the token's own subject?"). New constraints are added to validScopeConstraints; domains opt individual domain:action prefixes into accepting a constraint suffix via scopeConstrainablePrefixes.

const (
	// ScopeConstraintSelf restricts a scope to requests where the resource
	// being accessed belongs to the token's own subject, i.e.
	// resource.id == subject.username. Callers determine this themselves
	// (the scope layer has no resource awareness) and pass ScopeConstraintSelf
	// to ScopeAllows when true.
	ScopeConstraintSelf ScopeConstraint = "self"
)

type ScopesObligation

type ScopesObligation struct {
	// Scopes is the list of scopes the policy permits on the new token.
	Scopes []string
}

ScopesObligation is the typed representation of the "scopes" obligation key returned by the policy engine in a PolicyResult for token:create.

func ParseScopesObligation

func ParseScopesObligation(obligations map[string]string) (ScopesObligation, bool)

ParseScopesObligation reads the "scopes" key from the obligations map. Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set a scopes obligation.

type SessionAction

type SessionAction string

SessionAction is the typed representation of a session policy action.

const (
	// SessionActionStart is the action evaluated when a new session is being
	// established. The policy result may carry a "record" obligation that
	// instructs the enforcer what kind of recording to apply to the session.
	SessionActionStart SessionAction = "session:start"

	// SessionActionList is the action evaluated when listing sessions. The
	// scope is controlled by the resource fields: both id and owner set scopes
	// to one workspace; owner only scopes to a user; neither means all sessions.
	SessionActionList SessionAction = "session:list"
)

type SessionContext

type SessionContext struct {
	// Type is the kind of session being established (context["session_type"]).
	Type SessionType

	// Source is the component that initiated the session (context["session_source"]).
	Source SessionSource
}

SessionContext holds the ambient session attributes supplied by the caller in the context map of the EvaluateRequest.

type SessionListEvalRequest

type SessionListEvalRequest struct {
	Resource WorkspaceResource
}

SessionListEvalRequest is the validated, typed model for session:list policy evaluation. Both resource fields are optional; their combination controls the listing scope (see the contract comment at the top of this file).

func NewSessionListEvalRequest

func NewSessionListEvalRequest() *SessionListEvalRequest

NewSessionListEvalRequest returns a SessionListEvalRequest ready to be built. Chain WithWorkspace and/or WithOwner to narrow the scope, then call Build.

func SessionListEvalRequestFromProto

func SessionListEvalRequestFromProto(req *authzv1.EvaluateRequest) (*SessionListEvalRequest, error)

SessionListEvalRequestFromProto converts a gRPC EvaluateRequest into a validated SessionListEvalRequest.

func (*SessionListEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied.

func (*SessionListEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest. Implements EvalRequest.

func (*SessionListEvalRequest) Validate

func (r *SessionListEvalRequest) Validate() error

Validate checks the request: if a workspace id is set, owner must also be set. Implements EvalRequest.

func (*SessionListEvalRequest) WithOwner

WithOwner sets the owner username.

func (*SessionListEvalRequest) WithWorkspace

func (r *SessionListEvalRequest) WithWorkspace(workspaceID string) *SessionListEvalRequest

WithWorkspace sets the workspace name; requires WithOwner to also be called.

type SessionSource

type SessionSource string

SessionSource identifies the component that initiated the session.

const (
	// SessionSourceSSHProxy is set when the session originates from the SSH proxy.
	SessionSourceSSHProxy SessionSource = "ssh-proxy"

	// SessionSourceAPIServer is set when the session originates from the API server.
	SessionSourceAPIServer SessionSource = "api-server"
)

type SessionStartEvalRequest

type SessionStartEvalRequest struct {
	Action   SessionAction
	Resource WorkspaceResource
	Context  SessionContext
}

SessionStartEvalRequest is the validated, typed model for session policy evaluation. Use NewSessionStartEvalRequest to start building, then chain With* methods and call Build to get a validated instance. Use SessionStartEvalRequestFromProto to convert directly from a gRPC EvaluateRequest.

func NewSessionStartEvalRequest

func NewSessionStartEvalRequest(action SessionAction, workspaceID string, sessionType SessionType) *SessionStartEvalRequest

NewSessionStartEvalRequest begins building a SessionStartEvalRequest for the given action, workspace ID, and session type. Chain With* methods to supply additional fields, then call Build to validate and obtain the final struct.

func SessionStartEvalRequestFromProto

func SessionStartEvalRequestFromProto(req *authzv1.EvaluateRequest) (*SessionStartEvalRequest, error)

SessionStartEvalRequestFromProto converts a gRPC EvaluateRequest into a validated SessionStartEvalRequest. Returns an error if the request does not conform to the session policy contract.

func (*SessionStartEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*SessionStartEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Only non-empty resource attributes are included. Implements EvalRequest.

func (*SessionStartEvalRequest) Validate

func (r *SessionStartEvalRequest) Validate() error

Validate checks the request against the session policy contract: the action must be recognized, core resource fields must be present, and the session type must be a known value. Implements EvalRequest.

func (*SessionStartEvalRequest) WithBlueprint

func (r *SessionStartEvalRequest) WithBlueprint(blueprint string) *SessionStartEvalRequest

WithBlueprint sets the blueprint name on the resource.

func (*SessionStartEvalRequest) WithOwner

WithOwner sets the workspace owner on the resource.

func (*SessionStartEvalRequest) WithSource

WithSource sets the session source on the context.

type SessionType

type SessionType string

SessionType describes the kind of session being established.

const (
	// SessionTypeShell is an interactive shell/PTY session (terminal recording).
	SessionTypeShell SessionType = "shell"

	// SessionTypeTCPIP is a TCP/IP port-forwarding session (network traffic recording).
	SessionTypeTCPIP SessionType = "tcpip"

	// SessionTypeExec is a non-interactive exec session (single command, no PTY).
	SessionTypeExec SessionType = "exec"

	// SessionTypeSFTP is an SFTP subsystem session (file transfer).
	SessionTypeSFTP SessionType = "sftp"
)

type SudoObligation

type SudoObligation struct {
	// Granted is true when the policy grants sudo access, false when it denies it.
	Granted bool
}

SudoObligation is the typed representation of the "sudo" obligation key returned by the policy engine in a PolicyResult for user:onboard or user:create.

func ParseSudoObligation

func ParseSudoObligation(obligations map[string]string) (SudoObligation, bool)

ParseSudoObligation reads the "sudo" key from the obligations map. Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set a sudo obligation — in that case the enforcer should preserve its existing default rather than overwriting it.

type TokenCreateContext

type TokenCreateContext struct {
	// Source is how the token creation was initiated (context["source"]).
	Source TokenCreateSource
}

TokenCreateContext holds the ambient attributes for a token:create request.

type TokenCreateSource

type TokenCreateSource string

TokenCreateSource identifies how the token creation was initiated.

const (
	// TokenCreateSourceWebFlow is set when the token is issued at the end of an
	// OAuth/device login flow initiated by the CLI.
	TokenCreateSourceWebFlow TokenCreateSource = "web-flow"

	// TokenCreateSourceAPI is set when the token is created via a direct API request.
	TokenCreateSourceAPI TokenCreateSource = "api"
)

type UserAuthContext

type UserAuthContext struct {
	// Surface is the login surface being authenticated (context["surface"]).
	Surface AuthSurface
}

UserAuthContext holds the context-scoped attributes for a user:auth policy check.

type UserAuthEvalRequest

type UserAuthEvalRequest struct {
	Resource UserResource
	Context  UserAuthContext
}

UserAuthEvalRequest is the validated, typed model for user:auth policy evaluation. Use NewUserAuthEvalRequest to start building, then chain With* methods and call Build to get a validated instance.

func NewUserAuthEvalRequest

func NewUserAuthEvalRequest(username string) *UserAuthEvalRequest

NewUserAuthEvalRequest begins building a UserAuthEvalRequest for the given username. Chain With* methods to supply additional fields, then call Build to validate and obtain the final struct.

func UserAuthEvalRequestFromProto

func UserAuthEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserAuthEvalRequest, error)

UserAuthEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserAuthEvalRequest. Returns an error if the request does not conform to the user:auth contract.

func (*UserAuthEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserAuthEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserAuthEvalRequest) Validate

func (r *UserAuthEvalRequest) Validate() error

Validate checks the request against the user:auth contract: ID and IDP are required, and surface must be a recognized value. Implements EvalRequest.

func (*UserAuthEvalRequest) WithIDP

WithIDP sets the identity provider name on the resource.

func (*UserAuthEvalRequest) WithOrg

WithOrg sets the organization on the resource.

func (*UserAuthEvalRequest) WithSurface added in v0.32.1

func (r *UserAuthEvalRequest) WithSurface(surface AuthSurface) *UserAuthEvalRequest

WithSurface sets the login surface being authenticated on the context.

type UserAuthMethod

type UserAuthMethod string

UserAuthMethod is the typed representation of a user authentication method.

const (
	UserAuthMethodPublicKey UserAuthMethod = "publickey"
	UserAuthMethodPassword  UserAuthMethod = "password"
)

type UserClaims

type UserClaims struct {
	jwt.RegisteredClaims

	// Email is the user's email address.
	Email string `json:"email,omitempty"`

	// Name is the user's full name.
	Name string `json:"name,omitempty"`

	// UID is the POSIX user-id of the user.
	UID uint32 `json:"uid"`

	// GID is the POSIX primary group-id of the user.
	GID uint32 `json:"gid"`

	// Roles lists the roles granted to the user.
	Roles []models.Role `json:"roles,omitempty"`

	// Organization is the user's organisation.
	Organization string `json:"org,omitempty"`

	// Source identifies the identity provider that owns this user record.
	Source string `json:"source,omitempty"`

	// Shell is the user's default login shell.
	Shell string `json:"shell,omitempty"`

	// Sudo indicates whether the user has sudo privileges.
	Sudo bool `json:"sudo,omitempty"`
}

UserClaims are the JWT claims embedded in tokens issued for a user. Standard registered claims are promoted from jwt.RegisteredClaims; the remaining fields carry k8Shell-specific user attributes.

func ParseUnverifiedClaims

func ParseUnverifiedClaims(tokenStr string, checkExp bool) (*UserClaims, error)

ParseUnverifiedClaims decodes the claims from tokenStr without verifying the signature or validating any registered claims (exp, iss, aud, etc.). Use this only where the token has already been verified by another means, or when you need to inspect claims (e.g. check expiry) before a full verify.

func (*UserClaims) GetUsername

func (c *UserClaims) GetUsername() string

type UserCreateEvalRequest added in v0.32.0

type UserCreateEvalRequest struct {
	Resource UserResource
}

UserCreateEvalRequest is the validated, typed model for user:create policy evaluation. Use NewUserCreateEvalRequest to start building, then chain With* methods and call Build to get a validated instance.

user:create authorizes an admin to create a brand-new local user record -- one with no backing identity provider, unlike user:onboard. The acting principal is the admin performing the creation, not the new user, so callers evaluate this with the admin's own token rather than one issued for the user being created.

func NewUserCreateEvalRequest added in v0.32.0

func NewUserCreateEvalRequest(username string) *UserCreateEvalRequest

NewUserCreateEvalRequest begins building a UserCreateEvalRequest for the given username. Chain With* methods to supply additional fields, then call Build to validate and obtain the final struct.

func UserCreateEvalRequestFromProto added in v0.32.0

func UserCreateEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserCreateEvalRequest, error)

UserCreateEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserCreateEvalRequest. Returns an error if the request does not conform to the user:create contract.

func (*UserCreateEvalRequest) Build added in v0.32.0

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserCreateEvalRequest) ToProto added in v0.32.0

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserCreateEvalRequest) Validate added in v0.32.0

func (r *UserCreateEvalRequest) Validate() error

Validate checks the request against the user:create contract. Implements EvalRequest.

func (*UserCreateEvalRequest) WithOrg added in v0.32.0

WithOrg sets the organization the new user will belong to.

type UserDataType

type UserDataType string

UserDataType identifies which slice of user data is being accessed in user:read and user:write. UserDataTypeSudo, UserDataTypeLocked, UserDataTypeOrg, UserDataTypePosix, and UserDataTypePassword are write-only values: user:read never selects them individually, since UserDataTypeProfile already returns the full profile view including sudo, locked, org, and uid/gid, and a password is never readable at all.

const (
	UserDataTypeProfile     UserDataType = "profile"
	UserDataTypeCredentials UserDataType = "credentials"
	UserDataTypeBlueprints  UserDataType = "blueprints"
	UserDataTypeRoles       UserDataType = "roles"
	UserDataTypeKeys        UserDataType = "keys"
	UserDataTypeSudo        UserDataType = "sudo"
	UserDataTypeLocked      UserDataType = "locked"
	UserDataTypeOrg         UserDataType = "org"
	UserDataTypePosix       UserDataType = "posix"
	UserDataTypePassword    UserDataType = "password"
)

type UserDeleteEvalRequest added in v0.32.0

type UserDeleteEvalRequest struct {
	Resource UserResource
}

UserDeleteEvalRequest is the validated, typed model for user:delete policy evaluation. Use NewUserDeleteEvalRequest to start building, then chain With* methods and call Build to get a validated instance.

Like user:create, the acting principal is the admin performing the deletion, not the user being deleted, so callers evaluate this with the admin's own token.

func NewUserDeleteEvalRequest added in v0.32.0

func NewUserDeleteEvalRequest(username string) *UserDeleteEvalRequest

NewUserDeleteEvalRequest begins building a UserDeleteEvalRequest for the given username. Chain With* methods to supply additional fields, then call Build to validate and obtain the final struct.

func UserDeleteEvalRequestFromProto added in v0.32.0

func UserDeleteEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserDeleteEvalRequest, error)

UserDeleteEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserDeleteEvalRequest. Returns an error if the request does not conform to the user:delete contract.

func (*UserDeleteEvalRequest) Build added in v0.32.0

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserDeleteEvalRequest) ToProto added in v0.32.0

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserDeleteEvalRequest) Validate added in v0.32.0

func (r *UserDeleteEvalRequest) Validate() error

Validate checks the request against the user:delete contract. Implements EvalRequest.

func (*UserDeleteEvalRequest) WithOrg added in v0.32.0

WithOrg sets the user's organization on the resource.

type UserListEvalRequest

type UserListEvalRequest struct{}

UserListEvalRequest is the validated, typed model for user:list policy evaluation. No resource id is required; the subject claims determine access.

func NewUserListEvalRequest

func NewUserListEvalRequest() *UserListEvalRequest

NewUserListEvalRequest returns a UserListEvalRequest ready to be built.

func UserListEvalRequestFromProto

func UserListEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserListEvalRequest, error)

UserListEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserListEvalRequest.

func (*UserListEvalRequest) Build

Build returns the request. It is the required terminator for the builder chain.

func (*UserListEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserListEvalRequest) Validate

func (r *UserListEvalRequest) Validate() error

Validate is a no-op for user:list; no fields are required. Implements EvalRequest.

type UserOnboardEvalRequest

type UserOnboardEvalRequest struct {
	Resource UserResource
}

UserOnboardEvalRequest is the validated, typed model for user:onboard policy evaluation. Use NewUserOnboardEvalRequest to start building, then chain With* methods and call Build to get a validated instance.

func NewUserOnboardEvalRequest

func NewUserOnboardEvalRequest(username string) *UserOnboardEvalRequest

NewUserOnboardEvalRequest begins building a UserOnboardEvalRequest for the given username. Chain With* methods to supply additional fields, then call Build to validate and obtain the final struct.

func UserOnboardEvalRequestFromProto

func UserOnboardEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserOnboardEvalRequest, error)

UserOnboardEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserOnboardEvalRequest. Returns an error if the request does not conform to the user:onboard contract.

func (*UserOnboardEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserOnboardEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserOnboardEvalRequest) Validate

func (r *UserOnboardEvalRequest) Validate() error

Validate checks the request against the user:onboard contract. Implements EvalRequest.

func (*UserOnboardEvalRequest) WithIDP

WithIDP sets the identity provider name on the resource.

func (*UserOnboardEvalRequest) WithOrg

WithOrg sets the organization on the resource.

type UserReadEvalRequest

type UserReadEvalRequest struct {
	Resource UserResource
	DataType UserDataType
}

UserReadEvalRequest is the validated, typed model for user:read policy evaluation. Use NewUserReadEvalRequest to start building, then call Build to get a validated instance.

func NewUserReadEvalRequest

func NewUserReadEvalRequest(username string) *UserReadEvalRequest

NewUserReadEvalRequest begins building a UserReadEvalRequest for the given target username.

func UserReadEvalRequestFromProto

func UserReadEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserReadEvalRequest, error)

UserReadEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserReadEvalRequest.

func (*UserReadEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserReadEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserReadEvalRequest) Validate

func (r *UserReadEvalRequest) Validate() error

Validate checks the request against the user:read contract. Implements EvalRequest.

func (*UserReadEvalRequest) WithDataType

WithDataType sets the data type being accessed.

type UserResource

type UserResource struct {
	// ID is the username (resource.id in the EvaluateRequest).
	ID string

	// IDP is the identity provider through which the user was onboarded
	// (resource.attributes["idp"]).
	IDP string

	// Org is the user's organization (resource.attributes["org"]).
	Org string
}

UserResource holds the resource-scoped attributes for a user policy check.

type UserTokenCreateEvalRequest

type UserTokenCreateEvalRequest struct {
	Resource UserResource
	Context  TokenCreateContext
}

UserTokenCreateEvalRequest is the validated, typed model for token:create policy evaluation. The resource ID is the username of the token owner.

func NewUserTokenCreateEvalRequest

func NewUserTokenCreateEvalRequest(username string) *UserTokenCreateEvalRequest

NewUserTokenCreateEvalRequest begins building a UserTokenCreateEvalRequest for the given username (the token owner). Call WithSource then Build.

func UserTokenCreateEvalRequestFromProto

func UserTokenCreateEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserTokenCreateEvalRequest, error)

UserTokenCreateEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserTokenCreateEvalRequest.

func (*UserTokenCreateEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserTokenCreateEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserTokenCreateEvalRequest) Validate

func (r *UserTokenCreateEvalRequest) Validate() error

Validate checks the request against the token:create contract. Implements EvalRequest.

func (*UserTokenCreateEvalRequest) WithSource

WithSource sets the token creation source on the context.

type UserTokenDeleteEvalRequest added in v0.34.0

type UserTokenDeleteEvalRequest struct {
	Resource UserResource
}

UserTokenDeleteEvalRequest is the validated, typed model for token:delete policy evaluation. The resource ID is the username who owns the token being permanently deleted.

func NewUserTokenDeleteEvalRequest added in v0.34.0

func NewUserTokenDeleteEvalRequest(username string) *UserTokenDeleteEvalRequest

NewUserTokenDeleteEvalRequest begins building a UserTokenDeleteEvalRequest for the given username (the token owner). Call Build to validate.

func UserTokenDeleteEvalRequestFromProto added in v0.34.0

func UserTokenDeleteEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserTokenDeleteEvalRequest, error)

UserTokenDeleteEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserTokenDeleteEvalRequest.

func (*UserTokenDeleteEvalRequest) Build added in v0.34.0

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserTokenDeleteEvalRequest) ToProto added in v0.34.0

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserTokenDeleteEvalRequest) Validate added in v0.34.0

func (r *UserTokenDeleteEvalRequest) Validate() error

Validate checks the request against the token:delete contract. Implements EvalRequest.

type UserTokenReadEvalRequest

type UserTokenReadEvalRequest struct {
	Resource UserResource
}

UserTokenReadEvalRequest is the validated, typed model for token:read policy evaluation. The resource ID is the username whose tokens are being read.

func NewUserTokenReadEvalRequest

func NewUserTokenReadEvalRequest(username string) *UserTokenReadEvalRequest

NewUserTokenReadEvalRequest begins building a UserTokenReadEvalRequest for the given username (the token owner). Call Build to validate.

func UserTokenReadEvalRequestFromProto

func UserTokenReadEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserTokenReadEvalRequest, error)

UserTokenReadEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserTokenReadEvalRequest.

func (*UserTokenReadEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserTokenReadEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserTokenReadEvalRequest) Validate

func (r *UserTokenReadEvalRequest) Validate() error

Validate checks the request against the token:read contract. Implements EvalRequest.

type UserTokenWriteEvalRequest added in v0.34.0

type UserTokenWriteEvalRequest struct {
	Resource UserResource
}

UserTokenWriteEvalRequest is the validated, typed model for token:write policy evaluation. The resource ID is the username who owns the token being updated (active flag and/or scopes).

func NewUserTokenWriteEvalRequest added in v0.34.0

func NewUserTokenWriteEvalRequest(username string) *UserTokenWriteEvalRequest

NewUserTokenWriteEvalRequest begins building a UserTokenWriteEvalRequest for the given username (the token owner). Call Build to validate.

func UserTokenWriteEvalRequestFromProto added in v0.34.0

func UserTokenWriteEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserTokenWriteEvalRequest, error)

UserTokenWriteEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserTokenWriteEvalRequest.

func (*UserTokenWriteEvalRequest) Build added in v0.34.0

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserTokenWriteEvalRequest) ToProto added in v0.34.0

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserTokenWriteEvalRequest) Validate added in v0.34.0

func (r *UserTokenWriteEvalRequest) Validate() error

Validate checks the request against the token:write contract. Implements EvalRequest.

type UserWriteEvalRequest added in v0.29.11

type UserWriteEvalRequest struct {
	Resource UserResource
	DataType UserDataType
}

UserWriteEvalRequest is the validated, typed model for user:write policy evaluation. It covers all mutations to a user record: profile fields, roles, blueprints, and auth keys. Use NewUserWriteEvalRequest to build it.

func NewUserWriteEvalRequest added in v0.29.11

func NewUserWriteEvalRequest(username string) *UserWriteEvalRequest

NewUserWriteEvalRequest begins building a UserWriteEvalRequest for the given target username. Call WithDataType then Build to validate and obtain the final struct.

func UserWriteEvalRequestFromProto added in v0.29.11

func UserWriteEvalRequestFromProto(req *authzv1.EvaluateRequest) (*UserWriteEvalRequest, error)

UserWriteEvalRequestFromProto converts a gRPC EvaluateRequest into a validated UserWriteEvalRequest.

func (*UserWriteEvalRequest) Build added in v0.29.11

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*UserWriteEvalRequest) ToProto added in v0.29.11

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. Implements EvalRequest.

func (*UserWriteEvalRequest) Validate added in v0.29.11

func (r *UserWriteEvalRequest) Validate() error

Validate checks the request against the user:write contract. Implements EvalRequest.

func (*UserWriteEvalRequest) WithDataType added in v0.29.13

WithDataType sets the data type being mutated.

type UsernameObligation added in v0.30.11

type UsernameObligation struct {
	// Username is the single user the enforcer should restrict the listing to.
	Username string
}

UsernameObligation is the typed representation of the "username" obligation key returned by the policy engine in a PolicyResult for session:list.

func ParseUsernameObligation added in v0.30.11

func ParseUsernameObligation(obligations map[string]string) (UsernameObligation, bool)

ParseUsernameObligation reads the "username" key from the obligations map. Returns (obligation, true) when the key is present, (zero value, false) when the policy did not set a username obligation — in that case the enforcer should not scope the listing to a single user.

type WorkspaceAccessEvalRequest

type WorkspaceAccessEvalRequest struct {
	Action   WorkspaceAction
	Resource WorkspaceResource
}

WorkspaceAccessEvalRequest is the validated, typed model for workspace:read and workspace:delete. The resource id is the workspace name; the owner attribute identifies who owns it.

func NewWorkspaceAccessEvalRequest

func NewWorkspaceAccessEvalRequest(action WorkspaceAction, workspaceName string) *WorkspaceAccessEvalRequest

NewWorkspaceAccessEvalRequest begins building a WorkspaceAccessEvalRequest.

func WorkspaceAccessEvalRequestFromProto

func WorkspaceAccessEvalRequestFromProto(req *authzv1.EvaluateRequest) (*WorkspaceAccessEvalRequest, error)

WorkspaceAccessEvalRequestFromProto converts a gRPC EvaluateRequest into a validated WorkspaceAccessEvalRequest.

func (*WorkspaceAccessEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied.

func (*WorkspaceAccessEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest. Implements EvalRequest.

func (*WorkspaceAccessEvalRequest) Validate

func (r *WorkspaceAccessEvalRequest) Validate() error

Validate checks the request against the workspace:read / workspace:delete contract. Implements EvalRequest.

func (*WorkspaceAccessEvalRequest) WithOwner

WithOwner sets the owner username on the resource.

type WorkspaceAction

type WorkspaceAction string

WorkspaceAction is the typed representation of a workspace policy action.

const (
	// WorkspaceActionProvision is the action evaluated before a workspace is
	// provisioned. The full blueprint is carried in context["blueprint"] as a
	// YAML string. The policy result may carry patch obligations (keys prefixed
	// with ObligationKeyPatchPrefix) that the enforcer must apply to the
	// blueprint before provisioning proceeds.
	WorkspaceActionProvision WorkspaceAction = "workspace:provision"

	WorkspaceActionList    WorkspaceAction = "workspace:list"
	WorkspaceActionCreate  WorkspaceAction = "workspace:create"
	WorkspaceActionRead    WorkspaceAction = "workspace:read"
	WorkspaceActionDelete  WorkspaceAction = "workspace:delete"
	WorkspaceActionConnect WorkspaceAction = "workspace:connect"
	WorkspaceActionFiles   WorkspaceAction = "workspace:files"
	WorkspaceActionApp     WorkspaceAction = "workspace:app"
)

type WorkspaceAppEvalRequest

type WorkspaceAppEvalRequest struct {
	Resource WorkspaceResource
	App      string
	Op       WorkspaceAppOp
}

WorkspaceAppEvalRequest is the validated, typed model for workspace:app.

func NewWorkspaceAppEvalRequest

func NewWorkspaceAppEvalRequest(workspaceName, appName string) *WorkspaceAppEvalRequest

NewWorkspaceAppEvalRequest begins building a WorkspaceAppEvalRequest for the given workspace name and app name.

func WorkspaceAppEvalRequestFromProto

func WorkspaceAppEvalRequestFromProto(req *authzv1.EvaluateRequest) (*WorkspaceAppEvalRequest, error)

WorkspaceAppEvalRequestFromProto converts a gRPC EvaluateRequest into a validated WorkspaceAppEvalRequest.

func (*WorkspaceAppEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied.

func (*WorkspaceAppEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest. Implements EvalRequest.

func (*WorkspaceAppEvalRequest) Validate

func (r *WorkspaceAppEvalRequest) Validate() error

Validate checks the request against the workspace:app contract. Implements EvalRequest.

func (*WorkspaceAppEvalRequest) WithOp

WithOp sets the app operation.

func (*WorkspaceAppEvalRequest) WithOwner

WithOwner sets the owner username on the resource.

type WorkspaceAppOp

type WorkspaceAppOp string

WorkspaceAppOp is the operation applied to an app for workspace:app.

const (
	WorkspaceAppOpRead    WorkspaceAppOp = "read"
	WorkspaceAppOpInstall WorkspaceAppOp = "install"
	WorkspaceAppOpStart   WorkspaceAppOp = "start"
	WorkspaceAppOpStop    WorkspaceAppOp = "stop"
)

type WorkspaceConnectContext

type WorkspaceConnectContext struct {
	Type WorkspaceConnectType
	Port string // non-empty only when Type is WorkspaceConnectTypePortForward
}

WorkspaceConnectContext holds the session type and optional port for workspace:connect.

type WorkspaceConnectEvalRequest

type WorkspaceConnectEvalRequest struct {
	Resource WorkspaceResource
	Context  WorkspaceConnectContext
}

WorkspaceConnectEvalRequest is the validated, typed model for workspace:connect.

func NewWorkspaceConnectEvalRequest

func NewWorkspaceConnectEvalRequest(workspaceName string) *WorkspaceConnectEvalRequest

NewWorkspaceConnectEvalRequest begins building a WorkspaceConnectEvalRequest for the given workspace name.

func WorkspaceConnectEvalRequestFromProto

func WorkspaceConnectEvalRequestFromProto(req *authzv1.EvaluateRequest) (*WorkspaceConnectEvalRequest, error)

WorkspaceConnectEvalRequestFromProto converts a gRPC EvaluateRequest into a validated WorkspaceConnectEvalRequest.

func (*WorkspaceConnectEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied.

func (*WorkspaceConnectEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest. Implements EvalRequest.

func (*WorkspaceConnectEvalRequest) Validate

func (r *WorkspaceConnectEvalRequest) Validate() error

Validate checks the request against the workspace:connect contract. Implements EvalRequest.

func (*WorkspaceConnectEvalRequest) WithOwner

WithOwner sets the owner username on the resource.

func (*WorkspaceConnectEvalRequest) WithPort

WithPort sets the port; required when type is WorkspaceConnectTypePortForward.

func (*WorkspaceConnectEvalRequest) WithType

WithType sets the connection type.

type WorkspaceConnectType

type WorkspaceConnectType string

WorkspaceConnectType is the kind of interactive session for workspace:connect.

const (
	WorkspaceConnectTypeWebshell    WorkspaceConnectType = "webshell"
	WorkspaceConnectTypeWebfiles    WorkspaceConnectType = "webfiles"
	WorkspaceConnectTypePortForward WorkspaceConnectType = "portforward"
)

type WorkspaceEvalRequest

type WorkspaceEvalRequest struct {
	Action   WorkspaceAction
	Resource WorkspaceResource
	Context  WorkspaceProvisionContext
}

WorkspaceEvalRequest is the validated, typed model for workspace policy evaluation. Use NewWorkspaceEvalRequest to start building, then chain With* methods and call Build to get a validated instance. Use WorkspaceEvalRequestFromProto to convert directly from a gRPC EvaluateRequest.

func NewWorkspaceEvalRequest

func NewWorkspaceEvalRequest(action WorkspaceAction, workspaceID string) *WorkspaceEvalRequest

NewWorkspaceEvalRequest begins building a WorkspaceEvalRequest for the given action and workspace ID. Chain With* methods to supply additional fields, then call Build to validate and obtain the final struct.

func WorkspaceEvalRequestFromProto

func WorkspaceEvalRequestFromProto(req *authzv1.EvaluateRequest) (*WorkspaceEvalRequest, error)

WorkspaceEvalRequestFromProto converts a gRPC EvaluateRequest into a validated WorkspaceEvalRequest. Returns an error if the request does not conform to the workspace policy contract.

func (*WorkspaceEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied. It is the required terminator for the builder chain.

func (*WorkspaceEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest, attaching the supplied JWT token. The blueprint is marshaled to YAML and carried in context["blueprint"]. Implements EvalRequest.

func (*WorkspaceEvalRequest) Validate

func (r *WorkspaceEvalRequest) Validate() error

Validate checks the request against the workspace policy contract: the action must be recognized, and resource ID, owner, and blueprint context are all required for workspace:provision. Implements EvalRequest.

func (*WorkspaceEvalRequest) WithBlueprint

WithBlueprint sets the full blueprint struct in the provision context; required for WorkspaceActionProvision.

func (*WorkspaceEvalRequest) WithBlueprintName

func (r *WorkspaceEvalRequest) WithBlueprintName(name string) *WorkspaceEvalRequest

WithBlueprintName sets the blueprint name on the resource attributes.

func (*WorkspaceEvalRequest) WithMode

WithMode sets the provisioning mode; required for WorkspaceActionProvision.

func (*WorkspaceEvalRequest) WithOwner

func (r *WorkspaceEvalRequest) WithOwner(owner string) *WorkspaceEvalRequest

WithOwner sets the username of the user provisioning the workspace.

func (*WorkspaceEvalRequest) WithWorkload

func (r *WorkspaceEvalRequest) WithWorkload(name, namespace, kind string) *WorkspaceEvalRequest

WithWorkload sets the target workload fields; required when mode is WorkspaceProvisionModeInject.

type WorkspaceFilesEvalRequest

type WorkspaceFilesEvalRequest struct {
	Resource WorkspaceResource
	Op       WorkspaceFilesOp
}

WorkspaceFilesEvalRequest is the validated, typed model for workspace:files.

func NewWorkspaceFilesEvalRequest

func NewWorkspaceFilesEvalRequest(workspaceName string) *WorkspaceFilesEvalRequest

NewWorkspaceFilesEvalRequest begins building a WorkspaceFilesEvalRequest for the given workspace name.

func WorkspaceFilesEvalRequestFromProto

func WorkspaceFilesEvalRequestFromProto(req *authzv1.EvaluateRequest) (*WorkspaceFilesEvalRequest, error)

WorkspaceFilesEvalRequestFromProto converts a gRPC EvaluateRequest into a validated WorkspaceFilesEvalRequest.

func (*WorkspaceFilesEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied.

func (*WorkspaceFilesEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest. Implements EvalRequest.

func (*WorkspaceFilesEvalRequest) Validate

func (r *WorkspaceFilesEvalRequest) Validate() error

Validate checks the request against the workspace:files contract. Implements EvalRequest.

func (*WorkspaceFilesEvalRequest) WithOp

WithOp sets the file transfer direction.

func (*WorkspaceFilesEvalRequest) WithOwner

WithOwner sets the owner username on the resource.

type WorkspaceFilesOp

type WorkspaceFilesOp string

WorkspaceFilesOp is the direction of file transfer for workspace:files.

const (
	WorkspaceFilesOpDownload WorkspaceFilesOp = "download"
	WorkspaceFilesOpUpload   WorkspaceFilesOp = "upload"
)

type WorkspaceOwnerEvalRequest

type WorkspaceOwnerEvalRequest struct {
	Action   WorkspaceAction
	Resource WorkspaceResource
}

WorkspaceOwnerEvalRequest is the validated, typed model for workspace:list and workspace:create. Resource.ID is empty — there is no specific workspace; Resource.Owner identifies whose workspace collection is being accessed or extended.

func NewWorkspaceOwnerEvalRequest

func NewWorkspaceOwnerEvalRequest(action WorkspaceAction, owner string) *WorkspaceOwnerEvalRequest

NewWorkspaceOwnerEvalRequest begins building a WorkspaceOwnerEvalRequest for the given action and owner username.

func WorkspaceOwnerEvalRequestFromProto

func WorkspaceOwnerEvalRequestFromProto(req *authzv1.EvaluateRequest) (*WorkspaceOwnerEvalRequest, error)

WorkspaceOwnerEvalRequestFromProto converts a gRPC EvaluateRequest into a validated WorkspaceOwnerEvalRequest.

func (*WorkspaceOwnerEvalRequest) Build

Build validates the request and returns it if all constraints are satisfied.

func (*WorkspaceOwnerEvalRequest) ToProto

ToProto serializes the typed request into a gRPC EvaluateRequest. Implements EvalRequest.

func (*WorkspaceOwnerEvalRequest) Validate

func (r *WorkspaceOwnerEvalRequest) Validate() error

Validate checks the request against the workspace:list / workspace:create contract. Implements EvalRequest.

type WorkspaceProvisionContext

type WorkspaceProvisionContext struct {
	Blueprint         *models.Blueprint
	Mode              WorkspaceProvisionMode
	WorkloadName      string
	WorkloadNamespace string
	WorkloadKind      string
}

WorkspaceProvisionContext holds the full blueprint being provisioned and the provisioning mode. The enforcer must apply any ProvisionPatch obligations to Blueprint before provisioning proceeds.

type WorkspaceProvisionMode

type WorkspaceProvisionMode string

WorkspaceProvisionMode controls how the workspace is attached to its runtime.

const (
	// WorkspaceProvisionModeStandalone creates a new independent workspace pod.
	WorkspaceProvisionModeStandalone WorkspaceProvisionMode = "standalone"

	// WorkspaceProvisionModeInject injects the workspace into an existing
	// workload. WorkloadName, WorkloadNamespace, and WorkloadKind are required.
	WorkspaceProvisionModeInject WorkspaceProvisionMode = "inject"
)

type WorkspaceResource

type WorkspaceResource struct {
	// ID is the workspace name (resource.id in the EvaluateRequest).
	ID string

	// Owner is the username of the user provisioning the workspace
	// (resource.attributes["owner"]).
	Owner string

	// Blueprint is the blueprint name (resource.attributes["blueprint"]).
	Blueprint string
}

WorkspaceResource holds the resource-scoped attributes for a workspace policy check.

Jump to

Keyboard shortcuts

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