iampolicystream

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package iampolicystream records IAM evaluation events in a bounded ring buffer, fans them out to live subscribers and derives least-privilege policy suggestions from them.

Index

Constants

View Source
const (
	DecisionAllow = "allow"
	DecisionDeny  = "deny"
)

Decision values recorded on an Event.

View Source
const (
	ReasonIdentityPolicy   = "identity-policy"
	ReasonResourcePolicy   = "resource-policy"
	ReasonPermissionBound  = "permission-boundary"
	ReasonImplicitDeny     = "implicit-deny"
	ReasonUnresolvedCaller = "unresolved-principal"
)

Deny-reason values recorded on an Event.

View Source
const (
	// DefaultCapacity is the ring size used when New is given a non-positive capacity.
	DefaultCapacity = 2000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Time         time.Time `json:"timestamp"`
	RequestID    string    `json:"requestId,omitempty"`
	Service      string    `json:"service"`
	Operation    string    `json:"operation"`
	Action       string    `json:"action"`
	Resource     string    `json:"resource"`
	Principal    string    `json:"principal"`
	Decision     string    `json:"decision"`
	Reason       string    `json:"reason,omitempty"`
	MatchedSid   string    `json:"matchedSid,omitempty"`
	MatchedBy    string    `json:"matchedBy,omitempty"`
	Suggested    *Policy   `json:"suggestedPolicy,omitempty"`
	ConditionKey []string  `json:"conditionKeys,omitempty"`
	Seq          uint64    `json:"seq"`
	StatementIdx int       `json:"matchedStatementIndex"`
	PolicyIdx    int       `json:"matchedPolicyIndex"`
	Enforced     bool      `json:"enforced"`
}

Event is one evaluated request.

type Filter

type Filter struct {
	Since     time.Time
	Decision  string
	Service   string
	Principal string
	AfterSeq  uint64
}

Filter selects events; zero fields match everything.

func (Filter) Match

func (f Filter) Match(e Event) bool

Match reports whether e passes the filter.

type Policy

type Policy struct {
	Version   string      `json:"Version"`
	Statement []Statement `json:"Statement"`
}

Policy is an IAM policy document.

func StatementFor

func StatementFor(action, resource string) *Policy

StatementFor returns the minimal Allow policy permitting action on resource.

type Recorder

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

Recorder is a bounded, concurrency-safe event ring with live fan-out.

func New

func New(capacity int) *Recorder

New returns a Recorder holding at most capacity events.

func (*Recorder) Clear

func (r *Recorder) Clear()

Clear discards all retained events.

func (*Recorder) Dropped

func (r *Recorder) Dropped() uint64

Dropped reports how many live deliveries were skipped due to slow subscribers.

func (*Recorder) Record

func (r *Recorder) Record(e Event)

Record stamps e with a sequence number, stores it and notifies subscribers. A subscriber whose buffer is full misses the event rather than blocking.

func (*Recorder) Snapshot

func (r *Recorder) Snapshot(keep func(Event) bool) []Event

Snapshot returns the retained events, oldest first, that pass keep (nil keeps all).

func (*Recorder) Subscribe

func (r *Recorder) Subscribe(ctx context.Context) <-chan Event

Subscribe returns a channel of live events. The subscription ends, and the channel is closed, when ctx is done.

func (*Recorder) Subscribers

func (r *Recorder) Subscribers() int

Subscribers reports the number of live subscriptions.

type Statement

type Statement struct {
	Effect   string   `json:"Effect"`
	Action   []string `json:"Action"`
	Resource []string `json:"Resource"`
}

Statement is one Allow statement of a suggested policy.

type Suggestion

type Suggestion struct {
	Policy         Policy   `json:"policy"`
	BlockedByDeny  []string `json:"blockedByExplicitDeny,omitempty"`
	EventsConsumed int      `json:"eventsConsumed"`
}

Suggestion is a least-privilege policy derived from recorded events.

func Suggest

func Suggest(events []Event, includeAllowed bool) Suggestion

Suggest builds one Allow statement per distinct resource covering every consumed action. Events denied by an explicit Deny or permission boundary cannot be fixed by an identity Allow and are listed in BlockedByDeny. Allowed events are consumed only when includeAllowed is set.

Jump to

Keyboard shortcuts

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