Service accounts
| Type | Identity for a program, a server or an integration |
|---|---|
| Also known as | Machine identity, non-human identity, workload identity |
| Credentials | Short-lived tokens issued to the running workload, or long-lived keys |
| Platforms | Google Cloud, Kubernetes, AWS, Microsoft Entra, Linux |
| Related | Short-lived credentials and OIDC federation, Orphaned access tokens |
A nightly job that copies a database export into cloud storage runs with nobody at the keyboard, yet the storage service still has to know who is calling and what that caller may do. The answer is a service account: an account that belongs to a program or a compute workload instead of a person.1 The account receives permissions like any user, and the program proves it is that account with a credential.
Names by platform
On Google Cloud an account is identified by a unique email address and is both a principal, which can be granted roles, and a resource, on which other people can be granted roles.1 Kubernetes keeps a ServiceAccount object per namespace and separates it from user accounts by purpose: workloads and automation on one side, people on the other.2 Microsoft Entra groups applications, service principals and managed identities as workload identities.3
| Platform | Identity | Credential handed to the running program |
|---|---|---|
| Google Cloud | Service account attached to a VM or service | OAuth 2.0 access token, valid 1 hour by default |
| Google Cloud | Service account with a downloaded key | Private key file, no expiry unless one is set |
| Kubernetes 1.22 and later | ServiceAccount assigned to a Pod | Projected token that expires and is rotated |
| Kubernetes, token Secret | ServiceAccount | Token that never expires or rotates |
| AWS | IAM role on EC2 or Lambda | Temporary credentials picked up by the SDK |
| Azure | Managed identity | Entra token; the credential is not visible to the developer |
Attached credentials and keys
A program can authenticate as a service account in two ways. In the first, the account is attached to the machine or service that runs the program, and the platform hands the program short-lived access tokens; on Google Cloud they expire after one hour unless configured otherwise, and the private half of Google's own signing key pair stays in escrow where no customer can read it.4 AWS delivers a role's temporary credentials to EC2 and Lambda the same way, so no long-lived user key has to be copied to the workload.5 An Azure system-assigned managed identity lives and dies with its resource: deleting the virtual machine deletes the identity.3
In the second, someone creates a key. A Google service account can hold up to ten user-managed keys; Google keeps only the public part and returns the private key to the person who created it, who downloads it as a file.4 The program signs a JSON Web Token with that file and trades it for an access token. Such a key stays valid until it is deleted, because none is given an expiry date by default.6
Kubernetes went through the same change. Since version 1.22 a Pod receives a token from the TokenRequest API, mounted as a projected volume, which expires and is replaced automatically. Before 1.24 the cluster created a permanent token for every service account, stored as a Secret that never expired.2
Why the keys are valuable
A leaked password is unlikely to work against an account that uses two-step verification. A service account has no extra sign-in check, so a leaked key is likely to work.6 Attackers look for keys in open-source repositories, public storage buckets and data dumps from breached services, and, inside networks they have broken into, in email inboxes, file shares, backups and temporary folders. Removing a committed key from the repository does not help, since the history keeps it; the key has to be deleted in the cloud account (Exposed credentials in source code repositories).6
Permissions travel with the account. Anyone allowed to impersonate a service account can reach everything that account can reach.1 Two defaults widen this. The Compute Engine and App Engine default accounts receive the Editor role on their project when they are created, and every Kubernetes Pod without an assigned account runs as its namespace's default account.12 An account with more rights than its job needs is an over-privileged token.
Forgotten accounts
In October 2023 an attacker who broke into Okta obtained a batch of Cloudflare credentials. Cloudflare meant to rotate all of them, but out of thousands it missed one service token and three service accounts, in the mistaken belief that they were unused.7 One belonged to the Smartsheet integration and held administrator rights in Jira. On 16 November the attacker used it to create an ordinary-looking Atlassian user and add it to groups, so that access would survive the removal of the service account; on 22 November the same rights let them install the Sliver command-and-control tool through a Jira plugin. The clean-up that followed replaced more than 5,000 production credentials.7
Google treats an account with no activity for more than 180 days as dormant and advises disabling an unused account before deleting it, since a disabled account can be switched back on if something breaks.1 On AWS, unused users, roles and credentials are meant to be reviewed and removed on a regular basis.5
Reducing the exposure
Attaching the account to the workload, or using OIDC federation for systems outside the cloud, means no key file exists to leak. Google Cloud organizations created on or after 3 May 2024 block key creation and key upload by default; older ones can enforce the same two policy constraints. Where a key must exist, it can be given an expiry time, and a policy set to DISABLE_KEY makes Google disable keys it finds exposed in public, without a promise that it finds them all.6 Keys that remain are rotated on a schedule (Rotating API keys at each provider).
Each workload gets its own account with only the roles it uses (Principle of least privilege), and the automatic Editor grant for default accounts is switched off.1 In Kubernetes, a Pod that never calls the cluster API can refuse the token outright:2
apiVersion: v1
kind: Pod
metadata:
name: report-job
spec:
automountServiceAccountToken: false
containers:
- name: app
image: example/report:1.0On a Linux server
A Linux server has its own service accounts: system users created with useradd --system, which take their user IDs from a separate range (from 101 by default) and get no password ageing data.8 System accounts such as http or ftp usually get nologin as their shell, a program that refuses every login.9
In SecFlash
SecFlash reports a change to an account's user ID, login shell or password state as SF-DET-104 on the Detections page; a service account that gains a shell or a password becomes a way to log in.
See also
- Secrets management
- Cloud instance metadata service
- Additional cloud credentials
- Stolen cloud credentials
- Serverless function abuse
- Stolen OAuth tokens
- Default credentials
- Cloud discovery
- Category: Secrets
References
- a b c d e f Google Cloud (n.d.). "Service accounts overview". Google Cloud IAM documentation.
- a b c d Kubernetes (n.d.). "Service Accounts". Kubernetes Documentation.
- a b Microsoft (n.d.). "What are managed identities for Azure resources?". Microsoft Learn.
- a b Google Cloud (n.d.). "Service account credentials". Google Cloud IAM documentation.
- a b "Security best practices in IAM". AWS Identity and Access Management User Guide. Amazon Web Services.
- a b c d Google Cloud (n.d.). "Best practices for managing service account keys". Google Cloud IAM documentation.
- a b Prince, M., Graham-Cumming, J. and Bourzikas, G. (1 February 2024). "Thanksgiving 2023 security incident". The Cloudflare Blog.
- back "useradd(8)". Linux manual pages. man7.org.
- back "nologin(8)". Linux manual pages. man7.org.