Wizard: rm pem validation, add cert warning

Since we support pem, cer, and der, we'd have to validate against each
of these on the frontend. Let's just check that the file is not empty,
and leave this upto users. On top of that, concatenated certificates are
supported, validating that would be too much. This commit also switches
token expiration error into a warning.
This commit is contained in:
Anna Vítová 2025-03-13 16:16:17 +01:00 committed by Klara Simickova
parent b6cdfdb102
commit 75792bcc0a
4 changed files with 6 additions and 18 deletions

View file

@ -88,7 +88,7 @@ const SatelliteRegistration = () => {
? 'Must be a .PEM/.CER/.CRT file no larger than 512 KB'
: validated === 'error'
? stepValidation.errors['certificate']
: 'Drag and drop a file or upload one'}
: 'Drag and drop a valid certificate file or upload one'}
</HelperTextItem>
</HelperText>
</FormHelperText>

View file

@ -46,6 +46,7 @@ const SatelliteRegistrationCommand = () => {
placeholder="Registration command"
stepValidation={stepValidation}
fieldName="command"
warning={stepValidation.errors.expired}
/>
<FormHelperText>
<HelperText>

View file

@ -1,5 +0,0 @@
export const isValidPEM = (cert: string): boolean => {
return /-----BEGIN CERTIFICATE-----[\s\S]+-----END CERTIFICATE-----/.test(
cert.trim()
);
};

View file

@ -1,14 +1,9 @@
import React, { useEffect, useState } from 'react';
import { CheckCircleIcon } from '@patternfly/react-icons';
import { jwtDecode } from 'jwt-decode';
import { isValidPEM } from './certificates';
import { jwtDecode } from 'jwt-decode';
import { isValidPEM } from './certificates';
import { UNIQUE_VALIDATION_DELAY } from '../../../constants';
import { useLazyGetBlueprintsQuery } from '../../../store/backendApi';
import { useAppSelector } from '../../../store/hooks';
@ -153,7 +148,7 @@ export function useRegistrationValidation(): StepValidation {
if (registrationType === 'register-satellite') {
const errors = {};
if (caCertificate && (caCertificate === '' || !isValidPEM(caCertificate))) {
if (caCertificate === '') {
Object.assign(errors, {
certificate:
'Valid certificate must be present if you are registering Satellite.',
@ -179,14 +174,13 @@ export function useRegistrationValidation(): StepValidation {
if (decoded.exp < currentTimeSeconds + dayInSeconds) {
const expirationDate = new Date(decoded.exp * 1000);
Object.assign(errors, {
command:
expired:
'The token is already expired or will expire by next day. Expiration date: ' +
expirationDate,
});
return {
errors: errors,
disabledNext:
caCertificate === undefined || !isValidPEM(caCertificate),
disabledNext: caCertificate === undefined,
};
}
}
@ -197,9 +191,7 @@ export function useRegistrationValidation(): StepValidation {
return {
errors: errors,
disabledNext:
Object.keys(errors).length > 0 ||
caCertificate === undefined ||
!isValidPEM(caCertificate),
Object.keys(errors).length > 0 || caCertificate === undefined,
};
}