IncidentResponsev2

4.64 Validate No Unauthorized or Unsanctioned Accounts or API Keys Remain (Local, Cloud - IAM, Service Accounts, API Tokens)

Task

Identify and remove unauthorized, stale, or over-permissive user accounts, service accounts, and API credentials across local systems and cloud environments (AWS, Azure, GCP).


Conditions

Given access to local system account lists, AD accounts, cloud IAM and API credential stores.


Standards


End State

All unauthorized accounts and API credentials are identified, disabled/removed, and fully documented.


Notes


Manual Steps

Step 1: Enumerate Local System and Active Directory Accounts

Windows Local

Get-LocalUser

Look for:

Linux/macOS Local

cat /etc/passwd

Look for:

Active Directory

Get-ADUser -Filter * -Properties LastLogonDate, Enabled | Select-Object Name, Enabled, LastLogonDate

Look for:

Operator Note: Use AD group memberships to help identify high privilege accounts → validate necessity.


Step 2: Enumerate API Keys and Service Accounts - AWS

List IAM Users and Access Keys

aws iam list-users
aws iam list-access-keys --user-name USERNAME

Look for:

Identify Long-Lived API Keys

aws iam get-access-key-last-used --access-key-id KEY_ID

Look for:

Identify IAM Roles and Attached Policies

aws iam list-roles
aws iam list-role-policies --role-name ROLENAME

Look for:


Step 3: Enumerate API Keys and Service Accounts - Azure

Azure AD Users and Applications

Get-AzADUser
Get-AzADServicePrincipal

Look for:

Application Secrets and Certificates (API Tokens)

Get-AzADAppCredential -ObjectId OBJECT_ID

Look for:

Azure Automation RunAs Accounts

Get-AzAutomationAccount

Look for:


Step 4: Enumerate API Keys and Service Accounts - GCP

IAM Service Accounts and Roles

gcloud iam service-accounts list
gcloud projects get-iam-policy PROJECT_ID

Look for:

API Keys

gcloud alpha services api-keys list

Look for:

OAuth Client Secrets

gcloud iam service-accounts keys list --iam-account SERVICE_ACCOUNT_EMAIL

Look for:

Operator Note: API keys and service accounts are frequently exploited for lateral movement in cloud.


Step 5: Validate and Investigate Accounts / Keys

Operator Note: Absence of recent use + unknown owner = High Risk → escalate for removal.


Step 6: Remove or Disable Unauthorized or Unused Accounts / Keys

Local

Windows
Disable-LocalUser -Name "username"
Remove-LocalUser -Name "username"
Linux/macOS
sudo usermod -L username
sudo userdel username

Active Directory

Disable-ADAccount -Identity "username"
Remove-ADUser -Identity "username"

AWS

aws iam delete-user --user-name USERNAME
aws iam delete-access-key --user-name USERNAME --access-key-id KEYID
aws iam delete-role --role-name ROLENAME

Azure

Remove-AzADUser -ObjectId USERID
Remove-AzADServicePrincipal -ObjectId OBJECTID

GCP

gcloud iam service-accounts delete SERVICE_ACCOUNT_EMAIL
gcloud alpha services api-keys delete KEY_ID

Step 7: Validate Removal and Document


Dependencies


Other Available Tools

Tool Platform Installation Usage
PowerShell Windows Built-in AD + local account validation
AWS CLI Cross-platform Package manager IAM + access keys
Azure CLI / PowerShell Cross-platform Package manager Azure AD + app credentials
GCloud CLI Cross-platform Package manager IAM + API keys
CloudTrail / Sentinel / Security Command Center Cloud Native API and credential usage audit

Operator Recommendations and Additional Tools

Operator Checklist

Best Practices


References


Revision History

Date Version Description Author
2025-05-02 1.0 Created from scratch with deep operator guidance across local, AD, cloud IAM + API credentials Leo