modelaccesspolicy

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPolicyName is the model access policy Obot creates for everyone when there are
	// none: the default gateway profile.
	DefaultPolicyName = system.ModelAccessPolicyPrefix + "-default"
)

Variables

This section is empty.

Functions

func AppliesToEveryone added in v0.28.0

func AppliesToEveryone(subjects []types.Subject) bool

AppliesToEveryone reports whether a policy's subjects include everyone.

func DefaultPolicy added in v0.28.0

func DefaultPolicy(models []types.ModelResource) *v1.ModelAccessPolicy

DefaultPolicy is the model access policy Obot creates for everyone when there are none. It grants the given models, the default model aliases.

func EnsureEveryoneProfile added in v0.28.0

func EnsureEveryoneProfile(ctx context.Context, c kclient.Client) (string, error)

EnsureEveryoneProfile returns a gateway profile that applies to everyone, for the guardrail policies upgrades create from message policies that applied to everyone. Guardrail policies apply through profile membership, not models, so a profile without models works for them. It is the Default Policy, or another policy for everyone. With no policies at all, it creates the Default Policy, as Obot does on first start, so that doesn't change; with policies but none for everyone, it creates an "Everyone" profile that grants no models. Names are fixed, so replicas starting together create one.

func EnsureProfile added in v0.28.0

func EnsureProfile(ctx context.Context, c kclient.Client, name, displayName string, subjects []types.Subject) error

EnsureProfile creates a gateway profile with the given name, display name and subjects, and no models, unless it exists.

func EnsureProfiles added in v0.28.0

func EnsureProfiles(ctx context.Context, c kclient.Client) ([]string, error)

EnsureProfiles returns the names of every gateway profile, for settings upgrades carry over to each of them. With no policies at all, it creates the Default Policy, as Obot does on first start, and returns it. Its name is fixed, so replicas starting together create one.

func IsAllowedDefaultModelAlias added in v0.25.0

func IsAllowedDefaultModelAlias(alias string) bool

IsAllowedDefaultModelAlias reports whether alias can be granted by a model access policy.

func IsAllowedModelUsage added in v0.25.0

func IsAllowedModelUsage(usage types.ModelUsage) bool

IsAllowedModelUsage reports whether usage can be granted by a model access policy.

func IsInvalidModelResource added in v0.25.0

func IsInvalidModelResource(err error) bool

IsInvalidModelResource reports whether err identifies a model resource that cannot be used in a model access policy.

func ValidateModelResource added in v0.25.0

func ValidateModelResource(
	ctx context.Context,
	reader kclient.Reader,
	namespace string,
	resource types.ModelResource,
) error

ValidateModelResource validates one model access policy resource.

func ValidateModelResources added in v0.25.0

func ValidateModelResources(
	ctx context.Context,
	reader kclient.Reader,
	namespace string,
	resources []types.ModelResource,
) error

ValidateModelResources validates all explicit models and default aliases in a policy. Wildcard selectors are allowed because they are selection rules rather than concrete model additions.

Types

type Helper

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

func NewHelper

func NewHelper(ctx context.Context, backend backend.Backend) (*Helper, error)

func (*Helper) GetUserAllowedModels

func (h *Helper) GetUserAllowedModels(user kuser.Info) (map[string]bool, bool, error)

GetUserAllowedModels returns the model IDs that a user can access. Model access policies only grant models with an allowed usage, including when a policy contains a wildcard or suffix selector.

func (*Helper) GetUserAllowedTargetModels added in v0.23.0

func (h *Helper) GetUserAllowedTargetModels(user kuser.Info, provider, dialect string) (allowed map[string]bool, allowAll bool, _ error)

GetUserAllowedTargetModels returns the set of provider-native target model ids (v1.Model.Spec.Manifest.TargetModel) for provider that the user is allowed to use. When dialect is non-empty, only models using that dialect are returned. A target is included iff a configured, active model maps to it and the user is allowed that model. This mirrors the access check enforced by the LLM passthrough: a target appears here iff a request for it would succeed.

