sourcepolicy

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sourcepolicy reads and applies a source policy: what a team refuses for every ConfigMap and Git source, held in an immutable ConfigMap a resource selects with sourcePolicyFrom.

The document is YAML with three optional rules:

allowedGitHosts:      # the only host[:port] a Git source may name
  - git.example.com
allowedConfigMaps:    # the only ConfigMaps a ConfigMap source may name
  - inventory-schema
maxContentBytes: 1048576   # the most the selected files may hold together

A rule that is absent refuses nothing. A list that is present and empty allows nothing of its kind. Any other field is refused, so a rule misspelled does not read as a rule kept.

Index

Constants

View Source
const MaxDocumentBytes = 64 << 10

MaxDocumentBytes bounds the policy document.

Variables

View Source
var ErrRefused = errors.New("the source policy refuses this source")

ErrRefused is every refusal of a source by its policy, matched with errors.Is. The message names the rule.

Functions

func LiveBinding

func LiveBinding(ctx context.Context, reader client.Reader, namespace string, selector *corev1.ConfigMapKeySelector) (*operatorv1alpha1.SourcePolicyBinding, error)

LiveBinding is the binding of the policy a selector names now, as a plan binds it, or nil when the selector names none. A plan is current only while it names the same policy, or none and no policy is named.

func Read

func Read(ctx context.Context, reader client.Reader, namespace string, selector *corev1.ConfigMapKeySelector) (Policy, Binding, error)

Read reads the policy a selector names, from an immutable ConfigMap, and returns it with its binding.

func StillBinds

func StillBinds(ctx context.Context, reader client.Reader, namespace string, selector *corev1.ConfigMapKeySelector, bound *operatorv1alpha1.SourcePolicyBinding) error

StillBinds refuses a plan computed under another source policy than the one its resource names now.

Types

type Binding

type Binding struct {
	UID    types.UID
	Digest string
}

Binding is the policy object and the digest of the bytes it was read from: another ConfigMap under the same name, or other bytes, is another policy.

type Policy

type Policy struct {
	AllowedGitHosts   *[]string `json:"allowedGitHosts,omitempty"`
	AllowedConfigMaps *[]string `json:"allowedConfigMaps,omitempty"`
	MaxContentBytes   *int64    `json:"maxContentBytes,omitempty"`
}

Policy is a parsed source policy.

func Parse

func Parse(document []byte) (Policy, error)

Parse reads a policy document and refuses one it cannot read exactly.

func (Policy) CheckConfigMap

func (p Policy) CheckConfigMap(name string) error

CheckConfigMap refuses a ConfigMap source the policy does not allow.

func (Policy) CheckContentBytes

func (p Policy) CheckContentBytes(size int64) error

CheckContentBytes refuses selected files that hold more than the policy allows together.

func (Policy) CheckGitHost

func (p Policy) CheckGitHost(authority string) error

CheckGitHost refuses a Git source whose authority, host[:port], the policy does not allow. Hosts compare without case.

Jump to

Keyboard shortcuts

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