Repository navigation
feat(helm): control-plane Deployment + Service + Secret + SA + RBAC (#96) - #107
girosole60 wants to merge 1 commit into
Conversation
rrskris
left a comment
There was a problem hiding this comment.
#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-dashboard2. 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 -dThat 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]>
31fc66b to
bc45529
Compare
|
Rebased onto
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. |
…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]>
…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
left a comment
There was a problem hiding this comment.
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:
- The scanner calls cluster-wide RBAC APIs, but
control-plane-rbac.yamlcreates a namespaced Role/RoleBinding. Itsclusterrolesandclusterrolebindingsgrants are ineffective, andserviceaccountsis missing for token-automount scanning. Match the read-only cluster scope indeploy/cronjob.yaml. - The chart defaults to
ghcr.io/kaaval/control-plane, while the publish workflow buildsghcr.io/kaaval/kaaval. Correct the image default as part of making the chart installable. controlPlane.envis documented as a map but rendered directly into the container'senvlist. Render map entries asname/valueitems, or change the declared contract consistently.serviceAccount.nameis 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.
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 toappVersiontemplates/control-plane-service.yaml— ClusterIP service, port 8000templates/control-plane-secret.yaml— Opaque Secret with admin-password, secret-key, refresh-secret-key, and database-url derived from the postgresql subcharttemplates/control-plane-serviceaccount.yaml— ServiceAccount, gated byserviceAccount.createtemplates/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/healthvalues.yamlwithcontrolPlane.service.targetPort: 8000Acceptance criteria
helm lintpasses (0 errors, 0 warnings)helm templaterenders all templates with correct names, selectors, and env vars/health(shallow), not/health?deep=1DATABASE_URLcomes from the postgresql subchart, never hardcodedVerify locally
Requires