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:
- Authored — whatever the component’s
resourcesproperty set explicitly. The stringunlimitedunderlimits.cpuorlimits.memoryis 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 ofwebserviceandworker, and theirinitContainersandsidecarsentries. It is refused by name underrequests, underpodResourcesand onpostgresql(“no intrinsic default to opt out of”), under any resource name other than cpu and memory, and, with theresource-maximumrefusal class, when the policy setsMaxCPU()/MaxMemory()for that resource: an absent limit is no bound, so it is never read as under the maximum.nullis still absence, not an opt-out. A policy sub-option to acceptunlimitedas a policy default is not provided. - Policy default —
ApplyPolicyfills any request/limit the author left unset fromoam.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 eachinitContainersandsidecarsentry, by the same rules. Each default that fills a value is reported to the provenance report as apolicyentry, at the path the author would have written:resources.requests.cpufor the main container,initContainers[0].resources.requests.cpufor the first init container. A request lowered to the authored limit (tier 3 below) carries the detailcapped-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 theresource-default-limitrefusal 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 the1Gistorage.sizefallback) is reported as abuiltinentry, not aspolicy. So is what the parser ofwebserviceandworkerfills when the author wrote no value (an explicitnullcounts as no value):replicas1,ports[i].protocolTCP(also in asidecarsentry and in a restartableinitContainersentry), theaccessModesReadWriteOnceof apvcvolume that references a claim. The rawdeployment,statefulset,daemonset,jobandcronjobfill none of these, and their fill reports hold nopolicyorbuiltinentry. The one value a rawstatefulsethas filled for it is the storage class of a claim template that authors none, from the ClusterProfile’spvccapability, which the report names as the capability’s. Awebserviceorworkerwith a non-RWX claim and no authoredstrategyis built with theRecreatestrategy, a decision taken when the object is generated; it is reported atstrategy.typefrom the same predicate the generator uses. A path is reported by one source only, the one whose value stands: where the policy default fillsreplicas, the entry ispolicy, and under ascalertrait 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. - Intrinsic handler default —
buildResourceRequirementsfills anything still unset atGenerate()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, solimits.memory: 64Miwith 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 policyDefaultMemoryRequest()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 abuiltinentry (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 holdsautomountServiceAccountTokenwhere the kind switches the token mount off, which it does when the component sets neitherserviceAccountNamenorautomountServiceAccountToken. A value the author wrote or a policy default filled is never abuiltinentry.
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.RefusalPrivilegedon a workload kind’s ownApplyPolicy, on an operator CR’s pod template, on an object a chart renders, and on apassthroughormanifestsobject, 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.RefusalResourceMaximumfor a cpu or memory request or limit (a container’s, a pod’s, the block a CloudNativePG kind, analertmanager, athanosruleror aprometheuscarries, and the pod template of an ACME HTTP01 solver on anissueror aclusterissuer),oam.RefusalStorageMaximumfor a claim’s request, a claim template’s, a generic ephemeral volume’s, a PersistentVolume’s capacity and acnpg-clustervolume, the1Gifallback ofpostgresqlincluded, which its post-policy step holds to the maximum.oam.RefusalReplicaMaximumcoversreplicas, a HorizontalPodAutoscaler’smaxReplicasandcnpg-cluster’sinstances. - 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-clustermakes 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: asecretcomponent, a Secret thatpassthroughor amanifestssource carries,helmtemplate’ssecretValues, acertificate’s keystore password (keystores.jks.password,keystores.pkcs12.password), and in asecretstoreor aclustersecretstorea credential written as avalueand the data of thefakeprovider. A Secret named in thetarget.manifestof anexternalsecretorclusterexternalsecrethas the same class and is an*oam.TargetManifestRefusal, whicherrors.Asfinds: 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: theurlof amanifestsorcrdsource, ahelmtemplatechart source, the Flux source kinds, anoci://url that does not name its registry, and abucketendpoint on Amazon S3. - An object that cannot be read is
oam.RefusalUnreadableObjecton 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 thepassthroughandmanifestsentries. - Unclassified, though it is the component’s violation: the rules that hold with or
without a policy and are checked at the policy step (
ephemeralContainersand 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 (anitemsarray on a kind that is no list, for one). - A redirect of a
manifestsurlsource to a host outside the allowed registries is a fetch failure, with the error a fetch failure has and nooam.ViolationError; that error holds theoam.PolicyRefusalof classoam.RefusalRegistry, whicherrors.Asreaches.
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,schemaVolumesand the others) are shared with types that declare none. A type states its own bounds in itsPropertySchema, throughoam.DeclareBoundsand one ofworkloadBounds,roleBounds,podBounds,podTemplateBounds,registryBounds(the properties that name where a source is fetched from),manifestsBounds,passthroughBounds,helmTemplateBoundsorhelmBounds(bounds.go);fluxcd-providerstates its oneexplicit-secretbound, onaddress, in its own schema.postgresqland the CloudNativePG kinds usepostgresqlBounds,cnpgClusterBounds,cnpgPoolerBounds(the pod classes ofpodTemplateBoundsontemplate, andregistryonpgbouncer),cnpgObjectStoreBoundsandcnpgImageCatalogBounds. - A refusal with no authored value is declared on the property that changes the outcome. Under a
registry allowlist a
postgresqlcomponent that names noimageNamecomposes the default image fromversion, 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 defaultstorageSizeis refused. Each is declared where the author can change it:imageName, the openpoolernode andstorageSize. Acnpg-clusterthat names neitherimageNamenorimageCatalogRef, and acnpg-poolerthat names its PgBouncer image by none ofpgbouncer.image,pgbouncer.imageCatalogRefand an image of a template container namedpgbouncer, are refused the same way, onimageNameandpgbouncer. The instance count of acnpg-pooleris not policed, so it declares nothing. - A document is bounded by its objects, not by one key. In a
manifestssourceinlineis the document andurlnames it, and apassthroughobjectis one object, an open node. Each lists the ten classes ofdocumentClasses(enforceManifestPolicy,enforcePassthroughPolicy): a core Secret, an object the check cannot read, and every objectenforceRenderedObjectPolicyholds (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).urllistsregistryfor its own host too. Ahelmtemplatedeclaresregistryonsource.url, and on its two open nodes the classes of the objects its chart renders (renderedClasses):valueslists nine,secretValuesthose nine andexplicit-secret, since a value there is refused itself. A Secret a chart renders is not refused, sovalueshas noexplicit-secret.source.url,chartandversionname the chart and declare none of them.helmdeclaresexplicit-secretonsecretValuesunder both deliveries (helmBounds) and nothing onvalues: under template delivery it is bounded ashelmtemplateis.object-kindis 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’sname, for one), expects the class, and expects the refusal gone once the one policy setting behind it is relaxed. That last step tellshostNetwork,hostPIDandhostIPCapart, which share a class. - A HostProcess container is bounded, and invalid alone.
hostProcess: trueon one container is refused asprivileged. 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 setshostNetwork: true: a pod with one HostProcess container must have only such containers. The pod-levelpodSecurityContext.windowsOptions.hostProcessneedshostNetwork: true, which the parser checks before the policy runs. - A
pvcvolume is bounded only where it generates a claim. Onwebserviceandworkerapvcvolume with noclaimNamegenerates its claim fromsize, and that claim is held to the storage maximum. The schema declares nosizeon a volume, so the two types declarestorage-maximumon 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, aspersistentVolumeClaim.claimName, and generates none, so the storage maximum has nothing to hold there. - A
persistentvolumeis bounded onhostPath,localandcapacity. AhostPathor alocalsource names a path on the node and is refused ashost-pathunless the policy allows hostPath volumes; acsiorflexVolumesource is not checked and declares nothing.capacityis an open object, so thestorage-maximumclass sits on the node (persistentVolumeBounds) and the bound applies to itsstoragekey only: any other key is not read. Thepersistentvolumeclaimkind declares the same class onsize, the one property that authors its storage, an unauthoredsizetaking the policy’s storage default and being held to the maximum as an authored one is.crddeclaresregistryonurlonly: a CustomResourceDefinition passes the check on the objects of a document, soinlinehas no class. - The kinds that hold one decoded spec declare the property each refusal sits on.
metallb-bgppeerdeclaresexplicit-secretonpassword, andcertificateon its openkeystoresnode.issuerandclusterissuerdeclareresource-maximumon the openacmenode, for the cpu and memory of the pod an HTTP01 solver starts (issuerBounds).secretstoreandclustersecretstoredeclareexplicit-secreton the openprovidernode (secretStoreBounds): a credential written as thevalueof a union, or the data of thefakeprovider.externalsecretandclusterexternalsecretdeclareexplicit-secretandunreadable-objecton the open node that holdstarget.manifest,targetandexternalSecretSpec(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,alertmanagerandthanosrulerdeclarereplica-maximumonreplicas, and aprometheusalso onshards(the pods are replicas times shards);registryonimage, which is refused unset under an allowlist because the operator then chooses it;storage-maximumonstorage; andresource-maximumonresources. Theirvolumes,containersandinitContainersare open nodes and list the classes of every value below them (monitoringBounds); the reloader the operator generates runs its own image unless a patch incontainersorinitContainersnames one, so that patch is held to the allowlist. Aprometheusalso declaresregistryandresource-maximumonthanos, andexplicit-secretonremoteWrite,remoteReadandapiserverConfig; athanosruler,explicit-secretonremoteWrite. Aprometheusand analertmanagerdeclarehost-namespaceonhostNetworkandprivilegedonsecurityContext. Athanosrulerdeclares nothing onsecurityContext: 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 analertmanagerand athanosrulerwhoseresourcesnames none) is held to the memory maximum and sits onresources; the row that holdsresourcesshows the authored form only.podmonitor,prometheus-probe,prometheusruleandservicemonitorraise no policy refusal and declare nothing. - The VolSync kinds declare the classes on each mover.
replicationsourceandreplicationdestinationhold each mover as an open node (volsyncBounds):storage-maximumfor the capacity of the volume it provisions (capacity, restic’scacheCapacityand a source’s syncthingconfigCapacity) andresource-maximumformoverResources. Thersyncmover, over SSH, is run as root with seven added Linux capabilities whenever it is authored, so it declarescontainer-capabilityand has no security context.rsyncTLS,rclone,resticand, on a source,syncthingdeclareprivileged, formoverSecurityContext.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:
- What it holds: the fields the kind’s policy checks read, from the same mapping: the listed
containersandinitContainers,volumes,securityContext,hostNetworkwhere the spec has it (aThanosRuler’s has none),dnsPolicy, and thenameserversofdnsConfig. 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
searchesandoptionsofdnsConfigare not in the view either.Kind Generated containers Generated init containers alertmanageralertmanager,config-reloaderinit-config-reloaderprometheusprometheus,config-reloader, andthanos-sidecarwherethanosis setinit-config-reloaderthanosrulerthanos-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}.nameis empty or an IANA service name, unique among the component’s non-empty names.protocolisTCP(the default),UDPorSCTP.portis a number from 1 to 65535 or an IANA port name (a string of digits is not a name).selectoris required and hasmatchLabelsalone, 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:
helmreleasedecodes the rest as itsHelmReleaseSpec,helmtemplatesplits it off as it doesscopeOverrides, andhelmdoes not put it inhelmOwnedKeys, 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 directEndpointscall alike. What thehelmlowering refuses after its decode is not seen byEndpoints. - 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, andhelmunder Flux delivery) and akubeConfig(another cluster;helmreleaseonly,helmandhelmtemplatetake none). A nullkubeConfigreads as absent.helmtemplaterenders into the application namespace and takes notargetNamespace. The otherHelmReleaseSpecfields 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 ofdependsOn,install.createNamespace(creates the namespace the release already targets) andcommonMetadata(labels and annotations only).postRendererscan 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
endpointsproperty.
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.
| Type | Key | Object | Name |
|---|---|---|---|
every kind component (configmap, secret, deployment, cnpg-cluster, and the rest of the types that take objectName) | object | the object the type declares | objectName, else the Naming hook’s, else the component name |
postgresql | cluster | Cluster | clusterObjectName, else the component name |
postgresql | app_secret | Secret <cluster>-app | derived from cluster; absent when recovery.secret.name is set, because CloudNativePG then uses that Secret and generates none |
postgresql | rw_service | Service <cluster>-rw | derived from cluster; always present, because the component offers no setting that disables the operator’s default Services |
postgresql | objectstore | ObjectStore | present when backup is set; backup.objectStoreObjectName, else the component name |
webservice, worker | deployment | Deployment | deploymentObjectName, else the component name |
webservice | service | Service | serviceObjectName, else the component name |
webservice, worker | serviceaccount | ServiceAccount | serviceAccountObjectName, else the component name; absent when serviceAccountName names an existing account |
webservice, worker | claim_<volume> | PersistentVolumeClaim | one 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.