Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v2.4.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: BSD-3-Clause Imports: 70 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionKeyAuthenticated = "authenticated"
	SessionKeySID           = "sid"
	SessionKeyUsername      = "user"
	SessionKeyCSRF          = "csrf"
	ContextKeyUser          = "user"
	ContextKeyUsername      = "username"
	ContextKeyIPAClient     = "ipa"
	UserCategoryUnverified  = "mokey-user-unverified"
	UserCategoryPending     = "mokey-user-pending"
	TokenAccountVerify      = "verify"
	TokenPasswordReset      = "reset"
	TokenEmailChange        = "emailchange"
	TokenInvite             = "invite"
	TokenOTPRecovery        = "otprecovery"
	TokenUsedPrefix         = "used-"
	TokenIssuedPrefix       = "issued-"
	SessionKeyLoginTime     = "login_time"
	PasswordChangedPrefix   = "pwchanged-"
)
View Source
const (
	DefaultPort = 80
)
View Source
const SessionKeyWebAuthn = "webauthn_registration"

Variables

View Source
var (
	ErrDomainNotAllowed = errors.New("Email domain not allowed")
	ErrInvalidUsername  = errors.New("Username is invalid. May only include letters, numbers, _, -, .")
)
View Source
var Version = "dev"

Functions

func AllowedDomains

func AllowedDomains() string

func BaseURL

func BaseURL(ctx *fiber.Ctx) string

func BreakNewlines

func BreakNewlines(s string) template.HTML

func ConfigValueBool

func ConfigValueBool(key string) bool

func ConfigValueString

func ConfigValueString(key string) string

func ConfigValueStringSlice

func ConfigValueStringSlice(key string) []string

func GenerateSecret

func GenerateSecret(n int) (string, error)

func GenerateSecretString

func GenerateSecretString(n int) (string, error)

func HTTPErrorHandler

func HTTPErrorHandler(c *fiber.Ctx, err error) error

func LimitReachedHandler

func LimitReachedHandler(c *fiber.Ctx) error

func LoadTranslations

func LoadTranslations() error

LoadTranslations loads the embedded translation files and any additional .toml files from site.translations_dir. A file named <lang>.toml defines (or fully replaces) the language <lang>.

func MarkTokenUsed

func MarkTokenUsed(token, prefix string, claims *Token, storage fiber.Storage)

MarkTokenUsed runs after the token's action has taken effect, so a storage failure cannot be rolled back: it is logged, and the token stays valid until it expires

func NewToken

func NewToken(username, email, prefix string, storage fiber.Storage) (string, error)

func NotFoundHandler

func NotFoundHandler(c *fiber.Ctx) error

func PhoneCode

func PhoneCode(stored string) string

PhoneCode and PhoneNumber feed the two halves of the phone fields back into the form on render

func PhoneFlag

func PhoneFlag(code string) string

PhoneFlag returns the flag for a dial code, or "" when nothing matches.

func PhoneNumber

func PhoneNumber(stored string) string

func QRCode

func QRCode(otptoken *ipa.OTPToken, realm string) (string, error)

func RemoteIP

func RemoteIP(c *fiber.Ctx) string

RemoteIP returns the client address used for rate limiting and audit logging. X-Forwarded-For is only consulted when the direct peer is a configured trusted proxy (server.trusted_proxies), and entries are walked right to left skipping further trusted proxies — the leftmost values are client-supplied and forgeable.

func SecureHeaders

func SecureHeaders(c *fiber.Ctx) error

func SetDefaults

func SetDefaults()

func SplitSSHFP

func SplitSSHFP(fp string) []string

func T

func T(key string) string

T returns the translation for key in the configured site language, falling back to english and finally to the key itself.

func TimeAgo

func TimeAgo(t time.Time) string

Types

type AuditEvent

type AuditEvent struct {
	Time     time.Time `json:"time"`
	Message  string    `json:"message"`
	Username string    `json:"username,omitempty"`
	Actor    string    `json:"actor,omitempty"`
	IP       string    `json:"ip,omitempty"`
}

type AuditHook

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

func NewAuditHook

func NewAuditHook(storage fiber.Storage) *AuditHook

func (*AuditHook) Fire

func (h *AuditHook) Fire(entry *log.Entry) error

func (*AuditHook) Levels

func (h *AuditHook) Levels() []log.Level

type Emailer

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

func NewEmailer

func NewEmailer(storage fiber.Storage) (*Emailer, error)

