Gmail Forwarder
The email-forwarder microservice provides autonomous email ingestion and summarization for dedicated organizational mailboxes while enforcing strict Zero Trust Architecture (ZTA) boundaries.
1. Flow Architecture
sequenceDiagram
autonumber
actor Sender as External Sender
participant GSuite as Google Workspace Gmail
participant PubSub as GCP Pub/Sub (gmail-events-topic)
participant CR as Cloud Run (email-forwarder)
participant SM as GCP Secret Manager
participant OAuth as Google OAuth 2.0 Gateway
Sender->>GSuite: Delivers email to authorized mailbox
GSuite->>PubSub: Emits history push notification
PubSub->>CR: Invokes Cloud Run via OIDC-authenticated POST
CR->>SM: Retrieves encrypted refresh_token via link-local IAM
CR->>OAuth: Exchanges refresh_token for ephemeral access_token
CR->>GSuite: Fetches message history (userId = 'me')
Note right of GSuite: Google gateway cryptographically rejects any query outside authorized user
- One-Time Interactive Authorization: The mailbox owner executes a one-time Google Cloud internal OAuth 2.0 consent flow, granting
https://www.googleapis.com/auth/gmail.readonlystrictly for their mailbox. - Encrypted Token Storage: The generated refresh token is stored in Google Cloud Secret Manager (
email-forwarder-gmail-token). - Keyless Ingestion: When Pub/Sub triggers the Cloud Run container, the service uses its ambient Cloud Run IAM service account to read the token from Secret Manager, exchange it for a short-lived access token, and fetch the new message.
- Card Rendering: The forwarder formats the message summary and dispatches an interactive card to the designated Google Chat space.
2. Identity & Privilege Boundaries
- Dedicated Service Account: The ingestion service operates under
email-forwarder@<project_id>.iam.gserviceaccount.com, isolated from the main assistant VM runtime. - Minimal OAuth Scopes: The forwarder requests strictly read-only mailbox access:
https://www.googleapis.com/auth/gmail.readonly(Allows fetching message history for the authorized user only).
- Single-Mailbox Scope: The OAuth 2.0 access token is bound strictly to
userId: 'me'. The service cannot query or access any other mailboxes across the organization. - Token Secret Management: Refresh tokens are encrypted in Secret Manager. Access is restricted through link-local IAM identity bindings, eliminating static API keys and exported private keys.
3. Threat Model & Mitigations
| Threat Vector | Attack Path | Security Mitigation |
|---|---|---|
| Malformed MIME / Parser Exploit | External sender sends malicious email payload to exploit container parsing libraries. | Cloud Run gVisor sandbox provides kernel-level execution containment. User-scoped access token (userId = 'me') prevents querying other mailboxes if container compromise occurs. |
| Mailbox Scope Escalation | Compromised runtime attempts to access executive or HR communications. | Google OAuth 2.0 gateway cryptographically enforces mailbox boundaries; requests outside the authorized mailbox fail immediately with HTTP 403 Forbidden. |
| Credential Exfiltration | Attacker attempts to extract long-lived credentials from container memory. | Container holds only ephemeral access tokens valid for up to 60 minutes. Refresh tokens reside exclusively in Secret Manager with link-local IAM access. |
| Unauthorized Message Dispatch | Compromised forwarder attempts to send spoofed emails. | Service account and token hold strictly gmail.readonly. Outbound mail transmission (gmail.send) is not authorized. |