allowAll reports that the user may use every model without a usage restriction. Policy wildcards are enumerated by GetUserAllowedModels instead, so they only include eligible usages. When dialect is empty and allowAll is true, there is nothing to enumerate, so the returned map is nil and callers should skip filtering rather than treat the nil map as "allow nothing". A dialect filter always returns an enumerated target set and allowAll=false.

func (*Helper) PolicyAllowedModels added in v0.28.0

func (h *Helper) PolicyAllowedModels(policy *v1.ModelAccessPolicy) map[string]bool

PolicyAllowedModels returns the model IDs a single model access policy (gateway profile) grants, evaluated as GetUserAllowedModels evaluates each of a user's policies.

func (*Helper) ResolveModelReference added in v0.25.0

func (h *Helper) ResolveModelReference(ctx context.Context, client kclient.Client, namespace, provider, reference string) (*v1.Model, error)

ResolveModelReference resolves a model reference for provider. References may be default model aliases, Model resource names, or provider-native target model IDs. Alias and resource references take precedence over target IDs.

func (*Helper) ResolveTargetModel added in v0.23.0

func (h *Helper) ResolveTargetModel(provider, target string) (*v1.Model, error)

ResolveTargetModel finds the model of a provider whose target model is exactly target, such as the LLM gateway's "anthropic/claude-sonnet-4-5". When several match, the most recently created one wins.

func (*Helper) ResolveUpstreamModelName added in v0.28.0

func (h *Helper) ResolveUpstreamModelName(provider, name string, usable func(*v1.Model) bool) (*v1.Model, error)

ResolveUpstreamModelName resolves a model name a client sent to a provider whose target models are qualified with an upstream provider prefix ("openai/gpt-4o"), such as the LLM gateway, when the name isn't one of its target models. Clients that only know provider-native IDs send a bare name, such as Claude Code sending "claude-sonnet-4-5", and Anthropic's API accepts undated aliases, such as "claude-sonnet-4-5" for "claude-sonnet-4-5-20250929", which providers list only in their dated form. So name is matched, with or without its upstream provider prefix, against each model's upstream ID and against the dated versions of it.

When several models match, the first of these wins: one the caller may use (usable, when it isn't nil); the provider that made the model ("openai", "anthropic") over one that hosts copies of it (Azure, Bedrock, a custom provider); an exact ID over a dated version; the latest dated version; the most recently created model.

func (*Helper) UserHasAccessToModel

func (h *Helper) UserHasAccessToModel(user kuser.Info, modelID string) (bool, error)

UserHasAccessToModel returns true if the user has access to the model. Access is granted when: - The user is an admin or owner - A ModelAccessPolicy with wildcard subject selector (*) includes the model (or uses wildcard model selector) - A ModelAccessPolicy directly references the user and includes the model (or uses wildcard model selector) - A ModelAccessPolicy references a group the user belongs to and includes the model (or uses wildcard model selector)

func (*Helper) UserPolicies added in v0.28.0

func (h *Helper) UserPolicies(user kuser.Info) ([]*v1.ModelAccessPolicy, error)

UserPolicies returns the model access policies (gateway profiles) that apply to the user: those naming everyone (*), the user, or one of their auth provider or Obot groups. Each policy is returned once.

func (*Helper) UserProfileIDs added in v0.28.0

func (h *Helper) UserProfileIDs(user kuser.Info) ([]string, error)

UserProfileIDs returns the IDs of the gateway profiles (model access policies) that apply to the user. Guardrail policies apply through all of them; budgets only through those that grant the requested model (see UserProfileIDsForModel).

func (*Helper) UserProfileIDsForModel added in v0.28.0

func (h *Helper) UserProfileIDsForModel(user kuser.Info, modelID string) ([]string, error)

UserProfileIDsForModel returns the IDs of the user's gateway profiles that grant modelID. A budget covers only its own profile's models, so these are the profiles whose budgets apply to a request for the model.

Jump to

Keyboard shortcuts

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