Skip to content

fix: replace autodelete ClusterRoleBinding+default SA with scoped RoleBinding#406

Open
mgrzybek wants to merge 6 commits into
mainfrom
fix/c2-autodelete-serviceaccount
Open

fix: replace autodelete ClusterRoleBinding+default SA with scoped RoleBinding#406
mgrzybek wants to merge 6 commits into
mainfrom
fix/c2-autodelete-serviceaccount

Conversation

@mgrzybek

Copy link
Copy Markdown
Contributor

The autodelete CronJob was created without a dedicated ServiceAccount, falling back to default. The operator then bound default to the cluster-wide azimuth-caas-operator:edit ClusterRole, which granted every workload sharing that ServiceAccount in the namespace the ability to manage CaaS resources.

Changes in create_scheduled_delete_job:

  • Create a dedicated ServiceAccount autodelete-<cluster> in the tenant namespace with an ownerReference on the Cluster object so it is garbage-collected automatically on cluster deletion.
  • Replace the ClusterRoleBinding (cluster-scoped, default SA) with a namespaced RoleBinding targeting the new SA. A RoleBinding that references a ClusterRole scopes its permissions to the namespace.
  • Inject serviceAccountName into the CronJob pod spec.
  • Add pod-level securityContext (runAsNonRoot, runAsUser 65534, seccompProfile RuntimeDefault) and container-level securityContext (allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, capabilities.drop ALL).
  • Reorder resource creation: ConfigMap → ServiceAccount → RoleBinding → CronJob, so the CronJob always starts with its identity and permissions in place.

…eBinding

The autodelete CronJob was created without a dedicated ServiceAccount,
falling back to `default`. The operator then bound `default` to the
cluster-wide `azimuth-caas-operator:edit` ClusterRole, which granted
every workload sharing that ServiceAccount in the namespace the ability
to manage CaaS resources.

Changes in create_scheduled_delete_job:
- Create a dedicated ServiceAccount `autodelete-<cluster>` in the
  tenant namespace with an ownerReference on the Cluster object so it
  is garbage-collected automatically on cluster deletion.
- Replace the ClusterRoleBinding (cluster-scoped, `default` SA) with a
  namespaced RoleBinding targeting the new SA. A RoleBinding that
  references a ClusterRole scopes its permissions to the namespace.
- Inject serviceAccountName into the CronJob pod spec.
- Add pod-level securityContext (runAsNonRoot, runAsUser 65534,
  seccompProfile RuntimeDefault) and container-level securityContext
  (allowPrivilegeEscalation: false, readOnlyRootFilesystem: true,
  capabilities.drop ALL).
- Reorder resource creation: ConfigMap → ServiceAccount → RoleBinding →
  CronJob, so the CronJob always starts with its identity and
  permissions in place.
@mgrzybek
mgrzybek requested a review from a team as a code owner June 22, 2026 09:52
mgrzybek added 2 commits June 22, 2026 11:58
Signed-off-by: Mathieu Grzybek <mathieu@stackhpc.com>
Signed-off-by: Mathieu Grzybek <mathieu@stackhpc.com>
irt-shpc
irt-shpc previously approved these changes Jun 29, 2026
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