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 authenticationv1 "k8s.io/api/authentication/v1" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 "k8s.io/apimachinery/pkg/runtime" 23 "k8s.io/apimachinery/pkg/types" 24 ) 25 26 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 27 28 // AdmissionReview describes an admission review request/response. 29 type AdmissionReview struct { 30 metav1.TypeMeta `json:",inline"` 31 // Request describes the attributes for the admission request. 32 // +optional 33 Request *AdmissionRequest `json:"request,omitempty" protobuf:"bytes,1,opt,name=request"` 34 // Response describes the attributes for the admission response. 35 // +optional 36 Response *AdmissionResponse `json:"response,omitempty" protobuf:"bytes,2,opt,name=response"` 37 } 38 39 // AdmissionRequest describes the admission.Attributes for the admission request. 40 type AdmissionRequest struct { 41 // UID is an identifier for the individual request/response. It allows us to distinguish instances of requests which are 42 // otherwise identical (parallel requests, requests when earlier requests did not modify etc) 43 // The UID is meant to track the round trip (request/response) between the KAS and the WebHook, not the user request. 44 // It is suitable for correlating log entries between the webhook and apiserver, for either auditing or debugging. 45 UID types.UID `json:"uid" protobuf:"bytes,1,opt,name=uid"` 46 // Kind is the fully-qualified type of object being submitted (for example, v1.Pod or autoscaling.v1.Scale) 47 Kind metav1.GroupVersionKind `json:"kind" protobuf:"bytes,2,opt,name=kind"` 48 // Resource is the fully-qualified resource being requested (for example, v1.pods) 49 Resource metav1.GroupVersionResource `json:"resource" protobuf:"bytes,3,opt,name=resource"` 50 // SubResource is the subresource being requested, if any (for example, "status" or "scale") 51 // +optional 52 SubResource string `json:"subResource,omitempty" protobuf:"bytes,4,opt,name=subResource"` 53 54 // RequestKind is the fully-qualified type of the original API request (for example, v1.Pod or autoscaling.v1.Scale). 55 // If this is specified and differs from the value in "kind", an equivalent match and conversion was performed. 56 // 57 // For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of 58 // `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, 59 // an API request to apps/v1beta1 deployments would be converted and sent to the webhook 60 // with `kind: {group:"apps", version:"v1", kind:"Deployment"}` (matching the rule the webhook registered for), 61 // and `requestKind: {group:"apps", version:"v1beta1", kind:"Deployment"}` (indicating the kind of the original API request). 62 // 63 // See documentation for the "matchPolicy" field in the webhook configuration type for more details. 64 // +optional 65 RequestKind *metav1.GroupVersionKind `json:"requestKind,omitempty" protobuf:"bytes,13,opt,name=requestKind"` 66 // RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). 67 // If this is specified and differs from the value in "resource", an equivalent match and conversion was performed. 68 // 69 // For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of 70 // `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, 71 // an API request to apps/v1beta1 deployments would be converted and sent to the webhook 72 // with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for), 73 // and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original API request). 74 // 75 // See documentation for the "matchPolicy" field in the webhook configuration type. 76 // +optional 77 RequestResource *metav1.GroupVersionResource `json:"requestResource,omitempty" protobuf:"bytes,14,opt,name=requestResource"` 78 // RequestSubResource is the name of the subresource of the original API request, if any (for example, "status" or "scale") 79 // If this is specified and differs from the value in "subResource", an equivalent match and conversion was performed. 80 // See documentation for the "matchPolicy" field in the webhook configuration type. 81 // +optional 82 RequestSubResource string `json:"requestSubResource,omitempty" protobuf:"bytes,15,opt,name=requestSubResource"` 83 84 // Name is the name of the object as presented in the request. On a CREATE operation, the client may omit name and 85 // rely on the server to generate the name. If that is the case, this field will contain an empty string. 86 // +optional 87 Name string `json:"name,omitempty" protobuf:"bytes,5,opt,name=name"` 88 // Namespace is the namespace associated with the request (if any). 89 // +optional 90 Namespace string `json:"namespace,omitempty" protobuf:"bytes,6,opt,name=namespace"` 91 // Operation is the operation being performed. This may be different than the operation 92 // requested. e.g. a patch can result in either a CREATE or UPDATE Operation. 93 Operation Operation `json:"operation" protobuf:"bytes,7,opt,name=operation"` 94 // UserInfo is information about the requesting user 95 UserInfo authenticationv1.UserInfo `json:"userInfo" protobuf:"bytes,8,opt,name=userInfo"` 96 // Object is the object from the incoming request. 97 // +optional 98 Object runtime.RawExtension `json:"object,omitempty" protobuf:"bytes,9,opt,name=object"` 99 // OldObject is the existing object. Only populated for DELETE and UPDATE requests. 100 // +optional 101 OldObject runtime.RawExtension `json:"oldObject,omitempty" protobuf:"bytes,10,opt,name=oldObject"` 102 // DryRun indicates that modifications will definitely not be persisted for this request. 103 // Defaults to false. 104 // +optional 105 DryRun *bool `json:"dryRun,omitempty" protobuf:"varint,11,opt,name=dryRun"` 106 // Options is the operation option structure of the operation being performed. 107 // e.g. `meta.k8s.io/v1.DeleteOptions` or `meta.k8s.io/v1.CreateOptions`. This may be 108 // different than the options the caller provided. e.g. for a patch request the performed 109 // Operation might be a CREATE, in which case the Options will a 110 // `meta.k8s.io/v1.CreateOptions` even though the caller provided `meta.k8s.io/v1.PatchOptions`. 111 // +optional 112 Options runtime.RawExtension `json:"options,omitempty" protobuf:"bytes,12,opt,name=options"` 113 } 114 115 // AdmissionResponse describes an admission response. 116 type AdmissionResponse struct { 117 // UID is an identifier for the individual request/response. 118 // This must be copied over from the corresponding AdmissionRequest. 119 UID types.UID `json:"uid" protobuf:"bytes,1,opt,name=uid"` 120 121 // Allowed indicates whether or not the admission request was permitted. 122 Allowed bool `json:"allowed" protobuf:"varint,2,opt,name=allowed"` 123 124 // Result contains extra details into why an admission request was denied. 125 // This field IS NOT consulted in any way if "Allowed" is "true". 126 // +optional 127 Result *metav1.Status `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` 128 129 // The patch body. Currently we only support "JSONPatch" which implements RFC 6902. 130 // +optional 131 Patch []byte `json:"patch,omitempty" protobuf:"bytes,4,opt,name=patch"` 132 133 // The type of Patch. Currently we only allow "JSONPatch". 134 // +optional 135 PatchType *PatchType `json:"patchType,omitempty" protobuf:"bytes,5,opt,name=patchType"` 136 137 // AuditAnnotations is an unstructured key value map set by remote admission controller (e.g. error=image-blacklisted). 138 // MutatingAdmissionWebhook and ValidatingAdmissionWebhook admission controller will prefix the keys with 139 // admission webhook name (e.g. imagepolicy.example.com/error=image-blacklisted). AuditAnnotations will be provided by 140 // the admission webhook to add additional context to the audit log for this request. 141 // +optional 142 AuditAnnotations map[string]string `json:"auditAnnotations,omitempty" protobuf:"bytes,6,opt,name=auditAnnotations"` 143 144 // warnings is a list of warning messages to return to the requesting API client. 145 // Warning messages describe a problem the client making the API request should correct or be aware of. 146 // Limit warnings to 120 characters if possible. 147 // Warnings over 256 characters and large numbers of warnings may be truncated. 148 // +optional 149 Warnings []string `json:"warnings,omitempty" protobuf:"bytes,7,rep,name=warnings"` 150 } 151 152 // PatchType is the type of patch being used to represent the mutated object 153 type PatchType string 154 155 // PatchType constants. 156 const ( 157 PatchTypeJSONPatch PatchType = "JSONPatch" 158 ) 159 160 // Operation is the type of resource operation being checked for admission control 161 type Operation string 162 163 // Operation constants 164 const ( 165 Create Operation = "CREATE" 166 Update Operation = "UPDATE" 167 Delete Operation = "DELETE" 168 Connect Operation = "CONNECT" 169 ) 170