Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateAPIKey() (plainKey string, keyHash string, keyID string, prefix string, err error)
- func GenerateSessionID() (string, error)
- func GenerateUID() (string, error)
- func HasPermission(role Role, explicitPerms []string, required Permission) bool
- func HashAPIKey(key string) string
- func HashPassword(password string) (string, error)
- func ParsePermissionsJSON(s string) []string
- func ValidAccessLevel(level string) bool
- func VerifyPassword(password, hash string) bool
- type APIKey
- type ActorContext
- type Claims
- type DB
- func (db *DB) CleanupExpiredSessions() (int64, error)
- func (db *DB) Close() error
- func (db *DB) CountUsers() (int, error)
- func (db *DB) CreateAPIKey(key *APIKey) (int64, error)
- func (db *DB) CreateSession(session *Session) (int64, error)
- func (db *DB) CreateUser(user *User) (int64, error)
- func (db *DB) CreateUserDeployment(ud *UserDeployment) (int64, error)
- func (db *DB) DeactivateAPIKey(id int64) error
- func (db *DB) DeleteAPIKey(id int64) error
- func (db *DB) DeleteAllUserDeployments(userID int64) error
- func (db *DB) DeleteUser(id int64) error
- func (db *DB) DeleteUserDeployment(userID int64, deploymentName string) error
- func (db *DB) GetAPIKeyByHash(hash string) (*APIKey, error)
- func (db *DB) GetAPIKeyByID(id int64) (*APIKey, error)
- func (db *DB) GetAPIKeysByUserID(userID int64) ([]APIKey, error)
- func (db *DB) GetAllAPIKeys() ([]APIKey, error)
- func (db *DB) GetDeploymentUsers(deploymentName string) ([]UserDeployment, error)
- func (db *DB) GetSessionByID(sessionID string) (*Session, error)
- func (db *DB) GetSessionByTokenHash(hash string) (*Session, error)
- func (db *DB) GetUserByID(id int64) (*User, error)
- func (db *DB) GetUserByUID(uid string) (*User, error)
- func (db *DB) GetUserByUsername(username string) (*User, error)
- func (db *DB) GetUserDeployments(userID int64) ([]UserDeployment, error)
- func (db *DB) GetUserDeploymentsMap(userID int64) (map[string]string, error)
- func (db *DB) GetUsers() ([]User, error)
- func (db *DB) RevokeSession(sessionID string) error
- func (db *DB) RevokeUserSessions(userID int64) error
- func (db *DB) UpdateAPIKey(key *APIKey) error
- func (db *DB) UpdateAPIKeyLastUsed(id int64, ip string) error
- func (db *DB) UpdateUser(user *User) error
- func (db *DB) UpdateUserDeployment(userID int64, deploymentName, accessLevel string) error
- func (db *DB) UpdateUserLastLogin(id int64) error
- func (db *DB) UpdateUserPassword(id int64, passwordHash string) error
- type DeploymentAccess
- type Manager
- func (m *Manager) AssignDeployment(userID int64, deploymentName, accessLevel string, grantedBy int64) error
- func (m *Manager) BuildActorContext(user *User, apiKey *APIKey) (*ActorContext, error)
- func (m *Manager) CleanupExpiredSessions() (int64, error)
- func (m *Manager) Close() error
- func (m *Manager) CreateAPIKey(userID int64, name, description string, role Role, permissions []string, ...) (*APIKey, string, error)
- func (m *Manager) CreateAPIKeyFromRaw(rawKey string, userID int64, name, description string, role Role, ...) (*APIKey, error)
- func (m *Manager) CreateSession(userID int64, apiKeyID int64, sessionID, tokenHash, clientIP string, ...) (*Session, error)
- func (m *Manager) CreateUser(username, email, password string, role Role, permissions []string) (*User, error)
- func (m *Manager) DeactivateAPIKey(id int64) error
- func (m *Manager) DeleteAPIKey(id int64) error
- func (m *Manager) DeleteUser(id int64, actorID int64) error
- func (m *Manager) GetAPIKey(id int64) (*APIKey, error)
- func (m *Manager) GetAPIKeysByUser(userID int64) ([]APIKey, error)
- func (m *Manager) GetAllAPIKeys() ([]APIKey, error)
- func (m *Manager) GetDeploymentUsers(deploymentName string) ([]UserDeployment, error)
- func (m *Manager) GetLegacyKeyIndex(key string) int
- func (m *Manager) GetSessionByID(sessionID string) (*Session, error)
- func (m *Manager) GetSessionByToken(tokenHash string) (*Session, error)
- func (m *Manager) GetUser(id int64) (*User, error)
- func (m *Manager) GetUserByUID(uid string) (*User, error)
- func (m *Manager) GetUserByUsername(username string) (*User, error)
- func (m *Manager) GetUserDeployments(userID int64) ([]UserDeployment, error)
- func (m *Manager) GetUserDeploymentsMap(userID int64) (map[string]string, error)
- func (m *Manager) GetUsers() ([]User, error)
- func (m *Manager) RemoveDeploymentAccess(userID int64, deploymentName string) error
- func (m *Manager) RevokeSession(sessionID string) error
- func (m *Manager) RevokeUserSessions(userID int64) error
- func (m *Manager) UpdateAPIKey(id int64, name, description string, role Role, permissions []string, ...) (*APIKey, error)
- func (m *Manager) UpdateAPIKeyLastUsed(keyID int64, ip string) error
- func (m *Manager) UpdatePassword(userID int64, newPassword string) error
- func (m *Manager) UpdateUser(user *User) error
- func (m *Manager) UpdateUserDeployment(userID int64, deploymentName, accessLevel string) error
- func (m *Manager) ValidateAPIKey(plainKey string) (*APIKey, *User, error)
- func (m *Manager) ValidateCredentials(username, password string) (*User, error)
- func (m *Manager) ValidateLegacyAPIKey(key string) bool
- type Middleware
- func (m *Middleware) ActorForTokenString(token string, clientIP string) (*ActorContext, error)
- func (m *Middleware) GenerateJWT(username string) (string, error)
- func (m *Middleware) GenerateJWTForUser(user *User, sessionID string) (string, error)
- func (m *Middleware) GetAuthStatus(c *gin.Context)
- func (m *Middleware) IsAuthEnabled() bool
- func (m *Middleware) Login(c *gin.Context)
- func (m *Middleware) RequireAuth() gin.HandlerFunc
- func (m *Middleware) RequireDeploymentAccess(level string) gin.HandlerFunc
- func (m *Middleware) RequirePermission(perms ...Permission) gin.HandlerFunc
- func (m *Middleware) SetManager(manager *Manager)
- func (m *Middleware) ValidateToken(c *gin.Context)
- func (m *Middleware) ValidateTokenString(token string) bool
- type Permission
- type Role
- type Session
- type User
- type UserDeployment
Constants ¶
View Source
const ( AccessLevelRead = "read" AccessLevelWrite = "write" AccessLevelAdmin = "admin" )
Variables ¶
View Source
var ( ErrUserNotFound = errors.New("user not found") ErrUserExists = errors.New("user already exists") ErrInvalidPassword = errors.New("invalid password") ErrAPIKeyNotFound = errors.New("api key not found") ErrAPIKeyExpired = errors.New("api key has expired") ErrAPIKeyInactive = errors.New("api key is inactive") ErrSessionNotFound = errors.New("session not found") ErrSessionExpired = errors.New("session has expired") ErrSessionRevoked = errors.New("session has been revoked") ErrInvalidRole = errors.New("invalid role") ErrUserInactive = errors.New("user account is inactive") ErrCannotDeleteSelf = errors.New("cannot delete your own account") )
Functions ¶
func GenerateAPIKey ¶ added in v0.1.5
func GenerateSessionID ¶ added in v0.1.5
func GenerateUID ¶ added in v0.1.5
func HasPermission ¶ added in v0.1.5
func HasPermission(role Role, explicitPerms []string, required Permission) bool
func HashAPIKey ¶ added in v0.1.5
func HashPassword ¶ added in v0.1.5
func ParsePermissionsJSON ¶ added in v0.1.5
func ValidAccessLevel ¶ added in v0.1.5
func VerifyPassword ¶ added in v0.1.5
Types ¶
type APIKey ¶ added in v0.1.5
type APIKey struct {
ID int64 `json:"id"`
KeyID string `json:"key_id"`
UserID int64 `json:"user_id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
KeyHash string `json:"-"`
KeyPrefix string `json:"key_prefix"`
Role Role `json:"role,omitempty"`
Permissions []string `json:"permissions,omitempty"`
Deployments DeploymentAccess `json:"deployments,omitempty"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
LastUsedAt time.Time `json:"last_used_at,omitempty"`
LastUsedIP string `json:"last_used_ip,omitempty"`
IsActive bool `json:"is_active"`
CreatedAt time.Time `json:"created_at"`
}
func (*APIKey) GetDeploymentsJSON ¶ added in v0.1.5
func (*APIKey) GetPermissionsJSON ¶ added in v0.1.5
type ActorContext ¶ added in v0.1.5
type ActorContext struct {
Type string `json:"type"`
UserID int64 `json:"user_id,omitempty"`
User *User `json:"user,omitempty"`
APIKey *APIKey `json:"api_key,omitempty"`
Role Role `json:"role"`
Permissions []string `json:"permissions,omitempty"`
Deployments map[string]string `json:"deployments,omitempty"`
}
func GetActorFromContext ¶ added in v0.1.5
func GetActorFromContext(c *gin.Context) *ActorContext
func (*ActorContext) CanAccessDeployment ¶ added in v0.1.5
func (a *ActorContext) CanAccessDeployment(name string, requiredLevel string) bool
func (*ActorContext) HasPermission ¶ added in v0.1.5
func (a *ActorContext) HasPermission(p Permission) bool
type Claims ¶
type Claims struct {
Username string `json:"username"`
UserID int64 `json:"user_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
jwt.RegisteredClaims
}
type DB ¶ added in v0.1.5
type DB struct {
// contains filtered or unexported fields
}
func (*DB) CleanupExpiredSessions ¶ added in v0.1.5
func (*DB) CountUsers ¶ added in v0.1.5
func (*DB) CreateSession ¶ added in v0.1.5
func (*DB) CreateUserDeployment ¶ added in v0.1.5
func (db *DB) CreateUserDeployment(ud *UserDeployment) (int64, error)
func (*DB) DeactivateAPIKey ¶ added in v0.1.5
func (*DB) DeleteAPIKey ¶ added in v0.1.5
func (*DB) DeleteAllUserDeployments ¶ added in v0.1.5
func (*DB) DeleteUser ¶ added in v0.1.5
func (*DB) DeleteUserDeployment ¶ added in v0.1.5
func (*DB) GetAPIKeyByHash ¶ added in v0.1.5
func (*DB) GetAPIKeysByUserID ¶ added in v0.1.5
func (*DB) GetAllAPIKeys ¶ added in v0.1.5
func (*DB) GetDeploymentUsers ¶ added in v0.1.5
func (db *DB) GetDeploymentUsers(deploymentName string) ([]UserDeployment, error)
func (*DB) GetSessionByID ¶ added in v0.1.5
func (*DB) GetSessionByTokenHash ¶ added in v0.1.5
func (*DB) GetUserByUsername ¶ added in v0.1.5
func (*DB) GetUserDeployments ¶ added in v0.1.5
func (db *DB) GetUserDeployments(userID int64) ([]UserDeployment, error)
func (*DB) GetUserDeploymentsMap ¶ added in v0.1.5
func (*DB) RevokeSession ¶ added in v0.1.5
func (*DB) RevokeUserSessions ¶ added in v0.1.5
func (*DB) UpdateAPIKey ¶ added in v0.2.0
func (*DB) UpdateAPIKeyLastUsed ¶ added in v0.1.5
func (*DB) UpdateUser ¶ added in v0.1.5
func (*DB) UpdateUserDeployment ¶ added in v0.1.5
func (*DB) UpdateUserLastLogin ¶ added in v0.1.5
type DeploymentAccess ¶ added in v0.2.0
func ParseDeploymentsJSON ¶ added in v0.1.5
func ParseDeploymentsJSON(s string) DeploymentAccess
func (*DeploymentAccess) UnmarshalJSON ¶ added in v0.2.0
func (d *DeploymentAccess) UnmarshalJSON(data []byte) error
type Manager ¶ added in v0.1.5
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶ added in v0.1.5
func (*Manager) AssignDeployment ¶ added in v0.1.5
func (*Manager) BuildActorContext ¶ added in v0.1.5
func (m *Manager) BuildActorContext(user *User, apiKey *APIKey) (*ActorContext, error)
func (*Manager) CleanupExpiredSessions ¶ added in v0.1.5
func (*Manager) CreateAPIKey ¶ added in v0.1.5
func (*Manager) CreateAPIKeyFromRaw ¶ added in v0.1.5
func (*Manager) CreateSession ¶ added in v0.1.5
func (*Manager) CreateUser ¶ added in v0.1.5
func (*Manager) DeactivateAPIKey ¶ added in v0.1.5
func (*Manager) DeleteAPIKey ¶ added in v0.1.5
func (*Manager) DeleteUser ¶ added in v0.1.5
func (*Manager) GetAPIKeysByUser ¶ added in v0.1.5
func (*Manager) GetAllAPIKeys ¶ added in v0.1.5
func (*Manager) GetDeploymentUsers ¶ added in v0.1.5
func (m *Manager) GetDeploymentUsers(deploymentName string) ([]UserDeployment, error)
func (*Manager) GetLegacyKeyIndex ¶ added in v0.1.5
func (*Manager) GetSessionByID ¶ added in v0.1.5
func (*Manager) GetSessionByToken ¶ added in v0.1.5
func (*Manager) GetUserByUID ¶ added in v0.1.5
func (*Manager) GetUserByUsername ¶ added in v0.1.5
func (*Manager) GetUserDeployments ¶ added in v0.1.5
func (m *Manager) GetUserDeployments(userID int64) ([]UserDeployment, error)
func (*Manager) GetUserDeploymentsMap ¶ added in v0.1.5
func (*Manager) RemoveDeploymentAccess ¶ added in v0.1.5
func (*Manager) RevokeSession ¶ added in v0.1.5
func (*Manager) RevokeUserSessions ¶ added in v0.1.5
func (*Manager) UpdateAPIKey ¶ added in v0.2.0
func (*Manager) UpdateAPIKeyLastUsed ¶ added in v0.1.5
func (*Manager) UpdatePassword ¶ added in v0.1.5
func (*Manager) UpdateUser ¶ added in v0.1.5
func (*Manager) UpdateUserDeployment ¶ added in v0.1.5
func (*Manager) ValidateAPIKey ¶ added in v0.1.5
func (*Manager) ValidateCredentials ¶ added in v0.1.5
func (*Manager) ValidateLegacyAPIKey ¶ added in v0.1.5
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
func NewMiddleware ¶
func NewMiddleware(cfg *config.AuthConfig) *Middleware
func NewMiddlewareWithManager ¶ added in v0.1.5
func NewMiddlewareWithManager(cfg *config.AuthConfig, manager *Manager) *Middleware
func (*Middleware) ActorForTokenString ¶ added in v0.2.0
func (m *Middleware) ActorForTokenString(token string, clientIP string) (*ActorContext, error)
func (*Middleware) GenerateJWT ¶
func (m *Middleware) GenerateJWT(username string) (string, error)
func (*Middleware) GenerateJWTForUser ¶ added in v0.1.5
func (m *Middleware) GenerateJWTForUser(user *User, sessionID string) (string, error)
func (*Middleware) GetAuthStatus ¶
func (m *Middleware) GetAuthStatus(c *gin.Context)
func (*Middleware) IsAuthEnabled ¶ added in v0.1.5
func (m *Middleware) IsAuthEnabled() bool
func (*Middleware) Login ¶
func (m *Middleware) Login(c *gin.Context)
func (*Middleware) RequireAuth ¶
func (m *Middleware) RequireAuth() gin.HandlerFunc
func (*Middleware) RequireDeploymentAccess ¶ added in v0.1.5
func (m *Middleware) RequireDeploymentAccess(level string) gin.HandlerFunc
func (*Middleware) RequirePermission ¶ added in v0.1.5
func (m *Middleware) RequirePermission(perms ...Permission) gin.HandlerFunc
func (*Middleware) SetManager ¶ added in v0.1.5
func (m *Middleware) SetManager(manager *Manager)
func (*Middleware) ValidateToken ¶
func (m *Middleware) ValidateToken(c *gin.Context)
func (*Middleware) ValidateTokenString ¶ added in v0.1.5
func (m *Middleware) ValidateTokenString(token string) bool
type Permission ¶ added in v0.1.5
type Permission string
const ( PermDeploymentsRead Permission = "deployments:read" PermDeploymentsWrite Permission = "deployments:write" PermDeploymentsDelete Permission = "deployments:delete" PermCertificatesRead Permission = "certificates:read" PermCertificatesWrite Permission = "certificates:write" PermCertificatesDelete Permission = "certificates:delete" PermNetworksRead Permission = "networks:read" PermNetworksWrite Permission = "networks:write" PermNetworksDelete Permission = "networks:delete" PermSecurityRead Permission = "security:read" PermSecurityWrite Permission = "security:write" PermBackupsRead Permission = "backups:read" PermBackupsWrite Permission = "backups:write" PermBackupsDelete Permission = "backups:delete" PermUsersRead Permission = "users:read" PermUsersWrite Permission = "users:write" PermUsersDelete Permission = "users:delete" PermAPIKeysRead Permission = "apikeys:read" PermAPIKeysWrite Permission = "apikeys:write" PermAPIKeysDelete Permission = "apikeys:delete" PermSettingsRead Permission = "settings:read" PermSettingsWrite Permission = "settings:write" PermAuditRead Permission = "audit:read" PermContainersRead Permission = "containers:read" PermContainersWrite Permission = "containers:write" PermContainersDelete Permission = "containers:delete" PermImagesRead Permission = "images:read" PermImagesWrite Permission = "images:write" PermImagesDelete Permission = "images:delete" PermVolumesRead Permission = "volumes:read" PermVolumesWrite Permission = "volumes:write" PermVolumesDelete Permission = "volumes:delete" PermDatabasesRead Permission = "databases:read" PermDatabasesWrite Permission = "databases:write" PermDatabasesDelete Permission = "databases:delete" PermInfrastructureRead Permission = "infrastructure:read" PermInfrastructureWrite Permission = "infrastructure:write" PermSchedulerRead Permission = "scheduler:read" PermSchedulerWrite Permission = "scheduler:write" PermSchedulerDelete Permission = "scheduler:delete" PermSystemRead Permission = "system:read" PermSystemWrite Permission = "system:write" PermSystemFiles Permission = "system:files" PermDNSRead Permission = "dns:read" PermDNSWrite Permission = "dns:write" PermRegistriesRead Permission = "registries:read" PermRegistriesWrite Permission = "registries:write" PermRegistriesDelete Permission = "registries:delete" PermTemplatesRead Permission = "templates:read" PermTemplatesWrite Permission = "templates:write" PermTrafficRead Permission = "traffic:read" PermTrafficWrite Permission = "traffic:write" PermClusterRead Permission = "cluster:read" PermClusterWrite Permission = "cluster:write" )
func EffectivePermissions ¶ added in v0.1.5
func EffectivePermissions(user *User, role Role) []Permission
func GetAllPermissions ¶ added in v0.1.5
func GetAllPermissions() []Permission
func GetRolePermissions ¶ added in v0.1.5
func GetRolePermissions(role Role) []Permission
func (Permission) String ¶ added in v0.1.5
func (p Permission) String() string
type Session ¶ added in v0.1.5
type Session struct {
ID int64 `json:"id"`
SessionID string `json:"session_id"`
UserID int64 `json:"user_id"`
APIKeyID int64 `json:"api_key_id,omitempty"`
TokenHash string `json:"-"`
ExpiresAt time.Time `json:"expires_at"`
RevokedAt time.Time `json:"revoked_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
ClientIP string `json:"client_ip,omitempty"`
}
type User ¶ added in v0.1.5
type User struct {
ID int64 `json:"id"`
UID string `json:"uid"`
Username string `json:"username"`
Email string `json:"email,omitempty"`
PasswordHash string `json:"-"`
Role Role `json:"role"`
Permissions []string `json:"permissions,omitempty"`
IsActive bool `json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
LastLoginAt time.Time `json:"last_login_at,omitempty"`
}
func (*User) GetPermissionsJSON ¶ added in v0.1.5
Click to show internal directories.
Click to hide internal directories.