approvals

package
v0.0.0-...-230ac96 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisplayTOTPSetup

func DisplayTOTPSetup(w io.Writer, sessionID, secret string) error

DisplayTOTPSetup writes the TOTP setup screen (QR code + manual secret) to the writer.

func FormatTOTPURI

func FormatTOTPURI(sessionID, secret string) string

FormatTOTPURI creates an otpauth:// URI for the given session and secret.

func GenerateTOTPSecret

func GenerateTOTPSecret() (string, error)

GenerateTOTPSecret generates a new 20-byte (160-bit) TOTP secret. Returns the secret as a base32-encoded string.

func ValidateTOTPCode

func ValidateTOTPCode(code, secret string) bool

ValidateTOTPCode validates a 6-digit TOTP code against the given secret. Uses standard TOTP parameters: SHA1, 6 digits, 30-second period, ±1 period skew.

Types

type Emitter

type Emitter interface {
	AppendEvent(ctx context.Context, ev types.Event) error
	Publish(ev types.Event)
}

type Grant

type Grant struct {
	SessionID string
	Kind      string
	Target    string
	Operation string
	ExpiresAt time.Time
}

Grant is an approved access that is still in its grant period.

type Launcher

type Launcher func(ctx context.Context, req Request) error

Launcher shows a pending request to a person, who then resolves it out of band. It returns once the dialog is up, not once it is answered.

func DialogLauncher

func DialogLauncher() (Launcher, error)

DialogLauncher reports that the approval dialog exists only on macOS. Configuration validation refuses approvals.mode: gui elsewhere, so this is reached only by a caller that skipped validation.

type Manager

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

func New

func New(mode string, timeout time.Duration, emit Emitter) *Manager

func (*Manager) Ask

func (m *Manager) Ask(req Request)

Ask starts an approval for req and returns at once. If an identical request is waiting, or a person answered one in the grant period, it opens no new dialog.

func (*Manager) GetWebAuthnChallenge

func (m *Manager) GetWebAuthnChallenge(ctx context.Context, approvalID, userID string) (*WebAuthnChallenge, error)

GetWebAuthnChallenge returns a WebAuthn challenge for an approval request.

Authorization note: The userID parameter represents the operator making the approval decision. Session ownership validation (ensuring the operator is authorized to approve requests for this session) is performed at a higher layer (e.g., API authentication middleware). This design separates concerns: the approval manager handles approval logic, while access control is handled by the transport layer.

func (*Manager) Granted

func (m *Manager) Granted(sessionID, kind, target, operation string) bool

Granted reports whether a person approved this access in the grant period.

func (*Manager) Grants

func (m *Manager) Grants(sessionID string) []Grant

Grants returns the session's approved accesses that are still in their grant period.

func (*Manager) ListPending

func (m *Manager) ListPending() []Request

func (*Manager) OnGrantChange

func (m *Manager) OnGrantChange(fn func(sessionID string))

OnGrantChange sets a function that runs when a grant starts or ends. The macOS daemon uses it to send the system extension a new policy snapshot.

func (*Manager) RequestApproval

func (m *Manager) RequestApproval(ctx context.Context, req Request) (Resolution, error)

RequestApproval asks a person to approve req and waits for the answer.

If grants are on (SetGrantTTL), an identical request that is still waiting shares its answer, and a person's answer is reused for the grant period.

func (*Manager) Resolve

func (m *Manager) Resolve(id string, approved bool, reason string) bool

func (*Manager) ResolveWithWebAuthn

func (m *Manager) ResolveWithWebAuthn(ctx context.Context, approvalID, userID string, responseJSON []byte) error

ResolveWithWebAuthn resolves an approval using WebAuthn assertion.

Authorization note: The userID parameter represents the operator making the approval decision. Session ownership validation (ensuring the operator is authorized to approve requests for this session) is performed at a higher layer (e.g., API authentication middleware). This design separates concerns: the approval manager handles approval logic, while access control is handled by the transport layer.

func (*Manager) SetGrantTTL

func (m *Manager) SetGrantTTL(ttl time.Duration)

SetGrantTTL turns grants on. A person's answer to a request then applies to every identical request for ttl.

func (*Manager) SetLauncher

func (m *Manager) SetLauncher(l Launcher)

SetLauncher sets how gui mode shows a request. Without one, gui mode denies every request at once with a reason, rather than letting it sit until the timeout with nothing on screen.

func (*Manager) SetTOTPSecretLookup

func (m *Manager) SetTOTPSecretLookup(lookup func(sessionID string) string)

SetTOTPSecretLookup sets the callback for retrieving TOTP secrets by session ID. Required when using TOTP approval mode.

func (*Manager) SetWebAuthnApprover

func (m *Manager) SetWebAuthnApprover(approver *WebAuthnApprover)

SetWebAuthnApprover sets the WebAuthn approver (required for webauthn mode).

type Request

type Request struct {
	ID        string         `json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	ExpiresAt time.Time      `json:"expires_at"`
	SessionID string         `json:"session_id"`
	CommandID string         `json:"command_id,omitempty"`
	Kind      string         `json:"kind"` // "command" | "file" | "network"
	Target    string         `json:"target,omitempty"`
	Rule      string         `json:"rule,omitempty"`
	Message   string         `json:"message,omitempty"`
	Fields    map[string]any `json:"fields,omitempty"`
}

type Resolution

type Resolution struct {
	Approved bool      `json:"approved"`
	Reason   string    `json:"reason,omitempty"`
	At       time.Time `json:"at"`
}

type WebAuthnApprover

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

WebAuthnApprover handles WebAuthn-based approvals.

func NewWebAuthnApprover

func NewWebAuthnApprover(service *auth.WebAuthnService) *WebAuthnApprover

NewWebAuthnApprover creates a new WebAuthn approver.

func (*WebAuthnApprover) CreateChallenge

func (w *WebAuthnApprover) CreateChallenge(ctx context.Context, req Request, userID string) (*WebAuthnChallenge, error)

CreateChallenge generates a WebAuthn challenge for an approval request.

func (*WebAuthnApprover) VerifyResponse

func (w *WebAuthnApprover) VerifyResponse(ctx context.Context, userID string, responseJSON []byte) error

VerifyResponse validates a WebAuthn assertion response.

type WebAuthnChallenge

type WebAuthnChallenge struct {
	ApprovalID string                        `json:"approval_id"`
	SessionID  string                        `json:"session_id"`
	Challenge  *protocol.CredentialAssertion `json:"challenge"`
	ExpiresAt  time.Time                     `json:"expires_at"`
}

WebAuthnChallenge represents a pending WebAuthn approval challenge.

Jump to

Keyboard shortcuts

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