Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 5 of 6 · Worked example · 20 min · revision 2

Securing the SaaS Tenants Everyone Forgets

Review a Google Workspace-style tenant export for risky external sharing, over-permissive third-party OAuth grants and accounts without MFA, rank the fixes by impact with a Python script that stays quiet on safe settings, and connect the result back to the shared responsibility model.

Contentsand lesson path

What you will learn

  • Review a SaaS collaboration tenant (for example Microsoft 365 or Google Workspace) for risky external sharing, over-permissive third-party OAuth app grants and accounts without MFA, and prioritise the fixes.
  • Explain the shared responsibility split for IaaS, PaaS and SaaS services and identify the controls the customer owns in a given architecture.

Prerequisites: Cloud Basics

01. The problem

A security team can spend months hardening its cloud infrastructure and still lose data through a SaaS (software as a service) tenant such as Google Workspace or Microsoft 365. As the shared responsibility lesson showed, in SaaS the provider runs almost the whole stack, but the customer still owns identities, sharing and which third-party apps may read company data. These are settings in an admin console, not servers, and they are easy to forget.

Three weaknesses cause most SaaS incidents. A file shared with "anyone with the link" or "public on the web" is readable without an account, so a leaked link is a leaked file. A third-party app that a user consented to may hold a token with wide scopes, such as full access to mail or Drive, and keep that access without the user present. And an account without multi-factor authentication (MFA), especially an administrator, can be taken over with a stolen password. In this worked example you review a tenant from its exported reports, rank the fixes by impact, and prove the ranking ignores safe settings. Everything runs locally with Python 3.12 on three JSON files; no tenant is needed. Work in a folder called saas-review; the first command creates it.

02. Step 1: The tenant exports

Admin consoles export their state. Google Workspace has a Users list (with 2-Step Verification status and admin role), a Drive audit that reports each file's link-sharing visibility, and an app-access report of third-party OAuth grants with their scopes. The generator below writes a small version of all three, with the field values Google uses, such as the visibility people_with_link and public_on_the_web, and the high-risk scope strings from Google's app-access control list. Save it as make_exports.py and run it.

Python · saas-review/make_exports.py
"""Writes three JSON exports shaped like a Google Workspace admin report."""
import json

# is_super_admin / is_delegated_admin mirror the Directory API isAdmin and
# isDelegatedAdmin flags; helpdesk holds the pre-built Help Desk Admin role.
users = [
    {"email": "[email protected]", "is_super_admin": True,
     "is_delegated_admin": False, "two_step_enrolled": True,
     "suspended": False, "last_login": "2026-11-15"},
    {"email": "[email protected]", "is_super_admin": False,
     "is_delegated_admin": True, "two_step_enrolled": False,
     "suspended": False, "last_login": "2026-11-15"},
    {"email": "[email protected]", "is_super_admin": False,
     "is_delegated_admin": False, "two_step_enrolled": True,
     "suspended": False, "last_login": "2026-11-15"},
    {"email": "[email protected]", "is_super_admin": False,
     "is_delegated_admin": False, "two_step_enrolled": False,
     "suspended": False, "last_login": "2026-11-14"},
    {"email": "[email protected]", "is_super_admin": False,
     "is_delegated_admin": False, "two_step_enrolled": True,
     "suspended": False, "last_login": "2026-11-13"},
    {"email": "[email protected]", "is_super_admin": False,
     "is_delegated_admin": False, "two_step_enrolled": False,
     "suspended": True, "last_login": "2026-08-01"},
]
# Drive files and their link-sharing visibility, as the Drive audit reports it.
files = [
    {"doc_id": "d1", "doc_title": "Customer contracts",
     "owner": "[email protected]", "visibility": "people_with_link",
     "sensitive": True},
    {"doc_id": "d2", "doc_title": "Board minutes Q3", "owner": "[email protected]",
     "visibility": "public_on_the_web", "sensitive": True},
    {"doc_id": "d3", "doc_title": "Office lunch menu", "owner": "[email protected]",
     "visibility": "public_on_the_web", "sensitive": False},
    {"doc_id": "d4", "doc_title": "Partner price list", "owner": "[email protected]",
     "visibility": "shared_externally", "sensitive": False},
    {"doc_id": "d5", "doc_title": "Internal roadmap", "owner": "[email protected]",
     "visibility": "private", "sensitive": True},
]
# Third-party OAuth app grants: which users consented, and to which scopes.
grants = [
    {"app_name": "MailSorter", "client_id": "100.apps", "verified": False,
     "scopes": ["https://mail.google.com/",
                "https://www.googleapis.com/auth/userinfo.email"],
     "users": ["[email protected]", "[email protected]", "[email protected]"]},
    {"app_name": "DriveBackup", "client_id": "200.apps", "verified": False,
     "scopes": ["https://www.googleapis.com/auth/drive"],
     "users": ["[email protected]"]},
    {"app_name": "CalSync", "client_id": "300.apps", "verified": True,
     "scopes": ["https://www.googleapis.com/auth/calendar.readonly"],
     "users": ["[email protected]", "[email protected]"]},
]
for name, data in (("users", users), ("files", files), ("grants", grants)):
    with open(f"{name}.json", "w") as fh:
        json.dump(data, fh, indent=2)
