iam

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package iam evaluates AWS-style JSON policies (§7): statements allow or deny actions ("service:ScaleService") on resources ("srn:syncloud:project/shop/env/production/service/web"), with optional conditions. An explicit Deny beats an Allow, which beats the implicit deny.

Index

Constants

View Source
const (
	KeyMFAPresent     = "syn:MFAPresent"     // "true" | "false"
	KeySourceIP       = "syn:SourceIp"       // the caller's address
	KeyCredentialType = "syn:CredentialType" // session | token | access_key | role_session
)

Condition keys (§7.1).

View Source
const Version = "2026-01"

Version is the only policy language version.

Variables

This section is empty.

Functions

func AllowsAny

func AllowsAny(stmts []Attached, action string, c Context) bool

AllowsAny reports whether some statement could allow action on some resource (list endpoints, whose results are then filtered per item).

func Match

func Match(pattern, s string) bool

Match reports whether a pattern with * (any run) and ? (one character) matches s. Action service names are matched case-sensitively, as written.

func ProjectResources

func ProjectResources(project string) []string

ProjectResources are the resources of one project.

Types

type Attached

type Attached struct {
	Policy    string // policy name
	Statement Statement
	Index     int
}

Attached is a statement with where it came from, for explanations.

type Context

type Context struct {
	MFA      bool
	SourceIP string
	CredType string
}

Context holds the condition values of a request.

type Decision

type Decision struct {
	Allowed bool      `json:"allowed"`
	Reason  string    `json:"reason"` // "allowed by …", "explicitly denied by …", "no policy allows it"
	By      *Attached `json:"-"`
	Policy  string    `json:"policy,omitempty"`
	Sid     string    `json:"sid,omitempty"`
}

Decision is the result of an evaluation.

func Evaluate

func Evaluate(stmts []Attached, action, resource string, c Context) Decision

Evaluate decides one request against a principal's statements.

type Document

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

Document is a policy.

func ManagedDocument

func ManagedDocument(name string) (Document, bool)

ManagedDocument returns a managed policy's document: "ReadOnly", or "Developer:shop" for a project template.

func Parse

func Parse(text []byte) (Document, error)

Parse reads and validates a policy document.

func (Document) Validate

func (d Document) Validate() error

Validate checks every statement.

type Managed

type Managed struct {
	Name        string
	Description string
	// PerProject templates take a project; the others are global.
	PerProject bool
	// contains filtered or unexported fields
}

Managed policies (§7) are built in and cannot be edited. Project-scoped ones are templates: attaching ProjectOwner for "shop" uses the policy "ProjectOwner:shop".

func ManagedPolicies

func ManagedPolicies() []Managed

ManagedPolicies lists the built-in policies.

type Statement

type Statement struct {
	Sid       string                           `json:"Sid,omitempty"`
	Effect    string                           `json:"Effect"` // Allow | Deny
	Action    StringList                       `json:"Action"`
	Resource  StringList                       `json:"Resource"`
	Condition map[string]map[string]StringList `json:"Condition,omitempty"`
}

Statement is one rule. Action and Resource accept a string or a list.

func (Statement) ConditionsHold

func (s Statement) ConditionsHold(c Context) bool

ConditionsHold reports whether a statement's conditions hold for c.

type StringList

type StringList []string

StringList unmarshals from a string or a list of strings.

func (*StringList) UnmarshalJSON

func (l *StringList) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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