|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import ( |
| 4 | + corev1 "k8s.io/api/core/v1" |
| 5 | + rbacv1 "k8s.io/api/rbac/v1" |
| 6 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 7 | + apimachinery "k8s.io/apimachinery/pkg/types" |
| 8 | +) |
| 9 | + |
| 10 | +type RequestPhase string |
| 11 | + |
| 12 | +const ( |
| 13 | + // AccessRequestPending is the phase if the AccessRequest has not been scheduled yet. |
| 14 | + AccessRequestPending RequestPhase = "Pending" |
| 15 | + // AccessRequestGranted is the phase if the AccessRequest has been granted. |
| 16 | + AccessRequestGranted RequestPhase = "Granted" |
| 17 | +) |
| 18 | + |
| 19 | +// +kubebuilder:validation:XValidation:rule="!has(oldSelf.clusterRef) || has(self.clusterRef)", message="clusterRef may not be removed once set" |
| 20 | +// +kubebuilder:validation:XValidation:rule="!has(oldSelf.requestRef) || has(self.requestRef)", message="requestRef may not be removed once set" |
| 21 | +type AccessRequestSpec struct { |
| 22 | + // ClusterRef is the reference to the Cluster for which access is requested. |
| 23 | + // If set, requestRef will be ignored. |
| 24 | + // This value is immutable. |
| 25 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="clusterRef is immutable" |
| 26 | + // +optional |
| 27 | + ClusterRef *ObjectReference `json:"clusterRef,omitempty"` |
| 28 | + |
| 29 | + // RequestRef is the reference to the ClusterRequest for whose Cluster access is requested. |
| 30 | + // Is ignored if clusterRef is set. |
| 31 | + // This value is immutable. |
| 32 | + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="requestRef is immutable" |
| 33 | + // +optional |
| 34 | + RequestRef *ObjectReference `json:"requestRef,omitempty"` |
| 35 | + |
| 36 | + // Permissions are the requested permissions. |
| 37 | + Permissions []PermissionsRequest `json:"permissions"` |
| 38 | +} |
| 39 | + |
| 40 | +type PermissionsRequest struct { |
| 41 | + // Namespace is the namespace for which the permissions are requested. |
| 42 | + // If empty, this will result in a ClusterRole, otherwise in a Role in the respective namespace. |
| 43 | + // Note that for a Role, the namespace needs to either exist or a permission to create it must be included in the requested permissions (it will be created automatically then), otherwise the request will be rejected. |
| 44 | + // +optional |
| 45 | + Namespace string `json:"namespace,omitempty"` |
| 46 | + |
| 47 | + // Rules are the requested RBAC rules. |
| 48 | + Rules []rbacv1.PolicyRule `json:"rules"` |
| 49 | +} |
| 50 | + |
| 51 | +// AccessRequestStatus defines the observed state of AccessRequest |
| 52 | +type AccessRequestStatus struct { |
| 53 | + // Conditions contains the conditions. |
| 54 | + // +optional |
| 55 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 56 | + |
| 57 | + // Phase is the current phase of the request. |
| 58 | + // +kubebuilder:default=Pending |
| 59 | + // +kubebuilder:validation:Enum=Pending;Granted;Denied |
| 60 | + Phase RequestPhase `json:"phase"` |
| 61 | + |
| 62 | + // SecretRef holds the reference to the secret that contains the actual credentials. |
| 63 | + SecretRef *SecretReference `json:"secretRef,omitempty"` |
| 64 | +} |
| 65 | + |
| 66 | +// +kubebuilder:object:root=true |
| 67 | +// +kubebuilder:subresource:status |
| 68 | +// +kubebuilder:resource:shortName=ar;areq |
| 69 | +// +kubebuilder:metadata:labels="openmcp.cloud/cluster=platform" |
| 70 | +// +kubebuilder:selectablefield:JSONPath=".status.phase" |
| 71 | +// +kubebuilder:printcolumn:JSONPath=".status.phase",name="Phase",type=string |
| 72 | + |
| 73 | +// AccessRequest is the Schema for the accessrequests API |
| 74 | +type AccessRequest struct { |
| 75 | + metav1.TypeMeta `json:",inline"` |
| 76 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 77 | + |
| 78 | + Spec AccessRequestSpec `json:"spec,omitempty"` |
| 79 | + Status AccessRequestStatus `json:"status,omitempty"` |
| 80 | +} |
| 81 | + |
| 82 | +// +kubebuilder:object:root=true |
| 83 | + |
| 84 | +// AccessRequestList contains a list of AccessRequest |
| 85 | +type AccessRequestList struct { |
| 86 | + metav1.TypeMeta `json:",inline"` |
| 87 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 88 | + Items []AccessRequest `json:"items"` |
| 89 | +} |
| 90 | + |
| 91 | +func init() { |
| 92 | + SchemeBuilder.Register(&AccessRequest{}, &AccessRequestList{}) |
| 93 | +} |
| 94 | + |
| 95 | +// ObjectReference is a reference to an object in any namespace. |
| 96 | +type ObjectReference apimachinery.NamespacedName |
| 97 | + |
| 98 | +// LocalObjectReference is a reference to an object in the same namespace as the resource referencing it. |
| 99 | +type LocalObjectReference corev1.LocalObjectReference |
| 100 | + |
| 101 | +// SecretReference is a reference to a secret in any namespace with a key. |
| 102 | +type SecretReference struct { |
| 103 | + ObjectReference `json:",inline"` |
| 104 | + // Key is the key in the secret to use. |
| 105 | + Key string `json:"key"` |
| 106 | +} |
| 107 | + |
| 108 | +// LocalSecretReference is a reference to a secret in the same namespace as the resource referencing it with a key. |
| 109 | +type LocalSecretReference struct { |
| 110 | + LocalObjectReference `json:",inline"` |
| 111 | + // Key is the key in the secret to use. |
| 112 | + Key string `json:"key"` |
| 113 | +} |
0 commit comments