Skip to content
Pwnversity
AUD-GOOGLE-WORKSPACEintermediate · 15 min · upd. 2026-11

Auditing Google Workspace

Google WorkspaceOAuthScubaGoggles

Google Workspace brings mail, documents, calendar, chat and, above all, the organization’s identity together in one console: many companies sign in to the rest of their applications with “Sign in with Google”. That is why the main risk is not in Gmail or Drive, but in who can administer the tenant and which applications can reach everyone’s data. This card walks through the settings reviewed in an authorized audit. The Microsoft equivalent is in Microsoft 365.

Google runs the platform and protects it. The customer decides:

  • who is a super admin and how they authenticate;
  • which OAuth applications can read data, and with which scopes;
  • which service accounts have domain-wide delegation;
  • how files and groups are shared outside the organization;
  • which logs are kept and who reads them.
flowchart LR
    U["Users"] -->|"2SV, security<br/>keys"| GW(("Google Workspace<br/>Admin console"))
    SA["Super admins<br/>(2 to 8, cloud-only accounts)"] --> GW
    GW --> D["Gmail, Drive,<br/>Calendar, Chat"]
    A["Third-party OAuth apps"] -->|"user<br/>consent"| D
    SV["GCP service account<br/>with domain-wide delegation"] -->|"acts as<br/>any user"| D
    GW -->|"«Sign in with Google»"| S["Other SaaS apps"]
    GW --> L["Audit logs<br/>Reports API, SIEM"]
Control What to look for CISA reference (SCuBA)
Super admins Too many, or just one; everyday accounts holding the super admin role Between 2 and 8 distinct super admins
Admin accounts Admins who sign in federated from another IdP Cloud-only accounts, separate from the federated IdP
2SV Users without 2-Step Verification; SMS or voice as the method Phishing-resistant MFA for everyone; never SMS or voice
Advanced Protection Admins and sensitive accounts outside the program Required for highly privileged accounts
Recovery Super admins who can recover their own account Self-recovery disabled
Session Sessions that never expire Re-authentication every 12 hours
Passwords Periodic expiry At least 12 characters (16 is better), no reuse and no expiry

Google is gradually enforcing 2SV on every administrator account. Once enforcement reaches an organization, admins cannot skip it: if one cannot turn on 2SV, the only way out is to remove their admin role. With a third-party SSO, Google also requires 2SV on the Google account itself, even if the provider already asks for MFA.

OAuth applications and domain-wide delegation

Section titled “OAuth applications and domain-wide delegation”

Security > Access and data control > API controls decides which applications can access data. Each configured app gets a level: Trusted, Limited, Specific Google data or Blocked.

  • Unconfigured apps. The CISA baseline asks that users cannot use unconfigured third-party apps and that unconfigured internal apps are not trusted. With that setting, user requests land in Apps pending review and an admin decides.
  • High-risk scopes. In Gmail, Drive and Chat, the dangerous scopes can be restricted: sending mail, deleting files.
  • List of apps with access. Accessed apps shows which apps have used data, how many users and with which scopes. It downloads as CSV.

Domain-wide delegation (DWD) goes further: it authorizes an app or a Google Cloud service account to act as any user in the domain for the granted scopes. Only a super admin can create it, but afterwards it lives in GCP:

  • Anyone who can create a new key for that service account can sign tokens and read anyone’s mail or Drive, without being a Workspace admin. This is the design Hunters named DeleFriend (November 2023). Unit 42 reported the same risk to Google.
  • The audit cross-checks both sides:
    • the list of DWD clients and their scopes, in API controls > Domain-wide delegation;
    • who holds iam.serviceAccountKeys.create on those accounts in GCP (see GCP).
  • Mitigations:
    • one service account per project;
    • minimal scopes;
    • block key creation with the iam.disableServiceAccountKeyCreation organization policy;
    • alert on the AUTHORIZE_API_CLIENT_ACCESS event.

Read-only queries with the Admin SDK (paths and scopes checked against the directory_v1 and reports_v1 discovery documents):

