Service accounts: non-human identities, their keys, and their reach
Service accounts outnumber people in most environments and rarely get reviewed. How to inventory them, replace static keys with workload identity, scope permissions, and detect interactive use.
Diagram
Reviewing one service account
Step 1 of 4
Find
List accounts and their keys.
$ gcloud iam service-accounts keys list --iam-account=etl@proj.iam.gserviceaccount.com KEY_ID CREATED_AT EXPIRES_AT 8f2a1c... 2023-02-14T10:12:00Z 9999-12-31T23:59:59Z
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
Static keys
- What fails
- Downloaded key files never expire unless someone deletes them.
- Who is affected
- Everything the account can reach, for as long as the key exists.
- What you would notice
- Keys older than 90 days, or never-expiring keys.
- What you change
- Replace with workload identity federation or managed identities.
Interactive use
- What fails
- People sign in as service accounts to get around MFA or approvals.
- Who is affected
- Audit trails, which lose the real person.
- What you would notice
- Console or interactive sign-ins by non-human accounts.
- What you change
- Block interactive sign-in and alert when it happens.
Unowned accounts
- What fails
- Accounts outlive the projects and people that created them.
- Who is affected
- Systems where old accounts still have rights.
- What you would notice
- Accounts with no owner tag and no recent use.
- What you change
- Require an owner tag and disable accounts unused for 90 days.
An inventory query per cloud
Each provider can list non-human identities and their last use. Start there, then join with your owner tags.
# AWS: users with access keys and last use
$ aws iam generate-credential-report && aws iam get-credential-report --query Content --output text | base64 -d | cut -d, -f1,9,10,11 | head
# Azure: service principals
$ az ad sp list --all --query "[].{name:displayName, created:createdDateTime}" -o tablePermissions follow usage
Use access analysis to see which permissions were actually used over 90 days, then remove the rest. AWS IAM Access Analyzer, GCP IAM Recommender, and Azure access reviews all produce that list.
Check yourself
Recognition and the fix. Nothing here is a procedure.
A service account key was created in 2023 and never expires. What is the better end state?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.
This page stands on its own. The lab and the glossary card are the next reading.