regulation

package
v4.39.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthType1FA is the string representing an auth log for first-factor authentication.
	AuthType1FA = "1FA"

	// AuthTypePasskey is the string representing an auth log for first-factor passkey authentication.
	AuthTypePasskey = "Passkey"

	// AuthTypeTOTP is the string representing an auth log for second-factor authentication via TOTP.
	AuthTypeTOTP = "TOTP"

	// AuthTypeWebAuthn is the string representing an auth log for second-factor authentication via FIDO2/CTAP2/WebAuthn.
	AuthTypeWebAuthn = "WebAuthn"

	// AuthTypeDuo is the string representing an auth log for second-factor authentication via DUO.
	AuthTypeDuo = "Duo"

	// AuthTypePassword is the string representing an auth log for second-factor authentication via a Password.
	AuthTypePassword = "Password"
)

Variables

View Source
var ErrUserIsBanned = fmt.Errorf("user is banned")

ErrUserIsBanned user is banned error message.

Functions

func FormatExpiresLong added in v4.39.0

func FormatExpiresLong(expires *time.Time) string

func FormatExpiresShort added in v4.39.0

func FormatExpiresShort(expires sql.NullTime) string

Types

type Ban added in v4.39.0

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

func NewBan added in v4.39.0

func NewBan(ban BanType, value string, expires *time.Time) *Ban

NewBan constructs a friendly version of ban information for easy formatting.

func (*Ban) Expires added in v4.39.0

func (b *Ban) Expires() *time.Time

func (*Ban) FormatExpires added in v4.39.0

func (b *Ban) FormatExpires() string

func (*Ban) IsBanned added in v4.39.0

func (b *Ban) IsBanned() bool

func (*Ban) Type added in v4.39.0

func (b *Ban) Type() BanType

func (*Ban) Value added in v4.39.0

func (b *Ban) Value() string

type BanType added in v4.39.0

type BanType int
const (
	BanTypeNone BanType = iota
	BanTypeIP
	BanTypeUser
)

type Context added in v4.36.0

type Context interface {
	context.Context
	MetricsRecorder

	GetLogger() *logrus.Entry
	RemoteIP() (ip net.IP)
}

Context represents a regulator context.

type MetricsRecorder added in v4.36.0

type MetricsRecorder interface {
	RecordAuthn(success, banned bool, authType string)
}

MetricsRecorder represents the methods used to record regulation.

type Regulator

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

Regulator an authentication regulator preventing attackers to brute force the service.

func NewRegulator

func NewRegulator(config schema.Regulation, store storage.RegulatorProvider, clock clock.Provider) *Regulator

NewRegulator create a regulator instance.

func (*Regulator) BanCheck added in v4.39.0

func (r *Regulator) BanCheck(ctx Context, username string) (ban BanType, value string, expires *time.Time, err error)

func (*Regulator) HandleAttempt added in v4.39.0

func (r *Regulator) HandleAttempt(ctx Context, successful, banned bool, username, requestURI, requestMethod, authType string)

Jump to

Keyboard shortcuts

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