← Back to Pull requests

vxpu/pki: write CA and SPIFFE certificates to a local directory #872

Closed
unknown closed this pull request without merging on Nov 24, 2026 15:01 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 03:50 UTC
Author

Implement the single-machine half of the first mTLS move (#662, #855)
so a laptop or single VM with no Kubernetes cluster can generate the
same CA and SPIFFE leaf certificates as files with one command.

Approach:

  • Add pki.EnsureDir in vxpu/pkg/pki/dir.go using the same CA/leaf

  • minting and verification code as EnsureK8s. It writes ca.crt and
    ca.key under <dir>/ca, and writes ca.crt, tls.crt, and tls.key under
    <dir>/coordinator and <dir>/agent without placing ca.key in either
    workload directory.
  • Place every file atomically through fileutil.WriteAtomic, writing

  • private keys with mode 0600 (from os.CreateTemp through rename) and
    certificates with mode 0644. Stage a newly minted CA pair inside a
    temporary directory (<dir>/.ca.tmp-) and rename it to <dir>/ca so
    ca.crt and ca.key appear together or not at all; remove stale
    .ca.tmp-
    staging directories on subsequent runs so a killed process
    never leaves an orphaned CA private key behind.
  • Keep re-runs idempotent and consistent: leave valid files untouched,

  • update stale workload ca.crt bundles, re-mint missing, expired,
    mismatched, or wrong-CA leaves from the CA in <dir>/ca, and refuse a
    malformed, expired, non-CA, or incomplete CA without overwriting any
    existing file. Log identities, expiries, status, and reason via klog
    with no private key material.
  • Add --out-dir to cmd/vxpu-pki-init rather than adding a subcommand to

  • cmd/vxpu. vxpu-pki-init already owns the PKI flags (--trust-domain,
    --workload-namespace, --ca-ttl, --leaf-ttl) and parallels the other
    standalone binaries (vxpu-agent, vxpu-router) run on a single host.
    Putting --out-dir on vxpu-pki-init avoids duplicating the PKI flag
    surface onto cmd/vxpu and keeps cluster and single-machine runs
    identical in flags and log output. Check whether --out-dir was passed
    via FlagSet.Visit so an explicit --out-dir "" fails with an empty
    directory error rather than falling through to Kubernetes mode. When
    --out-dir is set, run ignores KUBECONFIG from the environment,
    rejects --kubeconfig passed explicitly alongside --out-dir, checks
    errors early, and exits from main in one place.
  • Document single-machine usage in vxpu/docs/design.md, including why

  • one-machine runs intentionally keep the cluster service-account SPIFFE
    identities and what --workload-namespace means without a cluster. Add
    unit tests in vxpu/pkg/pki/pki_test.go and
    vxpu/cmd/vxpu-pki-init/main_test.go.

    Verification:

  • ap generate --verify //..., ap lint vxpu, ap test vxpu, and

  • go test -race ./pkg/fileutil/... ./pkg/pki/... ./cmd/vxpu-pki-init/... ./pkg/agent/...
    pass.
  • Smoke-tested go run ./cmd/vxpu-pki-init --out-dir twice against a

  • temp directory and verified 0600 key permissions, 0644 cert
    permissions, and status="created" followed by status="kept" logs.

    Fixes #870

    Diff: 355 lines (+266 / -89) across 4 files Reviewer: codebot-robot Review duration: 671m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.43) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 355 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.351
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #872"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.4% · Safe to merge
    18.4%