Documentation
¶
Overview ¶
Package access resolves resource permissions independently of HTTP routing. Tenant roles, API-key capabilities, and resource ownership guards remain separate checks; a KB grant does not replace them.
Index ¶
- Constants
- Variables
- func AuthorizeKBAccess(ctx context.Context, shares KBShareLookup, kbs []*types.KnowledgeBase) error
- func CloneDestination(ctx context.Context, sourceID string) (id string, create bool, creatorID string, err error)
- func HasKBGrant(ctx context.Context, kbID string, tenantID uint64, ...) bool
- func IsCrossTenantSuperuser(ctx context.Context, cfg *config.Config) bool
- func MessageReferencesFile(message *types.Message, reference string) bool
- func RejectMovingKnowledge(knowledge *types.Knowledge) error
- func RequireKBTransfer(ctx context.Context, source, target *types.KnowledgeBase, ...) error
- func RequireKBWrite(ctx context.Context, kb *types.KnowledgeBase) error
- func TransferTaskID(ctx context.Context) string
- func ValidateKBTransferCompatibility(source, target *types.KnowledgeBase, operation KBTransferOperation, ...) error
- func WithKBTaskWrite(ctx context.Context, kb *types.KnowledgeBase, expectedTenant uint64) (context.Context, error)
- func WithKBTransfer(ctx context.Context, source, target *types.KnowledgeBase, ...) (context.Context, error)
- func WithKBTransferTask(ctx context.Context, source, target *types.KnowledgeBase, ...) (context.Context, error)
- func WithSharedAgent(ctx context.Context, agent *types.CustomAgent) context.Context
- type AgentShareLookup
- type FileAccess
- func AuthorizeMessageFile(ctx context.Context, message *types.Message, reference string, ...) (FileAccess, error)
- func ResolveKBFile(ctx context.Context, grant *KBAccess, kbID, reference string, ...) (FileAccess, error)
- func ResolveMessageArtifact(ctx context.Context, message *types.Message, index int, ...) (FileAccess, error)
- func ResolveMessageFile(ctx context.Context, sessionID, messageID, reference string, ...) (FileAccess, error)
- type FileCatalog
- type KBAccess
- type KBPermissions
- type KBRequest
- type KBShareLookup
- type KBSharePermissionGuard
- type KBSharePermissions
- type KBTenantLookup
- type KBTransferOperation
- type KnowledgeOwnerLookup
- type MessageFileLookup
- type MessageKBShareAuthorizer
- type OwnershipDecision
- type OwnershipRequest
- type SharedAgentFileLookup
- type SharedAgentLookup
Constants ¶
const CreatorRoleFloor = types.TenantRoleContributor
CreatorRoleFloor is the lowest role at which creating a resource still lets the caller manage it. Below it a member mutates nothing, including what they created before being demoted.
Variables ¶
var ( ErrNotFound = errors.New("kb_access: not found") ErrForbidden = errors.New("kb_access: forbidden") ErrInvalidAgentSource = errors.New("kb_access: invalid agent source") )
Resource access errors retain distinct adapter response mappings.
var ( // ErrResourceNotFound means the ownership lookup found no resource visible // in the caller's tenant. HTTP adapters decide how to produce the 404. ErrResourceNotFound = errors.New("rbac: resource not found") // ErrOwnershipForbidden indicates neither ownership nor the required role. ErrOwnershipForbidden = errors.New("rbac: ownership or role insufficient") )
Functions ¶
func AuthorizeKBAccess ¶
func AuthorizeKBAccess( ctx context.Context, shares KBShareLookup, kbs []*types.KnowledgeBase, ) error
AuthorizeKBAccess rejects multi-KB searches whose scope includes a KB that the original caller is not entitled to read. Exact upstream grants support shared KB/agent execution; other foreign KBs need an organization permission check for the caller via KBPermissions, applying the 3-D cap (share role + caller's tenant-org role + tenant Viewer cap) introduced in Plan 3 of #1303.
Returning NotFound rather than Forbidden avoids leaking the existence of unauthorized KB IDs that the caller could not otherwise observe. Structured logs record the rejection with the offending kb_id (always safe — KB IDs are UUIDs without sensitive content) and the requesting tenant for audit.
func CloneDestination ¶
func CloneDestination(ctx context.Context, sourceID string) (id string, create bool, creatorID string, err error)
CloneDestination exposes only the destination already admitted by the request/worker; CopyKnowledgeBase cannot turn an empty ID into ambient write.
func HasKBGrant ¶
func HasKBGrant(ctx context.Context, kbID string, tenantID uint64, required types.OrgMemberRole) bool
HasKBGrant checks only previously resolved resource access. It never infers ownership from the execution tenant, and always reapplies API-key scope.
func IsCrossTenantSuperuser ¶ added in v0.9.0
IsCrossTenantSuperuser reports whether the caller's user attribute and the cluster-wide flag both allow bypassing workspace role gates. API-key and resource-scope authorization remain separate checks.
func MessageReferencesFile ¶
MessageReferencesFile examines only persisted rendering/output fields. Tool arguments and request metadata are not evidence of a returned file.
func RejectMovingKnowledge ¶
RejectMovingKnowledge is shared by admission and persisted service checks. Admission prevents misleading task acceptance; workers must recheck after enqueue because a move can claim the document in the intervening window.
func RequireKBTransfer ¶
func RequireKBTransfer(ctx context.Context, source, target *types.KnowledgeBase, operation KBTransferOperation) error
RequireKBTransfer consumes the exact caller, operation and resource-pair grant.
func RequireKBWrite ¶
func RequireKBWrite(ctx context.Context, kb *types.KnowledgeBase) error
RequireKBWrite consumes an explicit operation grant. Tenant ownership and role checks belong to the entry point that resolved the grant; an execution tenant alone, or a shared-agent/read grant, never authorizes a mutation.
func TransferTaskID ¶
TransferTaskID returns the admitted operation identity for retry checkpoints.
func ValidateKBTransferCompatibility ¶
func ValidateKBTransferCompatibility( source, target *types.KnowledgeBase, operation KBTransferOperation, mode string, tenant *types.Tenant, ) error
ValidateKBTransferCompatibility is shared by synchronous admission and task execution, so invalid modes/configurations fail before resource mutations.
func WithKBTaskWrite ¶
func WithKBTaskWrite(ctx context.Context, kb *types.KnowledgeBase, expectedTenant uint64) (context.Context, error)
WithKBTaskWrite is for trusted workers continuing an admitted operation. The worker supplies a server-loaded KB and verifies its child-resource bindings before any side effects. It grants only this KB, preserves the original caller (including an absent caller), and never creates an Admin. This is a task execution grant, not a way to authorize an incoming request.
func WithKBTransfer ¶
func WithKBTransfer( ctx context.Context, source, target *types.KnowledgeBase, operation KBTransferOperation, taskID string, create bool, ) (context.Context, error)
WithKBTransfer admits a pair of resources after the entry point has resolved the source and destination grants and applied its creator/role policy. A new clone destination must be a server-reserved ID; it is not an existing KB.
func WithKBTransferTask ¶
func WithKBTransferTask( ctx context.Context, source, target *types.KnowledgeBase, expectedTenant uint64, operation KBTransferOperation, taskID string, create bool, ) (context.Context, error)
WithKBTransferTask continues an admitted task. Both KBs must first be loaded with their persisted owners (or a reserved new clone destination). This scope cannot authorize a different pair or upgrade the worker into a tenant user.
func WithSharedAgent ¶
WithSharedAgent scopes execution after the caller has authorized this exact agent. Only its configured KBs receive read access; other source-tenant KBs and the source tenant's organization memberships are not inherited.
Types ¶
type AgentShareLookup ¶
type AgentShareLookup interface {
SharedAgentLookup
}
AgentShareLookup also supports read access through any reachable agent.
type FileAccess ¶
FileAccess is a request-local result, produced before storage is opened. Physical locators are not a substitute for KB/message authorization.
func AuthorizeMessageFile ¶
func AuthorizeMessageFile(ctx context.Context, message *types.Message, reference string, agents SharedAgentFileLookup, catalog FileCatalog, kbShares MessageKBShareAuthorizer, ) (FileAccess, error)
AuthorizeMessageFile also serves index-based artifact downloads after their session/message lookup. It never accepts an unchecked client message.
func ResolveKBFile ¶
func ResolveKBFile( ctx context.Context, grant *KBAccess, kbID, reference string, catalog FileCatalog, bindings interfaces.KBResourceLookup, ) (FileAccess, error)
ResolveKBFile requires the route's exact KB grant and an independent live explicit binding check. Rewriting the execution tenant is insufficient.
func ResolveMessageArtifact ¶
func ResolveMessageArtifact(ctx context.Context, message *types.Message, index int, agents SharedAgentFileLookup, catalog FileCatalog, kbShares MessageKBShareAuthorizer, ) (FileAccess, error)
ResolveMessageArtifact selects a persisted artifact after session ownership was checked. Session-owned output stays downloadable independently of the agent; source-owned output still requires its current sharing permission.
func ResolveMessageFile ¶
func ResolveMessageFile(ctx context.Context, sessionID, messageID, reference string, messages MessageFileLookup, agents SharedAgentFileLookup, catalog FileCatalog, kbShares MessageKBShareAuthorizer, ) (FileAccess, error)
ResolveMessageFile loads the session-authorized message using the original caller and rechecks its current sharing relationships on every request.
type FileCatalog ¶
type FileCatalog interface {
ResolvePath(context.Context, string) (string, *types.StoredResource, error)
}
FileCatalog resolves logical references to their stored owner and locator.
type KBAccess ¶
type KBAccess struct {
KnowledgeBase *types.KnowledgeBase
Caller types.Caller
EffectiveTenantID uint64
Permission types.OrgMemberRole
// contains filtered or unexported fields
}
KBAccess binds a resolved resource permission to its original caller.
func ResolveKB ¶
func ResolveKB(ctx context.Context, request KBRequest, kb *types.KnowledgeBase, required types.OrgMemberRole, shares KBShareLookup, agents AgentShareLookup, ) (*KBAccess, error)
ResolveKB authorizes a server-loaded KB (or a document's persisted KB/tenant reference). Its tenant is authoritative; resolving the owner from a share record again would add a lookup and a second source of truth. It never treats an effective resource tenant as the caller. Share lookup errors do not grant access; an independent agent grant may still allow reading. An explicit agent selector never falls back to another agent.
type KBPermissions ¶
type KBPermissions struct {
// contains filtered or unexported fields
}
KBPermissions combines caller ownership, exact context grants and organization shares for one service operation. Pass nil shares when that entry point does not permit organization expansion (for example, a caller without a user).
func NewKBPermissions ¶
func NewKBPermissions(ctx context.Context, shares KBShareLookup) *KBPermissions
NewKBPermissions resolves reads for one caller and operation.
func (*KBPermissions) Check ¶
func (p *KBPermissions) Check(kbID string, ownerTenantID uint64, required types.OrgMemberRole) (bool, error)
Check combines caller ownership, exact grants and organization sharing.
type KBRequest ¶
KBRequest keeps the authenticated caller separate from the resource tenant. AgentSourceTenantID is parsed only when the explicit-agent fallback is used.
type KBShareLookup ¶
type KBShareLookup interface {
}
KBShareLookup resolves organization sharing with the caller role cap.
type KBSharePermissionGuard ¶
type KBSharePermissionGuard = KBShareLookup
KBSharePermissionGuard is the org-share surface the message-scoped proxy needs for its shared-KB fallback.
type KBSharePermissions ¶
type KBSharePermissions struct {
// contains filtered or unexported fields
}
KBSharePermissions resolves organization grants for one caller during one operation. It deliberately does not grant tenant ownership or shared-agent access. Callers retain their own policy for lookup failures (abort or filter). Create a new instance for each operation; it is not a cross-request cache and must not be shared between goroutines.
func NewKBSharePermissions ¶
func NewKBSharePermissions( ctx context.Context, lookup KBShareLookup, tenantID uint64, role types.TenantRole, ) *KBSharePermissions
NewKBSharePermissions creates a request-local permission cache.
func (*KBSharePermissions) Check ¶
func (p *KBSharePermissions) Check(kbID string, required types.OrgMemberRole) (bool, error)
Check tests the required role against the cached organization permission.
func (*KBSharePermissions) Permission ¶
func (p *KBSharePermissions) Permission(kbID string) (types.OrgMemberRole, bool, error)
Permission caches both grants and failures so multiple documents/chunks in a KB observe the same decision, without repeating the membership queries.
type KBTenantLookup ¶
type KBTenantLookup interface {
GetKnowledgeBasesByIDsOnly(ctx context.Context, ids []string) ([]*types.KnowledgeBase, error)
}
KBTenantLookup resolves knowledge bases without a tenant filter, so a message's persisted retrieval evidence can be mapped back to the knowledge bases the chunks were retrieved from.
type KBTransferOperation ¶
type KBTransferOperation string
KBTransferOperation selects the source and destination permission contract.
const ( KBTransferClone KBTransferOperation = "clone" KBTransferMove KBTransferOperation = "move" )
Supported knowledge-base transfer operations.
type KnowledgeOwnerLookup ¶
type KnowledgeOwnerLookup interface {
GetKnowledgeByIDOnly(ctx context.Context, id string) (*types.Knowledge, error)
}
KnowledgeOwnerLookup resolves a knowledge entry to its knowledge base for message references that predate the denormalized knowledge_base_id field.
type MessageFileLookup ¶
type MessageFileLookup interface {
GetMessage(ctx context.Context, sessionID, messageID string) (*types.Message, error)
}
MessageFileLookup is the narrow message-service surface needed by the message-scoped file proxy. Keeping it small makes the authorization boundary independently testable.
type MessageKBShareAuthorizer ¶
type MessageKBShareAuthorizer struct {
}
MessageKBShareAuthorizer bundles the read-only lookups behind the message proxy's org-shared-KB fallback. A nil ShareGuard or KBs lookup disables the fallback. A live Bindings lookup is also required and can be supplied by the resource catalog. A nil Knowledges lookup only disables the pre-denormalization KnowledgeID path.
type OwnershipDecision ¶
OwnershipDecision contains the details adapters need for logs and audits. The error returned with it determines whether access was allowed.
func CheckOwnershipOrRole ¶
func CheckOwnershipOrRole( request OwnershipRequest, required types.TenantRole, lookup func() (string, error), ) (OwnershipDecision, error)
CheckOwnershipOrRole performs no resource lookup when API-key authorization, role, superuser status, or the RBAC rollout policy already settles the gate. The lookup must enforce tenant visibility before returning a creator ID.
type OwnershipRequest ¶
type OwnershipRequest struct {
UserID string
Role types.TenantRole
APIKey bool
CrossTenantSuperuser bool
Enforce bool
}
OwnershipRequest carries server-resolved identity and rollout policy. The cross-tenant bypass must already account for the cluster configuration. This gate does not replace API-key capabilities or resource-scope checks.
type SharedAgentFileLookup ¶
type SharedAgentFileLookup interface {
ctx context.Context,
tenantID uint64,
callerTenantRole types.TenantRole,
agentID string,
sourceTenantID ...uint64,
) (*types.CustomAgent, error)
}
SharedAgentFileLookup verifies that a source workspace's agent is still shared to the caller. Revoking the share therefore also revokes historical message-file access.
type SharedAgentLookup ¶
type SharedAgentLookup interface {
}
SharedAgentLookup verifies access to a particular shared agent.