auth

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MaxUsernameLength = 32

MaxUsernameLength is the default maximum username length

View Source
const MinJWTSecretLength = 32

MinJWTSecretLength is the minimum required length for JWT secrets (32 bytes = 256 bits)

Variables

This section is empty.

Functions

func ValidUsername

func ValidUsername(u string, maxLen int) bool

ValidUsername checks if a username is valid using strict allowlist validation - Not empty - Not too long (maxLen, default 32) - Matches strict allowlist: only letters, numbers, underscore, hyphen - Blocks shell metacharacters: ; & | ( ) $ ` < > etc.

SECURITY: This strict validation prevents command injection attacks when usernames are passed to any of the shell scripts in the codebase.

func ValidUsernameDefault

func ValidUsernameDefault(u string) bool

ValidUsernameDefault checks username with default max length

Types

type AuthRequest

type AuthRequest = authproto.AuthRequest

AuthRequest is an alias to shared authproto.AuthRequest

type AuthResponse

type AuthResponse = authproto.AuthResponse

AuthResponse is an alias to shared authproto.AuthResponse

type Claims

type Claims struct {
	Username string   `json:"username"`
	Groups   []string `json:"groups"`
	jwt.RegisteredClaims
}

Claims represents JWT claims

func (*Claims) CanAct added in v1.11.0

func (c *Claims) CanAct() bool

CanAct checks if the user can perform runtime actions (ban/unban/whitelist) Only admins and panel operators - NOT auditors

func (*Claims) CanConfig added in v1.11.0

func (c *Claims) CanConfig() bool

CanConfig checks if the user can modify configuration Only admins (nftban group) - NOT panel operators or auditors

func (*Claims) CanModify

func (c *Claims) CanModify() bool

CanModify is an alias for CanAct (runtime action permission) Deprecated: Use CanAct() for actions or CanConfig() for configuration

func (*Claims) CanRead added in v1.11.0

func (c *Claims) CanRead() bool

CanRead checks if the user can view logs, reports, and status All authenticated users with valid groups can read

func (*Claims) CanViewLogs

func (c *Claims) CanViewLogs() bool

CanViewLogs checks if the user can view log files

func (*Claims) HasAllGroups

func (c *Claims) HasAllGroups(groups ...string) bool

HasAllGroups checks if the user belongs to all of the specified groups

func (*Claims) HasAnyGroup

func (c *Claims) HasAnyGroup(groups ...string) bool

HasAnyGroup checks if the user belongs to any of the specified groups

func (*Claims) HasGroup

func (c *Claims) HasGroup(group string) bool

HasGroup checks if the user belongs to a specific group

func (*Claims) IsAdmin

func (c *Claims) IsAdmin() bool

IsAdmin checks if the user has admin privileges (nftban group) Admins have full access: config changes, service management, all actions

func (*Claims) IsAuditor added in v1.11.0

func (c *Claims) IsAuditor() bool

IsAuditor checks if the user is a read-only auditor Auditors can view logs/reports/status but CANNOT perform any actions

func (*Claims) IsOperator

func (c *Claims) IsOperator() bool

IsOperator checks if the user can perform runtime actions (ban/unban/status) Includes: nftban (admin) and nftban-panel (panel operators) Excludes: nftban-auditor (auditors are read-only, NOT operators)

func (*Claims) IsPanelOperator added in v1.11.0

func (c *Claims) IsPanelOperator() bool

IsPanelOperator checks if the user is a panel integration account Panel operators can perform runtime actions but NOT config changes

type PAMAuth

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

PAMAuth handles PAM-based authentication

func NewPAMAuth

func NewPAMAuth(cfg *config.Config) (*PAMAuth, error)

NewPAMAuth creates a new PAM authentication handler Returns error if JWT secret is too short (security requirement)

func (*PAMAuth) AuditLog

func (p *PAMAuth) AuditLog(username, action, result, clientIP string)

AuditLog writes an audit log entry

func (*PAMAuth) Authenticate

func (p *PAMAuth) Authenticate(username, password string) (*User, error)

Authenticate validates user credentials via Unix socket to auth service

func (*PAMAuth) GenerateToken

func (p *PAMAuth) GenerateToken(user *User) (string, error)

GenerateToken creates a JWT token for authenticated user

func (*PAMAuth) ValidateToken

func (p *PAMAuth) ValidateToken(tokenString string) (*Claims, error)

ValidateToken verifies and parses a JWT token

type User

type User struct {
	Username string
	UID      string
	GID      string
	Groups   []string
}

User represents an authenticated user

Jump to

Keyboard shortcuts

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