admissionpolicy

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT, Apache-2.0 Imports: 23 Imported by: 0

README

admissionpolicy

From k8s.io/apiserver v0.35.1, Apache 2.0, in LICENSE beside this file. It is what vet-validating-admission-policy evaluates a ValidatingAdmissionPolicy with, so that a policy decides a resource the way the API server would.

  • validator.go, interface.go, message.go and policy_decision.go are copied unchanged from pkg/admission/plugin/policy/validating, but for the package name.
  • matching.go is adapted from pkg/admission/plugin/policy/matching/matching.go and pkg/admission/plugin/policy/generic/policy_matcher.go: a namespace selector is matched against labels a caller supplies rather than against a namespace lister and an API client, and a nil selector matches everything, as the API server's defaulting makes it.

The validating package itself is not imported because it brings in the webhook admission plugin, and through it gRPC and the egress selector, which nothing else here needs. The packages these files use, such as pkg/admission/plugin/cel and pkg/admission/plugin/webhook/matchconditions, are imported as they are.

When k8s.io/apiserver is upgraded, compare these files with the new version's.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindingMatches

func BindingMatches(attr admission.Attributes, o admission.ObjectInterfaces, namespaceLabels NamespaceLabels,
	matchResources *v1.MatchResources) (bool, error)

BindingMatches returns whether a binding's matchResources match the request. A binding without any matches every request its policy does.

func DefinitionMatches

DefinitionMatches returns whether a policy's matchConstraints match the request, and the resource and kind it matched as.

Types

type AuditAnnotationCondition

type AuditAnnotationCondition struct {
	Key             string
	ValueExpression string
}

AuditAnnotationCondition contains the inputs needed to compile, evaluate and publish a cel audit annotation

func (*AuditAnnotationCondition) GetExpression

func (v *AuditAnnotationCondition) GetExpression() string

func (*AuditAnnotationCondition) ReturnTypes

func (v *AuditAnnotationCondition) ReturnTypes() []*celgo.Type

type MessageExpressionCondition

type MessageExpressionCondition struct {
	MessageExpression string
}

func (*MessageExpressionCondition) GetExpression

func (m *MessageExpressionCondition) GetExpression() string

func (*MessageExpressionCondition) ReturnTypes

func (m *MessageExpressionCondition) ReturnTypes() []*celgo.Type

type NamespaceLabels

type NamespaceLabels func(name string) (map[string]string, error)

NamespaceLabels returns the labels of the named Namespace.

type PolicyAuditAnnotation

type PolicyAuditAnnotation struct {
	Key     string
	Value   string
	Elapsed time.Duration
	Action  PolicyAuditAnnotationAction
	Error   string
}

type PolicyAuditAnnotationAction

type PolicyAuditAnnotationAction string
const (
	// AuditAnnotationActionPublish indicates that the audit annotation should be
	// published with the audit event.
	AuditAnnotationActionPublish PolicyAuditAnnotationAction = "publish"
	// AuditAnnotationActionError indicates that the valueExpression resulted
	// in an error.
	AuditAnnotationActionError PolicyAuditAnnotationAction = "error"
	// AuditAnnotationActionExclude indicates that the audit annotation should be excluded
	// because the valueExpression evaluated to null, or because FailurePolicy is Ignore
	// and the expression failed with a parse error, type check error, or runtime error.
	AuditAnnotationActionExclude PolicyAuditAnnotationAction = "exclude"
)

type PolicyDecision

type PolicyDecision struct {
	Action     PolicyDecisionAction
	Evaluation PolicyDecisionEvaluation
	Message    string
	Reason     metav1.StatusReason
	Elapsed    time.Duration
}

PolicyDecision contains the action determined from a cel evaluation along with metadata such as message, reason and duration

type PolicyDecisionAction

type PolicyDecisionAction string
const (
	ActionAdmit PolicyDecisionAction = "admit"
	ActionDeny  PolicyDecisionAction = "deny"
)

type PolicyDecisionEvaluation

type PolicyDecisionEvaluation string
const (
	EvalAdmit PolicyDecisionEvaluation = "admit"
	EvalError PolicyDecisionEvaluation = "error"
	EvalDeny  PolicyDecisionEvaluation = "deny"
)

type ValidateResult

type ValidateResult struct {
	// Decisions specifies the outcome of the validation as well as the details about the decision.
	Decisions []PolicyDecision
	// AuditAnnotations specifies the audit annotations that should be recorded for the validation.
	AuditAnnotations []PolicyAuditAnnotation
}

ValidateResult defines the result of a Validator.Validate operation.

type ValidationCondition

type ValidationCondition struct {
	Expression string
	Message    string
	Reason     *metav1.StatusReason
}

ValidationCondition contains the inputs needed to compile, evaluate and validate a cel expression

func (*ValidationCondition) GetExpression

func (v *ValidationCondition) GetExpression() string

func (*ValidationCondition) ReturnTypes

func (v *ValidationCondition) ReturnTypes() []*celgo.Type

type Validator

type Validator interface {
	// Validate is used to take cel evaluations and convert into decisions
	// runtimeCELCostBudget was added for testing purpose only. Callers should always use const RuntimeCELCostBudget from k8s.io/apiserver/pkg/apis/cel/config.go as input.
	Validate(ctx context.Context, matchedResource schema.GroupVersionResource, versionedAttr *admission.VersionedAttributes, versionedParams runtime.Object, namespace *corev1.Namespace, runtimeCELCostBudget int64, authz authorizer.Authorizer) ValidateResult
}

Validator is contains logic for converting ValidationEvaluation to PolicyDecisions

func NewValidator

func NewValidator(validationFilter cel.ConditionEvaluator, celMatcher matchconditions.Matcher, auditAnnotationFilter, messageFilter cel.ConditionEvaluator, failPolicy *v1.FailurePolicyType) Validator

type Variable

type Variable struct {
	Name       string
	Expression string
}

Variable is a named expression for composition.

func (*Variable) GetExpression

func (v *Variable) GetExpression() string

func (*Variable) GetName

func (v *Variable) GetName() string

func (*Variable) ReturnTypes

func (v *Variable) ReturnTypes() []*celgo.Type

Jump to

Keyboard shortcuts

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