policy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownApproval = errors.New("unknown approval")

ErrUnknownApproval is an id approve cannot find, or one that is already consumed or expired.

Functions

func ConfirmSentence

func ConfirmSentence(operationID string, params map[string]string) string

func DefaultApprovalDir

func DefaultApprovalDir() (string, error)

func WithInput

func WithInput(ctx context.Context, in Input) context.Context

Types

type Around

type Around func(ctx context.Context, op *catalog.Operation) (Decision, bool, error)

type Builtin

type Builtin struct {
	Caller string
	Allow  map[string]bool
}

Allow nil permits every declared permission.

func (Builtin) Check

func (b Builtin) Check(ctx context.Context, op *catalog.Operation) (Decision, error)

type CommandNotifier

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

func (*CommandNotifier) Pending

func (c *CommandNotifier) Pending(ctx context.Context, notice Notice) error

type Decision

type Decision string
const (
	DecisionAllow              Decision = "allow"
	DecisionDeny               Decision = "deny"
	DecisionConfirmationNeeded Decision = "confirmation_required"
)

func Check

func Check(ctx context.Context, hook Hook, op *catalog.Operation) (Decision, error)

type HTTPNotifier

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

func (*HTTPNotifier) Pending

func (h *HTTPNotifier) Pending(ctx context.Context, notice Notice) error

type Hook

type Hook interface {
	Check(ctx context.Context, op *catalog.Operation) (Decision, error)
}

type Input

type Input struct {
	Params    map[string]string
	Arguments map[string]any
	Caller    string
}

Input is the call under policy. Caller is the caller or tenant.

func InputFrom

func InputFrom(ctx context.Context) Input

type Notice

type Notice struct {
	ID        string
	Operation string
	Caller    string
}

Notice is a pending call. It carries no parameters and no credentials.

type Notifier

type Notifier interface {
	Pending(ctx context.Context, notice Notice) error
}

Notifier is told when a call is pending. It does not approve the call.

func NewWebhook

func NewWebhook(rawURL string, command []string) (Notifier, error)

type PendingConfirmation

type PendingConfirmation struct {
	ID          string            `json:"ID"`
	OperationID string            `json:"OperationID"`
	Params      map[string]string `json:"Params"`
}

type State

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

Consumed nonces are files in the signer directory. Two machines that share the secret and not that directory can each accept the token until expiry.

func NewState

func NewState() *State

func (*State) Approve

func (s *State) Approve(id string) (string, error)

Approve records a separate decision. The returned id is what a later invoke accepts once.

func (*State) ConsumeConfirmation

func (s *State) ConsumeConfirmation(approvalID, opID string, params map[string]string) (bool, error)

func (*State) ConsumeFor

func (s *State) ConsumeFor(caller, approvalID, opID string, params map[string]string) (bool, error)

ConsumeFor accepts an approved id once, and only for the caller that received it.

func (*State) Pending

func (s *State) Pending(id string) *PendingConfirmation

func (*State) RequestConfirmation

func (s *State) RequestConfirmation(opID string, params map[string]string) (string, error)

RequestConfirmation records a pending call. The id it returns does not authorize HTTP. A store error means the file was not written, so there is no pending id to approve.

func (*State) RequestFor

func (s *State) RequestFor(caller, opID string, params map[string]string) (string, error)

RequestFor records a pending call for one caller. The id it returns does not authorize HTTP. A store error means the file was not written, so there is no pending id to approve.

func (*State) SetNonceDir

func (s *State) SetNonceDir(dir string)

func (*State) SetSigner

func (s *State) SetSigner(secret []byte, ttl time.Duration) error

type Wrapped

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

func Wrap

func Wrap(next Hook, around Around) Wrapped

func (Wrapped) Check

func (w Wrapped) Check(ctx context.Context, op *catalog.Operation) (Decision, error)

Jump to

Keyboard shortcuts

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