ingest tags every record with a tenant_id Kafka header (built previously), but nothing consumed it to actually route the write. This closes that for ClickHouse: enterprise/cmd/enterprise-ingest (a second binary, mirroring enterprise-api) reuses ingest/consumer's own flush loop unchanged, with enterprise/internal/chwriter.Registry -- a per-tenant clickhousewriter.Writer registry -- swapped in as the writer. A batch pulled from the single shared Redpanda topic can mix records from many tenants, so WriteBatch groups by TenantID and dispatches each group to its own tenant's connection, fail- closed on an empty or unrecognized tenant_id. ingest/consumer and ingest/clickhousewriter move out of internal/ (same reason api/internal/* moved earlier this phase: enterprise/ can't import anything under another module's internal/). Their New() constructors now take small local Config structs instead of ingest/internal/config types, so enterprise/ doesn't need that import either. Building this surfaced a real bug: tenantprovision.ProvisionClickHouse only granted SELECT on a tenant's ClickHouse user, correct for chrunner's read-only use but not enough for chwriter reusing the same credential to write -- every real per-tenant write would have failed closed with a permission error. Fixed by widening the grant to SELECT, INSERT; no cross-tenant boundary is crossed by also allowing INSERT within a tenant's own database. Helm gates enterprise-ingest's Deployment on the same ingest.requireTenantCredential flag that already gates tag validation -- write-routing is meaningless without tagging already being required, so they're one decision, not two. docker-compose.yml's version is a disclosed, weaker approximation: it can't achieve Helm's genuine -mode=server/-mode=consumer split, so with the enterprise profile active both ingest and enterprise-ingest independently consume every message via different consumer groups -- harmless duplication for local verification only. Not built: Tantivy's independent Redpanda consumer (search/src/consumer.rs) still doesn't read the tenant_id header at all -- every record still lands in the one shared index regardless of tenant. Not run: the live-ClickHouse- gated tests (chwriter's cross-tenant routing test, tenantprovision's INSERT regression test) -- no Docker/database access in this environment; they're correct Go that has never executed, disclosed as such in docs/security/ threat-model.md and docs/phase-4-runbook.md §14.
deploy
Kubernetes deployment for Sentry, added in Phase 4 (/deploy was
deliberately stubbed through Phase 3 -- see /CLAUDE.md's Phase 3
non-goals). Two pieces:
operator/-- a small Go controller-runtime Operator managing one CRD (Tenant). Seeoperator/README.md.helm/sentry/-- a Helm chart covering everydocker-compose.ymlservice, plus the operator andTenantCRs whenenterprise.enabled=true. Seehelm/sentry/README.md.
What "multi-tenant-aware" means here, precisely
Per /docs/phase-4-isolation-design.md, tenant isolation itself lives at
the application layer inside enterprise/ (enterprise-api holds a
map of per-tenant ClickHouse connection pools via internal/chrunner;
search holds a map of per-tenant Tantivy indices via
src/registry.rs) -- not at the Kubernetes layer. This directory is
not "one Deployment per tenant" or a general multi-cluster system;
that's an explicit Phase 4 non-goal (see /CLAUDE.md). What it does
add:
- A
TenantCRD + controller (operator/internal/controller) that reflects real provisioning state ontostatus.phase/aReadycondition, derived from whetherenterprise-api -provision-tenanthas reported real ClickHouse provisioning. - A Helm chart that can install zero-or-more
TenantCRs (values.tenants) alongside the rest of the stack, and swapsapi's Deployment forenterprise-api's wheneverenterprise.enabledis true, so which query binary actually serves traffic is no longer a separately-forgettable decision (seehelm/sentry/README.md's "apivsenterprise-api" section).
Now unified, in a deliberately lightweight way: enterprise-api -provision-tenant=<id> stays the sole real actor — it's the only thing
that calls ClickHouse (CREATE DATABASE/CREATE USER/GRANT, via
enterprise/internal/tenantprovision) and writes rbacstore. What
changed: once it succeeds, it also syncs the result into the Tenant
CRD (enterprise/internal/tenantcrd) — creating the Secret with real
credentials (the controller no longer generates a placeholder one that
authenticated against nothing) and setting the status fields the
controller reads to compute Phase/Ready. The controller itself
gained no new credentials and still never touches ClickHouse/Postgres --
it's a pure function of spec.suspended and whatever
-provision-tenant has reported, never an independent second guess at
"is this tenant really provisioned." A Tenant reaching
status.phase: Active now means the same thing rbacstore.tenants. status='active' does, not two different claims — see
enterprise/internal/tenantcrd's and operator/internal/controller/ tenant_controller.go's doc comments for the full split, and
enterprise-api -provision-tenant's TENANT_CRD_NAMESPACE env var
(set automatically by the Helm chart when tenantOperator.enabled) to
turn this on. Deliberately not built: the operator's reconcile loop
itself calling ClickHouse/rbacstore directly (a "full unification"
option considered and set aside — it would give the operator two new
credential sets and require real reconcile-loop idempotency design for
an inherently one-shot external side effect, a bigger and riskier
change than this repo's provisioning story needed to close the actual
gap, which was two disconnected sources of truth, not two actors).
Verification status -- read before trusting this against a real cluster
Not verified against a live Kubernetes cluster. This environment has
no kubectl/kind/minikube/kubebuilder/cluster reachable, so
nothing here has been kubectl apply'd or helm install'd for real.
Same disclosed-limitation shape as /agent/README.md's "Windows-specific
agent code remains unverified on real Windows" from Phase 1 -- a real gap
to close before shipping, not swept under the rug.
What was actually verified, offline, in this environment (network access was available to fetch these tools, but no cluster):
deploy/operator:go build/go vet/go test ./...all pass, including reconciler tests against controller-runtime's fake client (internal/controller/tenant_controller_test.go) -- real reconcile logic exercised, but not against a real apiserver (noenvtestbinaries available; see that test file's doc comment).enterprise/internal/tenantcrd(the "lightweight unification" half-provision-tenantruns):go testpasses againstk8s.io/client-go's fake dynamic and typed clientsets -- real client library, fake transport, same shape asenterprise/internal/ searchclient's in-process gRPC tests. What this doesn't prove: thatsentry.io/v1alpha1.Tenant's real CRD schema (a real apiserver's OpenAPI validation) accepts exactly what this package writes -- thehelm template/kubeconform check below covers the schema shape, not a live write against it.deploy/operator/config/crd/sentry.io_tenants.yaml: parsed withsigs.k8s.io/yaml+ strict-unmarshaled into the realk8s.io/apiextensions-apiserverCustomResourceDefinitionGo type -- catches YAML syntax errors and structural mistakes, not a live-cluster admission check.deploy/helm/sentry:helm lintpasses;helm templaterenders cleanly under both default values and aenterprise.enabled: true+ two-tenant override; the rendered output was checked withkubeconform -strictagainst the real Kubernetes 1.31 OpenAPI schema for every built-in resource kind (22-31 resources depending on values, 0 invalid) -- this catches schema mistakes (wrong field names, wrong types) but not whether the resources actually reconcile correctly together on a live cluster (Job/StatefulSet startup ordering, PVC provisioning, actual pod scheduling). Specifically confirmed by parsing the rendered YAML (not just eyeballing it): exactly oneDeployment/Servicenamedsentry-apirenders in each mode, with theenterprise.enabled: truerender using theenterprise-apiimage and the default render using plainapi's. Also confirmed for thetenantOperator.enabled: truecase:enterprise-apigets its own ServiceAccount/Role/RoleBinding (exactlytenants/tenants/status/secrets, no more),tenant-operator's own ClusterRole no longer grantssecretsat all, andTENANT_CRD_NAMESPACEis set onenterprise-api's container only whentenantOperator.enabledis true.- Docker image builds (
operator/Dockerfileand every otherDockerfilethis chart references) were not verified in this session -- Docker's daemon wasn't reachable here either (see the Phase 4 task 5 conversation for why). Build and push every image this chart'svalues.yamlreferences before installing it.
Before relying on this in production: kind create cluster, helm install with --include-crds, and walk through
helm/sentry/README.md's two-tenant example end to end.