func (*Emailer) SendAccountVerifyEmail

func (e *Emailer) SendAccountVerifyEmail(user *ipa.User, ctx *fiber.Ctx) error

func (*Emailer) SendEmailChangeConfirmEmail

func (e *Emailer) SendEmailChangeConfirmEmail(user *ipa.User, newEmail string, ctx *fiber.Ctx) error

SendEmailChangeConfirmEmail sends a confirmation link to the NEW email address. The change is only applied after the link is visited.

func (*Emailer) SendEmailChangedNotification

func (e *Emailer) SendEmailChangedNotification(oldEmail string, user *ipa.User, ctx *fiber.Ctx) error

SendEmailChangedNotification notifies the OLD address that the account email was changed.

func (*Emailer) SendGroupDecisionEmail

func (e *Emailer) SendGroupDecisionEmail(user *ipa.User, group string, approved bool, reqType string) error

SendGroupDecisionEmail notifies the requester that a sponsor approved or denied their join or leave request. Called synchronously from GroupApprove/GroupDeny in the request path with a nil ctx, so the base URL comes from config rather than the request — mirrors SendNewLoginEmail's nil-ctx mechanism.

func (*Emailer) SendGroupRemovedEmail

func (e *Emailer) SendGroupRemovedEmail(user *ipa.User, group string) error

SendGroupRemovedEmail notifies a member that a sponsor removed them from a group directly (not via a leave request they initiated).

func (*Emailer) SendGroupRequestEmail

func (e *Emailer) SendGroupRequestEmail(manager *ipa.User, requester, group, reqType string) error

SendGroupRequestEmail notifies a group sponsor about a pending join or leave request. Called from a goroutine after the handler returns — no request context, mirrors SendNewLoginEmail.

func (*Emailer) SendInviteEmail

func (e *Emailer) SendInviteEmail(email string, ctx *fiber.Ctx) error

SendInviteEmail sends an account invitation to an email address. The recipient completes their profile via the /auth/invite/:token link.

func (*Emailer) SendMFAChangedEmail

func (e *Emailer) SendMFAChangedEmail(enabled bool, user *ipa.User, ctx *fiber.Ctx) error

func (*Emailer) SendNewLoginEmail

func (e *Emailer) SendNewLoginEmail(user *ipa.User, browser, os, ip string) error

SendNewLoginEmail notifies about a fresh sign-in. Called from a goroutine after the login response — no request context.

func (*Emailer) SendOTPRecoveryConfirmEmail

func (e *Emailer) SendOTPRecoveryConfirmEmail(user *ipa.User, ctx *fiber.Ctx) error

SendOTPRecoveryConfirmEmail sends the confirm-before-queue link for an OTP lockout recovery request

func (*Emailer) SendOTPRecoveryDecisionEmail

func (e *Emailer) SendOTPRecoveryDecisionEmail(user *ipa.User, approved bool) error

SendOTPRecoveryDecisionEmail notifies the requester that an admin approved or denied their OTP recovery request. Called synchronously from AdminUserAction in the request path with a nil ctx, so the base URL comes from config rather than the request — mirrors SendGroupDecisionEmail.

func (*Emailer) SendOTPTokenUpdatedEmail

func (e *Emailer) SendOTPTokenUpdatedEmail(added bool, user *ipa.User, ctx *fiber.Ctx) error

func (*Emailer) SendPasskeyUpdatedEmail

func (e *Emailer) SendPasskeyUpdatedEmail(added bool, user *ipa.User, ctx *fiber.Ctx) error

func (*Emailer) SendPasswordChangedEmail

func (e *Emailer) SendPasswordChangedEmail(user *ipa.User, ctx *fiber.Ctx) error

func (*Emailer) SendPasswordExpiryReminderEmail

func (e *Emailer) SendPasswordExpiryReminderEmail(user *ipa.User, days int) error

SendPasswordExpiryReminderEmail warns a user their password expires in the given number of days. Sent from the background sweep — no request context.

func (*Emailer) SendPasswordResetEmail

func (e *Emailer) SendPasswordResetEmail(user *ipa.User, ctx *fiber.Ctx) error

func (*Emailer) SendSSHKeyUpdatedEmail

func (e *Emailer) SendSSHKeyUpdatedEmail(added bool, user *ipa.User, ctx *fiber.Ctx) error

func (*Emailer) SendUsernameReminderEmail

func (e *Emailer) SendUsernameReminderEmail(email string, usernames []string, ctx *fiber.Ctx) error

