Databricks Long-Lifetime Token Generated
Description
Detects generation of personal access tokens (PATs) with lifetime exceeding 72 hours. Long-lived tokens increase the risk of credential theft and unauthorized access if compromised. Tokens with lifetime >90 days are elevated to MEDIUM, >1 year to HIGH severity.
Query · python
from panther_databricks_helpers import databricks_alert_context
def _token_duration_hours(event):
"""Calculate token lifetime in hours, or None if not determinable."""
try:
token_expiration = int(event.deep_get("requestParams", "tokenExpirationTime", default=0))
event_time_ms = event.get("timestamp", 0)
if not token_expiration or not event_time_ms:
return None
return (token_expiration - event_time_ms) / (1000 * 3600)
except (ValueError, TypeError):
return None
def rule(event):
if event.get("actionName") != "generateDbToken":
return False
duration = _token_duration_hours(event)
return duration is not None and duration > 72
def severity(event):
duration = _token_duration_hours(event)
if duration is None:
return "LOW"
# Severity
# >1 year (8760h) HIGH
# >90 days (2160h) MEDIUM
# otherwise LOW
if duration > 8760:
return "HIGH"
if duration > 2160:
return "MEDIUM"
return "LOW"
def title(event):
actor = event.deep_get("userIdentity", "email", default="Unknown User")
duration = _token_duration_hours(event)
if duration is not None:
return f"Long-lifetime token ({int(duration / 24)} days) generated by {actor}"
return f"Long-lifetime token generated by {actor}"
def alert_context(event):
duration = _token_duration_hours(event)
duration_days = duration / 24 if duration is not None else None
return databricks_alert_context(
event,
additional_fields={
"token_expiration_time": event.deep_get("requestParams", "tokenExpirationTime"),
"token_hash": event.deep_get("requestParams", "tokenHash"),
"token_duration_hours": duration,
"token_duration_days": duration_days,
},
)
Analyst notes
- Query audit logs for all token generation by this user in the past 30 days to identify patterns
- Check if the generated token has been used for API calls in the 24 hours after creation
- Find all other long-lifetime tokens (>72 hours) created in the past 90 days to establish baseline