1 /* 2 Copyright 2019 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 ) 22 23 // Rule is a tuple of APIGroups, APIVersion, and Resources.It is recommended 24 // to make sure that all the tuple expansions are valid. 25 type Rule struct { 26 // APIGroups is the API groups the resources belong to. '*' is all groups. 27 // If '*' is present, the length of the slice must be one. 28 // Required. 29 // +listType=atomic 30 APIGroups []string `json:"apiGroups,omitempty" protobuf:"bytes,1,rep,name=apiGroups"` 31 32 // APIVersions is the API versions the resources belong to. '*' is all versions. 33 // If '*' is present, the length of the slice must be one. 34 // Required. 35 // +listType=atomic 36 APIVersions []string `json:"apiVersions,omitempty" protobuf:"bytes,2,rep,name=apiVersions"` 37 38 // Resources is a list of resources this rule applies to. 39 // 40 // For example: 41 // 'pods' means pods. 42 // 'pods/log' means the log subresource of pods. 43 // '*' means all resources, but not subresources. 44 // 'pods/*' means all subresources of pods. 45 // '*/scale' means all scale subresources. 46 // '*/*' means all resources and their subresources. 47 // 48 // If wildcard is present, the validation rule will ensure resources do not 49 // overlap with each other. 50 // 51 // Depending on the enclosing object, subresources might not be allowed. 52 // Required. 53 // +listType=atomic 54 Resources []string `json:"resources,omitempty" protobuf:"bytes,3,rep,name=resources"` 55 56 // scope specifies the scope of this rule. 57 // Valid values are "Cluster", "Namespaced", and "*" 58 // "Cluster" means that only cluster-scoped resources will match this rule. 59 // Namespace API objects are cluster-scoped. 60 // "Namespaced" means that only namespaced resources will match this rule. 61 // "*" means that there are no scope restrictions. 62 // Subresources match the scope of their parent resource. 63 // Default is "*". 64 // 65 // +optional 66 Scope *ScopeType `json:"scope,omitempty" protobuf:"bytes,4,rep,name=scope"` 67 } 68 69 // ScopeType specifies a scope for a Rule. 70 // +enum 71 type ScopeType string 72 73 const ( 74 // ClusterScope means that scope is limited to cluster-scoped objects. 75 // Namespace objects are cluster-scoped. 76 ClusterScope ScopeType = "Cluster" 77 // NamespacedScope means that scope is limited to namespaced objects. 78 NamespacedScope ScopeType = "Namespaced" 79 // AllScopes means that all scopes are included. 80 AllScopes ScopeType = "*" 81 ) 82 83 // FailurePolicyType specifies a failure policy that defines how unrecognized errors from the admission endpoint are handled. 84 // +enum 85 type FailurePolicyType string 86 87 const ( 88 // Ignore means that an error calling the webhook is ignored. 89 Ignore FailurePolicyType = "Ignore" 90 // Fail means that an error calling the webhook causes the admission to fail. 91 Fail FailurePolicyType = "Fail" 92 ) 93 94 // ParameterNotFoundActionType specifies a failure policy that defines how a binding 95 // is evaluated when the param referred by its perNamespaceParamRef is not found. 96 type ParameterNotFoundActionType string 97 98 const ( 99 // Allow means all requests will be admitted if no param resources 100 // could be found. 101 AllowAction ParameterNotFoundActionType = "Allow" 102 // Deny means all requests will be denied if no param resources are found. 103 DenyAction ParameterNotFoundActionType = "Deny" 104 ) 105 106 // MatchPolicyType specifies the type of match policy. 107 // +enum 108 type MatchPolicyType string 109 110 const ( 111 // Exact means requests should only be sent to the webhook if they exactly match a given rule. 112 Exact MatchPolicyType = "Exact" 113 // Equivalent means requests should be sent to the webhook if they modify a resource listed in rules via another API group or version. 114 Equivalent MatchPolicyType = "Equivalent" 115 ) 116 117 // SideEffectClass specifies the types of side effects a webhook may have. 118 // +enum 119 type SideEffectClass string 120 121 const ( 122 // SideEffectClassUnknown means that no information is known about the side effects of calling the webhook. 123 // If a request with the dry-run attribute would trigger a call to this webhook, the request will instead fail. 124 SideEffectClassUnknown SideEffectClass = "Unknown" 125 // SideEffectClassNone means that calling the webhook will have no side effects. 126 SideEffectClassNone SideEffectClass = "None" 127 // SideEffectClassSome means that calling the webhook will possibly have side effects. 128 // If a request with the dry-run attribute would trigger a call to this webhook, the request will instead fail. 129 SideEffectClassSome SideEffectClass = "Some" 130 // SideEffectClassNoneOnDryRun means that calling the webhook will possibly have side effects, but if the 131 // request being reviewed has the dry-run attribute, the side effects will be suppressed. 132 SideEffectClassNoneOnDryRun SideEffectClass = "NoneOnDryRun" 133 ) 134 135 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 136 // +genclient 137 // +genclient:nonNamespaced 138 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 139 // +k8s:prerelease-lifecycle-gen:introduced=1.30 140 // ValidatingAdmissionPolicy describes the definition of an admission validation policy that accepts or rejects an object without changing it. 141 type ValidatingAdmissionPolicy struct { 142 metav1.TypeMeta `json:",inline"` 143 // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata. 144 // +optional 145 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 146 // Specification of the desired behavior of the ValidatingAdmissionPolicy. 147 Spec ValidatingAdmissionPolicySpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 148 // The status of the ValidatingAdmissionPolicy, including warnings that are useful to determine if the policy 149 // behaves in the expected way. 150 // Populated by the system. 151 // Read-only. 152 // +optional 153 Status ValidatingAdmissionPolicyStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 154 } 155 156 // ValidatingAdmissionPolicyStatus represents the status of an admission validation policy. 157 type ValidatingAdmissionPolicyStatus struct { 158 // The generation observed by the controller. 159 // +optional 160 ObservedGeneration int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"` 161 // The results of type checking for each expression. 162 // Presence of this field indicates the completion of the type checking. 163 // +optional 164 TypeChecking *TypeChecking `json:"typeChecking,omitempty" protobuf:"bytes,2,opt,name=typeChecking"` 165 // The conditions represent the latest available observations of a policy's current state. 166 // +optional 167 // +listType=map 168 // +listMapKey=type 169 Conditions []metav1.Condition `json:"conditions,omitempty" protobuf:"bytes,3,rep,name=conditions"` 170 } 171 172 // ValidatingAdmissionPolicyConditionType is the condition type of admission validation policy. 173 type ValidatingAdmissionPolicyConditionType string 174 175 // TypeChecking contains results of type checking the expressions in the 176 // ValidatingAdmissionPolicy 177 type TypeChecking struct { 178 // The type checking warnings for each expression. 179 // +optional 180 // +listType=atomic 181 ExpressionWarnings []ExpressionWarning `json:"expressionWarnings,omitempty" protobuf:"bytes,1,rep,name=expressionWarnings"` 182 } 183 184 // ExpressionWarning is a warning information that targets a specific expression. 185 type ExpressionWarning struct { 186 // The path to the field that refers the expression. 187 // For example, the reference to the expression of the first item of 188 // validations is "spec.validations[0].expression" 189 FieldRef string `json:"fieldRef" protobuf:"bytes,2,opt,name=fieldRef"` 190 // The content of type checking information in a human-readable form. 191 // Each line of the warning contains the type that the expression is checked 192 // against, followed by the type check error from the compiler. 193 Warning string `json:"warning" protobuf:"bytes,3,opt,name=warning"` 194 } 195 196 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 197 // +k8s:prerelease-lifecycle-gen:introduced=1.30 198 // ValidatingAdmissionPolicyList is a list of ValidatingAdmissionPolicy. 199 type ValidatingAdmissionPolicyList struct { 200 metav1.TypeMeta `json:",inline"` 201 // Standard list metadata. 202 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 203 // +optional 204 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 205 // List of ValidatingAdmissionPolicy. 206 Items []ValidatingAdmissionPolicy `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"` 207 } 208 209 // ValidatingAdmissionPolicySpec is the specification of the desired behavior of the AdmissionPolicy. 210 type ValidatingAdmissionPolicySpec struct { 211 // ParamKind specifies the kind of resources used to parameterize this policy. 212 // If absent, there are no parameters for this policy and the param CEL variable will not be provided to validation expressions. 213 // If ParamKind refers to a non-existent kind, this policy definition is mis-configured and the FailurePolicy is applied. 214 // If paramKind is specified but paramRef is unset in ValidatingAdmissionPolicyBinding, the params variable will be null. 215 // +optional 216 ParamKind *ParamKind `json:"paramKind,omitempty" protobuf:"bytes,1,rep,name=paramKind"` 217 218 // MatchConstraints specifies what resources this policy is designed to validate. 219 // The AdmissionPolicy cares about a request if it matches _all_ Constraints. 220 // However, in order to prevent clusters from being put into an unstable state that cannot be recovered from via the API 221 // ValidatingAdmissionPolicy cannot match ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding. 222 // Required. 223 MatchConstraints *MatchResources `json:"matchConstraints,omitempty" protobuf:"bytes,2,rep,name=matchConstraints"` 224 225 // Validations contain CEL expressions which is used to apply the validation. 226 // Validations and AuditAnnotations may not both be empty; a minimum of one Validations or AuditAnnotations is 227 // required. 228 // +listType=atomic 229 // +optional 230 Validations []Validation `json:"validations,omitempty" protobuf:"bytes,3,rep,name=validations"` 231 232 // failurePolicy defines how to handle failures for the admission policy. Failures can 233 // occur from CEL expression parse errors, type check errors, runtime errors and invalid 234 // or mis-configured policy definitions or bindings. 235 // 236 // A policy is invalid if spec.paramKind refers to a non-existent Kind. 237 // A binding is invalid if spec.paramRef.name refers to a non-existent resource. 238 // 239 // failurePolicy does not define how validations that evaluate to false are handled. 240 // 241 // When failurePolicy is set to Fail, ValidatingAdmissionPolicyBinding validationActions 242 // define how failures are enforced. 243 // 244 // Allowed values are Ignore or Fail. Defaults to Fail. 245 // +optional 246 FailurePolicy *FailurePolicyType `json:"failurePolicy,omitempty" protobuf:"bytes,4,opt,name=failurePolicy,casttype=FailurePolicyType"` 247 248 // auditAnnotations contains CEL expressions which are used to produce audit 249 // annotations for the audit event of the API request. 250 // validations and auditAnnotations may not both be empty; a least one of validations or auditAnnotations is 251 // required. 252 // +listType=atomic 253 // +optional 254 AuditAnnotations []AuditAnnotation `json:"auditAnnotations,omitempty" protobuf:"bytes,5,rep,name=auditAnnotations"` 255 256 // MatchConditions is a list of conditions that must be met for a request to be validated. 257 // Match conditions filter requests that have already been matched by the rules, 258 // namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. 259 // There are a maximum of 64 match conditions allowed. 260 // 261 // If a parameter object is provided, it can be accessed via the `params` handle in the same 262 // manner as validation expressions. 263 // 264 // The exact matching logic is (in order): 265 // 1. If ANY matchCondition evaluates to FALSE, the policy is skipped. 266 // 2. If ALL matchConditions evaluate to TRUE, the policy is evaluated. 267 // 3. If any matchCondition evaluates to an error (but none are FALSE): 268 // - If failurePolicy=Fail, reject the request 269 // - If failurePolicy=Ignore, the policy is skipped 270 // 271 // +patchMergeKey=name 272 // +patchStrategy=merge 273 // +listType=map 274 // +listMapKey=name 275 // +optional 276 MatchConditions []MatchCondition `json:"matchConditions,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,6,rep,name=matchConditions"` 277 278 // Variables contain definitions of variables that can be used in composition of other expressions. 279 // Each variable is defined as a named CEL expression. 280 // The variables defined here will be available under `variables` in other expressions of the policy 281 // except MatchConditions because MatchConditions are evaluated before the rest of the policy. 282 // 283 // The expression of a variable can refer to other variables defined earlier in the list but not those after. 284 // Thus, Variables must be sorted by the order of first appearance and acyclic. 285 // +patchMergeKey=name 286 // +patchStrategy=merge 287 // +listType=map 288 // +listMapKey=name 289 // +optional 290 Variables []Variable `json:"variables,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,7,rep,name=variables"` 291 } 292 293 // ParamKind is a tuple of Group Kind and Version. 294 // +structType=atomic 295 type ParamKind struct { 296 // APIVersion is the API group version the resources belong to. 297 // In format of "group/version". 298 // Required. 299 APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,1,rep,name=apiVersion"` 300 301 // Kind is the API kind the resources belong to. 302 // Required. 303 Kind string `json:"kind,omitempty" protobuf:"bytes,2,rep,name=kind"` 304 } 305 306 // Validation specifies the CEL expression which is used to apply the validation. 307 type Validation struct { 308 // Expression represents the expression which will be evaluated by CEL. 309 // ref: https://github.com/google/cel-spec 310 // CEL expressions have access to the contents of the API request/response, organized into CEL variables as well as some other useful variables: 311 // 312 // - 'object' - The object from the incoming request. The value is null for DELETE requests. 313 // - 'oldObject' - The existing object. The value is null for CREATE requests. 314 // - 'request' - Attributes of the API request([ref](/pkg/apis/admission/types.go#AdmissionRequest)). 315 // - 'params' - Parameter resource referred to by the policy binding being evaluated. Only populated if the policy has a ParamKind. 316 // - 'namespaceObject' - The namespace object that the incoming object belongs to. The value is null for cluster-scoped resources. 317 // - 'variables' - Map of composited variables, from its name to its lazily evaluated value. 318 // For example, a variable named 'foo' can be accessed as 'variables.foo'. 319 // - 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request. 320 // See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz 321 // - 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the 322 // request resource. 323 // 324 // The `apiVersion`, `kind`, `metadata.name` and `metadata.generateName` are always accessible from the root of the 325 // object. No other metadata properties are accessible. 326 // 327 // Only property names of the form `[a-zA-Z_.-/][a-zA-Z0-9_.-/]*` are accessible. 328 // Accessible property names are escaped according to the following rules when accessed in the expression: 329 // - '__' escapes to '__underscores__' 330 // - '.' escapes to '__dot__' 331 // - '-' escapes to '__dash__' 332 // - '/' escapes to '__slash__' 333 // - Property names that exactly match a CEL RESERVED keyword escape to '__{keyword}__'. The keywords are: 334 // "true", "false", "null", "in", "as", "break", "const", "continue", "else", "for", "function", "if", 335 // "import", "let", "loop", "package", "namespace", "return". 336 // Examples: 337 // - Expression accessing a property named "namespace": {"Expression": "object.__namespace__ > 0"} 338 // - Expression accessing a property named "x-prop": {"Expression": "object.x__dash__prop > 0"} 339 // - Expression accessing a property named "redact__d": {"Expression": "object.redact__underscores__d > 0"} 340 // 341 // Equality on arrays with list type of 'set' or 'map' ignores element order, i.e. [1, 2] == [2, 1]. 342 // Concatenation on arrays with x-kubernetes-list-type use the semantics of the list type: 343 // - 'set': `X + Y` performs a union where the array positions of all elements in `X` are preserved and 344 // non-intersecting elements in `Y` are appended, retaining their partial order. 345 // - 'map': `X + Y` performs a merge where the array positions of all keys in `X` are preserved but the values 346 // are overwritten by values in `Y` when the key sets of `X` and `Y` intersect. Elements in `Y` with 347 // non-intersecting keys are appended, retaining their partial order. 348 // Required. 349 Expression string `json:"expression" protobuf:"bytes,1,opt,name=Expression"` 350 // Message represents the message displayed when validation fails. The message is required if the Expression contains 351 // line breaks. The message must not contain line breaks. 352 // If unset, the message is "failed rule: {Rule}". 353 // e.g. "must be a URL with the host matching spec.host" 354 // If the Expression contains line breaks. Message is required. 355 // The message must not contain line breaks. 356 // If unset, the message is "failed Expression: {Expression}". 357 // +optional 358 Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"` 359 // Reason represents a machine-readable description of why this validation failed. 360 // If this is the first validation in the list to fail, this reason, as well as the 361 // corresponding HTTP response code, are used in the 362 // HTTP response to the client. 363 // The currently supported reasons are: "Unauthorized", "Forbidden", "Invalid", "RequestEntityTooLarge". 364 // If not set, StatusReasonInvalid is used in the response to the client. 365 // +optional 366 Reason *metav1.StatusReason `json:"reason,omitempty" protobuf:"bytes,3,opt,name=reason"` 367 // messageExpression declares a CEL expression that evaluates to the validation failure message that is returned when this rule fails. 368 // Since messageExpression is used as a failure message, it must evaluate to a string. 369 // If both message and messageExpression are present on a validation, then messageExpression will be used if validation fails. 370 // If messageExpression results in a runtime error, the runtime error is logged, and the validation failure message is produced 371 // as if the messageExpression field were unset. If messageExpression evaluates to an empty string, a string with only spaces, or a string 372 // that contains line breaks, then the validation failure message will also be produced as if the messageExpression field were unset, and 373 // the fact that messageExpression produced an empty string/string with only spaces/string with line breaks will be logged. 374 // messageExpression has access to all the same variables as the `expression` except for 'authorizer' and 'authorizer.requestResource'. 375 // Example: 376 // "object.x must be less than max ("+string(params.max)+")" 377 // +optional 378 MessageExpression string `json:"messageExpression,omitempty" protobuf:"bytes,4,opt,name=messageExpression"` 379 } 380 381 // Variable is the definition of a variable that is used for composition. A variable is defined as a named expression. 382 // +structType=atomic 383 type Variable struct { 384 // Name is the name of the variable. The name must be a valid CEL identifier and unique among all variables. 385 // The variable can be accessed in other expressions through `variables` 386 // For example, if name is "foo", the variable will be available as `variables.foo` 387 Name string `json:"name" protobuf:"bytes,1,opt,name=Name"` 388 389 // Expression is the expression that will be evaluated as the value of the variable. 390 // The CEL expression has access to the same identifiers as the CEL expressions in Validation. 391 Expression string `json:"expression" protobuf:"bytes,2,opt,name=Expression"` 392 } 393 394 // AuditAnnotation describes how to produce an audit annotation for an API request. 395 type AuditAnnotation struct { 396 // key specifies the audit annotation key. The audit annotation keys of 397 // a ValidatingAdmissionPolicy must be unique. The key must be a qualified 398 // name ([A-Za-z0-9][-A-Za-z0-9_.]*) no more than 63 bytes in length. 399 // 400 // The key is combined with the resource name of the 401 // ValidatingAdmissionPolicy to construct an audit annotation key: 402 // "{ValidatingAdmissionPolicy name}/{key}". 403 // 404 // If an admission webhook uses the same resource name as this ValidatingAdmissionPolicy 405 // and the same audit annotation key, the annotation key will be identical. 406 // In this case, the first annotation written with the key will be included 407 // in the audit event and all subsequent annotations with the same key 408 // will be discarded. 409 // 410 // Required. 411 Key string `json:"key" protobuf:"bytes,1,opt,name=key"` 412 413 // valueExpression represents the expression which is evaluated by CEL to 414 // produce an audit annotation value. The expression must evaluate to either 415 // a string or null value. If the expression evaluates to a string, the 416 // audit annotation is included with the string value. If the expression 417 // evaluates to null or empty string the audit annotation will be omitted. 418 // The valueExpression may be no longer than 5kb in length. 419 // If the result of the valueExpression is more than 10kb in length, it 420 // will be truncated to 10kb. 421 // 422 // If multiple ValidatingAdmissionPolicyBinding resources match an 423 // API request, then the valueExpression will be evaluated for 424 // each binding. All unique values produced by the valueExpressions 425 // will be joined together in a comma-separated list. 426 // 427 // Required. 428 ValueExpression string `json:"valueExpression" protobuf:"bytes,2,opt,name=valueExpression"` 429 } 430 431 // +genclient 432 // +genclient:nonNamespaced 433 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 434 // +k8s:prerelease-lifecycle-gen:introduced=1.30 435 436 // ValidatingAdmissionPolicyBinding binds the ValidatingAdmissionPolicy with paramerized resources. 437 // ValidatingAdmissionPolicyBinding and parameter CRDs together define how cluster administrators configure policies for clusters. 438 // 439 // For a given admission request, each binding will cause its policy to be 440 // evaluated N times, where N is 1 for policies/bindings that don't use 441 // params, otherwise N is the number of parameters selected by the binding. 442 // 443 // The CEL expressions of a policy must have a computed CEL cost below the maximum 444 // CEL budget. Each evaluation of the policy is given an independent CEL cost budget. 445 // Adding/removing policies, bindings, or params can not affect whether a 446 // given (policy, binding, param) combination is within its own CEL budget. 447 type ValidatingAdmissionPolicyBinding struct { 448 metav1.TypeMeta `json:",inline"` 449 // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata. 450 // +optional 451 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 452 // Specification of the desired behavior of the ValidatingAdmissionPolicyBinding. 453 Spec ValidatingAdmissionPolicyBindingSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"` 454 } 455 456 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 457 // +k8s:prerelease-lifecycle-gen:introduced=1.30 458 459 // ValidatingAdmissionPolicyBindingList is a list of ValidatingAdmissionPolicyBinding. 460 type ValidatingAdmissionPolicyBindingList struct { 461 metav1.TypeMeta `json:",inline"` 462 // Standard list metadata. 463 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 464 // +optional 465 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 466 // List of PolicyBinding. 467 Items []ValidatingAdmissionPolicyBinding `json:"items,omitempty" protobuf:"bytes,2,rep,name=items"` 468 } 469 470 // ValidatingAdmissionPolicyBindingSpec is the specification of the ValidatingAdmissionPolicyBinding. 471 type ValidatingAdmissionPolicyBindingSpec struct { 472 // PolicyName references a ValidatingAdmissionPolicy name which the ValidatingAdmissionPolicyBinding binds to. 473 // If the referenced resource does not exist, this binding is considered invalid and will be ignored 474 // Required. 475 PolicyName string `json:"policyName,omitempty" protobuf:"bytes,1,rep,name=policyName"` 476 477 // paramRef specifies the parameter resource used to configure the admission control policy. 478 // It should point to a resource of the type specified in ParamKind of the bound ValidatingAdmissionPolicy. 479 // 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. 480 // If the policy does not specify a ParamKind then this field is ignored, and the rules are evaluated without a param. 481 // +optional 482 ParamRef *ParamRef `json:"paramRef,omitempty" protobuf:"bytes,2,rep,name=paramRef"` 483 484 // MatchResources declares what resources match this binding and will be validated by it. 485 // Note that this is intersected with the policy's matchConstraints, so only requests that are matched by the policy can be selected by this. 486 // If this is unset, all resources matched by the policy are validated by this binding 487 // 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. 488 // Note that this is differs from ValidatingAdmissionPolicy matchConstraints, where resourceRules are required. 489 // +optional 490 MatchResources *MatchResources `json:"matchResources,omitempty" protobuf:"bytes,3,rep,name=matchResources"` 491 492 // validationActions declares how Validations of the referenced ValidatingAdmissionPolicy are enforced. 493 // If a validation evaluates to false it is always enforced according to these actions. 494 // 495 // Failures defined by the ValidatingAdmissionPolicy's FailurePolicy are enforced according 496 // to these actions only if the FailurePolicy is set to Fail, otherwise the failures are 497 // ignored. This includes compilation errors, runtime errors and misconfigurations of the policy. 498 // 499 // validationActions is declared as a set of action values. Order does 500 // not matter. validationActions may not contain duplicates of the same action. 501 // 502 // The supported actions values are: 503 // 504 // "Deny" specifies that a validation failure results in a denied request. 505 // 506 // "Warn" specifies that a validation failure is reported to the request client 507 // in HTTP Warning headers, with a warning code of 299. Warnings can be sent 508 // both for allowed or denied admission responses. 509 // 510 // "Audit" specifies that a validation failure is included in the published 511 // audit event for the request. The audit event will contain a 512 // `validation.policy.admission.k8s.io/validation_failure` audit annotation 513 // with a value containing the details of the validation failures, formatted as 514 // a JSON list of objects, each with the following fields: 515 // - message: The validation failure message string 516 // - policy: The resource name of the ValidatingAdmissionPolicy 517 // - binding: The resource name of the ValidatingAdmissionPolicyBinding 518 // - expressionIndex: The index of the failed validations in the ValidatingAdmissionPolicy 519 // - validationActions: The enforcement actions enacted for the validation failure 520 // Example audit annotation: 521 // `"validation.policy.admission.k8s.io/validation_failure": "[{\"message\": \"Invalid value\", {\"policy\": \"policy.example.com\", {\"binding\": \"policybinding.example.com\", {\"expressionIndex\": \"1\", {\"validationActions\": [\"Audit\"]}]"` 522 // 523 // Clients should expect to handle additional values by ignoring 524 // any values not recognized. 525 // 526 // "Deny" and "Warn" may not be used together since this combination 527 // needlessly duplicates the validation failure both in the 528 // API response body and the HTTP warning headers. 529 // 530 // Required. 531 // +listType=set 532 ValidationActions []ValidationAction `json:"validationActions,omitempty" protobuf:"bytes,4,rep,name=validationActions"` 533 } 534 535 // ParamRef describes how to locate the params to be used as input to 536 // expressions of rules applied by a policy binding. 537 // +structType=atomic 538 type ParamRef struct { 539 // name is the name of the resource being referenced. 540 // 541 // One of `name` or `selector` must be set, but `name` and `selector` are 542 // mutually exclusive properties. If one is set, the other must be unset. 543 // 544 // A single parameter used for all admission requests can be configured 545 // by setting the `name` field, leaving `selector` blank, and setting namespace 546 // if `paramKind` is namespace-scoped. 547 // 548 Name string `json:"name,omitempty" protobuf:"bytes,1,rep,name=name"` 549 550 // namespace is the namespace of the referenced resource. Allows limiting 551 // the search for params to a specific namespace. Applies to both `name` and 552 // `selector` fields. 553 // 554 // A per-namespace parameter may be used by specifying a namespace-scoped 555 // `paramKind` in the policy and leaving this field empty. 556 // 557 // - If `paramKind` is cluster-scoped, this field MUST be unset. Setting this 558 // field results in a configuration error. 559 // 560 // - If `paramKind` is namespace-scoped, the namespace of the object being 561 // evaluated for admission will be used when this field is left unset. Take 562 // care that if this is left empty the binding must not match any cluster-scoped 563 // resources, which will result in an error. 564 // 565 // +optional 566 Namespace string `json:"namespace,omitempty" protobuf:"bytes,2,rep,name=namespace"` 567 568 // selector can be used to match multiple param objects based on their labels. 569 // Supply selector: {} to match all resources of the ParamKind. 570 // 571 // If multiple params are found, they are all evaluated with the policy expressions 572 // and the results are ANDed together. 573 // 574 // One of `name` or `selector` must be set, but `name` and `selector` are 575 // mutually exclusive properties. If one is set, the other must be unset. 576 // 577 // +optional 578 Selector *metav1.LabelSelector `json:"selector,omitempty" protobuf:"bytes,3,rep,name=selector"` 579 580 // `parameterNotFoundAction` controls the behavior of the binding when the resource 581 // exists, and name or selector is valid, but there are no parameters 582 // matched by the binding. If the value is set to `Allow`, then no 583 // matched parameters will be treated as successful validation by the binding. 584 // If set to `Deny`, then no matched parameters will be subject to the 585 // `failurePolicy` of the policy. 586 // 587 // Allowed values are `Allow` or `Deny` 588 // 589 // Required 590 ParameterNotFoundAction *ParameterNotFoundActionType `json:"parameterNotFoundAction,omitempty" protobuf:"bytes,4,rep,name=parameterNotFoundAction"` 591 } 592 593 // MatchResources decides whether to run the admission control policy on an object based 594 // on whether it meets the match criteria. 595 // The exclude rules take precedence over include rules (if a resource matches both, it is excluded) 596 // +structType=atomic 597 type MatchResources struct { 598 // NamespaceSelector decides whether to run the admission control policy on an object based 599 // on whether the namespace for that object matches the selector. If the 600 // object itself is a namespace, the matching is performed on 601 // object.metadata.labels. If the object is another cluster scoped resource, 602 // it never skips the policy. 603 // 604 // For example, to run the webhook on any objects whose namespace is not 605 // associated with "runlevel" of "0" or "1"; you will set the selector as 606 // follows: 607 // "namespaceSelector": { 608 // "matchExpressions": [ 609 // { 610 // "key": "runlevel", 611 // "operator": "NotIn", 612 // "values": [ 613 // "0", 614 // "1" 615 // ] 616 // } 617 // ] 618 // } 619 // 620 // If instead you want to only run the policy on any objects whose 621 // namespace is associated with the "environment" of "prod" or "staging"; 622 // you will set the selector as follows: 623 // "namespaceSelector": { 624 // "matchExpressions": [ 625 // { 626 // "key": "environment", 627 // "operator": "In", 628 // "values": [ 629 // "prod", 630 // "staging" 631 // ] 632 // } 633 // ] 634 // } 635 // 636 // See 637 // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ 638 // for more examples of label selectors. 639 // 640 // Default to the empty LabelSelector, which matches everything. 641 // +optional 642 NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty" protobuf:"bytes,1,opt,name=namespaceSelector"` 643 // ObjectSelector decides whether to run the validation based on if the 644 // object has matching labels. objectSelector is evaluated against both 645 // the oldObject and newObject that would be sent to the cel validation, and 646 // is considered to match if either object matches the selector. A null 647 // object (oldObject in the case of create, or newObject in the case of 648 // delete) or an object that cannot have labels (like a 649 // DeploymentRollback or a PodProxyOptions object) is not considered to 650 // match. 651 // Use the object selector only if the webhook is opt-in, because end 652 // users may skip the admission webhook by setting the labels. 653 // Default to the empty LabelSelector, which matches everything. 654 // +optional 655 ObjectSelector *metav1.LabelSelector `json:"objectSelector,omitempty" protobuf:"bytes,2,opt,name=objectSelector"` 656 // ResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy matches. 657 // The policy cares about an operation if it matches _any_ Rule. 658 // +listType=atomic 659 // +optional 660 ResourceRules []NamedRuleWithOperations `json:"resourceRules,omitempty" protobuf:"bytes,3,rep,name=resourceRules"` 661 // ExcludeResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy should not care about. 662 // The exclude rules take precedence over include rules (if a resource matches both, it is excluded) 663 // +listType=atomic 664 // +optional 665 ExcludeResourceRules []NamedRuleWithOperations `json:"excludeResourceRules,omitempty" protobuf:"bytes,4,rep,name=excludeResourceRules"` 666 // matchPolicy defines how the "MatchResources" list is used to match incoming requests. 667 // Allowed values are "Exact" or "Equivalent". 668 // 669 // - Exact: match a request only if it exactly matches a specified rule. 670 // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, 671 // but "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`, 672 // a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the ValidatingAdmissionPolicy. 673 // 674 // - Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. 675 // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, 676 // and "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`, 677 // a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the ValidatingAdmissionPolicy. 678 // 679 // Defaults to "Equivalent" 680 // +optional 681 MatchPolicy *MatchPolicyType `json:"matchPolicy,omitempty" protobuf:"bytes,7,opt,name=matchPolicy,casttype=MatchPolicyType"` 682 } 683 684 // ValidationAction specifies a policy enforcement action. 685 // +enum 686 type ValidationAction string 687 688 const ( 689 // Deny specifies that a validation failure results in a denied request. 690 Deny ValidationAction = "Deny" 691 // Warn specifies that a validation failure is reported to the request client 692 // in HTTP Warning headers, with a warning code of 299. Warnings can be sent 693 // both for allowed or denied admission responses. 694 Warn ValidationAction = "Warn" 695 // Audit specifies that a validation failure is included in the published 696 // audit event for the request. The audit event will contain a 697 // `validation.policy.admission.k8s.io/validation_failure` audit annotation 698 // with a value containing the details of the validation failure. 699 Audit ValidationAction = "Audit" 700 ) 701 702 // NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames. 703 // +structType=atomic 704 type NamedRuleWithOperations struct { 705 // ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed. 706 // +listType=atomic 707 // +optional 708 ResourceNames []string `json:"resourceNames,omitempty" protobuf:"bytes,1,rep,name=resourceNames"` 709 // RuleWithOperations is a tuple of Operations and Resources. 710 RuleWithOperations `json:",inline" protobuf:"bytes,2,opt,name=ruleWithOperations"` 711 } 712 713 // +genclient 714 // +genclient:nonNamespaced 715 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 716 717 // ValidatingWebhookConfiguration describes the configuration of and admission webhook that accept or reject and object without changing it. 718 type ValidatingWebhookConfiguration struct { 719 metav1.TypeMeta `json:",inline"` 720 // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata. 721 // +optional 722 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 723 // Webhooks is a list of webhooks and the affected resources and operations. 724 // +optional 725 // +patchMergeKey=name 726 // +patchStrategy=merge 727 // +listType=map 728 // +listMapKey=name 729 Webhooks []ValidatingWebhook `json:"webhooks,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=Webhooks"` 730 } 731 732 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 733 734 // ValidatingWebhookConfigurationList is a list of ValidatingWebhookConfiguration. 735 type ValidatingWebhookConfigurationList struct { 736 metav1.TypeMeta `json:",inline"` 737 // Standard list metadata. 738 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 739 // +optional 740 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 741 // List of ValidatingWebhookConfiguration. 742 Items []ValidatingWebhookConfiguration `json:"items" protobuf:"bytes,2,rep,name=items"` 743 } 744 745 // +genclient 746 // +genclient:nonNamespaced 747 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 748 749 // MutatingWebhookConfiguration describes the configuration of and admission webhook that accept or reject and may change the object. 750 type MutatingWebhookConfiguration struct { 751 metav1.TypeMeta `json:",inline"` 752 // Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata. 753 // +optional 754 metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 755 // Webhooks is a list of webhooks and the affected resources and operations. 756 // +optional 757 // +patchMergeKey=name 758 // +patchStrategy=merge 759 // +listType=map 760 // +listMapKey=name 761 Webhooks []MutatingWebhook `json:"webhooks,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,2,rep,name=Webhooks"` 762 } 763 764 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 765 766 // MutatingWebhookConfigurationList is a list of MutatingWebhookConfiguration. 767 type MutatingWebhookConfigurationList struct { 768 metav1.TypeMeta `json:",inline"` 769 // Standard list metadata. 770 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 771 // +optional 772 metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 773 // List of MutatingWebhookConfiguration. 774 Items []MutatingWebhookConfiguration `json:"items" protobuf:"bytes,2,rep,name=items"` 775 } 776 777 // ValidatingWebhook describes an admission webhook and the resources and operations it applies to. 778 type ValidatingWebhook struct { 779 // The name of the admission webhook. 780 // Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where 781 // "imagepolicy" is the name of the webhook, and kubernetes.io is the name 782 // of the organization. 783 // Required. 784 Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 785 786 // ClientConfig defines how to communicate with the hook. 787 // Required 788 ClientConfig WebhookClientConfig `json:"clientConfig" protobuf:"bytes,2,opt,name=clientConfig"` 789 790 // Rules describes what operations on what resources/subresources the webhook cares about. 791 // The webhook cares about an operation if it matches _any_ Rule. 792 // However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks 793 // from putting the cluster in a state which cannot be recovered from without completely 794 // disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called 795 // on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects. 796 // +listType=atomic 797 Rules []RuleWithOperations `json:"rules,omitempty" protobuf:"bytes,3,rep,name=rules"` 798 799 // FailurePolicy defines how unrecognized errors from the admission endpoint are handled - 800 // allowed values are Ignore or Fail. Defaults to Fail. 801 // +optional 802 FailurePolicy *FailurePolicyType `json:"failurePolicy,omitempty" protobuf:"bytes,4,opt,name=failurePolicy,casttype=FailurePolicyType"` 803 804 // matchPolicy defines how the "rules" list is used to match incoming requests. 805 // Allowed values are "Exact" or "Equivalent". 806 // 807 // - Exact: match a request only if it exactly matches a specified rule. 808 // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, 809 // but "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`, 810 // a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the webhook. 811 // 812 // - Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. 813 // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, 814 // and "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`, 815 // a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the webhook. 816 // 817 // Defaults to "Equivalent" 818 // +optional 819 MatchPolicy *MatchPolicyType `json:"matchPolicy,omitempty" protobuf:"bytes,9,opt,name=matchPolicy,casttype=MatchPolicyType"` 820 821 // NamespaceSelector decides whether to run the webhook on an object based 822 // on whether the namespace for that object matches the selector. If the 823 // object itself is a namespace, the matching is performed on 824 // object.metadata.labels. If the object is another cluster scoped resource, 825 // it never skips the webhook. 826 // 827 // For example, to run the webhook on any objects whose namespace is not 828 // associated with "runlevel" of "0" or "1"; you will set the selector as 829 // follows: 830 // "namespaceSelector": { 831 // "matchExpressions": [ 832 // { 833 // "key": "runlevel", 834 // "operator": "NotIn", 835 // "values": [ 836 // "0", 837 // "1" 838 // ] 839 // } 840 // ] 841 // } 842 // 843 // If instead you want to only run the webhook on any objects whose 844 // namespace is associated with the "environment" of "prod" or "staging"; 845 // you will set the selector as follows: 846 // "namespaceSelector": { 847 // "matchExpressions": [ 848 // { 849 // "key": "environment", 850 // "operator": "In", 851 // "values": [ 852 // "prod", 853 // "staging" 854 // ] 855 // } 856 // ] 857 // } 858 // 859 // See 860 // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels 861 // for more examples of label selectors. 862 // 863 // Default to the empty LabelSelector, which matches everything. 864 // +optional 865 NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty" protobuf:"bytes,5,opt,name=namespaceSelector"` 866 867 // ObjectSelector decides whether to run the webhook based on if the 868 // object has matching labels. objectSelector is evaluated against both 869 // the oldObject and newObject that would be sent to the webhook, and 870 // is considered to match if either object matches the selector. A null 871 // object (oldObject in the case of create, or newObject in the case of 872 // delete) or an object that cannot have labels (like a 873 // DeploymentRollback or a PodProxyOptions object) is not considered to 874 // match. 875 // Use the object selector only if the webhook is opt-in, because end 876 // users may skip the admission webhook by setting the labels. 877 // Default to the empty LabelSelector, which matches everything. 878 // +optional 879 ObjectSelector *metav1.LabelSelector `json:"objectSelector,omitempty" protobuf:"bytes,10,opt,name=objectSelector"` 880 881 // SideEffects states whether this webhook has side effects. 882 // Acceptable values are: None, NoneOnDryRun (webhooks created via v1beta1 may also specify Some or Unknown). 883 // Webhooks with side effects MUST implement a reconciliation system, since a request may be 884 // rejected by a future step in the admission chain and the side effects therefore need to be undone. 885 // Requests with the dryRun attribute will be auto-rejected if they match a webhook with 886 // sideEffects == Unknown or Some. 887 SideEffects *SideEffectClass `json:"sideEffects" protobuf:"bytes,6,opt,name=sideEffects,casttype=SideEffectClass"` 888 889 // TimeoutSeconds specifies the timeout for this webhook. After the timeout passes, 890 // the webhook call will be ignored or the API call will fail based on the 891 // failure policy. 892 // The timeout value must be between 1 and 30 seconds. 893 // Default to 10 seconds. 894 // +optional 895 TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty" protobuf:"varint,7,opt,name=timeoutSeconds"` 896 897 // AdmissionReviewVersions is an ordered list of preferred `AdmissionReview` 898 // versions the Webhook expects. API server will try to use first version in 899 // the list which it supports. If none of the versions specified in this list 900 // supported by API server, validation will fail for this object. 901 // If a persisted webhook configuration specifies allowed versions and does not 902 // include any versions known to the API Server, calls to the webhook will fail 903 // and be subject to the failure policy. 904 // +listType=atomic 905 AdmissionReviewVersions []string `json:"admissionReviewVersions" protobuf:"bytes,8,rep,name=admissionReviewVersions"` 906 907 // MatchConditions is a list of conditions that must be met for a request to be sent to this 908 // webhook. Match conditions filter requests that have already been matched by the rules, 909 // namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. 910 // There are a maximum of 64 match conditions allowed. 911 // 912 // The exact matching logic is (in order): 913 // 1. If ANY matchCondition evaluates to FALSE, the webhook is skipped. 914 // 2. If ALL matchConditions evaluate to TRUE, the webhook is called. 915 // 3. If any matchCondition evaluates to an error (but none are FALSE): 916 // - If failurePolicy=Fail, reject the request 917 // - If failurePolicy=Ignore, the error is ignored and the webhook is skipped 918 // 919 // +patchMergeKey=name 920 // +patchStrategy=merge 921 // +listType=map 922 // +listMapKey=name 923 // +optional 924 MatchConditions []MatchCondition `json:"matchConditions,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,11,opt,name=matchConditions"` 925 } 926 927 // MutatingWebhook describes an admission webhook and the resources and operations it applies to. 928 type MutatingWebhook struct { 929 // The name of the admission webhook. 930 // Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where 931 // "imagepolicy" is the name of the webhook, and kubernetes.io is the name 932 // of the organization. 933 // Required. 934 Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 935 936 // ClientConfig defines how to communicate with the hook. 937 // Required 938 ClientConfig WebhookClientConfig `json:"clientConfig" protobuf:"bytes,2,opt,name=clientConfig"` 939 940 // Rules describes what operations on what resources/subresources the webhook cares about. 941 // The webhook cares about an operation if it matches _any_ Rule. 942 // However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks 943 // from putting the cluster in a state which cannot be recovered from without completely 944 // disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called 945 // on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects. 946 // +listType=atomic 947 Rules []RuleWithOperations `json:"rules,omitempty" protobuf:"bytes,3,rep,name=rules"` 948 949 // FailurePolicy defines how unrecognized errors from the admission endpoint are handled - 950 // allowed values are Ignore or Fail. Defaults to Fail. 951 // +optional 952 FailurePolicy *FailurePolicyType `json:"failurePolicy,omitempty" protobuf:"bytes,4,opt,name=failurePolicy,casttype=FailurePolicyType"` 953 954 // matchPolicy defines how the "rules" list is used to match incoming requests. 955 // Allowed values are "Exact" or "Equivalent". 956 // 957 // - Exact: match a request only if it exactly matches a specified rule. 958 // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, 959 // but "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`, 960 // a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the webhook. 961 // 962 // - Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. 963 // For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, 964 // and "rules" only included `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]`, 965 // a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the webhook. 966 // 967 // Defaults to "Equivalent" 968 // +optional 969 MatchPolicy *MatchPolicyType `json:"matchPolicy,omitempty" protobuf:"bytes,9,opt,name=matchPolicy,casttype=MatchPolicyType"` 970 971 // NamespaceSelector decides whether to run the webhook on an object based 972 // on whether the namespace for that object matches the selector. If the 973 // object itself is a namespace, the matching is performed on 974 // object.metadata.labels. If the object is another cluster scoped resource, 975 // it never skips the webhook. 976 // 977 // For example, to run the webhook on any objects whose namespace is not 978 // associated with "runlevel" of "0" or "1"; you will set the selector as 979 // follows: 980 // "namespaceSelector": { 981 // "matchExpressions": [ 982 // { 983 // "key": "runlevel", 984 // "operator": "NotIn", 985 // "values": [ 986 // "0", 987 // "1" 988 // ] 989 // } 990 // ] 991 // } 992 // 993 // If instead you want to only run the webhook on any objects whose 994 // namespace is associated with the "environment" of "prod" or "staging"; 995 // you will set the selector as follows: 996 // "namespaceSelector": { 997 // "matchExpressions": [ 998 // { 999 // "key": "environment", 1000 // "operator": "In", 1001 // "values": [ 1002 // "prod", 1003 // "staging" 1004 // ] 1005 // } 1006 // ] 1007 // } 1008 // 1009 // See 1010 // https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ 1011 // for more examples of label selectors. 1012 // 1013 // Default to the empty LabelSelector, which matches everything. 1014 // +optional 1015 NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty" protobuf:"bytes,5,opt,name=namespaceSelector"` 1016 1017 // ObjectSelector decides whether to run the webhook based on if the 1018 // object has matching labels. objectSelector is evaluated against both 1019 // the oldObject and newObject that would be sent to the webhook, and 1020 // is considered to match if either object matches the selector. A null 1021 // object (oldObject in the case of create, or newObject in the case of 1022 // delete) or an object that cannot have labels (like a 1023 // DeploymentRollback or a PodProxyOptions object) is not considered to 1024 // match. 1025 // Use the object selector only if the webhook is opt-in, because end 1026 // users may skip the admission webhook by setting the labels. 1027 // Default to the empty LabelSelector, which matches everything. 1028 // +optional 1029 ObjectSelector *metav1.LabelSelector `json:"objectSelector,omitempty" protobuf:"bytes,11,opt,name=objectSelector"` 1030 1031 // SideEffects states whether this webhook has side effects. 1032 // Acceptable values are: None, NoneOnDryRun (webhooks created via v1beta1 may also specify Some or Unknown). 1033 // Webhooks with side effects MUST implement a reconciliation system, since a request may be 1034 // rejected by a future step in the admission chain and the side effects therefore need to be undone. 1035 // Requests with the dryRun attribute will be auto-rejected if they match a webhook with 1036 // sideEffects == Unknown or Some. 1037 SideEffects *SideEffectClass `json:"sideEffects" protobuf:"bytes,6,opt,name=sideEffects,casttype=SideEffectClass"` 1038 1039 // TimeoutSeconds specifies the timeout for this webhook. After the timeout passes, 1040 // the webhook call will be ignored or the API call will fail based on the 1041 // failure policy. 1042 // The timeout value must be between 1 and 30 seconds. 1043 // Default to 10 seconds. 1044 // +optional 1045 TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty" protobuf:"varint,7,opt,name=timeoutSeconds"` 1046 1047 // AdmissionReviewVersions is an ordered list of preferred `AdmissionReview` 1048 // versions the Webhook expects. API server will try to use first version in 1049 // the list which it supports. If none of the versions specified in this list 1050 // supported by API server, validation will fail for this object. 1051 // If a persisted webhook configuration specifies allowed versions and does not 1052 // include any versions known to the API Server, calls to the webhook will fail 1053 // and be subject to the failure policy. 1054 // +listType=atomic 1055 AdmissionReviewVersions []string `json:"admissionReviewVersions" protobuf:"bytes,8,rep,name=admissionReviewVersions"` 1056 1057 // reinvocationPolicy indicates whether this webhook should be called multiple times as part of a single admission evaluation. 1058 // Allowed values are "Never" and "IfNeeded". 1059 // 1060 // Never: the webhook will not be called more than once in a single admission evaluation. 1061 // 1062 // IfNeeded: the webhook will be called at least one additional time as part of the admission evaluation 1063 // if the object being admitted is modified by other admission plugins after the initial webhook call. 1064 // Webhooks that specify this option *must* be idempotent, able to process objects they previously admitted. 1065 // Note: 1066 // * the number of additional invocations is not guaranteed to be exactly one. 1067 // * if additional invocations result in further modifications to the object, webhooks are not guaranteed to be invoked again. 1068 // * webhooks that use this option may be reordered to minimize the number of additional invocations. 1069 // * to validate an object after all mutations are guaranteed complete, use a validating admission webhook instead. 1070 // 1071 // Defaults to "Never". 1072 // +optional 1073 ReinvocationPolicy *ReinvocationPolicyType `json:"reinvocationPolicy,omitempty" protobuf:"bytes,10,opt,name=reinvocationPolicy,casttype=ReinvocationPolicyType"` 1074 1075 // MatchConditions is a list of conditions that must be met for a request to be sent to this 1076 // webhook. Match conditions filter requests that have already been matched by the rules, 1077 // namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. 1078 // There are a maximum of 64 match conditions allowed. 1079 // 1080 // The exact matching logic is (in order): 1081 // 1. If ANY matchCondition evaluates to FALSE, the webhook is skipped. 1082 // 2. If ALL matchConditions evaluate to TRUE, the webhook is called. 1083 // 3. If any matchCondition evaluates to an error (but none are FALSE): 1084 // - If failurePolicy=Fail, reject the request 1085 // - If failurePolicy=Ignore, the error is ignored and the webhook is skipped 1086 // 1087 // +patchMergeKey=name 1088 // +patchStrategy=merge 1089 // +listType=map 1090 // +listMapKey=name 1091 // +optional 1092 MatchConditions []MatchCondition `json:"matchConditions,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,12,opt,name=matchConditions"` 1093 } 1094 1095 // ReinvocationPolicyType specifies what type of policy the admission hook uses. 1096 // +enum 1097 type ReinvocationPolicyType string 1098 1099 const ( 1100 // NeverReinvocationPolicy indicates that the webhook must not be called more than once in a 1101 // single admission evaluation. 1102 NeverReinvocationPolicy ReinvocationPolicyType = "Never" 1103 // IfNeededReinvocationPolicy indicates that the webhook may be called at least one 1104 // additional time as part of the admission evaluation if the object being admitted is 1105 // modified by other admission plugins after the initial webhook call. 1106 IfNeededReinvocationPolicy ReinvocationPolicyType = "IfNeeded" 1107 ) 1108 1109 // RuleWithOperations is a tuple of Operations and Resources. It is recommended to make 1110 // sure that all the tuple expansions are valid. 1111 type RuleWithOperations struct { 1112 // Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * 1113 // for all of those operations and any future admission operations that are added. 1114 // If '*' is present, the length of the slice must be one. 1115 // Required. 1116 // +listType=atomic 1117 Operations []OperationType `json:"operations,omitempty" protobuf:"bytes,1,rep,name=operations,casttype=OperationType"` 1118 // Rule is embedded, it describes other criteria of the rule, like 1119 // APIGroups, APIVersions, Resources, etc. 1120 Rule `json:",inline" protobuf:"bytes,2,opt,name=rule"` 1121 } 1122 1123 // OperationType specifies an operation for a request. 1124 // +enum 1125 type OperationType string 1126 1127 // The constants should be kept in sync with those defined in k8s.io/kubernetes/pkg/admission/interface.go. 1128 const ( 1129 OperationAll OperationType = "*" 1130 Create OperationType = "CREATE" 1131 Update OperationType = "UPDATE" 1132 Delete OperationType = "DELETE" 1133 Connect OperationType = "CONNECT" 1134 ) 1135 1136 // WebhookClientConfig contains the information to make a TLS 1137 // connection with the webhook 1138 type WebhookClientConfig struct { 1139 // `url` gives the location of the webhook, in standard URL form 1140 // (`scheme://host:port/path`). Exactly one of `url` or `service` 1141 // must be specified. 1142 // 1143 // The `host` should not refer to a service running in the cluster; use 1144 // the `service` field instead. The host might be resolved via external 1145 // DNS in some apiservers (e.g., `kube-apiserver` cannot resolve 1146 // in-cluster DNS as that would be a layering violation). `host` may 1147 // also be an IP address. 1148 // 1149 // Please note that using `localhost` or `127.0.0.1` as a `host` is 1150 // risky unless you take great care to run this webhook on all hosts 1151 // which run an apiserver which might need to make calls to this 1152 // webhook. Such installs are likely to be non-portable, i.e., not easy 1153 // to turn up in a new cluster. 1154 // 1155 // The scheme must be "https"; the URL must begin with "https://". 1156 // 1157 // A path is optional, and if present may be any string permissible in 1158 // a URL. You may use the path to pass an arbitrary string to the 1159 // webhook, for example, a cluster identifier. 1160 // 1161 // Attempting to use a user or basic auth e.g. "user:password@" is not 1162 // allowed. Fragments ("#...") and query parameters ("?...") are not 1163 // allowed, either. 1164 // 1165 // +optional 1166 URL *string `json:"url,omitempty" protobuf:"bytes,3,opt,name=url"` 1167 1168 // `service` is a reference to the service for this webhook. Either 1169 // `service` or `url` must be specified. 1170 // 1171 // If the webhook is running within the cluster, then you should use `service`. 1172 // 1173 // +optional 1174 Service *ServiceReference `json:"service,omitempty" protobuf:"bytes,1,opt,name=service"` 1175 1176 // `caBundle` is a PEM encoded CA bundle which will be used to validate the webhook's server certificate. 1177 // If unspecified, system trust roots on the apiserver are used. 1178 // +optional 1179 CABundle []byte `json:"caBundle,omitempty" protobuf:"bytes,2,opt,name=caBundle"` 1180 } 1181 1182 // ServiceReference holds a reference to Service.legacy.k8s.io 1183 type ServiceReference struct { 1184 // `namespace` is the namespace of the service. 1185 // Required 1186 Namespace string `json:"namespace" protobuf:"bytes,1,opt,name=namespace"` 1187 // `name` is the name of the service. 1188 // Required 1189 Name string `json:"name" protobuf:"bytes,2,opt,name=name"` 1190 1191 // `path` is an optional URL path which will be sent in any request to 1192 // this service. 1193 // +optional 1194 Path *string `json:"path,omitempty" protobuf:"bytes,3,opt,name=path"` 1195 1196 // If specified, the port on the service that hosting webhook. 1197 // Default to 443 for backward compatibility. 1198 // `port` should be a valid port number (1-65535, inclusive). 1199 // +optional 1200 Port *int32 `json:"port,omitempty" protobuf:"varint,4,opt,name=port"` 1201 } 1202 1203 // MatchCondition represents a condition which must by fulfilled for a request to be sent to a webhook. 1204 type MatchCondition struct { 1205 // Name is an identifier for this match condition, used for strategic merging of MatchConditions, 1206 // as well as providing an identifier for logging purposes. A good name should be descriptive of 1207 // the associated expression. 1208 // Name must be a qualified name consisting of alphanumeric characters, '-', '_' or '.', and 1209 // must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or 1210 // '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]') with an 1211 // optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName') 1212 // 1213 // Required. 1214 Name string `json:"name" protobuf:"bytes,1,opt,name=name"` 1215 1216 // Expression represents the expression which will be evaluated by CEL. Must evaluate to bool. 1217 // CEL expressions have access to the contents of the AdmissionRequest and Authorizer, organized into CEL variables: 1218 // 1219 // 'object' - The object from the incoming request. The value is null for DELETE requests. 1220 // 'oldObject' - The existing object. The value is null for CREATE requests. 1221 // 'request' - Attributes of the admission request(/pkg/apis/admission/types.go#AdmissionRequest). 1222 // 'authorizer' - A CEL Authorizer. May be used to perform authorization checks for the principal (user or service account) of the request. 1223 // See https://pkg.go.dev/k8s.io/apiserver/pkg/cel/library#Authz 1224 // 'authorizer.requestResource' - A CEL ResourceCheck constructed from the 'authorizer' and configured with the 1225 // request resource. 1226 // Documentation on CEL: https://kubernetes.io/docs/reference/using-api/cel/ 1227 // 1228 // Required. 1229 Expression string `json:"expression" protobuf:"bytes,2,opt,name=expression"` 1230 } 1231