accessgate

package
v0.13.5 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultResumeTTL       = 12 * time.Hour
	DefaultLocalSessionTTL = 12 * time.Hour
)
View Source
const DefaultFailedAttemptRetention = 30 * time.Minute

Variables

View Source
var ErrChallengeExpired = errors.New("sign-in expired; enter your environment password again")
View Source
var ErrInvalidPassword = errors.New("invalid password")
View Source
var ErrRecoveryPending = errors.New("host recovery is pending; finish security setup on the host")
View Source
var ErrRestartRequired = errors.New("restart this Runtime to apply the saved environment password before changing security settings")
View Source
var ErrSecondFactor = errors.New("enter an authenticator code or recovery code")

Functions

func AuthenticationErrorCode added in v0.13.0

func AuthenticationErrorCode(err error) string

func HashPassword added in v0.13.0

func HashPassword(password string) ([]byte, error)

func IsRateLimited

func IsRateLimited(err error) bool

func ReadPasswordHash added in v0.13.0

func ReadPasswordHash(stateDir string) ([]byte, error)

ReadPasswordHash reads the single committed authority after migration.

func RegisterTyped

func RegisterTyped[TReq any, TResp any](r *sessionrpc.Router, typeID uint32, gate *Gate, meta *session.Meta, policy RPCAccessPolicy, h func(ctx context.Context, req *TReq) (*TResp, error))

func RequireRPC

func RequireRPC(gate *Gate, meta *session.Meta, policy RPCAccessPolicy) error

func RetryAfter

func RetryAfter(err error) time.Duration

func WritePasswordHash added in v0.13.0

func WritePasswordHash(stateDir string, hash []byte) error

WritePasswordHash is called by the Runtime owner under its state lock. Clearing is explicit; an omitted startup secret never clears a saved hash.

Types

type AttemptPolicy

type AttemptPolicy struct {
	Steps     []AttemptPolicyStep
	Retention time.Duration
}

type AttemptPolicyStep

type AttemptPolicyStep struct {
	Failures int
	Cooldown time.Duration
}

type AuthenticationRequest added in v0.13.0

type AuthenticationRequest struct {
	Password     string `json:"password,omitempty"`
	Delegation   string `json:"delegation,omitempty"`
	ResumeToken  string `json:"resume_token,omitempty"`
	ChallengeID  string `json:"challenge_id,omitempty"`
	Code         string `json:"code,omitempty"`
	RecoveryCode string `json:"recovery_code,omitempty"`
}

AuthenticationRequest is shared by browser, encrypted proxy and native streams. A challenge is an authentication-only capability, never a business credential.

type ExpiredLocalSession added in v0.11.0

type ExpiredLocalSession struct {
	AccessSessionID string
}

type Gate

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

func New

func New(opts Options) *Gate

func NewWithPasswordHash added in v0.13.0

func NewWithPasswordHash(hash []byte) (*Gate, error)

NewWithPasswordHash restores server-owned authentication without retaining a plaintext password. An empty hash explicitly disables the gate.

func OpenPersistent added in v0.13.0

func OpenPersistent(dir string) (*Gate, error)

func (*Gate) AuthenticateChannel added in v0.13.0

func (g *Gate) AuthenticateChannel(channelID string, req AuthenticationRequest, subject string) (*UnlockResult, error)

func (*Gate) AuthenticateLocal added in v0.13.0

func (g *Gate) AuthenticateLocal(req AuthenticationRequest, subject, binding string) (*LocalSessionResult, error)

func (*Gate) CanResumeMeta

func (g *Gate) CanResumeMeta(resumeToken string, meta session.Meta) bool

func (*Gate) Close added in v0.13.0

func (g *Gate) Close() error

func (*Gate) DelegateCodeSpace added in v0.13.0

func (g *Gate) DelegateCodeSpace(channelID, codeSpaceID string) (string, error)

DelegateCodeSpace narrows an authenticated Env App session to one editor. The child still receives its own independently checked permission metadata.

func (*Gate) Enabled

func (g *Gate) Enabled() bool

func (*Gate) IsChannelUnlocked

func (g *Gate) IsChannelUnlocked(channelID string) bool

func (*Gate) IsLocalSessionValid

func (g *Gate) IsLocalSessionValid(token string) bool

func (*Gate) LocalSessionExpiresAt added in v0.11.0

func (g *Gate) LocalSessionExpiresAt(token string) (time.Time, bool)

LocalSessionExpiresAt resolves the active deadline for an opaque Local UI session token without exposing any other session state to callers.

func (*Gate) Manage added in v0.13.0

func (g *Gate) Manage(binding, label string, req SecurityRequest) (*SecurityResult, error)

Manage is reachable only through the authenticated private owner control service or an offline CLI holding the same environment state lock.

func (*Gate) MintLocalSession

func (g *Gate) MintLocalSession(password string) (*LocalSessionResult, error)

func (*Gate) MintLocalSessionFromResumeToken

func (g *Gate) MintLocalSessionFromResumeToken(resumeToken string, meta session.Meta) (*LocalSessionResult, error)

func (*Gate) MintLocalSessionWithSubject

func (g *Gate) MintLocalSessionWithSubject(password, subject string) (*LocalSessionResult, error)

func (*Gate) RegisterChannel

