Skip to content

mitm: add server's own hostname as SAN on minted leaf certs#166

Merged
dangtony98 merged 3 commits intomainfrom
mitm-cert-baseurl-san
May 11, 2026
Merged

mitm: add server's own hostname as SAN on minted leaf certs#166
dangtony98 merged 3 commits intomainfrom
mitm-cert-baseurl-san

Conversation

@dangtony98
Copy link
Copy Markdown
Contributor

Summary

  • Clients that route HTTPS_PROXY to the agent-vault MITM proxy and TLS-verify against the proxy's own hostname (rather than the upstream SNI) currently fail because minted leaves only carry the upstream's SAN. Today the workaround is a InsecureSkipVerify shim on the client side.
  • Reuse the existing AGENT_VAULT_ADDR / baseURL plumbing (already threaded into mitm.Options.BaseURL for help-link text) to add the proxy's hostname as an additional SAN on every minted leaf. New ca.Options.ExtraSANs []string is populated once at boot in attachMITMIfEnabled from srv.BaseURL(); MintLeaf appends it to the cert template, routing IP literals into IPAddresses and DNS names into DNSNames, deduping against the primary SNI.
  • Set AGENT_VAULT_ADDR=http://agent-vault-hnh0:14321 on a service and every minted leaf now carries agent-vault-hnh0 as a SAN — the shim can be deleted.

Implementation notes

  • Cache stays keyed by SNI (the extras are a process-lifetime constant, so cached *tls.Certificate instances remain consistent).
  • MintLeaf's signature is unchanged; the two MITM call sites (internal/mitm/proxy.go:120, internal/mitm/connect.go:110) are untouched.
  • AGENT_VAULT_ADDR env-var description updated in both docs/self-hosting/environment-variables.mdx and docs/reference/cli.mdx to mention the new SAN behavior.

Test plan

  • make test — full Go suite green; new TestMintLeaf_IncludesExtraDNSSans and TestMintLeaf_IncludesExtraIPSans cover the SAN injection + dedup paths and the IP-vs-DNS routing.
  • go vet ./... clean.
  • Manual smoke on Render: set AGENT_VAULT_ADDR=http://agent-vault-hnh0:14321, redeploy, confirm openssl s_client -connect agent-vault-hnh0:14322 -servername api.linear.app | openssl x509 -text -noout shows DNS:agent-vault-hnh0 alongside DNS:api.linear.app, then drop the talent-agent InsecureSkipVerify shim and verify the client connects clean.

Clients that route HTTPS_PROXY to the agent-vault MITM proxy and TLS-verify
against the proxy's own hostname (rather than the upstream SNI) currently
fail because minted leaves only carry the upstream's SAN. Reuse the existing
AGENT_VAULT_ADDR / baseURL plumbing to add the proxy's hostname as an
additional SAN on every leaf, so the proxy-hop handshake matches without a
shim. Routes IP literals into IPAddresses and DNS names into DNSNames,
deduping against the primary SNI.
@infisical-review-police
Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-agent-vault-166-mitm-add-server-s-own-hostname-as-san-on-minted-leaf-c

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

The prior comment claimed "malformed entries are silently dropped," but
the only filtering in New() is an empty-string check; non-IP entries are
treated as DNS names without further validation.
@dangtony98
Copy link
Copy Markdown
Contributor Author

@claude review

Comment thread internal/ca/soft.go
Comment thread internal/ca/soft.go
Comment thread cmd/server.go
@mintlify
Copy link
Copy Markdown

mintlify Bot commented May 11, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
agent-vault 🟢 Ready View Preview May 11, 2026, 12:52 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Addresses review feedback on PR #166:

- ExtraSANs entries now run through validateSNI so malformed inputs
  (underscores, leading hyphens, spaces, etc.) are silently dropped
  instead of being appended to DNSNames verbatim. Docstring updated
  to match.
- Extra-DNS dedup against the per-request SNI uses strings.EqualFold,
  matching RFC 6125 case-insensitive DNS-ID semantics. Avoids redundant
  SANs when AGENT_VAULT_ADDR carries mixed case.
- .env.example mentions the new MITM SAN-injection side effect of
  AGENT_VAULT_ADDR, in line with the docs/ updates and CLAUDE.md's
  env-var doc convention.
@dangtony98 dangtony98 merged commit c9af129 into main May 11, 2026
10 checks passed
@dangtony98 dangtony98 deleted the mitm-cert-baseurl-san branch May 11, 2026 01:09
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