Skip to content

fix: auto-generate CA cert in portless trust instead of erroring#128

Open
elliotllliu wants to merge 2 commits intovercel-labs:mainfrom
elliotllliu:fix/trust-auto-generate-ca
Open

fix: auto-generate CA cert in portless trust instead of erroring#128
elliotllliu wants to merge 2 commits intovercel-labs:mainfrom
elliotllliu:fix/trust-auto-generate-ca

Conversation

@elliotllliu
Copy link
Copy Markdown
Contributor

Summary

Fixes #124portless trust no longer fails with "CA certificate not found. Run with --https first." on Windows (or any platform).

Problem

portless trust checks if the CA cert exists and errors with "Run with --https first" if it doesn't. But --https is only a valid flag for portless proxy start, not portless trust. Users hit a dead-end loop:

$ portless trust
Failed to trust CA: CA certificate not found. Run with --https first.

$ portless trust --https
Failed to trust CA: CA certificate not found. Run with --https first.

Fix

When the CA cert doesn't exist, trustCA() now auto-generates it via generateCA() before proceeding to trust it. This makes portless trust self-contained — no need to run portless proxy start --https first.

Changes

  • packages/portless/src/certs.ts: trustCA() calls generateCA() when the CA cert is missing

When running `portless trust`, if the CA certificate doesn't exist
yet, auto-generate it instead of returning the confusing error
'CA certificate not found. Run with --https first.'

The --https flag is only valid for `portless proxy start`, not for
`portless trust`, so the error message was a dead end. Now
`portless trust` is self-contained: it generates the CA if needed,
then trusts it.

Fixes vercel-labs#124
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 17, 2026

@elliotllliu is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@vercel vercel bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

Test asserts "CA certificate not found" error but trustCA was changed to auto-generate the CA cert, so the test always fails.

Fix on Vercel

@ctate
Copy link
Copy Markdown
Collaborator

ctate commented Mar 17, 2026

Thanks for the fix! The approach of auto-generating the CA via generateCA() is clean and matches how ensureCerts() already handles this.

One thing needed before merging: the test at certs.test.ts:319 ("returns error when CA cert is missing") fails since it still expects the old error message. Please update it to reflect the new auto-generation behavior. Once CI is green, this is good to go!

Update the 'CA cert missing' test to reflect the new behavior where
trustCA() auto-generates the CA instead of returning an error.
The test now verifies that:
- CA file is created when missing
- No 'CA certificate not found' error is returned
- Trust may still fail in CI (non-interactive) but for platform reasons
@elliotllliu
Copy link
Copy Markdown
Contributor Author

Updated in 40540bf — test now verifies the auto-generation behavior instead of expecting the old error message. Thanks for the review!

@ctate
Copy link
Copy Markdown
Collaborator

ctate commented Mar 19, 2026

@elliotllliu Thanks for the update! The concept is correct and the production code is good, but the test has a filename typo ("ca.crt" vs "ca.pem") that causes CI to fail. Once that's fixed this is good to merge.

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.

[BUG] portless trust --https still reports "Run with --https first" on Windows

2 participants