AKS Cron Job

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an aks cron job by defining a schedule and a pod template. The cluster controller then creates a new job object at each scheduled time. Platform teams use these scheduled workloads for backups, data syncs, and report builds. Teams often grant broad cluster roles to both the job pods and the engineers who fix them. When roles are too broad, one bad script or shell command can affect the whole namespace. How an aks cron job works with Kubernetes permissions A scheduled workload in Ku

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up an aks cron job by defining a schedule and a pod template. The cluster controller then creates a new job object at each scheduled time. Platform teams use these scheduled workloads for backups, data syncs, and report builds. Teams often grant broad cluster roles to both the job pods and the engineers who fix them. When roles are too broad, one bad script or shell command can affect the whole namespace.

How an aks cron job works with Kubernetes permissions

A scheduled workload in Kubernetes runs pods on a repeating timer. Each time the timer fires, the control plane starts a job pod. That pod runs its container command and stops when the task finishes. To talk to the cluster API or read secrets, the pod uses a service account. Engineers also need cluster permissions to check job status, read logs, or start a manual test run.

Kubernetes controls these permissions through role-based rules on the API server. A Role sets permissions inside one namespace. A ClusterRole sets rules across the whole cluster or for cluster-scoped resources like nodes. Permissions in Kubernetes are additive, which means there are no deny rules. You link a Role or ClusterRole to a user or service account with a RoleBinding. If you use a ClusterRoleBinding, those permissions apply across every namespace in the cluster.

Engineers who watch scheduled jobs also use subresources in the API. Reading container output requires permission on the pod log subresource. Opening a shell inside a running job pod requires permission on the pod exec subresource. When you build roles for your team, you list these subresources with a slash after the pod resource name.

What native RBAC solves and what it leaves open

Native Kubernetes roles do a good job of controlling who can talk to the API server. You can limit a developer so they only see jobs in a single namespace. You can also separate read-only log permissions from full pod creation rights. This keeps users out of namespaces they do not own.

Still, native role bindings stop at the API check. Once RBAC allows a user to run an exec session inside a job pod, the cluster steps back. Kubernetes does not check individual shell commands inside that session. If a scheduled pod holds database keys or cloud tokens, any engineer with exec rights can read them.

AKS Managed Identity: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

The same problem happens when engineers read job output or run one-off tasks against production data. A job script might print customer emails, phone numbers, or card numbers to the log stream. Native RBAC only decides if a user can open the log or start the shell. It cannot mask sensitive fields in flight or ask for peer review before a risky command runs.

How to tighten scheduled job security in daily operations

Start by giving each scheduled workload its own dedicated service account. Bind that account to a namespace Role instead of a ClusterRole whenever possible. Only list the exact API resources and verbs the job needs to finish its task.

Next, separate day-to-day viewing permissions from debugging permissions for your engineering team. Give engineers access to view job status in their namespace Role. Keep pod exec permissions out of standard developer roles. When someone must run commands inside a job container, you need controls that inspect the session itself.

Check Kubernetes API requests and responses on the wire

Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.

On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.

Frequently asked questions

How do I let an engineer read job logs without granting shell access?

Create a namespace Role that grants get and list verbs on the pods log subresource. Do not include the pods exec subresource in that Role, and bind it with a RoleBinding.

Why should I avoid ClusterRoleBinding for an aks cron job?

A ClusterRoleBinding grants permissions across every namespace in the cluster. Using a namespace RoleBinding limits the service account or user to one specific namespace.

Can Kubernetes RBAC block specific shell commands inside a job pod?

No, Kubernetes RBAC only checks if a user has permission to call the pod exec subresource. It does not inspect or block the shell commands that run inside the container.

The query runs. The emails stay hidden.