1 /* 2 Copyright 2021 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 v1beta1 18 19 import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 21 // +genclient 22 // +kubebuilder:object:root=true 23 // +kubebuilder:resource:categories=gateway-api,shortName=refgrant 24 // +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` 25 // +kubebuilder:storageversion 26 27 // ReferenceGrant identifies kinds of resources in other namespaces that are 28 // trusted to reference the specified kinds of resources in the same namespace 29 // as the policy. 30 // 31 // Each ReferenceGrant can be used to represent a unique trust relationship. 32 // Additional Reference Grants can be used to add to the set of trusted 33 // sources of inbound references for the namespace they are defined within. 34 // 35 // All cross-namespace references in Gateway API (with the exception of cross-namespace 36 // Gateway-route attachment) require a ReferenceGrant. 37 // 38 // ReferenceGrant is a form of runtime verification allowing users to assert 39 // which cross-namespace object references are permitted. Implementations that 40 // support ReferenceGrant MUST NOT permit cross-namespace references which have 41 // no grant, and MUST respond to the removal of a grant by revoking the access 42 // that the grant allowed. 43 type ReferenceGrant struct { 44 metav1.TypeMeta `json:",inline"` 45 metav1.ObjectMeta `json:"metadata,omitempty"` 46 47 // Spec defines the desired state of ReferenceGrant. 48 Spec ReferenceGrantSpec `json:"spec,omitempty"` 49 50 // Note that `Status` sub-resource has been excluded at the 51 // moment as it was difficult to work out the design. 52 // `Status` sub-resource may be added in future. 53 } 54 55 // +kubebuilder:object:root=true 56 // ReferenceGrantList contains a list of ReferenceGrant. 57 type ReferenceGrantList struct { 58 metav1.TypeMeta `json:",inline"` 59 metav1.ListMeta `json:"metadata,omitempty"` 60 Items []ReferenceGrant `json:"items"` 61 } 62 63 // ReferenceGrantSpec identifies a cross namespace relationship that is trusted 64 // for Gateway API. 65 type ReferenceGrantSpec struct { 66 // From describes the trusted namespaces and kinds that can reference the 67 // resources described in "To". Each entry in this list MUST be considered 68 // to be an additional place that references can be valid from, or to put 69 // this another way, entries MUST be combined using OR. 70 // 71 // Support: Core 72 // 73 // +kubebuilder:validation:MinItems=1 74 // +kubebuilder:validation:MaxItems=16 75 From []ReferenceGrantFrom `json:"from"` 76 77 // To describes the resources that may be referenced by the resources 78 // described in "From". Each entry in this list MUST be considered to be an 79 // additional place that references can be valid to, or to put this another 80 // way, entries MUST be combined using OR. 81 // 82 // Support: Core 83 // 84 // +kubebuilder:validation:MinItems=1 85 // +kubebuilder:validation:MaxItems=16 86 To []ReferenceGrantTo `json:"to"` 87 } 88 89 // ReferenceGrantFrom describes trusted namespaces and kinds. 90 type ReferenceGrantFrom struct { 91 // Group is the group of the referent. 92 // When empty, the Kubernetes core API group is inferred. 93 // 94 // Support: Core 95 Group Group `json:"group"` 96 97 // Kind is the kind of the referent. Although implementations may support 98 // additional resources, the following types are part of the "Core" 99 // support level for this field. 100 // 101 // When used to permit a SecretObjectReference: 102 // 103 // * Gateway 104 // 105 // When used to permit a BackendObjectReference: 106 // 107 // * GRPCRoute 108 // * HTTPRoute 109 // * TCPRoute 110 // * TLSRoute 111 // * UDPRoute 112 Kind Kind `json:"kind"` 113 114 // Namespace is the namespace of the referent. 115 // 116 // Support: Core 117 Namespace Namespace `json:"namespace"` 118 } 119 120 // ReferenceGrantTo describes what Kinds are allowed as targets of the 121 // references. 122 type ReferenceGrantTo struct { 123 // Group is the group of the referent. 124 // When empty, the Kubernetes core API group is inferred. 125 // 126 // Support: Core 127 Group Group `json:"group"` 128 129 // Kind is the kind of the referent. Although implementations may support 130 // additional resources, the following types are part of the "Core" 131 // support level for this field: 132 // 133 // * Secret when used to permit a SecretObjectReference 134 // * Service when used to permit a BackendObjectReference 135 Kind Kind `json:"kind"` 136 137 // Name is the name of the referent. When unspecified, this policy 138 // refers to all resources of the specified Group and Kind in the local 139 // namespace. 140 // 141 // +optional 142 Name *ObjectName `json:"name,omitempty"` 143 } 144