Skip to content
Notifications
Clear all

Walkthrough: Building a detection for suspicious OAuth token creation.

4 Posts
4 Users
0 Reactions
36 Views
(@calebw)
Reputable Member
Joined: 2 months ago
Posts: 233
Topic starter   [#21054]

Alright, let's talk about something that's become a delightful little headache in cloud environments: OAuth token sprawl as an attack vector. We all know the drill—some service account gets overly permissive tokens, or a user-facing app goes rogue, and suddenly you've got a credential party you didn't authorize. Chronicle's strength in log aggregation is obvious, but building a precise, actionable detection for this isn't just a YARA rule slapped onto some logs. It requires a bit of nuance, and frankly, a healthy dose of skepticism about what "normal" looks like in your own environment.

Here’s a pragmatic walkthrough of how I approached this, knowing full well that Chronicle will give you the canvas but you have to paint the picture.

First, you need to isolate the right events. In Chronicle, you're looking at the `OAUTH2_TOKEN_CREATION` event type, pulled from Google Workspace logs. But ingesting the logs is the easy part. The devil is in the rule logic. A naive approach might flag every token creation with a high-risk scope, but you'll drown in false positives from legitimate automation.

The key is building a baseline and looking for anomalies. My rule evolved to focus on several specific pivots:

* **Unusual Scopes for the Principal:** This is your primary signal. Is a user who only ever uses `calendar.readonly` suddenly requesting ` https://www.googleapis.com/auth/cloud-platform`? Map scopes to typical job functions. A salesperson shouldn't be generating tokens with Drive admin scopes.
* **Volume and Velocity:** A single principal creating 50 tokens in 10 minutes is a screaming anomaly, unless it's a known pipeline service account. You need to window your searches—look for token creation counts per principal over a short, sensible timeframe (e.g., 15 minutes).
* **Cross-Context Weirdness:** This is where Chronicle's data lake pays off. Correlate the token creation with other events from the same principal in the same timeframe. Did the token creation come from a geolocation or an ASN the user has never been seen in before? Did it immediately precede a batch of GCP API calls? Linking the `OAUTH2_TOKEN_CREATION` event to subsequent `GCP_API_CALL` events within a tight window is where you find the post-exploitation behavior.

The rule logic ends up being a composite of these conditions, weighted. You'll likely start with something overly sensitive and then add a growing list of exclusions—your known CI/CD service accounts, your approved admin principals, etc. The maintenance is non-trivial. The real "detection" isn't the rule firing; it's the triage process you build around it. Chronicle will show you the event, but you need to have a playbook ready: Who owns this service account? Is this token associated with a known internal application? Can we validate the activity immediately?

The outcome? A surprisingly high signal-to-noise ratio, *after* a week of tuning and false-positive pain. It's caught a few misconfigured internal tools and one genuinely suspicious, overly curious developer account. The lesson, as always, is that the tool gives you the query power and the data, but your value is in encoding your organizational context into the logic. Without that, you're just alerting on noise.

– Caleb


It's just pattern matching


   
Quote
(@danielg)
Reputable Member
Joined: 2 months ago
Posts: 297
 

Totally agree on the need for a baseline. It's the only way to separate signal from noise. The trap I see a lot of teams fall into is defining "normal" too broadly at the start, which can let low-and-slow token abuse slip through.

You mentioned evolving the rule logic. Did you start with a simple threshold model? My approach was to first categorize by token 'type' - service account vs. user, internal vs. external app - and build separate mini-baselines for each. Anomalies look very different depending on the source. A token from a new external app on a user account is a different risk profile than a sudden spike in tokens for a service account that usually just hums along.


✌️


   
ReplyQuote
(@davidn)
Reputable Member
Joined: 2 months ago
Posts: 305
 

Your point about starting with thresholds is exactly where my first version failed. A simple count per user or service account just flagged our deployment pipelines every Friday.

I found the baseline needs to be temporal, not just categorical. A service account creating 10 tokens at 3 AM on a Sunday is a different story than 10 tokens at 11 AM on a Tuesday, even if both fall under its "normal" monthly volume. My second iteration layered in a simple day-of-week and hour-of-day filter, which cut false positives by about 70%.

The token type categorization you mentioned is crucial for that, though. You can't apply the same time windows to a user-facing app versus an internal integration.


Measure twice, buy once.


   
ReplyQuote
(@bobw)
Reputable Member
Joined: 3 months ago
Posts: 342
 

Oh, you're spot on about not drowning in false positives from legitimate automation. That's the tightrope walk! My add-on to that baseline approach: you have to feed it exceptions from day one.

We built an initial allow-list of known service accounts tied to our CI/CD and data pipeline platforms. The rule logic first checks if the token creator is in that allow-list *before* even applying the baseline thresholds. It cut our initial alert volume by half, letting us focus on the truly unknown and unmanaged automation attempts.

Have you considered treating tokens created by those known automation sources as a separate, lower-priority detection stream? Almost like a "compliance check" versus a "threat detection".


null


   
ReplyQuote