Skip to content

Refresh cached TLS intercept certs before expiry#763

Open
venbrinoDev wants to merge 4 commits into
superradcompany:mainfrom
venbrinoDev:fix/certificate-expiry
Open

Refresh cached TLS intercept certs before expiry#763
venbrinoDev wants to merge 4 commits into
superradcompany:mainfrom
venbrinoDev:fix/certificate-expiry

Conversation

@venbrinoDev
Copy link
Copy Markdown

@venbrinoDev venbrinoDev commented May 20, 2026

Summary

We run Microsandbox for long-lived user runtimes in production, and this surfaced there as older sandboxes began failing TLS interception for intercepted hosts.

Fix TLS interception for long-lived sandboxes by refreshing cached per-domain leaf certificates when they are expired or near expiry.

Problem

Microsandbox caches generated intercept certs in TlsState.cert_cache, but cached entries were reused without checking whether the leaf cert had already expired.

In practice this caused older sandboxes to start failing TLS for intercepted hosts with errors like:

  • certificate has expired
  • SSL certificate problem: certificate has expired

Fix

  • store not_after on DomainCert
  • check cached cert expiry in TlsState::get_or_generate_cert()
  • regenerate and replace the cached cert when it is expired or within a small refresh window

Files changed

  • crates/network/lib/tls/certgen.rs
  • crates/network/lib/tls/state.rs

Testing

Passed:

cargo test -p microsandbox-network tls::certgen
cargo test -p microsandbox-network tls::state
cargo test -p microsandbox-network --lib

Happy to adjust this if there’s a preferred place to handle cert rotation or expiry checks.

Comment thread crates/network/lib/tls/certgen.rs Outdated
Copy link
Copy Markdown
Member

@toksdotdev toksdotdev left a comment

Choose a reason for hiding this comment

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

thanks for the fix. once the minor issue i raised is fixed, should be good to merge.

@venbrinoDev
Copy link
Copy Markdown
Author

okay @toksdotdev i do change that and make an update

@toksdotdev
Copy link
Copy Markdown
Member

can you take a look at the failing build. ty!

@venbrinoDev
Copy link
Copy Markdown
Author

can you take a look at the failing build. ty!

Sure currently looking at them to see why its failing

@venbrinoDev
Copy link
Copy Markdown
Author

venbrinoDev commented May 20, 2026

can you take a look at the failing build. ty!

was a formatting issue fixed and pushed

@toksdotdev
Copy link
Copy Markdown
Member

@venbrinoDev still some formatting issues.

@venbrinoDev
Copy link
Copy Markdown
Author

@venbrinoDev still some formatting issues.

ohh checking it out

@venbrinoDev
Copy link
Copy Markdown
Author

Resolved and pushed @toksdotdev also ran it locally incase of any further fmt or lint issue

@venbrinoDev
Copy link
Copy Markdown
Author

Hi @toksdotdev, any estimate on when the fix will be pushed? I’d like to update my package version once it’s out.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants