Skip to content

Commit fca4d27

Browse files
claudioloradamjensenbot
authored andcommitted
fix: TolerateNoHandshake ResourceSlice approval
Due to the Tenant public keys refactoring, a bug on the ResourceSlice approval has been introduced when authentication was checked, and the Tenant was configured in TolerateNoHandshake mode. In that case, as the controller tried to parse the empty Tenant public key, it failed.
1 parent ce762bc commit fca4d27

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

pkg/liqo-controller-manager/authentication/csr.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,17 @@ func CheckCSRForControlPlane(csr, publicKeyDER []byte, remoteClusterID liqov1bet
130130
}
131131

132132
// CheckCSRForResourceSlice checks a CSR for a resource slice.
133-
func CheckCSRForResourceSlice(publicKeyDER []byte, resourceSlice *authv1beta1.ResourceSlice, checkPublicKey bool) error {
134-
return checkCSR(resourceSlice.Spec.CSR, publicKeyDER, checkPublicKey,
133+
func CheckCSRForResourceSlice(tenantPublicKey []byte, resourceSlice *authv1beta1.ResourceSlice, checkPublicKey bool) error {
134+
var parsedPublicKey []byte
135+
if checkPublicKey {
136+
_, parsedPublicKeyDER, err := ParseTenantPublicKey(tenantPublicKey)
137+
if err != nil {
138+
return fmt.Errorf("failed to parse tenant public key: %w", err)
139+
}
140+
parsedPublicKey = parsedPublicKeyDER
141+
}
142+
143+
return checkCSR(resourceSlice.Spec.CSR, parsedPublicKey, checkPublicKey,
135144
func(x509Csr *x509.CertificateRequest) error {
136145
if x509Csr.Subject.CommonName != CommonNameResourceSliceCSR(resourceSlice) {
137146
return fmt.Errorf("invalid common name")

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,7 @@ func (r *RemoteResourceSliceReconciler) handleAuthenticationStatus(ctx context.C
182182
// check that the CSR is valid
183183
shouldCheckPublicKey := authv1beta1.GetAuthzPolicyValue(tenant.Spec.AuthzPolicy) != authv1beta1.TolerateNoHandshake
184184

185-
_, publicKeyDER, err := authentication.ParseTenantPublicKey(tenant.Spec.PublicKey)
186-
if err != nil {
187-
return fmt.Errorf("failed to parse public key in Tenant resource %q: %w", tenant.Name, err)
188-
}
189-
190-
if err := authentication.CheckCSRForResourceSlice(publicKeyDER, resourceSlice, shouldCheckPublicKey); err != nil {
185+
if err := authentication.CheckCSRForResourceSlice(tenant.Spec.PublicKey, resourceSlice, shouldCheckPublicKey); err != nil {
191186
klog.Errorf("Invalid CSR for the ResourceSlice %q: %s", client.ObjectKeyFromObject(resourceSlice), err)
192187
r.eventRecorder.Event(resourceSlice, corev1.EventTypeWarning, "InvalidCSR", err.Error())
193188
denyAuthentication(resourceSlice, r.eventRecorder)

0 commit comments

Comments
 (0)