Service accounts: scope permissions, protect credentials, and retire unused identities
Learn how to assign an owner and purpose to each service account, limit its permissions, prefer short-lived credentials, and safely review or retire it.
Service accounts: scope permissions, protect credentials, and retire unused identities
A service account is an identity that an application, automated job, or server uses to authenticate and act without a person signing in. Platforms may use other names, such as service principal, workload identity, or application identity, so check the actual principal and credential method rather than relying on the label. A service account still needs an owner, purpose, permissions, runtime, credential plan, and a process for expiry or revocation.
How service accounts differ from user accounts
A user account belongs to a person and is tied to that person's sign-in, recovery, and employment status. A service account is used by an automated process. It often cannot complete interactive MFA and may remain active for long periods or be connected to code, deployment systems, and cloud resources. Its protection therefore depends on how the workload proves its identity, which permissions it receives, how credentials are kept from being exposed, and how activity is monitored and access is revoked.
Every process using a service account inherits that account's permissions. If several applications or environments share one account, it becomes harder to identify the source of a compromise or stop just one workload. Where practical, assign a separate identity to each workload and environment, then restrict each identity to the resources and actions it needs.
Decide these items before creating one
| Item | Operational question |
|---|---|
| Accountable owner | Which team should be contacted if the account breaks or is no longer needed? |
| Purpose and runtime | Which application, job, or deployment pipeline uses it, and in which environment? |
| Permission scope | Which exact APIs, resources, and actions are needed? Are development and production permissions separate? |
| Authentication method | Can the runtime use an attached role, federated workload identity, or short-lived credentials? |
| Static secret | If a key is unavoidable, who stores, accesses, rotates, and revokes it, and what is disabled if it leaks? |
| Traceability and review | Can authentication and permission-use records be tied to a job or deployment ID? When are permissions reviewed? |
| Retirement | When a job ends or a team changes, are the account, keys, roles, tokens, and external trust links all removed? |
A practical operating sequence
**Confirm the need.** Before creating another service account, check whether the runtime offers a managed workload identity or an existing short-lived credential integration. Avoid reusing a person's password in an application.
**Assign it to one workload.** Record the owner, application, environment, data sensitivity, destinations, and expected usage. An account description alone is not a substitute for an accountable owner.
**Apply least privilege.** Separate required read, write, and administrative actions, and narrow them to specific projects, resources, or conditions. Check whether provider-created default accounts received broad permissions.
**Keep credentials short-lived and protected.** Prefer short-lived tokens or identity federation provided by the runtime. If a long-lived key is unavoidable, do not put it in source code, container images, repositories, logs, or ordinary configuration files. Deliver it from a controlled secrets store and document access, rotation, and revocation.
**Monitor use.** Check that the account is used only from the expected runtime and against expected APIs. Look for unusual locations, permissions, times, or call volumes. Make workload activity distinguishable from a person's interactive activity in logs.
**Review and retire deliberately.** If ownership or need is unclear, first check dependencies and the impact of stopping it; disable or isolate it where appropriate. Notify affected teams, observe errors and dependencies for a defined period, then remove the account, keys, and trust relationships.
When a static key is an exception
Some external tools or runtimes might not support short-lived identity federation. AWS, for example, documents that long-term access keys can be needed in specific situations where a workload cannot use an IAM role. This is a constrained exception, not the preferred general path. If it is necessary, use a dedicated identity with minimal permissions, controlled secret storage, regular key rotation, recent-use checks, and a rapid revocation procedure. Record a deadline and plan for moving to temporary credentials.
Google Cloud advises replacing service account keys with safer alternatives whenever possible and explains that someone holding a key can exercise the service account's permissions. Review not only roles granted to the account but also who can impersonate it. These are Google Cloud-specific mechanisms; the broader design concern on other platforms is that a stolen workload credential or overly broad delegation can grant the workload's access.
Example workflow and how to verify it
Suppose a fictional CI job uploads build artifacts to storage. First identify the CI runtime, then grant only the upload permission it needs on the destination bucket. Do not keep the token after the job finishes, and use a separate identity for deployment. In a controlled test, verify that upload to the approved location succeeds while reading or deleting another bucket and changing permissions are denied. This is an illustrative design, not a report of a real cloud test.
References
[Google Cloud service accounts overview](https://docs.cloud.google.com/iam/docs/service-account-overview) — service accounts, runtime attachment, short-lived credentials, impersonation, and permissions.
[Google Cloud service account security best practices](https://docs.cloud.google.com/iam/docs/best-practices-service-accounts) — risks associated with keys and impersonation.
[AWS IAM security best practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html) — role-based temporary credentials and exceptions for long-term keys.
[NIST SP 800-53 Rev. 5.1, AC-2 Account Management](https://csrc.nist.gov/CSRC/media/Projects/risk-management/800-53%20Downloads/800-53r5/SP_800-53_v5_1-derived-OSCAL.pdf) — account lifecycle and automated account-management controls. NIST is a control reference, not a universal law.