Skip to main content

Policy defaults, endpoints and outputs

Policy defaults & enforcement ordering

A container’s effective cpu/memory requests and limits are assembled in three tiers, in precedence order:

  1. Authored — whatever the component’s resources property set explicitly. The string unlimited under limits.cpu or limits.memory is an authored opt-out: the container gets no limit for that resource, because neither a policy default limit (tier 2) nor, for memory, the limit mirror (tier 3) is applied to it. It is accepted where a built-in default exists to opt out of: the main container of webservice and worker, and their initContainers and sidecars entries. It is refused by name under requests, under podResources and on postgresql (“no intrinsic default to opt out of”), under any resource name other than cpu and memory, and, with the resource-maximum refusal class, when the policy sets MaxCPU()/MaxMemory() for that resource: an absent limit is no bound, so it is never read as under the maximum. null is still absence, not an opt-out. A policy sub-option to accept unlimited as a policy default is not provided.
  2. Policy default — ApplyPolicy fills any request/limit the author left unset from oam.Policy.DefaultCPURequest()/DefaultMemoryRequest()/ DefaultCPULimit()/DefaultMemoryLimit(). A negative policy default fails the build, as a negative authored quantity does, since Kubernetes would refuse it at apply; zero is accepted. The defaults reach every container of the reshaped kinds below: the main container and each initContainers and sidecars entry, by the same rules. Each default that fills a value is reported to the provenance report as a policy entry, at the path the author would have written: resources.requests.cpu for the main container, initContainers[0].resources.requests.cpu for the first init container. A request lowered to the authored limit (tier 3 below) carries the detail capped-to-limit. A default limit that lands under the container’s request fails the build, since Kubernetes refuses a request above its limit (go-kure/launcher#1582): under an authored request the error names it and asks for a limit or a lower request, with the resource-default-limit refusal class (go-kure/launcher#1580), and where the policy’s default request is above its own default limit the error names the policy and carries no class. What the postgresql defaults step fills after the policy (enablePDB, and the 1Gi storage.size fallback) is reported as a builtin entry, not as policy. So is what the parser of webservice and worker fills when the author wrote no value (an explicit null counts as no value): replicas 1, ports[i].protocol TCP (also in a sidecars entry and in a restartable initContainers entry), the accessModes ReadWriteOnce of a pvc volume that references a claim. The raw deployment, statefulset, daemonset, job and cronjob fill none of these, and their fill reports hold no policy or builtin entry. The one value a raw statefulset has filled for it is the storage class of a claim template that authors none, from the ClusterProfile’s pvc capability, which the report names as the capability’s. A webservice or worker with a non-RWX claim and no authored strategy is built with the Recreate strategy, a decision taken when the object is generated; it is reported at strategy.type from the same predicate the generator uses. A path is reported by one source only, the one whose value stands: where the policy default fills replicas, the entry is policy, and under a scaler trait there is none, since the kind is then built without a count. The list is what the library reports today, not every default these kinds apply.
  3. Intrinsic handler default — buildResourceRequirements fills anything still unset at Generate() time: 100m CPU request, 128Mi memory request, and a memory limit mirroring the (possibly just-defaulted) memory request. A defaulted request never exceeds the limit authored for the same resource: it is the lower of the default and that limit, so limits.memory: 64Mi with no request renders a 64Mi request, not 128Mi. A limit at or above the default leaves the default request in place. The same holds for a policy default request (tier 2): it is held to the authored limit for that resource, and an authored request is never changed. Two consequences are easy to miss: a policy DefaultMemoryRequest() flows into the mirrored memory limit, and the handler never defaults a CPU limit. Each value this tier fills is reported to the provenance report as a builtin entry (go-kure/launcher#1580), at the path the author would have written and for every container: resources.requests.cpu, sidecars[0].resources.limits.memory. The report also holds automountServiceAccountToken where the kind switches the token mount off, which it does when the component sets neither serviceAccountName nor automountServiceAccountToken. A value the author wrote or a policy default filled is never a builtin entry.

oam.Policy.MaxCPU()/MaxMemory() are enforced against the effective value — what Generate() will actually emit, after all three tiers — not just the authored/policy-defaulted resources field. When a value came from the intrinsic tier specifically (absent from the authored/policy- defaulted value, present only after the intrinsic fallback), the error names it as a “generated default” so the mismatch isn’t mysterious.

This three-tier effective-value enforcement applies to the two kind components that call buildResourceRequirements on their main container (webservice, worker). The raw deployment, statefulset, daemonset, job and cronjob have no intrinsic or policy default tier: they enforce the maxima on the resources as authored, for every container of their template. postgresql is exempt: its lowering rule copies every entry of c.Resources straight onto the Cluster spec and never calls buildResourceRequirements, so it has no intrinsic tier for its existing direct-form checks to diverge from.

Init containers and sidecars receive the same three tiers as the main container: the policy defaults (tier 2) fill what an entry leaves unset before the intrinsic defaults do, so the policy maximum is checked against the value the policy supplied. An entry that authors its values keeps them, and unlimited opts an entry out of a default limit. ApplyPolicy enforces the entries too: each entry’s resources, image registry, securityContext.privileged, and securityContext.capabilities.add are checked against the same policy methods the main container uses, via the shared enforceExtraContainer helper. Both reshaped kind components (webservice and worker) enforce their initContainers and their sidecars. The raw deployment, statefulset, daemonset, job and cronjob have no sidecars: their further containers are entries of the pod spec’s containers (template.spec.containers, and under jobTemplate.spec on a cronjob), and their initContainers are those of the pod spec, each checked by enforcePodTemplatePolicy (see the deployment, statefulset, daemonset, cronjob and job sections of Kinds: core workloads). Errors name the authored list position and container, e.g. initContainers[0] "init": image "docker.io/x/y:v1" is not from an allowed registry [...].

The JobSpec-level properties of job and of cronjob’s job template are no longer parsed by launcher: each kind decodes the upstream spec whole (go-kure/launcher#1629), so suspend is the JobSpec field on job and the CronJobSpec field on cronjob, as upstream has it, and the cross-field rules of the Job API are left to the API server.

Policy refusal classes

Every refusal by the environment policy this package raises is an oam.PolicyRefusal with a class, which a consumer reads from oam.ViolationError.Class instead of matching text. The classes, what each covers and what stays unclassified are in site/content/api-reference/oam/policy-and-capability.md, “Refusal classes”. What is particular to this package:

  • The class does not depend on the path. A privileged container is oam.RefusalPrivileged on a workload kind’s own ApplyPolicy, on an operator CR’s pod template, on an object a chart renders, and on a passthrough or manifests object, at the transform and at generation: one check raises it.
  • cpu and memory are one class, storage another. The comparison with a maximum is shared and its text is the same for every resource, so the class comes from the caller: oam.RefusalResourceMaximum for a cpu or memory request or limit (a container’s, a pod’s, the block a CloudNativePG kind, an alertmanager, a thanosruler or a prometheus carries, and the pod template of an ACME HTTP01 solver on an issuer or a clusterissuer), oam.RefusalStorageMaximum for a claim’s request, a claim template’s, a generic ephemeral volume’s, a PersistentVolume’s capacity and a cnpg-cluster volume, the 1Gi fallback of postgresql included, which its post-policy step holds to the maximum. oam.RefusalReplicaMaximum covers replicas, a HorizontalPodAutoscaler’s maxReplicas and cnpg-cluster’s instances.
  • A request above the policy’s default limit is oam.RefusalResourceDefaultLimit: an authored cpu or memory request, on the main container, an init container or a sidecar of the reshaped workload kinds, above the limit the policy fills because the container authors none (go-kure/launcher#1582). The author has the remedy, a limit or a lower request. cnpg-cluster makes the same comparison when it generates its object, and that is a generation error with no violation and no class.
  • Secret material in the document is oam.RefusalExplicitSecret: a secret component, a Secret that passthrough or a manifests source carries, helmtemplate’s secretValues, a certificate’s keystore password (keystores.jks.password, keystores.pkcs12.password), and in a secretstore or a clustersecretstore a credential written as a value and the data of the fake provider. A Secret named in the target.manifest of an externalsecret or clusterexternalsecret has the same class and is an *oam.TargetManifestRefusal, which errors.As finds: a consumer tells it from the other refusals of this class by the type, never by the message.
  • A source host is oam.RefusalRegistry, as an image’s registry is: the url of a manifests or crd source, a helmtemplate chart source, the Flux source kinds, an oci:// url that does not name its registry, and a bucket endpoint on Amazon S3.
  • An object that cannot be read is oam.RefusalUnreadableObject on the three paths that take an object written elsewhere (template delivery, passthrough, manifests): the refusals under “What cannot be read is refused, not passed” in the passthrough and manifests entries.
  • Unclassified, though it is the component’s violation: the rules that hold with or without a policy and are checked at the policy step (ephemeralContainers and the image rule on an object written elsewhere, an undeclared field on a workload or a claim a chart renders), a policy default or maximum that does not parse, a policy whose default request is above its own default limit (a defect of the policy: the document authors neither value), a request above a limit the policy did not fill on a config built in code, and a chart that does not render or whose render does not decode (an items array on a kind that is no list, for one).
  • A redirect of a manifests url source to a host outside the allowed registries is a fetch failure, with the error a fetch failure has and no oam.ViolationError; that error holds the oam.PolicyRefusal of class oam.RefusalRegistry, which errors.As reaches.

A new policy check in this package builds its refusal with oam.NewPolicyRefusal and a class constant; TestBuiltinPolicyRefusalsCarryAClass (pkg/oam) fails on one that does not.

Bounds in the schema. The two reshaped workload types (webservice, worker) and the nine kinds that take a pod as the API type (pod, podtemplate, deployment, statefulset, daemonset, job, cronjob, replicaset, replicationcontroller) publish, in boundedBy, the classes an authored value at a property can cause, and so do the Flux source family (helm, gitrepository, helmrepository, ocirepository, oci, bucket, helmrelease, imagerepository and resourcesetinputprovider) and manifests for where each is fetched from and, on manifests, the objects the source carries; passthrough for the object it emits; helmtemplate for the host of its chart, its secretValues and the objects its chart renders (values and secretValues); fluxcd-provider, which fetches nothing, for its address; crd for the host of its url; horizontalpodautoscaler for its maxReplicas; persistentvolume for a hostPath or local source and its capacity; persistentvolumeclaim for its size; metallb-bgppeer for its password and certificate for its keystores; issuer and clusterissuer for the pod of an HTTP01 solver; secretstore and clustersecretstore for the credentials they hold in the clear; externalsecret and clusterexternalsecret for the object their target.manifest has the operator write; and postgresql and the CloudNativePG kinds (cnpg-cluster, cnpg-pooler, cnpg-objectstore, cnpg-imagecatalog and cnpg-clusterimagecatalog) for what their policy check raises. The list of properties is in site/content/api-reference/oam/policy-and-capability.md, “Declared bounds”. What is particular to this package:

  • No schema fragment carries a bound. The fragments (schemaResources, schemaSecurityContext, schemaVolumes and the others) are shared with types that declare none. A type states its own bounds in its PropertySchema, through oam.DeclareBounds and one of workloadBounds, roleBounds, podBounds, podTemplateBounds, registryBounds (the properties that name where a source is fetched from), manifestsBounds, passthroughBounds, helmTemplateBounds or helmBounds (bounds.go); fluxcd-provider states its one explicit-secret bound, on address, in its own schema. postgresql and the CloudNativePG kinds use postgresqlBounds, cnpgClusterBounds, cnpgPoolerBounds (the pod classes of podTemplateBounds on template, and registry on pgbouncer), cnpgObjectStoreBounds and cnpgImageCatalogBounds.
  • A refusal with no authored value is declared on the property that changes the outcome. Under a registry allowlist a postgresql component that names no imageName composes the default image from version, which is refused as an authored one is, and a pooler that names no image is refused too; under a storage maximum below 1Gi the default storageSize is refused. Each is declared where the author can change it: imageName, the open pooler node and storageSize. A cnpg-cluster that names neither imageName nor imageCatalogRef, and a cnpg-pooler that names its PgBouncer image by none of pgbouncer.image, pgbouncer.imageCatalogRef and an image of a template container named pgbouncer, are refused the same way, on imageName and pgbouncer. The instance count of a cnpg-pooler is not policed, so it declares nothing.
  • A document is bounded by its objects, not by one key. In a manifests source inline is the document and url names it, and a passthrough object is one object, an open node. Each lists the ten classes of documentClasses (enforceManifestPolicy, enforcePassthroughPolicy): a core Secret, an object the check cannot read, and every object enforceRenderedObjectPolicy holds (the registry, privilege, host namespace, host path, capability and resource rules of a pod, the storage of a claim and of a PersistentVolume, and the replica maximum). url lists registry for its own host too. A helmtemplate declares registry on source.url, and on its two open nodes the classes of the objects its chart renders (renderedClasses): values lists nine, secretValues those nine and explicit-secret, since a value there is refused itself. A Secret a chart renders is not refused, so values has no explicit-secret. source.url, chart and version name the chart and declare none of them. helm declares explicit-secret on secretValues under both deliveries (helmBounds) and nothing on values: under template delivery it is bounded as helmtemplate is. object-kind is the transform’s check on every application, so no property declares it.
  • A declaration needs a row. TestBoundedBy_DeclaredAndTested (pkg/oam/builtin/registry) fails for a declared class with no row in its table, and for a row no schema declares. A row changes the value at or below its path in a document that passes, with the keys that value needs beside it (a volume’s name, for one), expects the class, and expects the refusal gone once the one policy setting behind it is relaxed. That last step tells hostNetwork, hostPID and hostIPC apart, which share a class.
  • A HostProcess container is bounded, and invalid alone. hostProcess: true on one container is refused as privileged. Once the policy allows it, the object is still refused, as invalid, unless every container of the pod is a HostProcess one and the pod sets hostNetwork: true: a pod with one HostProcess container must have only such containers. The pod-level podSecurityContext.windowsOptions.hostProcess needs hostNetwork: true, which the parser checks before the policy runs.
  • A pvc volume is bounded only where it generates a claim. On webservice and worker a pvc volume with no claimName generates its claim from size, and that claim is held to the storage maximum. The schema declares no size on a volume, so the two types declare storage-maximum on the volume itself, volumes[], an open node (roleBounds). On the kinds that take the pod as the API type a volume names an existing claim, as persistentVolumeClaim.claimName, and generates none, so the storage maximum has nothing to hold there.
  • A persistentvolume is bounded on hostPath, local and capacity. A hostPath or a local source names a path on the node and is refused as host-path unless the policy allows hostPath volumes; a csi or flexVolume source is not checked and declares nothing. capacity is an open object, so the storage-maximum class sits on the node (persistentVolumeBounds) and the bound applies to its storage key only: any other key is not read. The persistentvolumeclaim kind declares the same class on size, the one property that authors its storage, an unauthored size taking the policy’s storage default and being held to the maximum as an authored one is. crd declares registry on url only: a CustomResourceDefinition passes the check on the objects of a document, so inline has no class.
  • The kinds that hold one decoded spec declare the property each refusal sits on. metallb-bgppeer declares explicit-secret on password, and certificate on its open keystores node. issuer and clusterissuer declare resource-maximum on the open acme node, for the cpu and memory of the pod an HTTP01 solver starts (issuerBounds). secretstore and clustersecretstore declare explicit-secret on the open provider node (secretStoreBounds): a credential written as the value of a union, or the data of the fake provider. externalsecret and clusterexternalsecret declare explicit-secret and unreadable-object on the open node that holds target.manifest, target and externalSecretSpec (targetManifestBounds): a Secret is refused under a policy that forbids explicit secrets, and a workload, a claim or an autoscaler is refused under any applied policy; no limit lifts it. The other five MetalLB kinds raise no policy refusal and declare nothing.
  • The Prometheus Operator workload kinds declare what the operator’s pods would be held to. prometheus, alertmanager and thanosruler declare replica-maximum on replicas, and a prometheus also on shards (the pods are replicas times shards); registry on image, which is refused unset under an allowlist because the operator then chooses it; storage-maximum on storage; and resource-maximum on resources. Their volumes, containers and initContainers are open nodes and list the classes of every value below them (monitoringBounds); the reloader the operator generates runs its own image unless a patch in containers or initContainers names one, so that patch is held to the allowlist. A prometheus also declares registry and resource-maximum on thanos, and explicit-secret on remoteWrite, remoteRead and apiserverConfig; a thanosruler, explicit-secret on remoteWrite. A prometheus and an alertmanager declare host-namespace on hostNetwork and privileged on securityContext. A thanosruler declares nothing on securityContext: its HostProcess switch needs a host network it has no field for, so it is refused as invalid before the policy. The memory request the operator fills (200Mi, for an alertmanager and a thanosruler whose resources names none) is held to the memory maximum and sits on resources; the row that holds resources shows the authored form only. podmonitor, prometheus-probe, prometheusrule and servicemonitor raise no policy refusal and declare nothing.
  • The VolSync kinds declare the classes on each mover. replicationsource and replicationdestination hold each mover as an open node (volsyncBounds): storage-maximum for the capacity of the volume it provisions (capacity, restic’s cacheCapacity and a source’s syncthing configCapacity) and resource-maximum for moverResources. The rsync mover, over SSH, is run as root with seven added Linux capabilities whenever it is authored, so it declares container-capability and has no security context. rsyncTLS, rclone, restic and, on a source, syncthing declare privileged, for moverSecurityContext.windowsOptions.hostProcess. A destination has no syncthing mover.

Pod view of a monitoring workload object (MonitoringPodSpec)

An object from which the Prometheus operator builds pods, the Alertmanager, Prometheus and ThanosRuler of the alertmanager, prometheus and thanosruler kinds, has no pod template: its pod fields sit under spec in the operator’s own type, so a consumer that scans the pods of the rendered output finds none to scan. MonitoringPodSpec(obj) returns them as a corev1.PodSpec, with the prefix its paths sit under in the object (spec) and whether the object is of such a kind:

if pod, prefix, ok := components.MonitoringPodSpec(obj); ok {
	// pod.Containers[0].SecurityContext is at <prefix>.containers[0].securityContext in obj.
	scanPod(pod, prefix)
}
  • What it holds: the fields the kind’s policy checks read, from the same mapping: the listed containers and initContainers, volumes, securityContext, hostNetwork where the spec has it (a ThanosRuler’s has none), dnsPolicy, and the nameservers of dnsConfig. A listed container named for one the operator generates is a patch the operator merges into that container, and is in the view as written.
  • What it does not hold: the containers the operator generates itself. Their images, arguments and security context are the operator’s, and launcher holds only what the author wrote. The searches and options of dnsConfig are not in the view either.
    KindGenerated containersGenerated init containers
    alertmanageralertmanager, config-reloaderinit-config-reloader
    prometheusprometheus, config-reloader, and thanos-sidecar where thanos is setinit-config-reloader
    thanosrulerthanos-ruler, config-reloadernone
  • A copy: a change to the view does not reach the object.
  • Typed objects only: an unstructured monitoring object is converted to its typed object first. Any other object, a nil one included, gives nil, "", false.

Declared endpoints of a chart

helm, helmrelease and helmtemplate implement oam.EndpointProvider from an endpoints property. A chart renders pods this package cannot see, so the author declares the pods a consumer connects to; nothing is derived from the chart. One shared schema and parser serve the three types.

  • An entry is {name?, protocol?, port, selector}. name is empty or an IANA service name, unique among the component’s non-empty names. protocol is TCP (the default), UDP or SCTP. port is a number from 1 to 65535 or an IANA port name (a string of digits is not a name). selector is required and has matchLabels alone, not empty: an empty selector would match every pod of the namespace. No other key is taken.
  • Not a chart value. The key is split off before any strict decode and never forwarded: helmrelease decodes the rest as its HelmReleaseSpec, helmtemplate splits it off as it does scopeOverrides, and helm does not put it in helmOwnedKeys, which are forwarded, so the lowered members are the same with and without it, under either delivery.
  • The type’s parse runs first. A component the type refuses has no endpoint and is refused in the parse’s words, with or without a declaration. A refused declaration names its path (endpoints[1].selector.matchLabels) and is refused by a build, by the lowering and by a direct Endpoints call alike. What the helm lowering refuses after its decode is not seen by Endpoints.
  • Application namespace and cluster only. An endpoint’s NetworkPolicy is created in the application namespace of the application’s own cluster, so the declared pods must run there. A declaration beside a property that places the pods elsewhere is refused, because launcher cannot compare that place with the application’s: an authored, non-empty targetNamespace (another namespace; helmrelease, and helm under Flux delivery) and a kubeConfig (another cluster; helmrelease only, helm and helmtemplate take none). A null kubeConfig reads as absent. helmtemplate renders into the application namespace and takes no targetNamespace. The other HelmReleaseSpec fields do not place the pods and are accepted: storageNamespace (where Helm keeps release state), serviceAccountName (the identity Helm acts as), the namespaces of the chart source (chart.spec.sourceRef, chartRef) and of dependsOn, install.createNamespace (creates the namespace the release already targets) and commonMetadata (labels and annotations only). postRenderers can patch an object’s namespace, but a patch is opaque to launcher, as are the chart’s own templates; the declared selector is the author’s claim about the rendered pods either way.
  • No declaration reports none, as before. A declaration is the only source: a workload type derives its endpoints from its container ports and takes no endpoints property.

Declared outputs

Every type that generates one object named after the component (a kind component: every type that takes objectName) publishes it as the output object, and postgresql, webservice and worker implement oam.OutputProvider for the objects they lower into, and postgresql also for the Secret and the Service CloudNativePG creates from its Cluster: the names of the objects a component generates, read through Transformer.ComponentOutputs before the document is built, and held by the build against the names it gives (see “Outputs” in site/content/api-reference/oam/names-and-overrides.md). A name is the author’s property, else the Naming hook’s, else the default, resolved by the code that names the object in the lowering, so a query and a build cannot differ. A component of postgresql, webservice or worker that the lowering refuses answers no outputs and is refused in the lowering’s own words. A kind component’s output is the engine’s own: it parses no properties, so the query answers for a component whose properties the build then refuses. The keys name and kind are reserved and no type declares them. Of the handlers, the four that name no single object (helmtemplate, manifests, crd and passthrough) publish nothing, and of the lowering rules only postgresql, webservice and worker declare outputs.

TypeKeyObjectName
every kind component (configmap, secret, deployment, cnpg-cluster, and the rest of the types that take objectName)objectthe object the type declaresobjectName, else the Naming hook’s, else the component name
postgresqlclusterClusterclusterObjectName, else the component name
postgresqlapp_secretSecret <cluster>-appderived from cluster; absent when recovery.secret.name is set, because CloudNativePG then uses that Secret and generates none
postgresqlrw_serviceService <cluster>-rwderived from cluster; always present, because the component offers no setting that disables the operator’s default Services
postgresqlobjectstoreObjectStorepresent when backup is set; backup.objectStoreObjectName, else the component name
webservice, workerdeploymentDeploymentdeploymentObjectName, else the component name
webserviceserviceServiceserviceObjectName, else the component name
webservice, workerserviceaccountServiceAccountserviceAccountObjectName, else the component name; absent when serviceAccountName names an existing account
webservice, workerclaim_<volume>PersistentVolumeClaimone per pvc volume that sets no claimName: the volume’s claimObjectName, else <component>-<volume> with each hyphen in either part written --; hyphens in the key become underscores

app_secret and rw_service are the derived outputs: the operator creates the Secret and the Service, so neither is in the built application and no object of the build holds it. The -ro and -r Services and the Services of a connection pooler are not declared. The build still re-applies the derivation to the held cluster name and fails if the output was answered another name. The inline object store of recovery.source is not declared. A claim’s name is resolved without the ClusterProfile pvc capability, which chooses its storage class and no name, so the query records no consumed capability key.