Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wizard: add satellite registration #2963

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

avitova
Copy link
Contributor

@avitova avitova commented Mar 5, 2025

This adds an option to paste the Satellite registration command + CA. Saving this information into the blueprint is still not done; I will create a follow-up; this is big PR as is.

@avitova avitova force-pushed the sat-reg branch 3 times, most recently from cc5aed1 to 6c11792 Compare March 5, 2025 11:41
@avitova
Copy link
Contributor Author

avitova commented Mar 5, 2025

Screencast.From.2025-03-05.10-51-23.mp4

So this is the UI change. We try to find the JWT token, in case it is not there, we disable the "next" button. We also show an error if the token is expired, but in that case, we let users through.
So far, we only allow some certificates. If you have any ideas how to validate this differently, please let me know.

@avitova avitova marked this pull request as ready for review March 5, 2025 11:50
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 30.08130% with 172 lines in your changes missing coverage. Please review.

Project coverage is 81.53%. Comparing base (978a37f) to head (e3f1eb1).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
...izard/steps/Registration/SatelliteRegistration.tsx 10.38% 69 Missing ⚠️
...ents/CreateImageWizard/utilities/useValidation.tsx 11.11% 48 Missing ⚠️
...ration/components/SatelliteRegistrationCommand.tsx 20.00% 32 Missing ⚠️
...ateImageWizard/steps/Registration/Registration.tsx 60.71% 11 Missing ⚠️
src/store/wizardSlice.ts 66.66% 7 Missing ⚠️
...onents/CreateImageWizard/utilities/certificates.ts 20.00% 4 Missing ⚠️
...nents/CreateImageWizard/utilities/requestMapper.ts 91.66% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2963      +/-   ##
==========================================
- Coverage   82.09%   81.53%   -0.57%     
==========================================
  Files         209      212       +3     
  Lines       23517    23754     +237     
  Branches     2329     2339      +10     
==========================================
+ Hits        19306    19367      +61     
- Misses       4182     4358     +176     
  Partials       29       29              
Files with missing lines Coverage Δ
...nts/CreateImageWizard/steps/Registration/index.tsx 100.00% <100.00%> (ø)
src/store/service/contentSourcesApi.ts 82.60% <ø> (ø)
src/store/service/imageBuilderApi.ts 86.88% <ø> (ø)
...t/Components/CreateImageWizard/wizardTestUtils.tsx 96.06% <100.00%> (ø)
...nents/CreateImageWizard/utilities/requestMapper.ts 94.87% <91.66%> (-0.07%) ⬇️
...onents/CreateImageWizard/utilities/certificates.ts 20.00% <20.00%> (ø)
src/store/wizardSlice.ts 87.95% <66.66%> (-0.52%) ⬇️
...ateImageWizard/steps/Registration/Registration.tsx 88.26% <60.71%> (-7.87%) ⬇️
...ration/components/SatelliteRegistrationCommand.tsx 20.00% <20.00%> (ø)
...ents/CreateImageWizard/utilities/useValidation.tsx 74.47% <11.11%> (-9.18%) ⬇️
... and 1 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 978a37f...e3f1eb1. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucasgarfield
Copy link
Collaborator

Love the validation guardrails!

package.json Outdated
@@ -19,6 +19,7 @@
"@sentry/webpack-plugin": "3.2.1",
"@unleash/proxy-client-react": "4.5.2",
"classnames": "2.5.1",
"jwt-decode": "^4.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New dependency! Can you please remove the ^? We rely on Dependabot to handle everything.

Also, I'd be curious to know about the decision to use jwt-decode. What was your selection criteria?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm re-reading my comment and I realized it is a bit curt. 😅

jwt-decode is probably fine but it would be nice to know why we chose it, especially in the commit message for the future - is it the most popular or well maintained library for this? Did we look into any alternatives, etc...? I don't have any specific problem with jwt-decode itself I'm just totally ignorant so some extra context would be nice. 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, that makes sense. I removed the ^, and added information into the commit, hopefully that's what you meant. :)

@regexowl
Copy link
Collaborator

regexowl commented Mar 6, 2025

+1 on pining the dep version, otherwise looks great! ❤️ One question - could isValidPEM go into validators.ts or are there more plans for certificates.ts?