func (g *Gate) RegisterChannel(meta session.Meta)

func (*Gate) RegisterChannelWithOptions

func (g *Gate) RegisterChannelWithOptions(meta session.Meta, opts RegisterChannelOptions)

func (*Gate) ResolveLocalSession added in v0.11.0

func (g *Gate) ResolveLocalSession(token string) (string, time.Time, bool)

func (*Gate) ResumeChannel

func (g *Gate) ResumeChannel(channelID string, resumeToken string) error

func (*Gate) RevokeLocalSession

func (g *Gate) RevokeLocalSession(token string)

func (*Gate) RevokeResumeToken

func (g *Gate) RevokeResumeToken(resumeToken string)

func (*Gate) SecurityStatus added in v0.13.0

func (g *Gate) SecurityStatus() SecurityStatus

func (*Gate) Status

func (g *Gate) Status(channelID string) Status

func (*Gate) TakeAccessSessionByResumeToken added in v0.11.0

func (g *Gate) TakeAccessSessionByResumeToken(resumeToken string) (string, bool)

TakeAccessSessionByResumeToken revokes the complete access-session lineage identified by an active resume token and returns its opaque internal ID.

func (*Gate) TakeExpiredLocalSessions added in v0.11.0

func (g *Gate) TakeExpiredLocalSessions(now time.Time) []ExpiredLocalSession

func (*Gate) TakeLocalSession added in v0.11.0

func (g *Gate) TakeLocalSession(token string) (string, bool)

func (*Gate) TwoFactorEnabled added in v0.13.0

func (g *Gate) TwoFactorEnabled() bool

func (*Gate) UnlockChannel

func (g *Gate) UnlockChannel(channelID string, password string) (*UnlockResult, error)

func (*Gate) UnlockChannelWithSubject

func (g *Gate) UnlockChannelWithSubject(channelID, password, subject string) (*UnlockResult, error)

func (*Gate) UnregisterChannel

func (g *Gate) UnregisterChannel(channelID string)

func (*Gate) VerifyPassword

func (g *Gate) VerifyPassword(password string) bool

type LocalSessionResult

type LocalSessionResult struct {
	SecondFactorRequired bool   `json:"second_factor_required,omitempty"`
	ChallengeID          string `json:"challenge_id,omitempty"`
	Unlocked             bool   `json:"unlocked"`
	SessionToken         string `json:"-"`
	AccessSessionID      string `json:"-"`
	SessionExpiresAtUnix int64  `json:"session_expires_at_unix_ms,omitempty"`
	ResumeToken          string `json:"resume_token,omitempty"`
	ResumeExpiresAtUnix  int64  `json:"resume_expires_at_unix_ms,omitempty"`
}

type Options

type Options struct {
	Logger          *slog.Logger
	Password        string
	ResumeTTL       time.Duration
	LocalSessionTTL time.Duration
	AttemptPolicy   AttemptPolicy
}

type RPCAccessPolicy

type RPCAccessPolicy int
const (
	RPCAccessProtected RPCAccessPolicy = iota
	RPCAccessPublic
)

type RateLimitError

type RateLimitError struct {
	RetryAfter time.Duration
}

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type RegisterChannelOptions

type RegisterChannelOptions struct {
	// Cancel closes the channel on revocation or expiry. It must not call back into Gate.
	Cancel          func()
	Trusted         bool
	AccessSessionID string
}

type SecurityRequest added in v0.13.0

type SecurityRequest struct {
	Action       string `json:"action"`
	OperationID  string `json:"operation_id,omitempty"`
	Password     string `json:"password,omitempty"`
	Code         string `json:"code,omitempty"`
	RecoveryCode string `json:"recovery_code,omitempty"`
	Saved        bool   `json:"saved,omitempty"`
}

type SecurityResult added in v0.13.0

type SecurityResult struct {
	SecurityStatus
	OperationID   string   `json:"operation_id,omitempty"`
	Secret        string   `json:"secret,omitempty"`
	QRImage       string   `json:"qr_image,omitempty"`
	RecoveryCodes []string `json:"recovery_codes,omitempty"`
}

type SecurityStatus added in v0.13.0

type SecurityStatus struct {
	Enabled                bool   `json:"enabled"`
	PasswordConfigured     bool   `json:"password_configured"`
	RecoveryPending        bool   `json:"recovery_pending"`
	RecoveryCodesRemaining int    `json:"recovery_codes_remaining"`
	Revision               uint64 `json:"revision"`
}

type Status

type Status struct {
	PasswordRequired  bool   `json:"password_required"`
	TwoFactorRequired bool   `json:"two_factor_required"`
	Unlocked          bool   `json:"unlocked"`
	FloeApp           string `json:"floe_app,omitempty"`
	CodeSpaceID       string `json:"code_space_id,omitempty"`
	SessionKind       string `json:"session_kind,omitempty"`
}

type UnlockResult

type UnlockResult struct {
	SecondFactorRequired bool   `json:"second_factor_required,omitempty"`
	ChallengeID          string `json:"challenge_id,omitempty"`
	Unlocked             bool   `json:"unlocked"`
	ResumeToken          string `json:"resume_token,omitempty"`
	ResumeExpiresAtUnix  int64  `json:"resume_expires_at_unix_ms,omitempty"`
}

Jump to

Keyboard shortcuts

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