SendUsernameReminderEmail mails the username(s) associated with an address. The recipient is identified only by email — no account context is leaked in the delivery metadata.

func (*Emailer) SendWelcomeEmail

func (e *Emailer) SendWelcomeEmail(user *ipa.User, ctx *fiber.Ctx) error

type FakeTLSTransport

type FakeTLSTransport struct {
	T http.RoundTripper
}

func (*FakeTLSTransport) RoundTrip

func (ftt *FakeTLSTransport) RoundTrip(req *http.Request) (*http.Response, error)

type GroupRequest

type GroupRequest struct {
	Username    string    `json:"username"`
	Type        string    `json:"type"`
	RequestedAt time.Time `json:"requested_at"`
}

type Metrics

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

func NewMetrics

func NewMetrics() *Metrics

NewMetrics returns the process-wide metrics instance. Counters register with the global prometheus registry, which panics on duplicate registration — so this must be a singleton.

func (*Metrics) Handler

func (m *Metrics) Handler(c *fiber.Ctx) error

type OTPRecoveryRequest

type OTPRecoveryRequest struct {
	Username    string    `json:"username"`
	RequestedAt time.Time `json:"requested_at"`
}

type PhoneCountry

type PhoneCountry struct {
	Name   string
	Alpha2 string
	Code   string // ITU-T E.164 dial code, digits only
	Flag   string // Unicode regional-indicator pair
}

PhoneCountry is one entry of the country-code picker.

func PhoneCountries

func PhoneCountries() []PhoneCountry

PhoneCountries feeds the country-code picker.

type PwPolicy

type PwPolicy struct {
	MinLength    int
	MinClasses   int
	HistorySize  int
	MaxLifeDays  int // pwpolicy_show reports max lifetime in days
	MinLifeHours int // ...and min lifetime in hours
	MaxFailure   int
}

PwPolicy is the password policy in effect for a user (pwpolicy_show). Zero values mean the attribute is unset in FreeIPA.

type Router

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

func NewRouter

func NewRouter(storage fiber.Storage) (*Router, error)

func (*Router) AccessTest

func (r *Router) AccessTest(c *fiber.Ctx) error

AccessTest runs FreeIPA's hbactest for the SESSION user against a host/service from the form. The username never comes from the form — users can only simulate their own access.

func (*Router) AccountCreate

func (r *Router) AccountCreate(c *fiber.Ctx) error

func (*Router) AccountSettings

func (r *Router) AccountSettings(c *fiber.Ctx) error

func (*Router) AccountVerify

func (r *Router) AccountVerify(c *fiber.Ctx) error

func (*Router) AccountVerifyResend

func (r *Router) AccountVerifyResend(c *fiber.Ctx) error

func (*Router) AdminAuditList

func (r *Router) AdminAuditList(c *fiber.Ctx) error

func (*Router) AdminOTPRecoveryList

func (r *Router) AdminOTPRecoveryList(c *fiber.Ctx) error

AdminOTPRecoveryList renders the OTP recovery queue for admin review. Always visible (unlike the pending-signup queue, which is gated by accounts.require_admin_verify).

func (*Router) AdminPendingList

func (r *Router) AdminPendingList(c *fiber.Ctx) error

AdminPendingList renders signups that confirmed their email and now wait for admin approval (require_admin_verify)

func (*Router) AdminUserAction

func (r *Router) AdminUserAction(c *fiber.Ctx) error

func (*Router) AdminUserList

func (r *Router) AdminUserList(c *fiber.Ctx) error

func (*Router) AppRevoke

func (r *Router) AppRevoke(c *fiber.Ctx) error

AppRevoke revokes the caller's consent for one connected OAuth client.

func (*Router) Authenticate

func (r *Router) Authenticate(c *fiber.Ctx) error

func (*Router) CSRF

func (r *Router) CSRF(c *fiber.Ctx) error

func (*Router) Captcha

func (r *Router) Captcha(c *fiber.Ctx) error

Captcha handler displays captcha image

func (*Router) CheckUser

func (r *Router) CheckUser(c *fiber.Ctx) error

func (*Router) ConsentGet

func (r *Router) ConsentGet(c *fiber.Ctx) error

func (*Router) EmailChangeConfirm

func (r *Router) EmailChangeConfirm(c *fiber.Ctx) error

EmailChangeConfirm applies a pending email change. GET renders a confirmation page, POST performs the change.

func (*Router) GroupApprove

