2 Copyright 2017 The Kubernetes Authors.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
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"
26 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
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.
33 Request *AdmissionRequest `json:"request,omitempty" protobuf:"bytes,1,opt,name=request"`
34 // Response describes the attributes for the admission response.
36 Response *AdmissionResponse `json:"response,omitempty" protobuf:"bytes,2,opt,name=response"`
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 type of object being manipulated. For example: Pod
47 Kind metav1.GroupVersionKind `json:"kind" protobuf:"bytes,2,opt,name=kind"`
48 // Resource is the name of the resource being requested. This is not the kind. For example: pods
49 Resource metav1.GroupVersionResource `json:"resource" protobuf:"bytes,3,opt,name=resource"`
50 // SubResource is the name of the subresource being requested. This is a different resource, scoped to the parent
51 // resource, but it may have a different kind. For instance, /pods has the resource "pods" and the kind "Pod", while
52 // /pods/foo/status has the resource "pods", the sub resource "status", and the kind "Pod" (because status operates on
53 // pods). The binding resource for a pod though may be /pods/foo/binding, which has resource "pods", subresource
54 // "binding", and kind "Binding".
56 SubResource string `json:"subResource,omitempty" protobuf:"bytes,4,opt,name=subResource"`
57 // Name is the name of the object as presented in the request. On a CREATE operation, the client may omit name and
58 // rely on the server to generate the name. If that is the case, this method will return the empty string.
60 Name string `json:"name,omitempty" protobuf:"bytes,5,opt,name=name"`
61 // Namespace is the namespace associated with the request (if any).
63 Namespace string `json:"namespace,omitempty" protobuf:"bytes,6,opt,name=namespace"`
64 // Operation is the operation being performed
65 Operation Operation `json:"operation" protobuf:"bytes,7,opt,name=operation"`
66 // UserInfo is information about the requesting user
67 UserInfo authenticationv1.UserInfo `json:"userInfo" protobuf:"bytes,8,opt,name=userInfo"`
68 // Object is the object from the incoming request prior to default values being applied
70 Object runtime.RawExtension `json:"object,omitempty" protobuf:"bytes,9,opt,name=object"`
71 // OldObject is the existing object. Only populated for UPDATE requests.
73 OldObject runtime.RawExtension `json:"oldObject,omitempty" protobuf:"bytes,10,opt,name=oldObject"`
74 // DryRun indicates that modifications will definitely not be persisted for this request.
77 DryRun *bool `json:"dryRun,omitempty" protobuf:"varint,11,opt,name=dryRun"`
80 // AdmissionResponse describes an admission response.
81 type AdmissionResponse struct {
82 // UID is an identifier for the individual request/response.
83 // This should be copied over from the corresponding AdmissionRequest.
84 UID types.UID `json:"uid" protobuf:"bytes,1,opt,name=uid"`
86 // Allowed indicates whether or not the admission request was permitted.
87 Allowed bool `json:"allowed" protobuf:"varint,2,opt,name=allowed"`
89 // Result contains extra details into why an admission request was denied.
90 // This field IS NOT consulted in any way if "Allowed" is "true".
92 Result *metav1.Status `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
94 // The patch body. Currently we only support "JSONPatch" which implements RFC 6902.
96 Patch []byte `json:"patch,omitempty" protobuf:"bytes,4,opt,name=patch"`
98 // The type of Patch. Currently we only allow "JSONPatch".
100 PatchType *PatchType `json:"patchType,omitempty" protobuf:"bytes,5,opt,name=patchType"`
102 // AuditAnnotations is an unstructured key value map set by remote admission controller (e.g. error=image-blacklisted).
103 // MutatingAdmissionWebhook and ValidatingAdmissionWebhook admission controller will prefix the keys with
104 // admission webhook name (e.g. imagepolicy.example.com/error=image-blacklisted). AuditAnnotations will be provided by
105 // the admission webhook to add additional context to the audit log for this request.
107 AuditAnnotations map[string]string `json:"auditAnnotations,omitempty" protobuf:"bytes,6,opt,name=auditAnnotations"`
110 // PatchType is the type of patch being used to represent the mutated object
111 type PatchType string
113 // PatchType constants.
115 PatchTypeJSONPatch PatchType = "JSONPatch"
118 // Operation is the type of resource operation being checked for admission control
119 type Operation string
121 // Operation constants
123 Create Operation = "CREATE"
124 Update Operation = "UPDATE"
125 Delete Operation = "DELETE"
126 Connect Operation = "CONNECT"