RBAC and ServiceAccounts

Configure ServiceAccounts, namespace-scoped RBAC roles via chart.rbac.roleRules, and chart.imagePullSecrets securely following least privilege.

RBAC and ServiceAccounts

In Chart mode, ohMyHelm manages the ServiceAccount, optional namespace-scoped RBAC permissions (Role and RoleBinding), and imagePullSecrets through three clearly separated keys directly under chart:.

Correct Configuration Keys at a Glance

Purpose Actual Key Generated Resources
Create/name a ServiceAccount chart.serviceAccount (create, annotations, name) v1/ServiceAccount
Enable namespace RBAC & rules chart.rbac (enabled, roleRules) rbac.authorization.k8s.io/v1/Role + RoleBinding
Private registry pull secrets chart.imagePullSecrets spec.template.spec.imagePullSecrets on the Pod

Configuring a ServiceAccount (chart.serviceAccount)

By default, ohMyHelm creates a dedicated ServiceAccount in Chart mode (create: true) whose name matches ohmyhelm.fullname:

chart:
  enabled: true
  fullnameOverride: "acme-api"

  serviceAccount:
    create: true
    name: ""          # Empty = ohmyhelm.fullname (here: acme-api)
    annotations:
      eks.amazonaws.com/role-arn: "arn:aws:iam::123456789012:role/acme-api"

If you want to use an existing ServiceAccount in the namespace, set create: false and specify its name (if name is left empty, the Pod falls back to default):

chart:
  enabled: true
  serviceAccount:
    create: false
    name: "existing-acme-sa"

Configuring Namespace RBAC (chart.rbac)

With chart.rbac.enabled: true, ohMyHelm creates the following resources in the release namespace:

  • a Role named <serviceAccountName>-role
  • a RoleBinding named <serviceAccountName>-rolebinding that binds this Role to the configured ServiceAccount

Example: Minimal Permissions for the Wait-for-Job Init Container

chart:
  enabled: true
  fullnameOverride: "acme-backend"

  serviceAccount:
    create: true

  rbac:
    enabled: true
    roleRules:
      - apiGroups: ["batch"]
        resources: ["jobs"]
        verbs: ["get", "list", "watch"]

Example: Read-Only Access to Specific ConfigMaps

chart:
  enabled: true
  fullnameOverride: "acme-config-reader"

  rbac:
    enabled: true
    roleRules:
      - apiGroups: [""]
        resources: ["configmaps"]
        resourceNames: ["acme-feature-flags"]
        verbs: ["get", "watch"]

Image Pull Secrets (chart.imagePullSecrets)

Reference the names of your registry secrets directly under chart.imagePullSecrets (for example, created using the imageCredentials helper):

imageCredentials:
  - name: acme-registry-secret
    namespace: acme-prod
    registry: https://registry.acme.corp
    username: ci-pull-bot
    accessToken: "<token>"

chart:
  enabled: true
  fullnameOverride: "acme-backend"
  imagePullSecrets:
    - name: acme-registry-secret
  container:
    image: registry.acme.corp/backend:2.0.0

ClusterRole and ClusterRoleBinding

chart.rbac creates only namespace-scoped Role and RoleBinding resources. If a workload requires cluster-wide permissions (ClusterRole / ClusterRoleBinding), define them cleanly using the manifests helper:

manifests:
  - apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    content:
      metadata:
        name: acme-node-reader
      rules:
        - apiGroups: [""]
          resources: ["nodes"]
          verbs: ["get", "list", "watch"]

  - apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    content:
      metadata:
        name: acme-node-reader-binding
      subjects:
        - kind: ServiceAccount
          name: acme-node-agent
          namespace: acme-ops
      roleRef:
        apiGroup: rbac.authorization.k8s.io
        kind: ClusterRole
        name: acme-node-reader

Related Pages