func (r *Router) GroupApprove(c *fiber.Ctx) error

func (*Router) GroupDeny

func (r *Router) GroupDeny(c *fiber.Ctx) error

func (*Router) GroupRemoveMember

func (r *Router) GroupRemoveMember(c *fiber.Ctx) error

GroupRemoveMember lets a sponsor remove a member directly, independent of the leave-request queue — the sponsor already holds standing authority over the group, the same authority Approve exercises.

func (*Router) GroupRequestJoin

func (r *Router) GroupRequestJoin(c *fiber.Ctx) error

GroupRequestJoin queues a join request for a managed group and notifies its sponsors

func (*Router) GroupRequestLeave

func (r *Router) GroupRequestLeave(c *fiber.Ctx) error

GroupRequestLeave queues a leave request for a group the user belongs to and notifies its sponsors. Membership can only be mutated by a sponsor's session (see groupAddMember), so leaving goes through the same approval queue as joining rather than executing instantly.

func (*Router) Healthz

func (r *Router) Healthz(c *fiber.Ctx) error

Healthz is an unauthenticated health check endpoint. It verifies the session storage backend and FreeIPA are reachable. Registered before the CSRF middleware so probes don't create sessions.

func (*Router) HydraError

func (r *Router) HydraError(c *fiber.Ctx) error

func (*Router) HydraLogout

func (r *Router) HydraLogout(c *fiber.Ctx) error

