generated.proto 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. /*
  2. Copyright The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // This file was autogenerated by go-to-protobuf. Do not edit it manually!
  14. syntax = "proto2";
  15. package k8s.io.api.admissionregistration.v1alpha1;
  16. import "k8s.io/api/admissionregistration/v1/generated.proto";
  17. import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto";
  18. import "k8s.io/apimachinery/pkg/runtime/generated.proto";
  19. import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto";
  20. // Package-wide variables from generator "generated".
  21. option go_package = "k8s.io/api/admissionregistration/v1alpha1";
  22. // ApplyConfiguration defines the desired configuration values of an object.
  23. message ApplyConfiguration {
  24. // expression will be evaluated by CEL to create an apply configuration.
  25. // ref: https://github.com/google/cel-spec
  26. //
  27. // Apply configurations are declared in CEL using object initialization. For example, this CEL expression
  28. // returns an apply configuration to set a single field:
  29. //
  30. // Object{
  31. // spec: Object.spec{
  32. // serviceAccountName: "example"
  33. // }
  34. // }
  35. //
  36. // Apply configurations may not modify atomic structs, maps or arrays due to the risk of accidental deletion of
  37. // values not included in the apply configuration.
  38. //
  39. // CEL expressions have access to the object types needed to create apply configurations:
  40. //
  41. // - 'Object' - CEL type of the resource object.
  42. // - 'Object.<fieldName>' - CEL type of object field (such as 'Object.spec')
  43. // - 'Object.<fieldName1>.<fieldName2>...<fieldNameN>` - CEL type of nested field (such as 'Object.spec.containers')
  44. //
  45. // CEL expressions have access to the contents of the API request, organized into CEL variables as well as some other useful variables:
  46. //
  47. // - 'object' - The object from the incoming request. The value is null for DELETE requests.
  48. // - 'oldObject' - The existing object. The value is null for CREATE requests.
  49. // - 'request' - Attributes of the API request([ref](/pkg/apis/admission/types.go#AdmissionRequest)).
  50. // - 'params' - Parameter resource referred to by the policy binding being evaluated. Only populated if the policy has a ParamKind.
  51. // - 'namespaceObject' - The namespace object that the incoming object belongs to. The value is null for cluster-scoped resources.
  52. // - 'variables' - Map of composited variables, from its name to its lazily evaluated value.
  53. // For example, a variable named 'foo' can be accessed as 'variables.foo'.
  54. // - 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.
  55. // See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
  56. // - 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the
  57. // request resource.
  58. //
  59. // The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the
  60. // object. No other metadata properties are accessible.
  61. //
  62. // Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible.
  63. // Required.
  64. optional string expression = 1;
  65. }
  66. // AuditAnnotation describes how to produce an audit annotation for an API request.
  67. message AuditAnnotation {
  68. // key specifies the audit annotation key. The audit annotation keys of
  69. // a ValidatingAdmissionPolicy must be unique. The key must be a qualified
  70. // name ([A-Za-z0-9][-A-Za-z0-9_.]*) no more than 63 bytes in length.
  71. //
  72. // The key is combined with the resource name of the
  73. // ValidatingAdmissionPolicy to construct an audit annotation key:
  74. // "{ValidatingAdmissionPolicy name}/{key}".
  75. //
  76. // If an admission webhook uses the same resource name as this ValidatingAdmissionPolicy
  77. // and the same audit annotation key, the annotation key will be identical.
  78. // In this case, the first annotation written with the key will be included
  79. // in the audit event and all subsequent annotations with the same key
  80. // will be discarded.
  81. //
  82. // Required.
  83. optional string key = 1;
  84. // valueExpression represents the expression which is evaluated by CEL to
  85. // produce an audit annotation value. The expression must evaluate to either
  86. // a string or null value. If the expression evaluates to a string, the
  87. // audit annotation is included with the string value. If the expression
  88. // evaluates to null or empty string the audit annotation will be omitted.
  89. // The valueExpression may be no longer than 5kb in length.
  90. // If the result of the valueExpression is more than 10kb in length, it
  91. // will be truncated to 10kb.
  92. //
  93. // If multiple ValidatingAdmissionPolicyBinding resources match an
  94. // API request, then the valueExpression will be evaluated for
  95. // each binding. All unique values produced by the valueExpressions
  96. // will be joined together in a comma-separated list.
  97. //
  98. // Required.
  99. optional string valueExpression = 2;
  100. }
  101. // ExpressionWarning is a warning information that targets a specific expression.
  102. message ExpressionWarning {
  103. // The path to the field that refers the expression.
  104. // For example, the reference to the expression of the first item of
  105. // validations is "spec.validations[0].expression"
  106. optional string fieldRef = 2;
  107. // The content of type checking information in a human-readable form.
  108. // Each line of the warning contains the type that the expression is checked
  109. // against, followed by the type check error from the compiler.
  110. optional string warning = 3;
  111. }
  112. // JSONPatch defines a JSON Patch.
  113. message JSONPatch {
  114. // expression will be evaluated by CEL to create a [JSON patch](https://jsonpatch.com/).
  115. // ref: https://github.com/google/cel-spec
  116. //
  117. // expression must return an array of JSONPatch values.
  118. //
  119. // For example, this CEL expression returns a JSON patch to conditionally modify a value:
  120. //
  121. // [
  122. // JSONPatch{op: "test", path: "/spec/example", value: "Red"},
  123. // JSONPatch{op: "replace", path: "/spec/example", value: "Green"}
  124. // ]
  125. //
  126. // To define an object for the patch value, use Object types. For example:
  127. //
  128. // [
  129. // JSONPatch{
  130. // op: "add",
  131. // path: "/spec/selector",
  132. // value: Object.spec.selector{matchLabels: {"environment": "test"}}
  133. // }
  134. // ]
  135. //
  136. // To use strings containing '/' and '~' as JSONPatch path keys, use "jsonpatch.escapeKey". For example:
  137. //
  138. // [
  139. // JSONPatch{
  140. // op: "add",
  141. // path: "/metadata/labels/" + jsonpatch.escapeKey("example.com/environment"),
  142. // value: "test"
  143. // },
  144. // ]
  145. //
  146. // CEL expressions have access to the types needed to create JSON patches and objects:
  147. //
  148. // - 'JSONPatch' - CEL type of JSON Patch operations. JSONPatch has the fields 'op', 'from', 'path' and 'value'.
  149. // See [JSON patch](https://jsonpatch.com/) for more details. The 'value' field may be set to any of: string,
  150. // integer, array, map or object. If set, the 'path' and 'from' fields must be set to a
  151. // [JSON pointer](https://datatracker.ietf.org/doc/html/rfc6901/) string, where the 'jsonpatch.escapeKey()' CEL
  152. // function may be used to escape path keys containing '/' and '~'.
  153. // - 'Object' - CEL type of the resource object.
  154. // - 'Object.<fieldName>' - CEL type of object field (such as 'Object.spec')
  155. // - 'Object.<fieldName1>.<fieldName2>...<fieldNameN>` - CEL type of nested field (such as 'Object.spec.containers')
  156. //
  157. // CEL expressions have access to the contents of the API request, organized into CEL variables as well as some other useful variables:
  158. //
  159. // - 'object' - The object from the incoming request. The value is null for DELETE requests.
  160. // - 'oldObject' - The existing object. The value is null for CREATE requests.
  161. // - 'request' - Attributes of the API request([ref](/pkg/apis/admission/types.go#AdmissionRequest)).
  162. // - 'params' - Parameter resource referred to by the policy binding being evaluated. Only populated if the policy has a ParamKind.
  163. // - 'namespaceObject' - The namespace object that the incoming object belongs to. The value is null for cluster-scoped resources.
  164. // - 'variables' - Map of composited variables, from its name to its lazily evaluated value.
  165. // For example, a variable named 'foo' can be accessed as 'variables.foo'.
  166. // - 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.
  167. // See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
  168. // - 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the
  169. // request resource.
  170. //
  171. // CEL expressions have access to [Kubernetes CEL function libraries](https://kubernetes.io/docs/reference/using-api/cel/#cel-options-language-features-and-libraries)
  172. // as well as:
  173. //
  174. // - 'jsonpatch.escapeKey' - Performs JSONPatch key escaping. '~' and '/' are escaped as '~0' and `~1' respectively).
  175. //
  176. // Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible.
  177. // Required.
  178. optional string expression = 1;
  179. }
  180. message MatchCondition {
  181. // Name is an identifier for this match condition, used for strategic merging of MatchConditions,
  182. // as well as providing an identifier for logging purposes. A good name should be descriptive of
  183. // the associated expression.
  184. // Name must be a qualified name consisting of alphanumeric characters, '-', '_' or '.', and
  185. // must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or
  186. // '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]') with an
  187. // optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName')
  188. //
  189. // Required.
  190. optional string name = 1;
  191. // Expression represents the expression which will be evaluated by CEL. Must evaluate to bool.
  192. // CEL expressions have access to the contents of the AdmissionRequest and Authorizer, organized into CEL variables:
  193. //
  194. // 'object' - The object from the incoming request. The value is null for DELETE requests.
  195. // 'oldObject' - The existing object. The value is null for CREATE requests.
  196. // 'request' - Attributes of the admission request(/pkg/apis/admission/types.go#AdmissionRequest).
  197. // 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.
  198. // See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
  199. // 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the
  200. // request resource.
  201. // Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/
  202. //
  203. // Required.
  204. optional string expression = 2;
  205. }
  206. // MatchResources decides whether to run the admission control policy on an object based
  207. // on whether it meets the match criteria.
  208. // The exclude rules take precedence over include rules (if a resource matches both, it is excluded)
  209. // +structType=atomic
  210. message MatchResources {
  211. // NamespaceSelector decides whether to run the admission control policy on an object based
  212. // on whether the namespace for that object matches the selector. If the
  213. // object itself is a namespace, the matching is performed on
  214. // object.metadata.labels. If the object is another cluster scoped resource,
  215. // it never skips the policy.
  216. //
  217. // For example, to run the webhook on any objects whose namespace is not
  218. // associated with "runlevel" of "0" or "1"; you will set the selector as
  219. // follows:
  220. // "namespaceSelector": {
  221. // "matchExpressions": [
  222. // {
  223. // "key": "runlevel",
  224. // "operator": "NotIn",
  225. // "values": [
  226. // "0",
  227. // "1"
  228. // ]
  229. // }
  230. // ]
  231. // }
  232. //
  233. // If instead you want to only run the policy on any objects whose
  234. // namespace is associated with the "environment" of "prod" or "staging";
  235. // you will set the selector as follows:
  236. // "namespaceSelector": {
  237. // "matchExpressions": [
  238. // {
  239. // "key": "environment",
  240. // "operator": "In",
  241. // "values": [
  242. // "prod",
  243. // "staging"
  244. // ]
  245. // }
  246. // ]
  247. // }
  248. //
  249. // See
  250. // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
  251. // for more examples of label selectors.
  252. //
  253. // Default to the empty LabelSelector, which matches everything.
  254. // +optional
  255. optional .k8s.io.apimachinery.pkg.apis.meta.v1.LabelSelector namespaceSelector = 1;
  256. // ObjectSelector decides whether to run the policy based on if the
  257. // object has matching labels. objectSelector is evaluated against both
  258. // the oldObject and newObject that would be sent to the policy's expression (CEL), and
  259. // is considered to match if either object matches the selector. A null
  260. // object (oldObject in the case of create, or newObject in the case of
  261. // delete) or an object that cannot have labels (like a
  262. // DeploymentRollback or a PodProxyOptions object) is not considered to
  263. // match.
  264. // Use the object selector only if the webhook is opt-in, because end
  265. // users may skip the admission webhook by setting the labels.
  266. // Default to the empty LabelSelector, which matches everything.
  267. // +optional
  268. optional .k8s.io.apimachinery.pkg.apis.meta.v1.LabelSelector objectSelector = 2;
  269. // ResourceRules describes what operations on what resources/subresources the admission policy matches.
  270. // The policy cares about an operation if it matches _any_ Rule.
  271. // +listType=atomic
  272. // +optional
  273. repeated NamedRuleWithOperations resourceRules = 3;
  274. // ExcludeResourceRules describes what operations on what resources/subresources the policy should not care about.
  275. // The exclude rules take precedence over include rules (if a resource matches both, it is excluded)
  276. // +listType=atomic
  277. // +optional
  278. repeated NamedRuleWithOperations excludeResourceRules = 4;
  279. // matchPolicy defines how the "MatchResources" list is used to match incoming requests.
  280. // Allowed values are "Exact" or "Equivalent".
  281. //
  282. // - Exact: match a request only if it exactly matches a specified rule.
  283. // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1,
  284. // but "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`,
  285. // the admission policy does not consider requests to apps/v1beta1 or extensions/v1beta1 API groups.
  286. //
  287. // - Equivalent: match a request if modifies a resource listed in rules, even via another API group or version.
  288. // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1,
  289. // and "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`,
  290. // the admission policy **does** consider requests made to apps/v1beta1 or extensions/v1beta1
  291. // API groups. The API server translates the request to a matched resource API if necessary.
  292. //
  293. // Defaults to "Equivalent"
  294. // +optional
  295. optional string matchPolicy = 7;
  296. }
  297. // MutatingAdmissionPolicy describes the definition of an admission mutation policy that mutates the object coming into admission chain.
  298. message MutatingAdmissionPolicy {
  299. // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
  300. // +optional
  301. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
  302. // Specification of the desired behavior of the MutatingAdmissionPolicy.
  303. optional MutatingAdmissionPolicySpec spec = 2;
  304. }
  305. // MutatingAdmissionPolicyBinding binds the MutatingAdmissionPolicy with parametrized resources.
  306. // MutatingAdmissionPolicyBinding and the optional parameter resource together define how cluster administrators
  307. // configure policies for clusters.
  308. //
  309. // For a given admission request, each binding will cause its policy to be
  310. // evaluated N times, where N is 1 for policies/bindings that don't use
  311. // params, otherwise N is the number of parameters selected by the binding.
  312. // Each evaluation is constrained by a [runtime cost budget](https://kubernetes.io/docs/reference/using-api/cel/#runtime-cost-budget).
  313. //
  314. // Adding/removing policies, bindings, or params can not affect whether a
  315. // given (policy, binding, param) combination is within its own CEL budget.
  316. message MutatingAdmissionPolicyBinding {
  317. // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
  318. // +optional
  319. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
  320. // Specification of the desired behavior of the MutatingAdmissionPolicyBinding.
  321. optional MutatingAdmissionPolicyBindingSpec spec = 2;
  322. }
  323. // MutatingAdmissionPolicyBindingList is a list of MutatingAdmissionPolicyBinding.
  324. message MutatingAdmissionPolicyBindingList {
  325. // Standard list metadata.
  326. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
  327. // +optional
  328. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
  329. // List of PolicyBinding.
  330. repeated MutatingAdmissionPolicyBinding items = 2;
  331. }
  332. // MutatingAdmissionPolicyBindingSpec is the specification of the MutatingAdmissionPolicyBinding.
  333. message MutatingAdmissionPolicyBindingSpec {
  334. // policyName references a MutatingAdmissionPolicy name which the MutatingAdmissionPolicyBinding binds to.
  335. // If the referenced resource does not exist, this binding is considered invalid and will be ignored
  336. // Required.
  337. optional string policyName = 1;
  338. // paramRef specifies the parameter resource used to configure the admission control policy.
  339. // It should point to a resource of the type specified in spec.ParamKind of the bound MutatingAdmissionPolicy.
  340. // If the policy specifies a ParamKind and the resource referred to by ParamRef does not exist, this binding is considered mis-configured and the FailurePolicy of the MutatingAdmissionPolicy applied.
  341. // If the policy does not specify a ParamKind then this field is ignored, and the rules are evaluated without a param.
  342. // +optional
  343. optional ParamRef paramRef = 2;
  344. // matchResources limits what resources match this binding and may be mutated by it.
  345. // Note that if matchResources matches a resource, the resource must also match a policy's matchConstraints and
  346. // matchConditions before the resource may be mutated.
  347. // When matchResources is unset, it does not constrain resource matching, and only the policy's matchConstraints
  348. // and matchConditions must match for the resource to be mutated.
  349. // Additionally, matchResources.resourceRules are optional and do not constraint matching when unset.
  350. // Note that this is differs from MutatingAdmissionPolicy matchConstraints, where resourceRules are required.
  351. // The CREATE, UPDATE and CONNECT operations are allowed. The DELETE operation may not be matched.
  352. // '*' matches CREATE, UPDATE and CONNECT.
  353. // +optional
  354. optional MatchResources matchResources = 3;
  355. }
  356. // MutatingAdmissionPolicyList is a list of MutatingAdmissionPolicy.
  357. message MutatingAdmissionPolicyList {
  358. // Standard list metadata.
  359. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
  360. // +optional
  361. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
  362. // List of ValidatingAdmissionPolicy.
  363. repeated MutatingAdmissionPolicy items = 2;
  364. }
  365. // MutatingAdmissionPolicySpec is the specification of the desired behavior of the admission policy.
  366. message MutatingAdmissionPolicySpec {
  367. // paramKind specifies the kind of resources used to parameterize this policy.
  368. // If absent, there are no parameters for this policy and the param CEL variable will not be provided to validation expressions.
  369. // If paramKind refers to a non-existent kind, this policy definition is mis-configured and the FailurePolicy is applied.
  370. // If paramKind is specified but paramRef is unset in MutatingAdmissionPolicyBinding, the params variable will be null.
  371. // +optional
  372. optional ParamKind paramKind = 1;
  373. // matchConstraints specifies what resources this policy is designed to validate.
  374. // The MutatingAdmissionPolicy cares about a request if it matches _all_ Constraints.
  375. // However, in order to prevent clusters from being put into an unstable state that cannot be recovered from via the API
  376. // MutatingAdmissionPolicy cannot match MutatingAdmissionPolicy and MutatingAdmissionPolicyBinding.
  377. // The CREATE, UPDATE and CONNECT operations are allowed. The DELETE operation may not be matched.
  378. // '*' matches CREATE, UPDATE and CONNECT.
  379. // Required.
  380. optional MatchResources matchConstraints = 2;
  381. // variables contain definitions of variables that can be used in composition of other expressions.
  382. // Each variable is defined as a named CEL expression.
  383. // The variables defined here will be available under `variables` in other expressions of the policy
  384. // except matchConditions because matchConditions are evaluated before the rest of the policy.
  385. //
  386. // The expression of a variable can refer to other variables defined earlier in the list but not those after.
  387. // Thus, variables must be sorted by the order of first appearance and acyclic.
  388. // +listType=atomic
  389. // +optional
  390. repeated Variable variables = 3;
  391. // mutations contain operations to perform on matching objects.
  392. // mutations may not be empty; a minimum of one mutation is required.
  393. // mutations are evaluated in order, and are reinvoked according to
  394. // the reinvocationPolicy.
  395. // The mutations of a policy are invoked for each binding of this policy
  396. // and reinvocation of mutations occurs on a per binding basis.
  397. //
  398. // +listType=atomic
  399. // +optional
  400. repeated Mutation mutations = 4;
  401. // failurePolicy defines how to handle failures for the admission policy. Failures can
  402. // occur from CEL expression parse errors, type check errors, runtime errors and invalid
  403. // or mis-configured policy definitions or bindings.
  404. //
  405. // A policy is invalid if paramKind refers to a non-existent Kind.
  406. // A binding is invalid if paramRef.name refers to a non-existent resource.
  407. //
  408. // failurePolicy does not define how validations that evaluate to false are handled.
  409. //
  410. // Allowed values are Ignore or Fail. Defaults to Fail.
  411. // +optional
  412. optional string failurePolicy = 5;
  413. // matchConditions is a list of conditions that must be met for a request to be validated.
  414. // Match conditions filter requests that have already been matched by the matchConstraints.
  415. // An empty list of matchConditions matches all requests.
  416. // There are a maximum of 64 match conditions allowed.
  417. //
  418. // If a parameter object is provided, it can be accessed via the `params` handle in the same
  419. // manner as validation expressions.
  420. //
  421. // The exact matching logic is (in order):
  422. // 1. If ANY matchCondition evaluates to FALSE, the policy is skipped.
  423. // 2. If ALL matchConditions evaluate to TRUE, the policy is evaluated.
  424. // 3. If any matchCondition evaluates to an error (but none are FALSE):
  425. // - If failurePolicy=Fail, reject the request
  426. // - If failurePolicy=Ignore, the policy is skipped
  427. //
  428. // +patchMergeKey=name
  429. // +patchStrategy=merge
  430. // +listType=map
  431. // +listMapKey=name
  432. // +optional
  433. repeated MatchCondition matchConditions = 6;
  434. // reinvocationPolicy indicates whether mutations may be called multiple times per MutatingAdmissionPolicyBinding
  435. // as part of a single admission evaluation.
  436. // Allowed values are "Never" and "IfNeeded".
  437. //
  438. // Never: These mutations will not be called more than once per binding in a single admission evaluation.
  439. //
  440. // IfNeeded: These mutations may be invoked more than once per binding for a single admission request and there is no guarantee of
  441. // order with respect to other admission plugins, admission webhooks, bindings of this policy and admission policies. Mutations are only
  442. // reinvoked when mutations change the object after this mutation is invoked.
  443. // Required.
  444. optional string reinvocationPolicy = 7;
  445. }
  446. // Mutation specifies the CEL expression which is used to apply the Mutation.
  447. message Mutation {
  448. // patchType indicates the patch strategy used.
  449. // Allowed values are "ApplyConfiguration" and "JSONPatch".
  450. // Required.
  451. //
  452. // +unionDiscriminator
  453. optional string patchType = 2;
  454. // applyConfiguration defines the desired configuration values of an object.
  455. // The configuration is applied to the admission object using
  456. // [structured merge diff](https://github.com/kubernetes-sigs/structured-merge-diff).
  457. // A CEL expression is used to create apply configuration.
  458. optional ApplyConfiguration applyConfiguration = 3;
  459. // jsonPatch defines a [JSON patch](https://jsonpatch.com/) operation to perform a mutation to the object.
  460. // A CEL expression is used to create the JSON patch.
  461. optional JSONPatch jsonPatch = 4;
  462. }
  463. // NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames.
  464. // +structType=atomic
  465. message NamedRuleWithOperations {
  466. // ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.
  467. // +listType=atomic
  468. // +optional
  469. repeated string resourceNames = 1;
  470. // RuleWithOperations is a tuple of Operations and Resources.
  471. optional .k8s.io.api.admissionregistration.v1.RuleWithOperations ruleWithOperations = 2;
  472. }
  473. // ParamKind is a tuple of Group Kind and Version.
  474. // +structType=atomic
  475. message ParamKind {
  476. // APIVersion is the API group version the resources belong to.
  477. // In format of "group/version".
  478. // Required.
  479. optional string apiVersion = 1;
  480. // Kind is the API kind the resources belong to.
  481. // Required.
  482. optional string kind = 2;
  483. }
  484. // ParamRef describes how to locate the params to be used as input to
  485. // expressions of rules applied by a policy binding.
  486. // +structType=atomic
  487. message ParamRef {
  488. // `name` is the name of the resource being referenced.
  489. //
  490. // `name` and `selector` are mutually exclusive properties. If one is set,
  491. // the other must be unset.
  492. //
  493. // +optional
  494. optional string name = 1;
  495. // namespace is the namespace of the referenced resource. Allows limiting
  496. // the search for params to a specific namespace. Applies to both `name` and
  497. // `selector` fields.
  498. //
  499. // A per-namespace parameter may be used by specifying a namespace-scoped
  500. // `paramKind` in the policy and leaving this field empty.
  501. //
  502. // - If `paramKind` is cluster-scoped, this field MUST be unset. Setting this
  503. // field results in a configuration error.
  504. //
  505. // - If `paramKind` is namespace-scoped, the namespace of the object being
  506. // evaluated for admission will be used when this field is left unset. Take
  507. // care that if this is left empty the binding must not match any cluster-scoped
  508. // resources, which will result in an error.
  509. //
  510. // +optional
  511. optional string namespace = 2;
  512. // selector can be used to match multiple param objects based on their labels.
  513. // Supply selector: {} to match all resources of the ParamKind.
  514. //
  515. // If multiple params are found, they are all evaluated with the policy expressions
  516. // and the results are ANDed together.
  517. //
  518. // One of `name` or `selector` must be set, but `name` and `selector` are
  519. // mutually exclusive properties. If one is set, the other must be unset.
  520. //
  521. // +optional
  522. optional .k8s.io.apimachinery.pkg.apis.meta.v1.LabelSelector selector = 3;
  523. // `parameterNotFoundAction` controls the behavior of the binding when the resource
  524. // exists, and name or selector is valid, but there are no parameters
  525. // matched by the binding. If the value is set to `Allow`, then no
  526. // matched parameters will be treated as successful validation by the binding.
  527. // If set to `Deny`, then no matched parameters will be subject to the
  528. // `failurePolicy` of the policy.
  529. //
  530. // Allowed values are `Allow` or `Deny`
  531. // Default to `Deny`
  532. // +optional
  533. optional string parameterNotFoundAction = 4;
  534. }
  535. // TypeChecking contains results of type checking the expressions in the
  536. // ValidatingAdmissionPolicy
  537. message TypeChecking {
  538. // The type checking warnings for each expression.
  539. // +optional
  540. // +listType=atomic
  541. repeated ExpressionWarning expressionWarnings = 1;
  542. }
  543. // ValidatingAdmissionPolicy describes the definition of an admission validation policy that accepts or rejects an object without changing it.
  544. message ValidatingAdmissionPolicy {
  545. // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
  546. // +optional
  547. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
  548. // Specification of the desired behavior of the ValidatingAdmissionPolicy.
  549. optional ValidatingAdmissionPolicySpec spec = 2;
  550. // The status of the ValidatingAdmissionPolicy, including warnings that are useful to determine if the policy
  551. // behaves in the expected way.
  552. // Populated by the system.
  553. // Read-only.
  554. // +optional
  555. optional ValidatingAdmissionPolicyStatus status = 3;
  556. }
  557. // ValidatingAdmissionPolicyBinding binds the ValidatingAdmissionPolicy with paramerized resources.
  558. // ValidatingAdmissionPolicyBinding and parameter CRDs together define how cluster administrators configure policies for clusters.
  559. //
  560. // For a given admission request, each binding will cause its policy to be
  561. // evaluated N times, where N is 1 for policies/bindings that don't use
  562. // params, otherwise N is the number of parameters selected by the binding.
  563. //
  564. // The CEL expressions of a policy must have a computed CEL cost below the maximum
  565. // CEL budget. Each evaluation of the policy is given an independent CEL cost budget.
  566. // Adding/removing policies, bindings, or params can not affect whether a
  567. // given (policy, binding, param) combination is within its own CEL budget.
  568. message ValidatingAdmissionPolicyBinding {
  569. // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata.
  570. // +optional
  571. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1;
  572. // Specification of the desired behavior of the ValidatingAdmissionPolicyBinding.
  573. optional ValidatingAdmissionPolicyBindingSpec spec = 2;
  574. }
  575. // ValidatingAdmissionPolicyBindingList is a list of ValidatingAdmissionPolicyBinding.
  576. message ValidatingAdmissionPolicyBindingList {
  577. // Standard list metadata.
  578. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
  579. // +optional
  580. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
  581. // List of PolicyBinding.
  582. repeated ValidatingAdmissionPolicyBinding items = 2;
  583. }
  584. // ValidatingAdmissionPolicyBindingSpec is the specification of the ValidatingAdmissionPolicyBinding.
  585. message ValidatingAdmissionPolicyBindingSpec {
  586. // PolicyName references a ValidatingAdmissionPolicy name which the ValidatingAdmissionPolicyBinding binds to.
  587. // If the referenced resource does not exist, this binding is considered invalid and will be ignored
  588. // Required.
  589. optional string policyName = 1;
  590. // paramRef specifies the parameter resource used to configure the admission control policy.
  591. // It should point to a resource of the type specified in ParamKind of the bound ValidatingAdmissionPolicy.
  592. // If the policy specifies a ParamKind and the resource referred to by ParamRef does not exist, this binding is considered mis-configured and the FailurePolicy of the ValidatingAdmissionPolicy applied.
  593. // If the policy does not specify a ParamKind then this field is ignored, and the rules are evaluated without a param.
  594. // +optional
  595. optional ParamRef paramRef = 2;
  596. // MatchResources declares what resources match this binding and will be validated by it.
  597. // Note that this is intersected with the policy's matchConstraints, so only requests that are matched by the policy can be selected by this.
  598. // If this is unset, all resources matched by the policy are validated by this binding
  599. // When resourceRules is unset, it does not constrain resource matching. If a resource is matched by the other fields of this object, it will be validated.
  600. // Note that this is differs from ValidatingAdmissionPolicy matchConstraints, where resourceRules are required.
  601. // +optional
  602. optional MatchResources matchResources = 3;
  603. // validationActions declares how Validations of the referenced ValidatingAdmissionPolicy are enforced.
  604. // If a validation evaluates to false it is always enforced according to these actions.
  605. //
  606. // Failures defined by the ValidatingAdmissionPolicy's FailurePolicy are enforced according
  607. // to these actions only if the FailurePolicy is set to Fail, otherwise the failures are
  608. // ignored. This includes compilation errors, runtime errors and misconfigurations of the policy.
  609. //
  610. // validationActions is declared as a set of action values. Order does
  611. // not matter. validationActions may not contain duplicates of the same action.
  612. //
  613. // The supported actions values are:
  614. //
  615. // "Deny" specifies that a validation failure results in a denied request.
  616. //
  617. // "Warn" specifies that a validation failure is reported to the request client
  618. // in HTTP Warning headers, with a warning code of 299. Warnings can be sent
  619. // both for allowed or denied admission responses.
  620. //
  621. // "Audit" specifies that a validation failure is included in the published
  622. // audit event for the request. The audit event will contain a
  623. // `validation.policy.admission.k8s.io/validation_failure` audit annotation
  624. // with a value containing the details of the validation failures, formatted as
  625. // a JSON list of objects, each with the following fields:
  626. // - message: The validation failure message string
  627. // - policy: The resource name of the ValidatingAdmissionPolicy
  628. // - binding: The resource name of the ValidatingAdmissionPolicyBinding
  629. // - expressionIndex: The index of the failed validations in the ValidatingAdmissionPolicy
  630. // - validationActions: The enforcement actions enacted for the validation failure
  631. // Example audit annotation:
  632. // `"validation.policy.admission.k8s.io/validation_failure": "[{\"message\": \"Invalid value\", {\"policy\": \"policy.example.com\", {\"binding\": \"policybinding.example.com\", {\"expressionIndex\": \"1\", {\"validationActions\": [\"Audit\"]}]"`
  633. //
  634. // Clients should expect to handle additional values by ignoring
  635. // any values not recognized.
  636. //
  637. // "Deny" and "Warn" may not be used together since this combination
  638. // needlessly duplicates the validation failure both in the
  639. // API response body and the HTTP warning headers.
  640. //
  641. // Required.
  642. // +listType=set
  643. repeated string validationActions = 4;
  644. }
  645. // ValidatingAdmissionPolicyList is a list of ValidatingAdmissionPolicy.
  646. message ValidatingAdmissionPolicyList {
  647. // Standard list metadata.
  648. // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
  649. // +optional
  650. optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1;
  651. // List of ValidatingAdmissionPolicy.
  652. repeated ValidatingAdmissionPolicy items = 2;
  653. }
  654. // ValidatingAdmissionPolicySpec is the specification of the desired behavior of the AdmissionPolicy.
  655. message ValidatingAdmissionPolicySpec {
  656. // ParamKind specifies the kind of resources used to parameterize this policy.
  657. // If absent, there are no parameters for this policy and the param CEL variable will not be provided to validation expressions.
  658. // If ParamKind refers to a non-existent kind, this policy definition is mis-configured and the FailurePolicy is applied.
  659. // If paramKind is specified but paramRef is unset in ValidatingAdmissionPolicyBinding, the params variable will be null.
  660. // +optional
  661. optional ParamKind paramKind = 1;
  662. // MatchConstraints specifies what resources this policy is designed to validate.
  663. // The AdmissionPolicy cares about a request if it matches _all_ Constraints.
  664. // However, in order to prevent clusters from being put into an unstable state that cannot be recovered from via the API
  665. // ValidatingAdmissionPolicy cannot match ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding.
  666. // Required.
  667. optional MatchResources matchConstraints = 2;
  668. // Validations contain CEL expressions which is used to apply the validation.
  669. // Validations and AuditAnnotations may not both be empty; a minimum of one Validations or AuditAnnotations is
  670. // required.
  671. // +listType=atomic
  672. // +optional
  673. repeated Validation validations = 3;
  674. // failurePolicy defines how to handle failures for the admission policy. Failures can
  675. // occur from CEL expression parse errors, type check errors, runtime errors and invalid
  676. // or mis-configured policy definitions or bindings.
  677. //
  678. // A policy is invalid if spec.paramKind refers to a non-existent Kind.
  679. // A binding is invalid if spec.paramRef.name refers to a non-existent resource.
  680. //
  681. // failurePolicy does not define how validations that evaluate to false are handled.
  682. //
  683. // When failurePolicy is set to Fail, ValidatingAdmissionPolicyBinding validationActions
  684. // define how failures are enforced.
  685. //
  686. // Allowed values are Ignore or Fail. Defaults to Fail.
  687. // +optional
  688. optional string failurePolicy = 4;
  689. // auditAnnotations contains CEL expressions which are used to produce audit
  690. // annotations for the audit event of the API request.
  691. // validations and auditAnnotations may not both be empty; a least one of validations or auditAnnotations is
  692. // required.
  693. // +listType=atomic
  694. // +optional
  695. repeated AuditAnnotation auditAnnotations = 5;
  696. // MatchConditions is a list of conditions that must be met for a request to be validated.
  697. // Match conditions filter requests that have already been matched by the rules,
  698. // namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests.
  699. // There are a maximum of 64 match conditions allowed.
  700. //
  701. // If a parameter object is provided, it can be accessed via the `params` handle in the same
  702. // manner as validation expressions.
  703. //
  704. // The exact matching logic is (in order):
  705. // 1. If ANY matchCondition evaluates to FALSE, the policy is skipped.
  706. // 2. If ALL matchConditions evaluate to TRUE, the policy is evaluated.
  707. // 3. If any matchCondition evaluates to an error (but none are FALSE):
  708. // - If failurePolicy=Fail, reject the request
  709. // - If failurePolicy=Ignore, the policy is skipped
  710. //
  711. // +patchMergeKey=name
  712. // +patchStrategy=merge
  713. // +listType=map
  714. // +listMapKey=name
  715. // +optional
  716. repeated MatchCondition matchConditions = 6;
  717. // Variables contain definitions of variables that can be used in composition of other expressions.
  718. // Each variable is defined as a named CEL expression.
  719. // The variables defined here will be available under `variables` in other expressions of the policy
  720. // except MatchConditions because MatchConditions are evaluated before the rest of the policy.
  721. //
  722. // The expression of a variable can refer to other variables defined earlier in the list but not those after.
  723. // Thus, Variables must be sorted by the order of first appearance and acyclic.
  724. // +patchMergeKey=name
  725. // +patchStrategy=merge
  726. // +listType=map
  727. // +listMapKey=name
  728. // +optional
  729. repeated Variable variables = 7;
  730. }
  731. // ValidatingAdmissionPolicyStatus represents the status of a ValidatingAdmissionPolicy.
  732. message ValidatingAdmissionPolicyStatus {
  733. // The generation observed by the controller.
  734. // +optional
  735. optional int64 observedGeneration = 1;
  736. // The results of type checking for each expression.
  737. // Presence of this field indicates the completion of the type checking.
  738. // +optional
  739. optional TypeChecking typeChecking = 2;
  740. // The conditions represent the latest available observations of a policy's current state.
  741. // +optional
  742. // +listType=map
  743. // +listMapKey=type
  744. repeated .k8s.io.apimachinery.pkg.apis.meta.v1.Condition conditions = 3;
  745. }
  746. // Validation specifies the CEL expression which is used to apply the validation.
  747. message Validation {
  748. // Expression represents the expression which will be evaluated by CEL.
  749. // ref: https://github.com/google/cel-spec
  750. // CEL expressions have access to the contents of the API request/response, organized into CEL variables as well as some other useful variables:
  751. //
  752. // - 'object' - The object from the incoming request. The value is null for DELETE requests.
  753. // - 'oldObject' - The existing object. The value is null for CREATE requests.
  754. // - 'request' - Attributes of the API request([ref](/pkg/apis/admission/types.go#AdmissionRequest)).
  755. // - 'params' - Parameter resource referred to by the policy binding being evaluated. Only populated if the policy has a ParamKind.
  756. // - 'namespaceObject' - The namespace object that the incoming object belongs to. The value is null for cluster-scoped resources.
  757. // - 'variables' - Map of composited variables, from its name to its lazily evaluated value.
  758. // For example, a variable named 'foo' can be accessed as 'variables.foo'.
  759. // - 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request.
  760. // See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz
  761. // - 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the
  762. // request resource.
  763. //
  764. // The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the
  765. // object. No other metadata properties are accessible.
  766. //
  767. // Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible.
  768. // Accessible property names are escaped according to the following rules when accessed in the expression:
  769. // - '__' escapes to '__underscores__'
  770. // - '.' escapes to '__dot__'
  771. // - '-' escapes to '__dash__'
  772. // - '/' escapes to '__slash__'
  773. // - Property names that exactly match a CEL RESERVED keyword escape to '__{keyword}__'. The keywords are:
  774. // "true", "false", "null", "in", "as", "break", "const", "continue", "else", "for", "function", "if",
  775. // "import", "let", "loop", "package", "namespace", "return".
  776. // Examples:
  777. // - Expression accessing a property named "namespace": {"Expression": "object.__namespace__ > 0"}
  778. // - Expression accessing a property named "x-prop": {"Expression": "object.x__dash__prop > 0"}
  779. // - Expression accessing a property named "redact__d": {"Expression": "object.redact__underscores__d > 0"}
  780. //
  781. // Equality on arrays with list type of 'set' or 'map' ignores element order, i.e. [1, 2] == [2, 1].
  782. // Concatenation on arrays with x-kubernetes-list-type use the semantics of the list type:
  783. // - 'set': `X + Y` performs a union where the array positions of all elements in `X` are preserved and
  784. // non-intersecting elements in `Y` are appended, retaining their partial order.
  785. // - 'map': `X + Y` performs a merge where the array positions of all keys in `X` are preserved but the values
  786. // are overwritten by values in `Y` when the key sets of `X` and `Y` intersect. Elements in `Y` with
  787. // non-intersecting keys are appended, retaining their partial order.
  788. // Required.
  789. optional string Expression = 1;
  790. // Message represents the message displayed when validation fails. The message is required if the Expression contains
  791. // line breaks. The message must not contain line breaks.
  792. // If unset, the message is "failed rule: {Rule}".
  793. // e.g. "must be a URL with the host matching spec.host"
  794. // If the Expression contains line breaks. Message is required.
  795. // The message must not contain line breaks.
  796. // If unset, the message is "failed Expression: {Expression}".
  797. // +optional
  798. optional string message = 2;
  799. // Reason represents a machine-readable description of why this validation failed.
  800. // If this is the first validation in the list to fail, this reason, as well as the
  801. // corresponding HTTP response code, are used in the
  802. // HTTP response to the client.
  803. // The currently supported reasons are: "Unauthorized", "Forbidden", "Invalid", "RequestEntityTooLarge".
  804. // If not set, StatusReasonInvalid is used in the response to the client.
  805. // +optional
  806. optional string reason = 3;
  807. // messageExpression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails.
  808. // Since messageExpression is used as a failure message, it must evaluate to a string.
  809. // If both message and messageExpression are present on a validation, then messageExpression will be used if validation fails.
  810. // If messageExpression results in a runtime error, the runtime error is logged, and the validation failure message is produced
  811. // as if the messageExpression field were unset. If messageExpression evaluates to an empty string, a string with only spaces, or a string
  812. // that contains line breaks, then the validation failure message will also be produced as if the messageExpression field were unset, and
  813. // the fact that messageExpression produced an empty string/string with only spaces/string with line breaks will be logged.
  814. // messageExpression has access to all the same variables as the `expression` except for 'authorizer' and 'authorizer.requestResource'.
  815. // Example:
  816. // "object.x must be less than max ("+string(params.max)+")"
  817. // +optional
  818. optional string messageExpression = 4;
  819. }
  820. // Variable is the definition of a variable that is used for composition.
  821. message Variable {
  822. // Name is the name of the variable. The name must be a valid CEL identifier and unique among all variables.
  823. // The variable can be accessed in other expressions through `variables`
  824. // For example, if name is "foo", the variable will be available as `variables.foo`
  825. optional string Name = 1;
  826. // Expression is the expression that will be evaluated as the value of the variable.
  827. // The CEL expression has access to the same identifiers as the CEL expressions in Validation.
  828. optional string Expression = 2;
  829. }