Documentation
¶
Overview ¶
Package access provides a simple way to manage access to resources, with a policy-based approach. It usses a simple policy language to define access rules, and URNs to express user, group and resources.
Index ¶
- Constants
- Variables
- func Is(u *urn.URN, i ResourceIdentifier) bool
- func WithNoop(ctx context.Context, t *testing.T, access pb.AccessServer, ...)
- type Access
- type Accessor
- type Action
- type Actions
- type Client
- type Condition
- type Conditions
- type Effect
- type Matcher
- type Opt
- type Partition
- type Partitions
- type Policer
- type Policy
- type Region
- type Regions
- type Resource
- type ResourceIdentifier
- type Resources
- type Rule
- type Rules
- type Service
- type Services
- type UnimplementedAccessor
Constants ¶
const DefaultVersion = "2023-03-28"
DefaultVersion
Variables ¶
var DefaultPartitions = Partitions{ "cloud": true, }
DefaultPartitions is the default list of partitions.
var DefaultRegions = Regions{ "eu-central-1": true, }
DefaultRegions is the default list of regions.
var DefaultServices = Services{ // contains filtered or unexported fields }
DefaultServices is the default list of services.
var GroupResourceIdentifier = func(u *urn.URN) bool { return u.Service == defaultAccessService && strings.HasPrefix(u.Resource.String(), "groups") }
GroupResourceIdentifier is the identifier for a group.
var IdentityBasedMatcher = func(l *urn.URN, r *urn.URN) bool { return (l.Namespace == r.Namespace || (l.Namespace == urn.Wildcard && r.Namespace == urn.Wildcard) || (l.Namespace == urn.Empty && r.Namespace == urn.Empty) || r.Namespace == urn.Wildcard || r.Namespace == urn.Empty) && (l.Partition == r.Partition || (l.Partition == urn.Wildcard && r.Partition == urn.Wildcard) || (l.Partition == urn.Empty && r.Partition == urn.Empty) || r.Partition == urn.Wildcard || r.Partition == urn.Empty) && (l.Service == r.Service || (l.Service == urn.Wildcard && r.Service == urn.Wildcard) || (l.Service == urn.Empty && r.Service == urn.Empty) || r.Service == urn.Wildcard || r.Service == urn.Empty) && (l.Region == r.Region || (l.Region == urn.Wildcard && r.Region == urn.Wildcard) || (l.Region == urn.Empty && r.Region == urn.Empty) || r.Region == urn.Wildcard || r.Region == urn.Empty) && (l.Identifier == r.Identifier || (l.Identifier == urn.Wildcard && r.Identifier == urn.Wildcard) || (l.Identifier == urn.Empty && r.Identifier == urn.Empty) || r.Identifier == urn.Wildcard || r.Identifier == urn.Empty) && (l.Resource == r.Resource || (l.Resource == urn.Wildcard && r.Resource == urn.Wildcard) || (l.Resource == urn.Empty && r.Resource == urn.Empty) || r.Resource == urn.Wildcard || r.Resource == urn.Empty) }
IdentityBasedMatcher is a matcher that matches the URN based on the identity.
var RoleResourceIdentifier = func(u *urn.URN) bool { return u.Service == defaultAccessService && strings.HasPrefix(u.Resource.String(), "roles") }
RoleResourceIdentifier is the identifier for a role.
var UserResourceIdentifier = func(u *urn.URN) bool { return u.Service == defaultAccessService && strings.HasPrefix(u.Resource.String(), "users") }
UserResourceIdentifier is the identifier for a user.
Functions ¶
Types ¶
type Accessor ¶ added in v0.5.2
type Accessor interface { // Allow returns true if the user is allowed to perform the action on the resource. Allow(ctx context.Context, principal *urn.URN, ressource *urn.URN, action Action) (bool, error) }
Accessor is the interface to allow or deny access.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the access client.
type Condition ¶ added in v0.5.2
type Condition struct { // Key is the key of the condition. Key string `json:"key" yaml:"key"` // Value is the value of the condition. Value string `json:"value" yaml:"value"` // Operator is the operator of the condition. Operator string `json:"operator" yaml:"operator"` }
Condition is a set of key-value pairs that define how a user can access a resource.
type Effect ¶ added in v0.5.2
type Effect string
Effect is the effect of the rule, it can be allow or deny.
const Allow Effect = "allow"
Allow effect.
const Deny Effect = "deny"
Deny effect.
type Partitions ¶ added in v0.5.2
Partitions is the list of partitions.
func (Partitions) Add ¶ added in v0.5.2
func (p Partitions) Add(partition Partition)
Add adds a partition to the list.
type Policer ¶ added in v0.5.2
type Policer interface { // Policies returns the policy for the given user. Policies(ctx context.Context, principal *urn.URN) ([]*Policy, error) }
Policer returns the policy for the given user.
type Policy ¶ added in v0.5.2
type Policy struct { // Version is the version of the policy. Version string `json:"version" yaml:"version"` // ID is the unique identifier of the policy. ID string `json:"id" yaml:"id"` // Name is the name of the policy. Name string `json:"name" yaml:"name"` // Description is the description of the policy. Description string `json:"description" yaml:"description"` // Rules is the list of rules that define how a user can access a resource. Rules Rules `json:"rules" yaml:"rules"` }
Policy is a set of rules that define how a user can access a resource.
func DefaultPolicy ¶ added in v0.5.2
func DefaultPolicy() *Policy
DefaultPolicy returns the default policy.
func (*Policy) UnmarshalJSON ¶ added in v0.5.2
UnmarshalJSON overwrite own policy with values of the given in policy in JSON format
func (*Policy) UnmarshalYAML ¶ added in v0.5.2
UnmarshalYAML overwrite own policy with values of the given policy in YAML format.
type Resource ¶ added in v0.5.2
type Resource string
Resource is the resource that the rule applies to.
type ResourceIdentifier ¶ added in v0.5.2
ResourceIdentifier is the unique identifier of a resource.
type Rule ¶ added in v0.5.2
type Rule struct { // ID is the unique identifier of the rule. ID string `json:"id" yaml:"id"` // Resources is the list of resources that the rule applies to. Resources Resources `json:"resources" yaml:"resources"` // Actions is the list of actions that the rule applies to. Actions Actions `json:"actions" yaml:"actions"` // Effect is the effect of the rule, it can be allow or deny. Effect Effect `json:"effect" yaml:"effect"` // Conditions is the list of conditions that the rule applies to. Conditions Conditions `json:"conditions" yaml:"conditions"` }
Rule is a set of conditions that define how a user can access a resource.
type UnimplementedAccessor ¶ added in v0.5.2
type UnimplementedAccessor struct{}
UnimplementedAccessor is the default implementation of the Accessor interface.