Documentation
¶
Index ¶
- func DisplayTOTPSetup(w io.Writer, sessionID, secret string) error
- func FormatTOTPURI(sessionID, secret string) string
- func GenerateTOTPSecret() (string, error)
- func ValidateTOTPCode(code, secret string) bool
- type Emitter
- type Grant
- type Launcher
- type Manager
- func (m *Manager) Ask(req Request)
- func (m *Manager) GetWebAuthnChallenge(ctx context.Context, approvalID, userID string) (*WebAuthnChallenge, error)
- func (m *Manager) Granted(sessionID, kind, target, operation string) bool
- func (m *Manager) Grants(sessionID string) []Grant
- func (m *Manager) ListPending() []Request
- func (m *Manager) OnGrantChange(fn func(sessionID string))
- func (m *Manager) RequestApproval(ctx context.Context, req Request) (Resolution, error)
- func (m *Manager) Resolve(id string, approved bool, reason string) bool
- func (m *Manager) ResolveWithWebAuthn(ctx context.Context, approvalID, userID string, responseJSON []byte) error
- func (m *Manager) SetGrantTTL(ttl time.Duration)
- func (m *Manager) SetLauncher(l Launcher)
- func (m *Manager) SetTOTPSecretLookup(lookup func(sessionID string) string)
- func (m *Manager) SetWebAuthnApprover(approver *WebAuthnApprover)
- type Request
- type Resolution
- type WebAuthnApprover
- type WebAuthnChallenge
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DisplayTOTPSetup ¶
DisplayTOTPSetup writes the TOTP setup screen (QR code + manual secret) to the writer.
func FormatTOTPURI ¶
FormatTOTPURI creates an otpauth:// URI for the given session and secret.
func GenerateTOTPSecret ¶
GenerateTOTPSecret generates a new 20-byte (160-bit) TOTP secret. Returns the secret as a base32-encoded string.
func ValidateTOTPCode ¶
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 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 ¶
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 ¶
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 (*Manager) Ask ¶
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 ¶
Granted reports whether a person approved this access in the grant period.
func (*Manager) Grants ¶
Grants returns the session's approved accesses that are still in their grant period.
func (*Manager) ListPending ¶
func (*Manager) OnGrantChange ¶
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 ¶
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) 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 ¶
SetGrantTTL turns grants on. A person's answer to a request then applies to every identical request for ttl.
func (*Manager) SetLauncher ¶
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 ¶
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 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.