Ventana de terminal
API=https://admin.googleapis.com/admin
# Administrators (scope admin.directory.user.readonly)
curl -s -H "Authorization: Bearer $T" "$API/directory/v1/users?customer=my_customer&query=isAdmin=true" | jq -r '.users[].primaryEmail'
# Role assignments (admin.directory.rolemanagement.readonly)
curl -s -H "Authorization: Bearer $T" "$API/directory/v1/customer/my_customer/roleassignments" | jq '.items | length'
# OAuth tokens a user has granted (admin.directory.user.security)
curl -s -H "Authorization: Bearer $T" "$API/directory/v1/users/ana@company.test/tokens" | jq -r '.items[] | .displayText + " " + (.scopes|join(","))'
# Domain-wide delegations granted (admin.reports.audit.readonly)
curl -s -H "Authorization: Bearer $T" "$API/reports/v1/activity/users/all/applications/admin?eventName=AUTHORIZE_API_CLIENT_ACCESS" | jq '.items[]?.events'
# OAuth grants from every user
curl -s -H "Authorization: Bearer $T" "$API/reports/v1/activity/users/all/applications/token?eventName=authorize" | jq '.items | length'

The CISA Gmail baseline has 36 policies. The ones you can check from outside, without console access, are the DNS ones:

  • an SPF record that fails non-approved senders;
  • DKIM turned on for every domain;
  • DMARC with p=reject.

From inside you review:

  • automatic forwarding to external domains;
  • mailbox delegation;
  • POP and IMAP access;
  • allowlists that bypass the spam filter.

Lab: SPF, DKIM, DMARC and MTA-STS over DNS

Section titled “Lab: SPF, DKIM, DMARC and MTA-STS over DNS”

A Python script queries the TXT records through the dns.google DNS-over-HTTPS API:

import json, sys, urllib.request
def txt(name):
r = json.load(urllib.request.urlopen(f"https://dns.google/resolve?name={name}&type=TXT", timeout=15))
return [a["data"].replace('" "', "").strip('"') for a in r.get("Answer", []) if a["type"] == 16]
for d in sys.argv[1:]:
spf = [t for t in txt(d) if t.startswith("v=spf1")]
dmarc = [t for t in txt(f"_dmarc.{d}") if t.startswith("v=DMARC1")]
dkim = [t for t in txt(f"google._domainkey.{d}") if "p=" in t]
sts = [t for t in txt(f"_mta-sts.{d}") if t.startswith("v=STSv1")]
print(f"== {d}")
print(" SPF :", spf[0][-40:] if spf else "MISSING")
if dmarc:
p = dict(kv.strip().split("=", 1) for kv in dmarc[0].split(";") if "=" in kv)
print(" DMARC : p=" + p.get("p", "?"), "| sp=" + p.get("sp", "-"), "| rua" if "rua" in p else "| no rua")
else:
print(" DMARC : MISSING")
if not dkim:
print(" DKIM : google selector not found (another selector may be in use)")
elif dkim[0].rstrip("; ").endswith("p="):
print(" DKIM : google selector with empty key (p=): revoked key, the domain does not sign")
else:
print(" DKIM : google selector published")
print(" MTA-STS:", "published" if sts else "no")

Real output from November 21, 2026:

$ python3 mail_dns.py google.com cisa.gov example.com
== google.com
SPF : v=spf1 include:_spf.google.com ~all
DMARC : p=reject | sp=- | rua
DKIM : google selector not found (another selector may be in use)
MTA-STS: published
== cisa.gov
SPF : include:spf-00376703.gpphosted.com -all
DMARC : p=reject | sp=- | rua
DKIM : google selector not found (another selector may be in use)
MTA-STS: no
== example.com
SPF : v=spf1 -all
DMARC : p=reject | sp=reject | no rua
DKIM : google selector with empty key (p=): revoked key, the domain does not sign
MTA-STS: no

