Documentation
¶
Index ¶
- Constants
- Variables
- type Grant
- type Service
- func (s *Service) CreateDelegationOnlyToken(ctx context.Context, principal authn.Principal, expires *time.Time) (Token, string, error)
- func (s *Service) CreateInventoryOnlyToken(ctx context.Context, principal authn.Principal, expires *time.Time) (Token, string, error)
- func (s *Service) CreateToken(ctx context.Context, principal authn.Principal, expires *time.Time, ...) (Token, string, error)
- func (s *Service) Delegate(ctx context.Context, principal authn.Principal, expires *time.Time, ...) (Token, string, error)
- func (s *Service) Grants(ctx context.Context, principal authn.Principal, afterID int64) ([]Grant, bool, error)
- func (s *Service) RevokeGrant(ctx context.Context, principal authn.Principal, id int64) error
- func (s *Service) RevokeToken(ctx context.Context, principal authn.Principal, id int64) error
- func (s *Service) Tokens(ctx context.Context, principal authn.Principal) ([]Token, error)
- type Token
Constants ¶
const MaxDelegatedTokenLifetime = time.Hour
MaxDelegatedTokenLifetime bounds tokens minted by Delegate: they exist so a service account can hand a narrowed credential to a single job.
const MaxTokenLifetime = 90 * 24 * time.Hour
Variables ¶
var ( ErrForbidden = errors.New("forbidden") ErrInvalid = errors.New("invalid token request") )
Functions ¶
This section is empty.
Types ¶
type Grant ¶
type Grant struct {
ID int64 `json:"id"`
ClientName string `json:"client_name"`
Scope string `json:"scope,omitempty"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt time.Time `json:"last_used_at"`
ExpiresAt time.Time `json:"expires_at"`
}
Grant is a connected MCP client as the account owner sees it.
type Service ¶
type Service struct {
Manager authn.TokenManager
Authorizer repositoryAuthorizer
// Repositories validates the target of a delegation-only mint. When nil,
// delegation-only principals are refused (fail closed).
Repositories activeRepositoryLookup
}
func (*Service) CreateDelegationOnlyToken ¶ added in v0.5.0
func (s *Service) CreateDelegationOnlyToken(ctx context.Context, principal authn.Principal, expires *time.Time) (Token, string, error)
CreateDelegationOnlyToken mints an administrator token whose only power is Delegate. It has no repository ceiling, so it never needs re-widening as repositories are onboarded, and it is refused by every other endpoint, so a leak grants no direct repository access. Only an interactive administrator may mint one; API tokens of any kind cannot.
func (*Service) CreateInventoryOnlyToken ¶ added in v0.13.0
func (s *Service) CreateInventoryOnlyToken(ctx context.Context, principal authn.Principal, expires *time.Time) (Token, string, error)
CreateInventoryOnlyToken mints an administrator token whose only power is reading the repository inventory. It has no repository ceiling, so it sees repositories onboarded after it was minted, and it is refused by every other endpoint and cannot delegate, so a leak exposes which repositories exist and how far they are indexed but none of their content. Only an interactive administrator may mint one; API tokens of any kind cannot.
func (*Service) CreateToken ¶
func (*Service) Delegate ¶
func (s *Service) Delegate(ctx context.Context, principal authn.Principal, expires *time.Time, repositoryIDs []int64) (Token, string, error)
Delegate lets an administrator authenticated with an API token mint a further token for the same user that is narrower than its own: a non-empty repository ceiling inside the caller's, and a mandatory expiry within MaxDelegatedTokenLifetime. Interactive sessions use CreateToken instead.
The child is stored as delegated and is refused here, so delegation is one generation deep: a child cannot renew itself past its own expiry, and revoking or expiring the parent ends the chain within an hour.
func (*Service) Grants ¶
func (s *Service) Grants(ctx context.Context, principal authn.Principal, afterID int64) ([]Grant, bool, error)
Grants lists the caller's live MCP OAuth grants. Like token management this is reserved for interactive sessions: an access token must not enumerate or revoke its siblings.
func (*Service) RevokeGrant ¶
RevokeGrant revokes one of the caller's MCP OAuth grants.
func (*Service) RevokeToken ¶
type Token ¶
type Token struct {
ID int64 `json:"id"`
Prefix string `json:"prefix"`
RepositoryIDs []int64 `json:"repository_ids,omitempty"`
DelegationOnly bool `json:"delegation_only,omitempty"`
InventoryOnly bool `json:"inventory_only,omitempty"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}