policies

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigName = "policy.json"
View Source
var PolyciesConfigDirs = dirs.MultiJoin("policies", dirs.SelfConfigDirs...)
View Source
var PolyciesConfigHome = dirs.Join(dirs.SelfConfigHome, "policies")

Functions

func CreateCommand added in v0.0.43

func CreateCommand(name string) error

func InspectCommand added in v0.0.43

func InspectCommand(name string) error

func PolicyFind added in v0.0.43

func PolicyFind(name string) (string, error)

func PolicyHomeDir added in v0.0.43

func PolicyHomeDir(name string) (string, error)

func PolicyList added in v0.0.43

func PolicyList() ([]string, error)

func PolicyRealpath added in v0.0.43

func PolicyRealpath(dir string) (string, error)

func PolicyServer

func PolicyServer(w http.ResponseWriter, req *http.Request)

func Print added in v0.0.43

func Print(name string) error

func PrintList added in v0.0.43

func PrintList() error

func RunServer

func RunServer() error

Types

type AuthorizationList added in v0.0.43

type AuthorizationList map[string]bool

func (AuthorizationList) Get added in v0.0.43

func (authz AuthorizationList) Get(name string) bool

type AuthorizationMap added in v0.0.43

type AuthorizationMap map[string]string

if authorizations is nil, authorizations is reset else, authorization is transformed using the map if the authorization is not found in the map, try with the empty string key if the authorization is not found, forward the authorization as it is

func (AuthorizationMap) MapAuthorization added in v0.0.43

func (a AuthorizationMap) MapAuthorization(authorization string) string

type MatchBearer

type MatchBearer struct {
	Token           string            `json:"token,omitempty"`             // Raw bearer token
	JWTAlg          string            `json:"jwt_alg,omitempty"`           // JWT algorithm
	JWTSecretBase64 string            `json:"jwt_secret_base64,omitempty"` // JWT secret key or shared secret
	JWTKeyBase64    string            `json:"jwt_key_base64,omitempty"`    // JWT public key
	Authorizations  AuthorizationList `json:"authorizations,omitempty"`
}

func (*MatchBearer) JWTKey added in v0.0.43

func (m *MatchBearer) JWTKey() ([]byte, error)

func (*MatchBearer) JWTSecret

func (m *MatchBearer) JWTSecret() ([]byte, error)

func (*MatchBearer) Matching

func (m *MatchBearer) Matching(mc *MatchContext, authorization string, default_authz AuthorizationList) (bool, error)

type MatchContext

type MatchContext struct {
	*Policies
	Request *http.Request
}

type Matcher

type Matcher struct {
	// A matcher matches if all of its defined matchers succeeds. if nothing
	// defined, it does not match
	Meta           map[string]string `json:"meta,omitempty"`                   // Metadata
	Authorizations AuthorizationMap  `json:"authorizations,omitempty"`         // Transform authorizations
	DefAuthz       AuthorizationList `json:"default_authorizations,omitempty"` // Default authorizations
	Always         bool              `json:"always,omitempty"`                 // Always match (conditioned to other defined matchers)
	Never          bool              `json:"never,omitempty"`                  // Never match, can be used to disable a matcher
	Skip           bool              `json:"skip,omitempty"`                   // Skip matches other than always and never
	All            []*Matcher        `json:"all,omitempty"`                    // All must match
	Any            []*Matcher        `json:"any,omitempty"`                    // Any must match
	None           []*Matcher        `json:"none,omitempty"`                   // None must match
	Bearer         []*MatchBearer    `json:"bearer,omitempty"`                 // A bearer token in the list should match
	Origin         []string          `json:"origin,omitempty"`                 // One of these origins must match the Origin header
	Policy         *PolicyRef        `json:"policy,omitempty"`                 // Match policy by name, fail if it does not exist
}

func (*Matcher) FindAllByMeta added in v0.0.43

func (m *Matcher) FindAllByMeta(meta map[string]string) []*Matcher

func (*Matcher) FindByMeta added in v0.0.43

func (m *Matcher) FindByMeta(meta map[string]string) *Matcher

func (*Matcher) Matching

func (m *Matcher) Matching(mc *MatchContext, authorization string, res_meta map[string]string) (bool, error, *Matcher)

type Policies

type Policies struct {
	ByName map[string]*Policy
	ByPath map[string]*Policy
}

func LoadPolicies

func LoadPolicies() (*Policies, error)

type Policy

type Policy struct {
	Name                 string     `json:"name"` // Must correspond to file name
	PolicyDir            string     `json:"-"`
	Match                []*Matcher `json:"match,omitempty"` // Policy match if any matcher succeeds
	DefaultAuthorization string     `json:"default_authorization,omitempty"`
}

func Create added in v0.0.43

func Create(name string) (*Policy, error)

func ReadFromDir added in v0.0.43

func ReadFromDir(dir string, name string) (*Policy, error)

func ReadFromName added in v0.0.43

func ReadFromName(name string) (*Policy, error)

func (*Policy) FindAllMatchers added in v0.0.43

func (p *Policy) FindAllMatchers(meta map[string]string) []*Matcher

func (*Policy) FindMatcher added in v0.0.43

func (p *Policy) FindMatcher(meta map[string]string) *Matcher

func (*Policy) Inspect added in v0.0.43

func (p *Policy) Inspect() (json.RawMessage, error)

func (*Policy) Matching

func (p *Policy) Matching(mc *MatchContext, authorization string, res_meta map[string]string) (res bool, err error, matcher *Matcher)

func (*Policy) Save added in v0.0.43

func (p *Policy) Save() error

func (*Policy) WriteToDir added in v0.0.43

func (p *Policy) WriteToDir(dir string) error

type PolicyMatcher

type PolicyMatcher interface {
	Matching(mc *MatchContext) (bool, error)
}

type PolicyNotFoundError added in v0.0.43

type PolicyNotFoundError struct {
	Name string
}

func (*PolicyNotFoundError) Error added in v0.0.43

func (err *PolicyNotFoundError) Error() string

type PolicyRef added in v0.0.43

type PolicyRef PolicyRefImplem

func (*PolicyRef) UnmarshalJSON added in v0.0.43

func (pr *PolicyRef) UnmarshalJSON(data []byte) error

type PolicyRefImplem added in v0.0.43

type PolicyRefImplem struct {
	Name           string           `json:"name"`
	Authorizations AuthorizationMap `json:"authorizations,omitempty"` // Authorization transformation
}

Jump to

Keyboard shortcuts

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