Documentation
¶
Index ¶
- Constants
- Variables
- func Cond_ArnLike(s *subject, left, right string) bool
- func Cond_IpAddress(s *subject, left netip.Addr, right netip.Prefix) bool
- func Cond_NumericEquals(s *subject, left, right int) bool
- func Cond_NumericGreaterThan(s *subject, left, right int) bool
- func Cond_NumericGreaterThanEquals(s *subject, left, right int) bool
- func Cond_NumericLessThan(s *subject, left, right int) bool
- func Cond_NumericLessThanEquals(s *subject, left, right int) bool
- func Cond_StringEquals(s *subject, left, right string) bool
- func Cond_StringLike(s *subject, left, right string) bool
- func Id(id string, idx int) string
- type AccessTuple
- type AuthContext
- type Bag
- type Compare
- func Mod_Binary(f func(*subject, string, string) bool) Compare
- func Mod_Bool(f func(*subject, string, string) bool) Compare
- func Mod_Date(f func(*subject, int, int) bool) Compare
- func Mod_IgnoreCase(f Compare) Compare
- func Mod_Network(f func(*subject, netip.Addr, netip.Prefix) bool) Compare
- func Mod_Number(f func(*subject, int, int) bool) Compare
- type CondInner
- type CondLift
- type CondMod
- type CondOuter
- type Decision
- type Extra
- type OptionF
- func WithAdditionalProperties(props map[string]string) OptionF
- func WithDefaultS3Key(key string) OptionF
- func WithEnableFuzzyMatchArn() OptionF
- func WithForceFailure() OptionF
- func WithOverlay(overlays *entities.Universe) OptionF
- func WithSkipServiceAuthorizationValidation() OptionF
- func WithTracing() OptionF
- type Options
- type Pool
- type SimResult
- type Simulator
- func (s *Simulator) AccessSummary(actions []string, opts Options) (map[string]int, error)
- func (s *Simulator) Product(ps, as, rs []string, opts Options) ([]AccessTuple, error)
- func (s *Simulator) Simulate(ac AuthContext) (*SimResult, error)
- func (s *Simulator) SimulateByArn(principalArn, action, resourceArn string) (*SimResult, error)
- func (s *Simulator) SimulateByArnWithOptions(principalArn, action, resourceArn string, opts Options) (*SimResult, error)
- func (s *Simulator) SimulateWithOptions(ac AuthContext, opts Options) (*SimResult, error)
- func (s *Simulator) WhichActions(principal, resource string, opts Options) ([]string, error)
- func (s *Simulator) WhichPrincipals(action, resource string, opts Options) ([]string, error)
- func (s *Simulator) WhichResources(principal, action string, opts Options) ([]string, error)
Constants ¶
const ( DEFAULT_TIME_FORMAT = "2006-01-02T15:04:05" EMPTY = "" TRUE = "true" FALSE = "false" )
Static values
Variables ¶
var ConditionOperatorMap = map[string]CondInner{ condition.StringEquals: Mod_ResolveVariables( Cond_MatchAny( Cond_StringEquals, ), ), condition.StringNotEquals: Mod_ResolveVariables( Mod_Not( Cond_MatchAny( Cond_StringEquals, ), ), ), condition.StringEqualsIgnoreCase: Mod_ResolveVariables( Cond_MatchAny( Mod_IgnoreCase( Cond_StringEquals, ), ), ), condition.StringNotEqualsIgnoreCase: Mod_ResolveVariables( Mod_Not( Cond_MatchAny( Mod_IgnoreCase( Cond_StringEquals, ), ), ), ), condition.StringLike: Mod_ResolveVariables( Cond_MatchAny( Cond_StringLike, ), ), condition.StringNotLike: Mod_ResolveVariables( Mod_Not( Cond_MatchAny( Cond_StringLike, ), ), ), condition.NumericEquals: Cond_MatchAny( Mod_Number( Cond_NumericEquals, ), ), condition.NumericNotEquals: Mod_Not( Cond_MatchAny( Mod_Number( Cond_NumericEquals, ), ), ), condition.NumericLessThan: Cond_MatchAny( Mod_Number( Cond_NumericLessThan, ), ), condition.NumericLessThanEquals: Cond_MatchAny( Mod_Number( Cond_NumericLessThanEquals, ), ), condition.NumericGreaterThan: Cond_MatchAny( Mod_Number( Cond_NumericGreaterThan, ), ), condition.NumericGreaterThanEquals: Cond_MatchAny( Mod_Number( Cond_NumericGreaterThanEquals, ), ), condition.DateEquals: Cond_MatchAny( Mod_Date( Cond_NumericEquals, ), ), condition.DateNotEquals: Mod_Not( Cond_MatchAny( Mod_Date( Cond_NumericEquals, ), ), ), condition.DateLessThan: Cond_MatchAny( Mod_Date( Cond_NumericLessThan, ), ), condition.DateLessThanEquals: Cond_MatchAny( Mod_Date( Cond_NumericLessThanEquals, ), ), condition.DateGreaterThan: Cond_MatchAny( Mod_Date( Cond_NumericGreaterThan, ), ), condition.DateGreaterThanEquals: Cond_MatchAny( Mod_Date( Cond_NumericGreaterThanEquals, ), ), condition.Bool: Mod_ResolveVariables( Cond_MatchAny( Mod_Bool( Mod_IgnoreCase( Cond_StringEquals, ), ), ), ), condition.BinaryEquals: Cond_MatchAny( Mod_Binary( Cond_StringEquals, ), ), condition.IpAddress: Cond_MatchAny( Mod_Network( Cond_IpAddress, ), ), condition.NotIpAddress: Mod_Not( Cond_MatchAny( Mod_Network( Cond_IpAddress, ), ), ), condition.ArnEquals: Mod_ResolveVariables( Cond_MatchAny( Cond_ArnLike, ), ), condition.ArnNotEquals: Mod_ResolveVariables( Mod_Not( Cond_MatchAny( Cond_ArnLike, ), ), ), condition.ArnLike: Mod_ResolveVariables( Cond_MatchAny( Cond_ArnLike, ), ), condition.ArnNotLike: Mod_ResolveVariables( Mod_Not( Cond_MatchAny( Cond_ArnLike, ), ), ), }
ConditionOperatorMap defines the mapping between operator names and functions
var DEFAULT_OPTIONS = NewOptions()
DEFAULT_OPTIONS uses all default configuration options for simulation
var TIME_FORMATS = []string{
"2006",
"2006-01",
"2006-01-02",
"2006-01-02T15:04",
"2006-01-02T15:04-0700",
"2006-01-02T15:04:05",
"2006-01-02T15:04:05Z",
"2006-01-02T15:04:05-0700",
"2006-01-02T15:04:05.999",
"2006-01-02T15:04:05.999Z",
"2006-01-02T15:04:05.999-0700",
}
var TestingSimulationOptions = NewOptions( WithSkipServiceAuthorizationValidation(), WithTracing(), )
TestingSimulationOptions provides a specific set of simulation options appropriate for most tests. It allows for exercising difficult-to-reach error paths while also allowing us to bend the rules a bit for testing -- fewer checks around the specifics of the dummy resource calls we use
var VariableExpansionRegex = regexp.MustCompile(`\${([a-zA-Z0-9]+:\S+?)}`)
VariableExpansionRegex defines the variable to use for expanding policy variables
Functions ¶
func Cond_ArnLike ¶
Cond_ArnLike defines the `ArnLike` condition function
func Cond_IpAddress ¶
Cond_IpAddress defines the `IpAddress` condition function
func Cond_NumericEquals ¶
Cond_NumericEquals defines the `NumericEquals` condition function
func Cond_NumericGreaterThan ¶
Cond_NumericGreaterThan defines the `NumericGreaterThan` condition function
func Cond_NumericGreaterThanEquals ¶
Cond_NumericGreaterThanEquals defines the `NumericGreaterThanEquals` condition function
func Cond_NumericLessThan ¶
Cond_NumericLessThan defines the `NumericLessThan` condition function
func Cond_NumericLessThanEquals ¶
Cond_NumericLessThanEquals defines the `NumericLessThanEquals` condition function
func Cond_StringEquals ¶
Cond_StringEquals defines the `StringEquals` condition function
func Cond_StringLike ¶
Cond_StringLike defines the `StringLike` condition function
Types ¶
type AccessTuple ¶
type AuthContext ¶
type AuthContext struct {
Action *types.Action
Principal *entities.FrozenPrincipal
Resource *entities.FrozenResource
Time time.Time
Properties Bag[string]
MultiValueProperties Bag[[]string]
}
AuthContext defines the tertiary context of a request that can be used for authz decisions TODO(nsiow) decide if this should be public or private type
func (*AuthContext) ConditionKey ¶
func (ac *AuthContext) ConditionKey(key string, opts Options) string
ConditionKey retrieves the value for the requested key from the AuthContext TODO(nsiow) key retrieval should be case insensitive... I think TODO(nsiow) support Trace object here for even lower level debugging
func (*AuthContext) MultiKey ¶
func (ac *AuthContext) MultiKey(key string, opts Options) []string
MultiKey retrieves the values for the requested key from the AuthContext
func (*AuthContext) Substitute ¶
func (ac *AuthContext) Substitute(value string, opts Options) string
Substitute resolves and replaces all IAM variables within the provided values
func (*AuthContext) Validate ¶
func (ac *AuthContext) Validate(opts Options) error
Validate checks that the given AuthContext is valid and ready for simulation
type Bag ¶
type Bag[T any] struct { // contains filtered or unexported fields }
Bag implements a generic looser map interface which case-folds its string keys
func NewBagFromMap ¶
NewBagFroMap creates and returns a new case-folded bag with the specified value type T, seeded using the folded key/values from the provided map
func (*Bag[T]) Check ¶
Check folds the input key and then checks the bag for a value matching the provided key
type Compare ¶
Compare defines a function used to compare a value to a single other value
The function should take in two strings where `left` is the observed value and `right` is what we are trying to match against
func Mod_Binary ¶
Mod_Binary validates and forwards on the base64 encoded values, allowing binary expressions
We reuse the string operators for this rather than a byte-by-byte comparison for ease, but for slightly faster comparison we should perform the byte-by-byte comparison to avoid the base64 encoding overhead
func Mod_IgnoreCase ¶
Mod_IgnoreCase defines a Condition modifier which ignores character casing
func Mod_Network ¶
Mod_Network converts the incoming strings into IP addresses/nets, allowing network expressions
type CondInner ¶
CondInner defines a function that accepts a left hand value and a right hand set of values and evaluates the outcome of the condition
func Cond_MatchAny ¶
func Mod_IfExists ¶
Mod_IfExists defines a Condition modifier which returns true if the key is not found
func Mod_MustExist ¶
Mod_MustExist defines a Condition modifier which returns false if the key is not found
func Mod_ResolveVariables ¶
Mod_ResolveVariables resolves and replaces all IAM variables within the provided values
type CondLift ¶
CondLift defines a function which "lifts" a ConditionInner operator
This function effectively contains the logic to map the "key" parameter of a ConditionOuter function to the "left" parameter of a ConditionInner function
type CondOuter ¶
CondOuter defines a function that accepts a key name and set of values and evaluates the outcome of the condition
func Mod_ForAllValues ¶
Mod_ForAllValues defines a Condition modifier targeting match-all logic for multivalued conditions
func Mod_ForAnyValues ¶
Mod_ForAnyValues defines a Condition modifier targeting match-any logic for multivalued conditions
func Mod_ForSingleValue ¶
Mod_ForSIngleValue defines a Condition modifier targeting match-any logic for single-valued conditions (the default)
func ResolveConditionEvaluator ¶
ResolveConditionEvaluator takes in an operator name and resolves it to a function
If the function could be resolved, the second return value is `true`. Otherwise, the second return value is `false`
type Decision ¶
type Decision struct {
// contains filtered or unexported fields
}
Decision maintains a unique list of Effect values
func (*Decision) Allowed ¶
Allowed determines whether or not the Decision corresponds to an IAM operation being allowed
func (*Decision) Denied ¶
Denied determines whether or not the Decision corresponds to an IAM operation being denied
func (*Decision) DeniedExplicit ¶
DeniedExplicit determines whether or not the Decision corresponds to an IAM operation being denied based on an explicit DENY decision TODO(nsiow) check for other instances in the code base where this should be used
type Extra ¶
type Extra struct {
ResourceAllowsExplicitPrincipal bool
}
Extra is a necessary evil of IAM evaluations quirks that need to be handled delicately
type OptionF ¶
type OptionF func(*Options)
OptionF implements the functional options pattern for simulator options
func WithAdditionalProperties ¶
WithAdditionalProperties adds the provided properties to the request context
func WithDefaultS3Key ¶
WithDefaultS3Key sets the provided S3 key as the default for all buckets
func WithEnableFuzzyMatchArn ¶
func WithEnableFuzzyMatchArn() OptionF
WithEnableFuzzyMatchArn turns on fuzzy-matching for ARN values
func WithForceFailure ¶
func WithForceFailure() OptionF
WithForceFailure causes all simulations to fail
func WithOverlay ¶
WithOverlay adds the provided "overlay" universe to our options
func WithSkipServiceAuthorizationValidation ¶
func WithSkipServiceAuthorizationValidation() OptionF
WithSkipServiceAuthorizationValidation toggles SkipServiceAuthorizationValidation to true
type Options ¶
type Options struct {
// SkipServiceAuthorizationValidation foregoes the usual validation via the Service Authorization
// Reference. This will result in faster simulation but at the cost of real-world accuracy
SkipServiceAuthorizationValidation bool
// EnableTracing turns on active tracing for requests. This incurs a minor performance penalty but
// allows for helpful explanations of how a particular simulation result was achieved
EnableTracing bool
// Context specifies additional key/value pairs that should be carried along in the Authorization
// context
Context Bag[string]
// Overlays allows one to specify a special "overlay" Universe in which entity lookup takes place
// over the primary simulation Universe
Overlay *entities.Universe
// DefaultS3Key specifies which S3 object key should be used to expand S3 bucket ARNs by default.
// In other words, it enables simulation against S3 object-level calls for operations where
// individual object keys cannot be provided
DefaultS3Key string
// EnableFuzzyMatchArn enables fuzzy-matching for principal/resource values. This will do a
// case-insensitive search based on user inputs, and return an error if more than one value
// matches
EnableFuzzyMatchArn bool
// ForceFailure causes all simulation results to throw an error. Primarily used for testing and
// debugging purposes
ForceFailure bool
}
Options contains all possible customizatons for simulator logic + behavior
func NewOptions ¶
NewOptions creates and returns a new Options struct parameterized with the provided options
type Pool ¶
type Pool struct {
Simulator *Simulator // TODO(nsiow) revisit this: make default Pool useful?
Ctx context.Context
// contains filtered or unexported fields
}
func (*Pool) NumWorkers ¶
func (*Pool) SetBatchSize ¶
func (*Pool) SetTimeout ¶
func (*Pool) SetWorkers ¶
type SimResult ¶
type SimResult struct {
// Principal corresponds to the ARN of the Principal used for this evaluation
Principal string
// Action corresponds to the AWS API action used for this evaluation
Action string
// Resource corresponds to the ARN of the Resource used for this evaluation
Resource string
// IsAllowed corresponds to whether or not the operation was allowed
IsAllowed bool
// Trace contains an evaluation trace providing context as to the access evaluation process
Trace *trace.Trace
}
SimResult defines the output of a policy simulation option
type Simulator ¶
Simulator provides the ability to simulate IAM policies and the interactions between Principals + Resources
func NewSimulator ¶
NewSimulator creates and returns a Simulator with the provided options
func (*Simulator) AccessSummary ¶
func (*Simulator) Product ¶
func (s *Simulator) Product(ps, as, rs []string, opts Options) ([]AccessTuple, error)
Product is a mostly-helper function (that can be used directly!) which calculates the Cartesian product of the provided simulation identifiers, while also filtering out any combinations that are not allowed.
func (*Simulator) Simulate ¶
func (s *Simulator) Simulate(ac AuthContext) (*SimResult, error)
Simulate determines whether the provided AuthContext would be allowed
func (*Simulator) SimulateByArn ¶
SimulateByArn determines whether the operation would be allowed between the Principal and Resource specified by the provided ARNs, using the Simulator's default options
func (*Simulator) SimulateByArnWithOptions ¶
func (s *Simulator) SimulateByArnWithOptions( principalArn, action, resourceArn string, opts Options) (*SimResult, error)
SimulateByArnWithOptions determines whether the operation would be allowed between the Principal and Resource specified by the provided ARNs, using the provided simulation Options
func (*Simulator) SimulateWithOptions ¶
func (s *Simulator) SimulateWithOptions(ac AuthContext, opts Options) (*SimResult, error)
Simulate determines whether the provided AuthContext would be allowed