Documentation
¶
Overview ¶
Package sourcepolicy reads and applies a source policy: what a team refuses for every ConfigMap, Git and HTTPS source, held in an immutable ConfigMap a resource selects with sourcePolicyFrom.
The document is YAML with four optional rules:
allowedGitHosts: # the only host[:port] a Git source may name - git.example.com allowedHTTPSHosts: # the only host[:port] an HTTPS source may name - artifacts.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
- Variables
- func LiveBinding(ctx context.Context, reader client.Reader, namespace string, ...) (*operatorv1alpha1.SourcePolicyBinding, error)
- func Read(ctx context.Context, reader client.Reader, namespace string, ...) (Policy, Binding, error)
- func StillBinds(ctx context.Context, reader client.Reader, namespace string, ...) error
- type Binding
- type Policy
Constants ¶
const MaxDocumentBytes = 64 << 10
MaxDocumentBytes bounds the policy document.
Variables ¶
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 ¶
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"`
AllowedHTTPSHosts *[]string `json:"allowedHTTPSHosts,omitempty"`
AllowedConfigMaps *[]string `json:"allowedConfigMaps,omitempty"`
MaxContentBytes *int64 `json:"maxContentBytes,omitempty"`
}
Policy is a parsed source policy.
func (Policy) CheckConfigMap ¶
CheckConfigMap refuses a ConfigMap source the policy does not allow.
func (Policy) CheckContentBytes ¶
CheckContentBytes refuses selected files that hold more than the policy allows together.
func (Policy) CheckGitHost ¶
CheckGitHost refuses a Git source whose authority, host[:port], the policy does not allow. Hosts compare as printable ASCII without case, as internal/sourcehost says.
func (Policy) CheckHTTPSHost ¶ added in v0.2.12
CheckHTTPSHost refuses an HTTPS source whose authority, host[:port], the policy does not allow. Hosts compare as printable ASCII without case. allowedGitHosts says nothing about an HTTPS source: a host a team clones from is not one it downloads from.