Documentation
¶
Index ¶
- Constants
- Variables
- func NewAppContext(ctx context.Context, av AppValidator) context.Context
- func NewGrpcAppCredential(ak *AccessKey) credentials.PerRPCCredentials
- func Sign(header TokenHeader, claims any, key any) (string, error)
- type AccessKey
- func (it *AccessKey) Allow(scopes ...string) bool
- func (*AccessKey) Descriptor() ([]byte, []int)deprecated
- func (it *AccessKey) Export() string
- func (x *AccessKey) GetDescription() string
- func (x *AccessKey) GetId() string
- func (x *AccessKey) GetRoles() []string
- func (x *AccessKey) GetScopes() []string
- func (x *AccessKey) GetSecret() string
- func (x *AccessKey) GetState() string
- func (x *AccessKey) GetType() string
- func (x *AccessKey) GetUser() string
- func (*AccessKey) ProtoMessage()
- func (x *AccessKey) ProtoReflect() protoreflect.Message
- func (x *AccessKey) Reset()
- func (x *AccessKey) String() string
- type AccessKeyManager
- type AccessToken
- type AppCredential
- type AppValidator
- type AuthClaims
- type Role
- func (*Role) Descriptor() ([]byte, []int)deprecated
- func (x *Role) GetDescription() string
- func (x *Role) GetName() string
- func (x *Role) GetPermissions() []string
- func (x *Role) GetState() string
- func (x *Role) GetTitle() string
- func (*Role) ProtoMessage()
- func (x *Role) ProtoReflect() protoreflect.Message
- func (x *Role) Reset()
- func (x *Role) String() string
- type Signer
- type SignerManager
- type TokenHeader
Constants ¶
View Source
const ( AccessKeyStateActive = "active" AccessKeyStateDisabled = "disabled" )
Variables ¶
View Source
var DefaultSigner = &hmacSigner{"HS256", crypto.SHA256}
View Source
var File_inauth_proto protoreflect.FileDescriptor
View Source
var Signers = SignerManager{ // contains filtered or unexported fields }
Functions ¶
func NewAppContext ¶
func NewAppContext(ctx context.Context, av AppValidator) context.Context
func NewGrpcAppCredential ¶
func NewGrpcAppCredential(ak *AccessKey) credentials.PerRPCCredentials
Types ¶
type AccessKey ¶
type AccessKey struct {
// Unique identifier for this access key.
// Generated as a semi-sequential hex string (e.g., "67f3a1b2c3d4e5f6").
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" toml:"id,omitempty"`
// The secret key used to sign AccessToken payloads.
// Generated as a 48-character base62 string. Must be kept confidential.
Secret string `protobuf:"bytes,2,opt,name=secret,proto3" json:"secret,omitempty" toml:"secret,omitempty"`
// The user or service principal this key belongs to.
User string `protobuf:"bytes,3,opt,name=user,proto3" json:"user,omitempty" toml:"user,omitempty"`
// The type of credential. Accepted values:
// - "User": human user access key (created via NewUserAccessKey).
// - "App": machine/service access key (created via NewAppAccessKey).
//
// The type affects token validation; for example, "App" tokens enforce
// a strict 60-second issued-at (iat) window to prevent replay attacks.
Type string `protobuf:"bytes,4,opt,name=type,proto3" json:"type,omitempty" toml:"type,omitempty"`
// The lifecycle state of this access key (e.g., "active", "disabled").
State string `protobuf:"bytes,5,opt,name=state,proto3" json:"state,omitempty" toml:"state,omitempty"`
// The names of RBAC roles assigned to this key. Role definitions are
// registered separately via AccessKeyManager.SetRole() and map to a
// set of permissions.
Roles []string `protobuf:"bytes,6,rep,name=roles,proto3" json:"roles,omitempty" toml:"roles,omitempty"`
// Fine-grained permission scopes granted to this key. Scopes are checked
// via the Allow() method, which requires ALL specified scopes to be present.
// Example scopes might include resource-level or action-level identifiers.
Scopes []string `protobuf:"bytes,11,rep,name=scopes,proto3" json:"scopes,omitempty" toml:"scopes,omitempty"`
// Optional. A human-readable description of this access key's purpose.
Description string `protobuf:"bytes,13,opt,name=description,proto3" json:"description,omitempty" toml:"description,omitempty"`
// contains filtered or unexported fields
}
AccessKey represents a long-lived credential used to authenticate and authorize API requests. Each key consists of a publicly visible ID and a secret that must be kept confidential.
AccessKeys are managed by AccessKeyManager and can be of two types:
- "User": represents a human user credential.
- "App": represents a machine/service credential used for programmatic access (e.g., gRPC calls between internal services).
Authentication flow:
- The client presents an AccessToken (signed with the AccessKey secret).
- The server resolves the AccessKey by ID from AccessKeyManager.
- The token signature is verified against the key's secret.
- Authorization is checked via roles, permissions, and scopes.
func NewAccessKey ¶
func NewAccessKey() *AccessKey
func NewAppAccessKey ¶
func NewAppAccessKey() *AccessKey
func NewUserAccessKey ¶
func NewUserAccessKey() *AccessKey
func ParseAccessKey ¶
func (*AccessKey) Descriptor
deprecated
func (*AccessKey) GetDescription ¶
func (*AccessKey) ProtoMessage ¶
func (*AccessKey) ProtoMessage()
func (*AccessKey) ProtoReflect ¶
func (x *AccessKey) ProtoReflect() protoreflect.Message
type AccessKeyManager ¶
type AccessKeyManager struct {
// contains filtered or unexported fields
}
func NewAccessKeyManager ¶
func NewAccessKeyManager() *AccessKeyManager
func (*AccessKeyManager) Count ¶
func (it *AccessKeyManager) Count() int
func (*AccessKeyManager) Del ¶
func (it *AccessKeyManager) Del(id string) error
func (*AccessKeyManager) Key ¶
func (it *AccessKeyManager) Key(id string) *AccessKey
func (*AccessKeyManager) Set ¶
func (it *AccessKeyManager) Set(k *AccessKey) error
func (*AccessKeyManager) SetRole ¶
func (it *AccessKeyManager) SetRole(r *Role) *AccessKeyManager
type AccessToken ¶
type AccessToken struct {
Header TokenHeader
Claims AuthClaims
// contains filtered or unexported fields
}
func NewAccessToken ¶
func NewAccessToken(accessToken string) (*AccessToken, error)
func NewAccessTokenWithContext ¶
func NewAccessTokenWithContext(ctx context.Context) (*AccessToken, error)
func (*AccessToken) IsExpired ¶
func (it *AccessToken) IsExpired() bool
func (*AccessToken) String ¶
func (it *AccessToken) String() string
func (*AccessToken) Verify ¶
func (it *AccessToken) Verify(keyMgr *AccessKeyManager) (*AccessKey, error)
type AppCredential ¶
type AppCredential interface {
AuthToken() string
}
func NewAppCredential ¶
func NewAppCredential(ak *AccessKey, args ...any) AppCredential
type AppValidator ¶
type AppValidator interface {
Verify(keyMgr *AccessKeyManager) error
AccessKey() *AccessKey
Allow(scopes ...string) bool
}
func AppContext ¶
func AppContext(ctx context.Context) AppValidator
func NewAppValidator ¶
func NewAppValidator(token string) (AppValidator, error)
func NewGrpcAppValidator ¶
func NewGrpcAppValidator(ctx context.Context, keyMgr *AccessKeyManager) (AppValidator, error)
type AuthClaims ¶
type Role ¶
type Role struct {
// The unique name identifier of the role (e.g., "admin", "viewer").
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty" toml:"name,omitempty"`
// Optional. A human-readable title for the role. Typically this
// is limited to 100 UTF-8 bytes.
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty" toml:"title,omitempty"`
// Optional. A human-readable description for the role.
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty" toml:"description,omitempty"`
// The names of the permissions this role grants when bound to an
// AccessKey. Permissions are stored as a set within AccessKeyManager
// for efficient lookup.
Permissions []string `protobuf:"bytes,7,rep,name=permissions,proto3" json:"permissions,omitempty" toml:"permissions,omitempty"`
// The lifecycle state of the role (e.g., "active", "disabled").
State string `protobuf:"bytes,10,opt,name=state,proto3" json:"state,omitempty" toml:"state,omitempty"`
// contains filtered or unexported fields
}
Role defines a named collection of permissions in the RBAC (Role-Based Access Control) system. Roles are registered with AccessKeyManager and then referenced by name from AccessKey.roles.
Permission resolution flow:
AccessKey.roles → Role lookup → Role.permissions
func (*Role) Descriptor
deprecated
func (*Role) GetDescription ¶
func (*Role) GetPermissions ¶
func (*Role) ProtoMessage ¶
func (*Role) ProtoMessage()
func (*Role) ProtoReflect ¶
func (x *Role) ProtoReflect() protoreflect.Message
type SignerManager ¶
type SignerManager struct {
// contains filtered or unexported fields
}
func (*SignerManager) Register ¶
func (it *SignerManager) Register(s Signer)
func (*SignerManager) Signer ¶
func (it *SignerManager) Signer(name string) Signer
type TokenHeader ¶
Click to show internal directories.
Click to hide internal directories.