Skip to content

feat(helm): control-plane Deployment + Service + Secret + SA + RBAC (#96) - #107

Open
girosole60 wants to merge 1 commit into
kaaval:mainfrom
girosole60:feat/helm-96-deployment
Open

girosole60 wants to merge 1 commit into
kaaval:mainfrom
girosole60:feat/helm-96-deployment

Conversation

@girosole60

Copy link
Copy Markdown
Contributor

What

Control-plane templates on top of the skeleton from #103 (which must land first). Adds:

  • templates/control-plane-deployment.yaml — Deployment with liveness/readiness probes on /health (shallow, not deep), env from Secret refs (DATABASE_URL, KAAVAL_SECRET_KEY, etc.), securityContext (non-root, runAsUser=1000), checksum annotation for rolling restart, image tag defaults to appVersion
  • templates/control-plane-service.yaml — ClusterIP service, port 8000
  • templates/control-plane-secret.yaml — Opaque Secret with admin-password, secret-key, refresh-secret-key, and database-url derived from the postgresql subchart
  • templates/control-plane-serviceaccount.yaml — ServiceAccount, gated by serviceAccount.create
  • templates/control-plane-rbac.yaml — Role + RoleBinding for Kubernetes RBAC read access (pods, services, deployments, roles, rolebindings, etc.)
  • templates/tests/test-connection.yaml — Helm test hook hitting /health
  • Updated values.yaml with controlPlane.service.targetPort: 8000

Acceptance criteria

  • helm lint passes (0 errors, 0 warnings)
  • helm template renders all templates with correct names, selectors, and env vars
  • Probes use /health (shallow), not /health?deep=1
  • DATABASE_URL comes from the postgresql subchart, never hardcoded
  • ServiceAccount, RBAC, and Secret are all created and properly referenced

Verify locally

cd deploy/helm/kaaval
helm dependency update
helm lint .
helm template .

Requires

@rrskris rrskris left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

#103 is merged, so this can be reviewed on its own diff now — please rebase onto main and the Chart.yaml/values.yaml/workflow commits will drop out, leaving just the templates.

The template structure is good: _helpers.tpl with proper fullname/labels/selectorLabels, a checksum/secret pod annotation so a secret change actually rolls the pods, a non-root securityContext, probes wired to named ports, and — the thing #102 got wrong — the Secret template really does create <fullname>-secrets, matching every secretRef/secretKeyRef in the Deployment. You also caught that the Deployment needs service.targetPort and added it to values. helm lint and helm template both pass.

But I rendered the chart and traced the references, and a default helm install cannot come up. Three of these are dangling references to things that don't exist — the same class of problem as #102, so I want to be precise about each.

1. The image doesn't exist

image: "ghcr.io/kaaval/control-plane:1.1.0"

publish.yml builds ghcr.io/kaaval/kaaval from the control-plane/ context and ghcr.io/kaaval/kaaval-dashboard from dashboard/. The image names are not the directory names. As rendered, this is ImagePullBackOff. Fix in values.yaml:

controlPlane:
  image:
    repository: ghcr.io/kaaval/kaaval
dashboard:
  image:
    repository: ghcr.io/kaaval/kaaval-dashboard

2. DATABASE_URL points at a Service that isn't rendered

The Secret builds the host as printf "%s-postgresql" (include "kaaval.fullname" .). Rendered, that is:

postgresql://kaaval:@release-name-kaaval-postgresql:5432/kaaval_db

The Bitnami subchart actually renders its Service as release-name-postgresql — I checked the output, the only Services are release-name-postgresql, release-name-postgresql-hl, and release-name-kaaval-control-plane. There is no release-name-kaaval-postgresql, so DNS resolution fails. A subchart names itself from its own fullname, not the parent's. Use printf "%s-postgresql" .Release.Name, or better, template off the subchart's own naming so fullnameOverride can't desync it.

3. …and the password in it is empty

Same string: postgresql://kaaval:@… — no password. With the default postgresql.auth.password: "", Bitnami generates a random password into its own secret. This chart hardcodes an empty one, so even with the hostname fixed, auth fails.

The values comment says the password is "REQUIRED in production", but this isn't only a production problem — the default install is broken. Either read the generated credential via postgresql.auth.existingSecret, or make the password required so the chart refuses to install half-configured rather than failing at runtime.

4. A namespaced Role cannot grant cluster-scoped resources

control-plane-rbac.yaml creates a Role + RoleBinding whose rules include clusterroles and clusterrolebindings. Kubernetes accepts that YAML without complaint, but the grant is silently inert: cluster-scoped resources are only reachable through a ClusterRole + ClusterRoleBinding. So list_cluster_role() — Kaaval's core cluster-wide RBAC scan — will 403 at runtime while the manifests look correct.

This needs splitting the way deploy/cronjob.yaml already does it: a namespaced Role for the namespaced resources, and a separate ClusterRole/ClusterRoleBinding for clusterroles/clusterrolebindings. Worth copying that file's shape directly, since it's the reviewed precedent.

While you're there: add serviceaccounts to the core-group read. #108 landed the CIS 5.1.6 token_automount rule since you opened this, and it reads ServiceAccount automount settings plus pod specs — see #119 for the equivalent fix I just made to deploy/cronjob.yaml. You have pods already; serviceaccounts is missing.

5. serviceAccount.create: false leaves a dangling reference

The ServiceAccount template is wrapped in {{- if .Values.serviceAccount.create }}, but the Deployment sets serviceAccountName: {{ include "kaaval.controlPlane.fullname" . }} unconditionally. Set create: false and the Deployment references a ServiceAccount that was never rendered. Relatedly, serviceAccount.name exists in values but nothing reads it.

The standard fix is one helper used by both:

{{- define "kaaval.controlPlane.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{- default (include "kaaval.controlPlane.fullname" .) .Values.serviceAccount.name -}}
{{- else -}}
{{- default "default" .Values.serviceAccount.name -}}
{{- end -}}
{{- end }}

6. Empty signing keys install silently

secrets.secretKey and secrets.refreshSecretKey default to "", so KAAVAL_SECRET_KEY="" reaches the control plane and JWTs get signed with an empty key. For a security product that should be a hard install failure, not a runtime surprise — required "secrets.secretKey must be set — generate with: openssl rand -hex 32" is the blunt version, and matches what .env.example already says about these being mandatory.


Items 1, 2, 3 and 4 are the blockers; 5 and 6 I'd like but won't hold the PR over if you'd rather split them out. To verify locally the way I did:

helm dependency update deploy/helm/kaaval
helm template deploy/helm/kaaval | grep -E 'image:|name: release-name'
helm template deploy/helm/kaaval | grep database-url | awk '{print $2}' | base64 -d

That last one is worth adding to your own loop — decoding the rendered secret is what turns "the template looks right" into "the connection string is right".

One aside you might enjoy: I piped the rendered chart through Kaaval's own scanner and it reported zero findings, including on the namespaced-Role-granting-cluster-resources mistake in item 4. That's a genuine gap in Kaaval's rule set rather than anything wrong with your chart, and I'm filing it as a rule request — your PR found us a missing detection.

Nothing here is a rewrite; it's mostly three strings and splitting one Role. Ping me when it's pushed and I'll re-verify the same way.

…emplates (kaaval#96)

- control-plane-deployment.yaml: probes (/health), env from secrets, securityContext, checksum annotation, image from values with appVersion fallback
- control-plane-service.yaml: ClusterIP, http port
- control-plane-secret.yaml: admin-password, secret-key, refresh-secret-key, database-url (from postgresql subchart)
- control-plane-serviceaccount.yaml: create on serviceAccount.create flag
- control-plane-rbac.yaml: Role/RoleBinding for k8s RBAC read
- tests/test-connection.yaml: helm test hook
- values.yaml: add targetPort: 8000

Signed-off-by: girosole60 <[email protected]>
@girosole60
girosole60 force-pushed the feat/helm-96-deployment branch from 31fc66b to bc45529 Compare September 16, 2026 15:19
@girosole60

Copy link
Copy Markdown
Contributor Author

Rebased onto main (6543c0e) as requested. The deploy/helm/ skeleton and the helm-lint workflow commits dropped out of the diff, leaving just the templates.

  • Diff is now deploy/helm/kaaval/templates/* (7 files) plus one line in values.yaml (targetPort: 8000) — 8 files, +250.
  • No conflicts after the rebase; the branch had gone dirty against main, it's clean now.
  • I also ran the verify block you said you couldn't check from your machine. Helm v4.2.3 locally (CI pins v3.14.4):
    • helm lint deploy/helm/kaaval → 1 chart(s) linted, 0 chart(s) failed
    • helm template deploy/helm/kaaval → 14 documents, all with apiVersion/kind, parsed clean
    • Caveat: kubectl isn't installed here, so I validated the rendered YAML with a YAML parser rather than actually running kubectl apply --dry-run=client -f -. That part of the acceptance criteria is still only covered by inspection, not executed on my side.
  • Acceptance details re-checked in the rendered output: both probes hit /health only (no ?deep=1), and DATABASE_URL / KAAVAL_SECRET_KEY / KAAVAL_REFRESH_SECRET_KEY / KAAVAL_ADMIN_PASSWORD all come from secretKeyRef, never literals.

All checks are green on this head (dco, lint, control-plane, dashboard, invigil, CodeQL). Ready for re-review — and I'm still interested in #97/#98 if they're unclaimed.

shariqueahmad108-ship-it added a commit to shariqueahmad108-ship-it/kaaval that referenced this pull request Sep 25, 2026
…aaval#120)

New rule_type ineffective_cluster_scope_grant (MEDIUM): a namespaced Role
whose rules name cluster-scoped resources (clusterroles,
clusterrolebindings, nodes, persistentvolumes, namespaces, CRDs, …). The
manifest applies cleanly but that part of the grant is inert, so the
workload hits 403s at runtime; this is the grant from kaaval#107's Helm chart.

Resources are matched per API group, so a same-named CRD in another group
doesn't fire; absent api_groups is treated as unspecified, like
effective_access. resources: ["*"] is left to wildcard_permissions, and
ClusterRoles are never flagged.

Remediation moves the resources into a ClusterRole + ClusterRoleBinding.
No CIS control covers this, so the citation is the Kubernetes RBAC docs
(#role-and-clusterrole). Adds the rbac-lister fixture (kaaval#20) and a
docs/rbac-rules.md row and note. The fixture scan stays at CRITICAL=1.

Closes kaaval#120

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: shariqueahmad108-ship-it <[email protected]>
shariqueahmad108-ship-it added a commit to shariqueahmad108-ship-it/kaaval that referenced this pull request Sep 25, 2026
…aaval#120)

New rule_type ineffective_cluster_scope_grant (MEDIUM): a namespaced Role
whose rules name cluster-scoped resources (clusterroles,
clusterrolebindings, nodes, persistentvolumes, namespaces, CRDs, …). The
manifest applies cleanly but that part of the grant is inert, so the
workload hits 403s at runtime; this is the grant from kaaval#107's Helm chart.

Resources are matched per API group, so a same-named CRD in another group
doesn't fire; absent api_groups is treated as unspecified, like
effective_access. resources: ["*"] is left to wildcard_permissions, and
ClusterRoles are never flagged.

Remediation moves the resources into a ClusterRole + ClusterRoleBinding.
No CIS control covers this, so the citation is the Kubernetes RBAC docs
(#role-and-clusterrole). Adds the rbac-lister fixture (kaaval#20) and a
docs/rbac-rules.md row and note. The fixture scan stays at CRITICAL=1.

Closes kaaval#120

Signed-off-by: shariqueahmad108-ship-it <[email protected]>

@rrskris rrskris left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The rebase and DCO cleanup are in place, and the explicit secret references and shallow health probes make the deployment easier to inspect. There are still functional deployment blockers in the templates:

  1. The scanner calls cluster-wide RBAC APIs, but control-plane-rbac.yaml creates a namespaced Role/RoleBinding. Its clusterroles and clusterrolebindings grants are ineffective, and serviceaccounts is missing for token-automount scanning. Match the read-only cluster scope in deploy/cronjob.yaml.
  2. The chart defaults to ghcr.io/kaaval/control-plane, while the publish workflow builds ghcr.io/kaaval/kaaval. Correct the image default as part of making the chart installable.
  3. controlPlane.env is documented as a map but rendered directly into the container's env list. Render map entries as name/value items, or change the declared contract consistently.
  4. serviceAccount.name is ignored, and the database URL always assumes a bundled database and literal password despite the existing-secret/disabled-database settings in values.yaml. Honor those settings or explicitly reject unsupported combinations.

Please validate both default and customized values, including a release name other than kaaval, a custom service account, and non-empty env. The issue remains open until the rendered deployment can perform the scanner's required reads.

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