HydraLogout implements the Hydra OIDC logout flow. Hydra redirects the user here with a logout_challenge; we destroy the local session, accept the challenge, and redirect the user back (e.g. to the client's post_logout_redirect_uri). See https://www.ory.sh/docs/hydra/concepts/logout

func (*Router) Index

func (r *Router) Index(c *fiber.Ctx) error

func (*Router) InviteAccept

func (r *Router) InviteAccept(c *fiber.Ctx) error

InviteAccept lets an invited user complete their own account. The token proves ownership of the invited email address, so the account is created enabled with no further email verification.

func (*Router) InviteSend

func (r *Router) InviteSend(c *fiber.Ctx) error

InviteSend handles the admin invite form. An invite token is emailed to the address; the invited user completes their own profile via InviteAccept. Works regardless of accounts.enable_signup.

func (*Router) Login

func (r *Router) Login(c *fiber.Ctx) error

func (*Router) LoginOAuthGet

func (r *Router) LoginOAuthGet(c *fiber.Ctx) error

func (*Router) LoginOAuthPost

func (r *Router) LoginOAuthPost(username, challenge string, c *fiber.Ctx) error
func (r *Router) Logo(c *fiber.Ctx) error

func (*Router) Logout

func (r *Router) Logout(c *fiber.Ctx) error

func (*Router) Metrics

func (r *Router) Metrics(c *fiber.Ctx) error

func (*Router) OTPRecoveryConfirm

func (r *Router) OTPRecoveryConfirm(c *fiber.Ctx) error

OTPRecoveryConfirm queues the recovery request after the emailed link is confirmed — mailbox possession is the identity proof

func (*Router) OTPRecoveryRequest

func (r *Router) OTPRecoveryRequest(c *fiber.Ctx) error

OTPRecoveryRequest renders and handles the "Lost OTP token?" form. Every POST outcome renders the same success page — unknown, blocked, and non-OTP accounts are indistinguishable from a real request.

func (*Router) OTPTokenAdd

func (r *Router) OTPTokenAdd(c *fiber.Ctx) error

func (*Router) OTPTokenDisable

func (r *Router) OTPTokenDisable(c *fiber.Ctx) error

func (*Router) OTPTokenEnable

func (r *Router) OTPTokenEnable(c *fiber.Ctx) error

func (*Router) OTPTokenList

func (r *Router) OTPTokenList(c *fiber.Ctx) error

func (*Router) OTPTokenModal

func (r *Router) OTPTokenModal(c *fiber.Ctx) error

func (*Router) OTPTokenRemove

func (r *Router) OTPTokenRemove(c *fiber.Ctx) error

func (*Router) OTPTokenVerify

func (r *Router) OTPTokenVerify(c *fiber.Ctx) error

func (*Router) PasskeyBegin

func (r *Router) PasskeyBegin(c *fiber.Ctx) error

func (*Router) PasskeyFinish

func (r *Router) PasskeyFinish(c *fiber.Ctx) error

func (*Router) PasskeyRemove

func (r *Router) PasskeyRemove(c *fiber.Ctx) error

func (*Router) PasswordChange

func (r *Router) PasswordChange(c *fiber.Ctx) error

func (*Router) PasswordExpired

func (r *Router) PasswordExpired(c *fiber.Ctx) error

func (*Router) PasswordForgot

func (r *Router) PasswordForgot(c *fiber.Ctx) error

func (*Router) PasswordReset

func (r *Router) PasswordReset(c *fiber.Ctx) error

func (*Router) RequireAdmin

func (r *Router) RequireAdmin(c *fiber.Ctx) error

func (*Router) RequireHTMX

func (r *Router) RequireHTMX(c *fiber.Ctx) error

func (*Router) RequireLogin

func (r *Router) RequireLogin(c *fiber.Ctx) error

func (*Router) RequireMFA

func (r *Router) RequireMFA(c *fiber.Ctx) error

func (*Router) RequireNoLogin

func (r *Router) RequireNoLogin(c *fiber.Ctx) error

func (*Router) RequireOTPSelfService

func (r *Router) RequireOTPSelfService(c *fiber.Ctx) error

RequireOTPSelfService blocks OTP mutations for read-only users. The buttons are hidden in the UI, but enforcement lives here.

func (*Router) SSHKeyAdd

func (r *Router) SSHKeyAdd(c *fiber.Ctx) error

func (*Router) SSHKeyList

func (r *Router) SSHKeyList(c *fiber.Ctx) error

func (*Router) SSHKeyModal

func (r *Router) SSHKeyModal(c *fiber.Ctx) error

func (*Router) SSHKeyRemove

func (r *Router) SSHKeyRemove(c *fiber.Ctx) error

func (*Router) SecurityList

func (r *Router) SecurityList(c *fiber.Ctx) error

func (*Router) SessionRevoke

func (r *Router) SessionRevoke(c *fiber.Ctx) error

SessionRevoke handles per-device revocation from the security page

func (*Router) SessionRevokeOthers

func (r *Router) SessionRevokeOthers(c *fiber.Ctx) error

SessionRevokeOthers signs the user out everywhere except this device

func (*Router) SetupRoutes

func (r *Router) SetupRoutes(app *fiber.App)

func (*Router) StartExpiryReminders

func (r *Router) StartExpiryReminders()

StartExpiryReminders launches the background sweep when reminders are configured. Runs for the lifetime of the process.

func (*Router) Styles

func (r *Router) Styles(c *fiber.Ctx) error

func (*Router) SubidGenerate

func (r *Router) SubidGenerate(c *fiber.Ctx) error

SubidGenerate allocates the subordinate id range for the logged-in user and re-renders the subid card. Generation is one-shot per user; a duplicate error just renders the existing range.

func (*Router) TwoFactorDisable

func (r *Router) TwoFactorDisable(c *fiber.Ctx) error

func (*Router) TwoFactorEnable

func (r *Router) TwoFactorEnable(c *fiber.Ctx) error

func (*Router) UsernameForgot

func (r *Router) UsernameForgot(c *fiber.Ctx) error

UsernameForgot emails the username(s) tied to an address. The response is identical whether or not the address matches an account — no enumeration.

type Server

type Server struct {
	ListenAddress string
	Scheme        string
	KeyFile       string
	CertFile      string
	// contains filtered or unexported fields
}

func NewServer

func NewServer(address string) (*Server, error)

func (*Server) Serve

func (s *Server) Serve() error

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

type SlackNotifier

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

func NewSlackNotifier

func NewSlackNotifier() *SlackNotifier

func (*SlackNotifier) SendSlackMessage

func (s *SlackNotifier) SendSlackMessage(email, message string) error

type TemplateRenderer

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

func NewTemplateRenderer

func NewTemplateRenderer() (*TemplateRenderer, error)

func (*TemplateRenderer) Load

func (t *TemplateRenderer) Load() error

func (*TemplateRenderer) Render

func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, layouts ...string) error

type Token

type Token struct {
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Timestamp time.Time `json:"-"`
}

func ParseToken

func ParseToken(token, prefix string, storage fiber.Storage) (*Token, error)

type UserSession

type UserSession struct {
	SID       string    `json:"sid"`
	LoginTime time.Time `json:"login_time"`
	IP        string    `json:"ip"`
	Browser   string    `json:"browser"`
	OS        string    `json:"os"`
	// Current is computed at render time, never stored
	Current bool `json:"-"`
}

Jump to

Keyboard shortcuts

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