print("wrote users.json, files.json, grants.json")
Terminal
mkdir -p saas-review && cd saas-review   # save make_exports.py here
python3 make_exports.py
Expected output
wrote users.json, files.json, grants.json

One file record from files.json looks like this. visibility is the Drive sharing value, and sensitive marks files that hold data such as customer contracts or board papers.

JSON · one record from files.json
{
  "doc_id": "d1",
  "doc_title": "Customer contracts",
  "owner": "[email protected]",
  "visibility": "people_with_link",
  "sensitive": true
}

The tenant has one super admin (with 2-Step Verification), a help-desk account that holds a delegated admin role but has no 2-Step, a CEO with 2-Step on, a sales team split on MFA, a suspended intern, two sensitive files shared publicly, a public lunch menu, a partner share, and three OAuth apps: an unverified mail app three people use, an unverified Drive-backup app one person uses, and a verified read-only calendar app. These stand in for the real risks a review turns up.

03. Step 2: Rank the fixes by impact

A long findings list is not a plan. You rank by impact and likelihood. An administrator without MFA comes first: a super admin can take over the whole tenant, and a delegated role can take over every account it manages. A public sensitive file is data already exposed, so it comes first too. Over-permissive OAuth grants come next, weighted by how many people use the app. Non-admin MFA gaps and non-sensitive public files follow. The script reads the three exports and prints the findings in that order. Save it as review.py.

Python · saas-review/review.py
"""Ranks SaaS tenant risks from the exports: MFA gaps, public links and OAuth grants."""
import json

# Google's high-risk Drive/Gmail scopes grant wide access to user data.
HIGH_RISK_SCOPES = {
    "https://mail.google.com/": "full mailbox access",
    "https://www.googleapis.com/auth/drive": "full Drive access",
    "https://www.googleapis.com/auth/gmail.readonly": "read all mail",
}
PUBLIC = {"people_with_link", "public_on_the_web"}   # reachable without an account


def load(name):
    return json.load(open(f"{name}.json"))


def findings():
    out = []   # (rank, kind, subject, detail)
    for u in load("users"):
        if u["suspended"] or u["two_step_enrolled"]:
            continue
        if u["is_super_admin"]:
            out.append((1, "admin-no-2sv", u["email"], "super admin without 2-Step"))
        elif u["is_delegated_admin"]:
            out.append((1, "admin-no-2sv", u["email"], "delegated admin, no 2-Step"))
        else:
            out.append((3, "user-no-2sv", u["email"], "user without 2-Step"))
    for f in load("files"):
        if f["visibility"] in PUBLIC:
            rank = 1 if f["sensitive"] else 4
            out.append((rank, "public-link", f["doc_title"],
                        f"{f['visibility']} (sensitive={f['sensitive']})"))
    for g in load("grants"):
        n = len(g["users"])
        risky = [HIGH_RISK_SCOPES[s] for s in g["scopes"] if s in HIGH_RISK_SCOPES]
        if risky:
            rank = 2 + (n < 3)   # 2 if many users, 3 if few
            note = "unverified" if not g["verified"] else "verified"
            out.append((rank, "oauth-grant", g["app_name"],
                        f"{', '.join(risky)}; {n} user{'s' * (n != 1)}; {note}"))
    return out


BAND = {1: "P1", 2: "P2", 3: "P3", 4: "P4"}
if __name__ == "__main__":
    for rank, kind, subject, detail in sorted(findings()):
        print(f"{BAND[rank]} {kind:13} {subject:22} {detail}")
Terminal
python3 review.py
Expected output
P1 admin-no-2sv  [email protected]  delegated admin, no 2-Step
P1 public-link   Board minutes Q3       public_on_the_web (sensitive=True)
P1 public-link   Customer contracts     people_with_link (sensitive=True)
P2 oauth-grant   MailSorter             full mailbox access; 3 users; unverified
P3 oauth-grant   DriveBackup            full Drive access; 1 user; unverified
P3 user-no-2sv   [email protected]    user without 2-Step
P4 public-link   Office lunch menu      public_on_the_web (sensitive=False)

