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

fix(dashmate): various ZeroSSL cert verification errors #2339

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

shumkov
Copy link
Member

@shumkov shumkov commented Nov 21, 2024

Issue being fixed or feature implemented

During obtaining certificate users receive a sequence of errors even if certificate is successfully verified.

First error:

domain_control_validation_failed

And on retry:

The given certificate is not ready for domain verification

It seem like a ZeroSSL bug but we need to handle it.

What was done?

  • Automatically retry on the domain_control_validation_failed error
  • Proceed on certificate download on the given certificate is not ready for domain verification error if status is issued

How Has This Been Tested?

Running locally

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced automatic retry logic for domain verification errors during SSL certificate acquisition.
  • Bug Fixes

    • Enhanced error handling for specific scenarios, including improved responses to certificate status and transient issues, resulting in a smoother user experience during validation.

@shumkov shumkov added this to the v1.6.0 milestone Nov 21, 2024
Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes in this pull request focus on enhancing error handling within the obtainZeroSSLCertificateTaskFactory function in obtainZeroSSLCertificateTaskFactory.js. Modifications include the introduction of an automatic retry mechanism for specific error scenarios during domain verification, particularly for error code 2831 and the 'domain_control_validation_failed' error. The overall task structure remains unchanged, ensuring consistent user interaction.

Changes

File Change Summary
packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js Enhanced error handling in obtainZeroSSLCertificateTaskFactory with automatic retry logic for specific error scenarios during domain verification.

Possibly related PRs

  • fix(dashmate): zero ssl certificate draft not saved #2297: This PR modifies the obtainZeroSSLCertificateTaskFactory function, which is directly related to the changes made in the main PR that also involves enhancements to the obtainZeroSSLCertificateTaskFactory function, specifically in error handling during the SSL certificate process.
  • fix(dashmate): cleanup zerossl certs command #2298: This PR introduces a new command for cleaning up ZeroSSL certificates, which is relevant as it operates within the same context of managing SSL certificates as the main PR's modifications to the obtainZeroSSLCertificateTaskFactory function.

Suggested labels

dashmate

Suggested reviewers

  • QuantumExplorer
  • pshenmic

🐰 In the garden of code, we strive,
With error handling, we thrive!
For certificates, we now retry,
With clearer paths, we reach the sky!
So hop along, let bugs be few,
In our code, we’ll make it new! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 97786f4 and 9f4bd60.

📒 Files selected for processing (1)
  • packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js (2)

180-188: LGTM! Consider adding more detailed comments and logging

The error handling for code 2831 (certificate not ready for verification) is well implemented. The solution to check the certificate status and proceed if it's already issued is a good approach.

Consider adding:

  1. More detailed comments explaining the ZeroSSL API behavior and why this specific error might occur when the certificate is actually issued
  2. Debug logging to help troubleshoot similar issues in the future
 // Error: The given certificate is not ready for domain verification
 // Sometimes this error means that certificate is already verified
 if (e.code === 2831) {
+  // ZeroSSL API occasionally returns error 2831 even when the certificate
+  // is already issued. This is a known API inconsistency.
   const certificate = await getCertificate(ctx.apiKey, ctx.certificate.id);
+  // Log the actual certificate status for debugging
+  console.debug(`Certificate ${ctx.certificate.id} status: ${certificate.status}`);
   // Just proceed on certificate download if we see it's already issued.
   if (certificate.status === 'issued') {
     return;
   }
 }

194-208: LGTM! Consider adding error type to debug logs

The error message and retry prompt are well-implemented with clear instructions about port configuration and firewall settings.

Consider adding the error type to debug logs for better troubleshooting:

 if (ctx.noRetry !== true) {
+  console.debug(`Certificate verification failed with error type: ${e.type}`);
   retry = await task.prompt({
     type: 'toggle',
     header: chalk`  An error occurred during verification: {red ${e.message}}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0cb24ea and 97786f4.

📒 Files selected for processing (1)
  • packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js (3)
Learnt from: shumkov
PR: dashpay/platform#2297
File: packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js:148-150
Timestamp: 2024-11-12T14:56:12.334Z
Learning: In the `obtainZeroSSLCertificateTaskFactory` function in `packages/dashmate/src/listr/tasks/ssl/zerossl/obtainZeroSSLCertificateTaskFactory.js`, the application already fails appropriately if `configFileRepository.write(configFile)` fails, so additional error handling around this operation is unnecessary.
Learnt from: shumkov
PR: dashpay/platform#2298
File: packages/dashmate/src/listr/tasks/ssl/zerossl/cleanupZeroSSLCertificatesTaskFactory.js:27-48
Timestamp: 2024-11-12T14:56:12.334Z
Learning: In `cleanupZeroSSLCertificatesTask` located in `packages/dashmate/src/listr/tasks/ssl/zerossl/cleanupZeroSSLCertificatesTaskFactory.js`, if the certificate listing API call fails, we prefer the entire command to fail without additional error handling.
Learnt from: shumkov
PR: dashpay/platform#2298
File: packages/dashmate/src/listr/tasks/ssl/zerossl/cleanupZeroSSLCertificatesTaskFactory.js:74-74
Timestamp: 2024-11-12T14:56:12.334Z
Learning: In the `cleanupZeroSSLCertificatesTask` function located in `packages/dashmate/src/listr/tasks/ssl/zerossl/cleanupZeroSSLCertificatesTaskFactory.js`, the team prefers to include a small fixed delay between all requests to avoid overloading ZeroSSL, rather than implementing exponential backoff.

@shumkov shumkov self-assigned this Nov 21, 2024
@shumkov shumkov merged commit 0d0f477 into v1.6-dev Nov 21, 2024
23 checks passed
@shumkov shumkov deleted the fix/dashmate/ssl-verification-errors branch November 21, 2024 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants