policyscope

package
v0.143.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package policyscope limits a local access-policy rule to an environment, an instance, or both (backstage spec/features/perimeter, REQ:local-rule-selectors and permission model §4.1).

A rule in a DALgo access document may carry two DataTug keys that DALgo itself does not know:

environment: production            # an environment kind
instance: factory-e-prod/factory   # <environment id>/<catalog id>

Project turns such a document into the plain DALgo document for one read: a rule whose selectors all match the instance the read opens keeps its place with the keys removed; any other selector rule is removed, as if the document did not contain it. DALgo precedence and deny by default are left to DALgo. A document with no selector is returned as the same bytes. When the read's instance (or, for an environment selector, its kind) is not known, Project refuses with ErrTargetUnknown and the caller must deny.

Index

Constants

View Source
const (
	KeyEnvironment = "environment"
	KeyInstance    = "instance"
)

Rule keys this package owns.

Variables

View Source
var ErrInvalidSelector = errors.New("policyscope: invalid rule selector")

ErrInvalidSelector marks a document whose selectors cannot be applied. The whole document is refused, never applied without them.

View Source
var ErrNoRules = errors.New("policyscope: no rule of the policy applies to this instance, so it denies every read")

ErrNoRules is returned when no rule of the document's top-level scopes applies to the target. DALgo cannot decode a document without a scope, so the caller stands a policy that denies every read in its place.

View Source
var ErrTargetUnknown = errors.New("policyscope: the instance this read opens is not known, so a policy that selects instances or environments denies it")

ErrTargetUnknown is returned for a document that uses a selector when the read's instance, or the environment kind a selector needs, is not known. Every such document denies that read.

View Source
var ErrUnsupportedCodec = errors.New("policyscope: only YAML and JSON policy documents can be inspected for rule selectors")

ErrUnsupportedCodec is returned for a codec other than DALgo's YAML and JSON codecs: its documents cannot be inspected for selectors.

Functions

func Denies

func Denies(err error) bool

Denies reports whether err from Project means the document denies every read of the target.

func Project

func Project(data []byte, codec access.Codec, t Target) ([]byte, error)

Project returns the plain DALgo document data stands for when read for t. A document with no selector is returned unchanged, as the same slice. Otherwise every rule whose selectors do not all match t is removed, the selector keys are removed from the rules that stay, and a scope left with no rule or child scope by that removal is removed with it. A document that uses a selector returns ErrTargetUnknown when t's instance is not known, or when a rule names an environment and t's kind is not known, and ErrNoRules when the projection leaves it no top-level scope.

func Scoped

func Scoped(data []byte, codec access.Codec) (bool, error)

Scoped reports whether any rule of the document names a selector. It refuses a document whose selectors cannot be applied.

func Unscoped

func Unscoped(data []byte, codec access.Codec) ([]byte, error)

Unscoped returns the document with every selector key removed and every rule kept, so DALgo can check a selector document's rules when it is loaded. It extends every selector rule to every instance: it must never decide a read. A document with no selector is returned unchanged.

Types

type Selector

type Selector struct {
	Environment datatug.EnvironmentKind
	Instance    string
}

Selector is the selectors one rule names. The zero Selector names none.

func (Selector) IsZero

func (s Selector) IsZero() bool

IsZero reports whether the selector names nothing.

func (Selector) Matches

func (s Selector) Matches(t Target) (bool, error)

Matches reports whether t satisfies every selector s names. It returns ErrTargetUnknown when t lacks a fact a selector needs.

func (Selector) Validate

func (s Selector) Validate() error

Validate refuses an environment that is not a known kind and an instance not written <environment>/<catalog>.

type Target

type Target struct {
	// Environment is the environment id, for example factory-e-prod.
	Environment string
	// Catalog is the catalog id inside the environment, for example factory.
	Catalog string
	// Kind is the environment's kind; empty or unknown means not known.
	Kind datatug.EnvironmentKind
}

Target is the instance one read opens: one catalog in one environment (decision 0008), and the kind stored on that environment.

func (Target) Instance

func (t Target) Instance() string

Instance is the target's instance id, <environment>/<catalog>, or "" when either part is not known.

Jump to

Keyboard shortcuts

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