The P1 group is the fix list for today. Enforce 2-Step Verification on the help-desk account, or remove its admin role until it enrols: Google's pre-built Help Desk Admin role can reset the passwords of users who are not administrators, so one stolen password opens every account it can reset. The super admin is absent only because its 2-Step is on; without it, it would top the list. Then remove the public sharing on the customer contracts and the board minutes. The CEO, who has 2-Step on and no admin role, is not a finding: rank by privilege in the tenant, not by job title.

The partner price list is shared_externally, which means shared with named people outside the company (here, a partner). That is intended sharing and does not appear; external sharing is a policy question, not an incident. The mail app is P2, above the Drive-backup app, because three people granted it full mailbox access. That widens the blast radius (how far one compromise reaches): one phished consent is one mailbox, but a popular rogue app reaches many. A wide grant is dangerous because the app keeps a refresh token and can act without the user present. The user passed MFA when they consented, so MFA does not revoke it. A password reset is not a reliable fix either. Google revokes tokens with Gmail scopes when the password changes, which would cut off MailSorter, but not tokens with only Drive scopes, such as DriveBackup's; in Microsoft 365, a web app's refresh token survives a password change. What ends the access is revoking the grant itself.

04. Step 3: Prove the review ignores safe settings

A review that flags everything is noise, and people learn to ignore it. The test asserts that safe settings never appear: a verified, low-risk calendar app, a private file even when it is sensitive, and users who have 2-Step Verification on or are suspended. This is the negative test for the review.

Python · saas-review/test_review.py
"""Negative tests: safe settings must not be flagged as findings."""
from review import findings

flagged = {(k, s) for _, k, s, _ in findings()}
# A verified, low-risk calendar app must not appear.
assert not any(s == "CalSync" for _, s in flagged), "CalSync wrongly flagged"
# A private file must not appear, even if sensitive.
assert not any(s == "Internal roadmap" for _, s in flagged), "private file flagged"
# Admins and users with 2-Step on, and the suspended user, must not be a 2SV finding.
for subject in ("[email protected]", "[email protected]", "[email protected]",
                "[email protected]"):
    assert ("admin-no-2sv", subject) not in flagged
    assert ("user-no-2sv", subject) not in flagged
print("ok: no safe setting flagged")
Terminal
python3 test_review.py
Expected output
ok: no safe setting flagged

The calendar app is verified and asks only for read-only calendar access, which is not on Google's high-risk list, so it is not a finding. The private roadmap is sensitive but reachable only by named people, so sharing is not the risk. Flagging these would bury the three P1 fixes that matter. The same ideas apply to Microsoft 365: there the risky app grant is a delegated permission such as Mail.ReadWrite together with offline_access, which hands the app a long-lived refresh token, and the tenant-wide fix is to restrict user consent to apps from verified publishers and low-risk permissions, sending the rest to an admin consent workflow.

05. Common mistakes

06. Check your understanding

Practice check · 3 questions

Prioritising SaaS fixes

Three questions about the review and the tenant settings.

Q1. Why does `test_review.py` assert that the CalSync app never appears in the findings?
Q2. `review.py` ranks MailSorter (P2) above DriveBackup (P3), even though DriveBackup asks for full Drive access. Why?
Q3. `review.py` flags the `people_with_link` customer contracts and the public lunch menu, but not the `shared_externally` partner price list. Why?
Practice only: not graded, not saved, not evidence.

07. Apply it

For the skill project, turn this into a tenant review you could hand to an owner:

  • Export (or mock, in this shape) the users, shared files and OAuth grants of a free or developer SaaS tenant.
  • Extend review.py with one more rule, such as flagging an admin whose last login is very old, and add a safe case the test proves is not flagged.
  • Produce a prioritised fix list: for each P1 and P2 finding, the exact setting to change (revoke the grant, remove the link, enforce 2-Step) and who owns the change.
  • Add the tenant-wide preventions: restrict user consent to verified publishers and low-risk scopes, and set public-link sharing off by default.

08. Review prompt

Without looking back, explain: which parts of a SaaS tenant the customer owns under shared responsibility; the three weaknesses a tenant review looks for; why an admin without MFA, super or delegated, and a public sensitive file are the first fixes; why a wide OAuth grant can survive a password reset and what actually revokes it; the difference between a public link and a named external share; and the tenant-wide setting that reduces risky consent grants.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check