How to read it:

  • example.com is a domain that sends no mail and says so everywhere: -all, p=reject and an empty DKIM key on any selector (it answers the same for a made-up one).
  • google.com ends its SPF with ~all (softfail). The CISA SPF policy asks to fail non-approved senders, so with that value it would not meet it; the real protection comes from its DMARC at reject.
  • The DKIM selector does not have to be called google. It is set in the console, so not finding it is not a finding on its own.
Service Common risk CISA baseline
Drive Files shared with “anyone with the link”; unrestricted external sharing External sharing only with allowlisted domains; no “anyone with the link”; new files private to their owner
Groups Groups open to the internet that publish internal conversations; anyone can create groups No external access unless the owner grants it; conversations visible to members only; creation restricted
Takeout A full export of an account before leaving the company Disabled
Marketplace Any user installs apps Approved apps only
Additional services Google services on by default that nobody uses Disabled if they have no individual control
  • System-defined alert rules turned on, notifying a person or a SIEM.
  • Retention: CISA asks for logs to be searchable for 3 months and retrievable for 12.
  • Reports API: admin, login, token, saml, drive and gmail are the most queried log applications.

ScubaGoggles, from CISA, exports the configuration with the Admin SDK and other Google APIs. It then compares it with the SCuBA baselines and produces an HTML and JSON report. It fixes nothing, and CISA still labels it alpha: results are verified by hand.

Policy count in the baselines on the main branch of the cisagov/ScubaGoggles repository, downloaded and counted with Python on November 21, 2026:

Baseline Policies Baseline Policies
Common controls 42 Chat 7
Gmail 36 Calendar 6
Drive and Docs 17 Classroom 6
Meet 9 Groups 6
Gemini 6 Assured controls 3
Sites 1 Total 139

The baselines are written for US federal agencies. Some policies do not carry over as they are, such as storing data in the US or sending DMARC reports to a DHS address. The rest is a very thorough checklist.

The audit covers the customer’s organization, with their authorization and a read-only account (a custom role, or one of the customer’s super admins present). Google’s infrastructure is out of scope: its flaws are reported to Google’s Bug Hunters program.

  • Salesloft Drift (August 2025). UNC6395 stole OAuth tokens from the Drift Email integration. On August 9 it used them to read mail from a very small number of Workspace accounts, only the ones configured to integrate with Drift. Google revoked those tokens and disabled the integration. For the audit: every app holding an OAuth token on Gmail is a door that does not go through the user’s 2SV.
  • DeleFriend (November 2023). Hunters and Unit 42 showed that a GCP identity allowed to create keys for a service account with DWD reaches every mailbox in the domain. It is not a bug that gets patched: it is how delegation works, which is why it is audited.
  • Abandoned domains and “Sign in with Google” (January 2025). Truffle Security bought the domain of a defunct startup and recreated former employees’ accounts. With them it got into services that trusted only the email address and domain, such as Slack, Notion, Zoom or an HR system. The lesson is to close the SaaS accounts and keep the domain when an organization shuts down. In your own apps, do not identify users by email address and domain alone. The stable token identifier is sub, although Truffle observed that it changes in 0.04% of sign-ins.
  • Between 2 and 8 super admins, cloud-only accounts, not used day to day
  • 2SV required for everyone; security keys or passkeys for admins; no SMS or voice
  • Admins and sensitive accounts in Advanced Protection; super admin self-recovery disabled
  • App passwords inventoried and revoked if unused
  • API controls: unconfigured third-party apps blocked; high-risk scopes restricted; Accessed apps reviewed
  • Domain-wide delegation inventoried with its scopes; service account keys controlled in GCP; alert on AUTHORIZE_API_CLIENT_ACCESS
  • SPF that fails non-approved senders, DKIM on every domain, DMARC p=reject
  • No external auto-forwarding, no POP/IMAP unless needed, no lists that bypass spam filtering
  • Drive without “anyone with the link” by default; external sharing only with allowlisted domains
  • Groups without external access or public conversations; Takeout disabled
  • System alerts on; logs in a SIEM; 3 months searchable and 12 retrievable
  • ScubaGoggles run and its results reviewed by hand