Also can't see the flag in stage unleash, could you please add it there as well? We might even want to gate it behind a preview constraint as this will probably affect IQE 🤔

Copy link
Collaborator

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 🧡

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: isn't [\s\S]+ equal to .+?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I tried to figure this out as well, we'd need to add "s" at the end of the regex, something like this:
/-----BEGIN CERTIFICATE-----.+-----END CERTIFICATE-----/s

Otherwise it would not accept certificates with more lines. I can do that if it makes the regex a bit more clear.

const decoded = jwtDecode(token);
if (decoded.exp) {
const currentTime = Date.now() / 1000;
if (decoded.exp < currentTime) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvement idea, not a blocker: this could potentially have a buffer.
I mean the image build takes about 15 minutes, so token expiring in half an hour doesn't give you much room to use the image 😛
We might want to figure out a warning intead in a follow-up :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, and I can do that as a followup. I still need to add the Satellite registration to the review step, add the command + certificate to the blueprint, so that it is saved. This could fit in too. ✏️ 📓

@ezr-ondrej
Copy link
Collaborator

Ugh there is a conflict already, that was fast 🤔

@avitova
Copy link
Contributor Author

avitova commented Mar 6, 2025

+1 on pining the dep version, otherwise looks great! ❤️ One question - could isValidPEM go into validators.ts or are there more plans for certificates.ts?

Uhm, I'd like to add also isDer/isCer, but I need to look into that one. On top of that, the plan might be that users could paste more certificates into one textfield, and we'd parse them all. But I think we should do this as a followup. But yeah, it will likely be a bit more complicated.

Also can't see the flag in stage unleash, could you please add it there as well? We might even want to gate it behind a preview constraint as this will probably affect IQE 🤔

Done, that's a good point, thanks!

@regexowl
Copy link
Collaborator

regexowl commented Mar 6, 2025

+1 on pining the dep version, otherwise looks great! ❤️ One question - could isValidPEM go into validators.ts or are there more plans for certificates.ts?

Uhm, I'd like to add also isDer/isCer, but I need to look into that one. On top of that, the plan might be that users could paste more certificates into one textfield, and we'd parse them all. But I think we should do this as a followup. But yeah, it will likely be a bit more complicated.

Got it! I don't have anything against splitting validators into separate files. Just curious 👍 Thinking about it we should probably do a bit of a cleanup around utilities and unsorted files in the Wizard folder, but that's completely outside of this PR's scope 😅

<HelperText>
{/* TODO: Add link to our docs */}
<HelperTextItem>
To generate command from Satellite, follow the documentation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, both no link and using a temporary relevant link work for me. We just need to remember to open a follow up when the new documentation is ready. 👍

ezr-ondrej
ezr-ondrej previously approved these changes Mar 10, 2025
Copy link
Collaborator

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right then, I think we can merge, the only change with the feature flag turned off should be change to radios, which should be fine in the interim :)

@regexowl
Copy link
Collaborator

Switch from a single checkbox to two radios might impact IQE, @tkoscieln could you please check if the tests will need an adjustment?

@ezr-ondrej
Copy link
Collaborator

Ah, right, that's the ci.int failure :/

@tkoscieln
Copy link
Contributor

@regexowl will do!

The jwt decode dependency helps us to keep track of the token that is
present in the Satellite command. jwt-decode is the most popular
dependency for the job, and very easy to use.
@avitova
Copy link
Contributor Author

avitova commented Mar 10, 2025

Oopsie, did not see the approval. I just put the docs link and fixed a bug, hope y'all do not mind. ✨

@avitova avitova requested a review from ezr-ondrej March 11, 2025 09:29
Copy link
Collaborator

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still fine, we need to fix the tests tho.
@tkoscieln would you do that and then merge this PR? or what's the process now?

@tkoscieln
Copy link
Contributor

I'll deploy the PR locally and see if it breaks something. If not, we can merge, if yes, I will do the necessary adjustments and then we can merge

@ezr-ondrej
Copy link
Collaborator

the failures in the CI seems to be related :)

>               raise WidgetOperationFailed("Failed to set the checkbox to requested value.")
E               widgetastic.exceptions.WidgetOperationFailed: Failed to set the checkbox to requested value.

@tkoscieln
Copy link
Contributor

Well, I'll do the adjustment then 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants