github.com/Azure/aad-pod-identity@v1.8.17/pkg/apis/aadpodidentity/types.go (about) 1 package aadpodidentity 2 3 import ( 4 api "k8s.io/api/core/v1" 5 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 6 ) 7 8 // EventType is a type that represents critical events that are sent to MIC. 9 type EventType int 10 11 const ( 12 // PodCreated is an event that is sent to the event channel when a pod is created. 13 PodCreated EventType = 0 14 15 // PodDeleted is an event that is sent to the event channel when a pod is deleted. 16 PodDeleted EventType = 1 17 18 // PodUpdated is an event that is sent to the event channel when a pod is updated. 19 PodUpdated EventType = 2 20 21 // IdentityCreated is an event that is sent to the event channel when an AzureIdentity is created. 22 IdentityCreated EventType = 3 23 24 // IdentityDeleted is an event that is sent to the event channel when an AzureIdentity is deleted. 25 IdentityDeleted EventType = 4 26 27 // IdentityUpdated is an event that is sent to the event channel when an AzureIdentity is updated. 28 IdentityUpdated EventType = 5 29 30 // BindingCreated is an event that is sent to the event channel when an AzureIdentityBinding is created. 31 BindingCreated EventType = 6 32 33 // BindingDeleted is an event that is sent to the event channel when an AzureIdentityBinding is deleted. 34 BindingDeleted EventType = 7 35 36 // BindingUpdated is an event that is sent to the event channel when an AzureIdentityBinding is updated. 37 BindingUpdated EventType = 8 38 39 // Exit is an event that is sent to the event channel when the program exits. 40 Exit EventType = 9 41 ) 42 43 const ( 44 // CRDGroup is the group name of aad-pod-identity CRDs. 45 CRDGroup = "aadpodidentity.k8s.io" 46 47 // CRDVersion is the version of the CRD group. 48 CRDVersion = "v1" 49 50 // CRDLabelKey is the static label that is used in pods. 51 CRDLabelKey = "aadpodidbinding" 52 53 // BehaviorKey is the key that describes the behavior of aad-pod-identity. 54 // Supported values: 55 // namespaced - used for running in namespaced mode. AzureIdentity, 56 // AzureIdentityBinding and pod in the same namespace 57 // will only be matched for this behavior. 58 BehaviorKey = "aadpodidentity.k8s.io/Behavior" 59 60 // BehaviorNamespaced indicates that aad-pod-identity is behaving in namespaced mode. 61 BehaviorNamespaced = "namespaced" 62 63 // AssignedIDCreated indicates that an AzureAssignedIdentity is created. 64 AssignedIDCreated = "Created" 65 66 // AssignedIDAssigned indicates that an identity has been assigned to the node. 67 AssignedIDAssigned = "Assigned" 68 69 // AssignedIDUnAssigned indicates that an identity has been unassigned from the node. 70 AssignedIDUnAssigned = "Unassigned" 71 ) 72 73 // AzureIdentity is the specification of the identity data structure. 74 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 75 type AzureIdentity struct { 76 metav1.TypeMeta `json:",inline"` 77 metav1.ObjectMeta `json:"metadata,omitempty"` 78 79 Spec AzureIdentitySpec `json:"spec"` 80 Status AzureIdentityStatus `json:"status"` 81 } 82 83 // AzureIdentityBinding brings together the spec of matching pods and the identity which they can use. 84 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 85 type AzureIdentityBinding struct { 86 metav1.TypeMeta `json:",inline"` 87 metav1.ObjectMeta `json:"metadata,omitempty"` 88 89 Spec AzureIdentityBindingSpec `json:"spec"` 90 Status AzureIdentityBindingStatus `json:"status"` 91 } 92 93 // AzureAssignedIdentity contains the identity <-> pod mapping which is matched. 94 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 95 type AzureAssignedIdentity struct { 96 metav1.TypeMeta `json:",inline"` 97 metav1.ObjectMeta `json:"metadata,omitempty"` 98 99 Spec AzureAssignedIdentitySpec `json:"spec"` 100 Status AzureAssignedIdentityStatus `json:"Status"` 101 } 102 103 // AzurePodIdentityException contains the pod selectors for all pods that don't require 104 // NMI to process and request token on their behalf. 105 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 106 type AzurePodIdentityException struct { 107 metav1.TypeMeta `json:",inline"` 108 metav1.ObjectMeta `json:"metadata,omitempty"` 109 110 Spec AzurePodIdentityExceptionSpec `json:"spec"` 111 Status AzurePodIdentityExceptionStatus `json:"Status"` 112 } 113 114 // AzureIdentityList contains a list of AzureIdentities. 115 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 116 type AzureIdentityList struct { 117 metav1.TypeMeta `json:",inline"` 118 metav1.ListMeta `json:"metadata"` 119 120 Items []AzureIdentity `json:"items"` 121 } 122 123 // AzureIdentityBindingList contains a list of AzureIdentityBindings. 124 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 125 type AzureIdentityBindingList struct { 126 metav1.TypeMeta `json:",inline"` 127 metav1.ListMeta `json:"metadata"` 128 129 Items []AzureIdentityBinding `json:"items"` 130 } 131 132 // AzureAssignedIdentityList contains a list of AzureAssignedIdentities. 133 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 134 type AzureAssignedIdentityList struct { 135 metav1.TypeMeta `json:",inline"` 136 metav1.ListMeta `json:"metadata"` 137 138 Items []AzureAssignedIdentity `json:"items"` 139 } 140 141 // AzurePodIdentityExceptionList contains a list of AzurePodIdentityExceptions. 142 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 143 type AzurePodIdentityExceptionList struct { 144 metav1.TypeMeta `json:",inline"` 145 metav1.ListMeta `json:"metadata"` 146 147 Items []AzurePodIdentityException `json:"items"` 148 } 149 150 // IdentityType represents different types of identities. 151 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 152 type IdentityType int 153 154 const ( 155 // UserAssignedMSI represents a user-assigned identity. 156 UserAssignedMSI IdentityType = 0 157 158 // ServicePrincipal represents a service principal. 159 ServicePrincipal IdentityType = 1 160 161 // ServicePrincipalCertificate represents a service principal certificate. 162 ServicePrincipalCertificate IdentityType = 2 163 ) 164 165 // AzureIdentitySpec describes the credential specifications of an identity on Azure. 166 type AzureIdentitySpec struct { 167 metav1.ObjectMeta `json:"metadata,omitempty"` 168 // UserAssignedMSI or Service Principal 169 Type IdentityType `json:"type"` 170 171 // User assigned MSI resource id. 172 ResourceID string `json:"resourceid"` 173 // Both User Assigned MSI and SP can use this field. 174 ClientID string `json:"clientid"` 175 176 // Used for service principal 177 ClientPassword api.SecretReference `json:"clientpassword"` 178 // Service principal primary tenant id. 179 TenantID string `json:"tenantid"` 180 // Service principal auxiliary tenant ids 181 AuxiliaryTenantIDs []string `json:"auxiliarytenantids"` 182 // For service principal. Option param for specifying the AD details. 183 ADResourceID string `json:"adresourceid"` 184 ADEndpoint string `json:"adendpoint"` 185 186 Replicas *int32 `json:"replicas"` 187 } 188 189 // AzureIdentityStatus contains the replica status of the resource. 190 type AzureIdentityStatus struct { 191 metav1.ObjectMeta `json:"metadata,omitempty"` 192 AvailableReplicas int32 `json:"availableReplicas"` 193 } 194 195 // AssignedIDState represents the state of an AzureAssignedIdentity 196 type AssignedIDState int 197 198 const ( 199 // Created - Default state of the assigned identity 200 Created AssignedIDState = 0 201 202 // Assigned - When the underlying platform assignment of 203 // managed identity is complete, the state moves to assigned 204 Assigned AssignedIDState = 1 205 ) 206 207 const ( 208 // AzureIDResource is the name of AzureIdentity. 209 AzureIDResource = "azureidentities" 210 211 // AzureIDBindingResource is the name of AzureIdentityBinding. 212 AzureIDBindingResource = "azureidentitybindings" 213 214 // AzureAssignedIDResource is the name of AzureAssignedIdentity. 215 AzureAssignedIDResource = "azureassignedidentities" 216 217 // AzurePodIdentityExceptionResource is the name of AzureIdentityException. 218 AzurePodIdentityExceptionResource = "azurepodidentityexceptions" 219 ) 220 221 // AzureIdentityBindingSpec matches the pod with the Identity. 222 // Used to indicate the potential matches to look for between the pod/deployment 223 // and the identities present. 224 type AzureIdentityBindingSpec struct { 225 metav1.ObjectMeta `json:"metadata,omitempty"` 226 AzureIdentity string `json:"azureidentity"` 227 Selector string `json:"selector"` 228 // Weight is used to figure out which of the matching identities would be selected. 229 Weight int `json:"weight"` 230 } 231 232 // AzureIdentityBindingStatus contains the status of an AzureIdentityBinding. 233 type AzureIdentityBindingStatus struct { 234 metav1.ObjectMeta `json:"metadata,omitempty"` 235 AvailableReplicas int32 `json:"availableReplicas"` 236 } 237 238 // AzureAssignedIdentitySpec contains the relationship 239 // between an AzureIdentity and an AzureIdentityBinding. 240 type AzureAssignedIdentitySpec struct { 241 metav1.ObjectMeta `json:"metadata,omitempty"` 242 AzureIdentityRef *AzureIdentity `json:"azureidentityref"` 243 AzureBindingRef *AzureIdentityBinding `json:"azurebindingref"` 244 Pod string `json:"pod"` 245 PodNamespace string `json:"podnamespace"` 246 NodeName string `json:"nodename"` 247 248 Replicas *int32 `json:"replicas"` 249 } 250 251 // AzureAssignedIdentityStatus contains the replica status of the resource. 252 type AzureAssignedIdentityStatus struct { 253 metav1.ObjectMeta `json:"metadata,omitempty"` 254 Status string `json:"status"` 255 AvailableReplicas int32 `json:"availableReplicas"` 256 } 257 258 // AzurePodIdentityExceptionSpec matches pods with the selector defined. 259 // If request originates from a pod that matches the selector, nmi will 260 // proxy the request and send response back without any validation. 261 type AzurePodIdentityExceptionSpec struct { 262 metav1.ObjectMeta `json:"metadata,omitempty"` 263 PodLabels map[string]string `json:"podLabels"` 264 } 265 266 // AzurePodIdentityExceptionStatus contains the status of an AzurePodIdentityException. 267 type AzurePodIdentityExceptionStatus struct { 268 metav1.ObjectMeta `json:"metadata,omitempty"` 269 Status string `json:"status"` 270 }