Skip to content

Commit 81e0bc7

Browse files
committed
Use pointer for AutzPolicy field
1 parent a7c3a4d commit 81e0bc7

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

apis/authentication/v1beta1/tenant_types.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ import (
2525
type AuthzPolicy string
2626

2727
const (
28-
// KeyExchange indicates that a key exchange must be performed before accepting any ResourceSlice.
29-
KeyExchange AuthzPolicy = "KeyExchange"
28+
// KeysExchange indicates that a keys exchange must be performed before accepting any ResourceSlice.
29+
KeysExchange AuthzPolicy = "KeysExchange"
3030
// TolerateNoHandshake indicates that the local cluster accepts ResourceSlices even when there
3131
// never have been a key exchange with the peer cluster.
3232
TolerateNoHandshake AuthzPolicy = "TolerateNoHandshake"
33+
// DefaultAuthzPolicy is the default authorization policy if nothing is provided.
34+
DefaultAuthzPolicy AuthzPolicy = KeysExchange
3335
)
3436

3537
// TenantResource is the name of the tenant resources.
@@ -44,15 +46,23 @@ var TenantGroupResource = schema.GroupResource{Group: GroupVersion.Group, Resour
4446
// TenantGroupVersionResource is groupResourceVersion used to register these objects.
4547
var TenantGroupVersionResource = GroupVersion.WithResource(TenantResource)
4648

49+
// GetAuthzPolicyValue returns the value of the pointer to an AuthzPolicy type, if the pointer is nil it returns the default value.
50+
func GetAuthzPolicyValue(policy *AuthzPolicy) AuthzPolicy {
51+
if policy == nil {
52+
return DefaultAuthzPolicy
53+
}
54+
return *policy
55+
}
56+
4757
// TenantSpec defines the desired state of Tenant.
4858
type TenantSpec struct {
4959
// ClusterID is the id of the consumer cluster.
5060
ClusterID liqov1beta1.ClusterID `json:"clusterID,omitempty"`
5161
// AuthzPolicy is the policy used by the cluster to authorize or reject an incoming ResourceSlice.
52-
// Default is KeyExchange.
53-
// +kubebuilder:validation:Enum=KeyExchange;TolerateNoHandshake
54-
// +kubebuilder:default=KeyExchange
55-
AuthzPolicy `json:"authzPolicy"`
62+
// Default is KeysExchange.
63+
// +kubebuilder:validation:Enum=KeysExchange;TolerateNoHandshake
64+
// +kubebuilder:default=KeysExchange
65+
*AuthzPolicy `json:"authzPolicy,omitempty"`
5666
// PublicKey is the public key of the tenant cluster.
5767
PublicKey []byte `json:"publicKey,omitempty"`
5868
// CSR is the Certificate Signing Request of the tenant cluster.

pkg/liqo-controller-manager/authentication/remoteresourceslice-controller/remoteresourceslice_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (r *RemoteResourceSliceReconciler) Reconcile(ctx context.Context, req ctrl.
165165
func (r *RemoteResourceSliceReconciler) handleAuthenticationStatus(ctx context.Context,
166166
resourceSlice *authv1beta1.ResourceSlice, tenant *authv1beta1.Tenant) error {
167167
// check that the CSR is valid
168-
shouldCheckPublicKey := tenant.Spec.AuthzPolicy != authv1beta1.TolerateNoHandshake
168+
shouldCheckPublicKey := authv1beta1.GetAuthzPolicyValue(tenant.Spec.AuthzPolicy) != authv1beta1.TolerateNoHandshake
169169
if err := authentication.CheckCSRForResourceSlice(tenant.Spec.PublicKey, resourceSlice, shouldCheckPublicKey); err != nil {
170170
klog.Errorf("Invalid CSR for the ResourceSlice %q: %s", client.ObjectKeyFromObject(resourceSlice), err)
171171
r.eventRecorder.Event(resourceSlice, corev1.EventTypeWarning, "InvalidCSR", err.Error())

pkg/liqo-controller-manager/authentication/tenant-controller/tenant_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (r *TenantReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
135135
clusterID := tenant.Spec.ClusterID
136136

137137
// If no handshake is tolerated, then do not perform the checks on the exchanged keys.
138-
if tenant.Spec.AuthzPolicy != authv1beta1.TolerateNoHandshake {
138+
if authv1beta1.GetAuthzPolicyValue(tenant.Spec.AuthzPolicy) != authv1beta1.TolerateNoHandshake {
139139
// get the nonce for the tenant
140140

141141
nonceSecret, err := getters.GetNonceSecretByClusterID(ctx, r.Client, clusterID)
@@ -196,7 +196,7 @@ func (r *TenantReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
196196
}()
197197

198198
// If no handshake is performed, then the user is charge of creating the authentication params and bind the right permissions.
199-
if tenant.Spec.AuthzPolicy != authv1beta1.TolerateNoHandshake {
199+
if authv1beta1.GetAuthzPolicyValue(tenant.Spec.AuthzPolicy) != authv1beta1.TolerateNoHandshake {
200200
// create the CSR and forge the AuthParams
201201

202202
authParams, err := r.IdentityProvider.ForgeAuthParams(ctx, &identitymanager.SigningRequestOptions{

pkg/liqo-controller-manager/core/foreigncluster-controller/status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ func (r *ForeignClusterReconciler) handleAuthenticationModuleStatus(ctx context.
191191
fc.Status.TenantNamespace.Local = tenant.Status.TenantNamespace
192192
}
193193

194-
if tenant.Spec.AuthzPolicy != authv1beta1.TolerateNoHandshake && tenant.Status.AuthParams == nil || tenant.Status.TenantNamespace == "" {
194+
// Define the status of the authentication module based on whether the keys exchange has been performed.
195+
expectKeysExchange := authv1beta1.GetAuthzPolicyValue(tenant.Spec.AuthzPolicy) != authv1beta1.TolerateNoHandshake
196+
if expectKeysExchange && tenant.Status.AuthParams == nil || tenant.Status.TenantNamespace == "" {
195197
fcutils.EnsureModuleCondition(&fc.Status.Modules.Authentication,
196198
liqov1beta1.AuthTenantStatusCondition, liqov1beta1.ConditionStatusNotReady,
197199
tenantNotReadyReason, tenantNotReadyMessage)

0 commit comments

Comments
 (0)