Skip to content

ci(check-file-contents): exclude OAuth scope URLs from endpoint scan#4

Merged
caohy1988 merged 1 commit into
mainfrom
ci/exclude-oauth-scopes-from-endpoint-check
Jun 1, 2026
Merged

ci(check-file-contents): exclude OAuth scope URLs from endpoint scan#4
caohy1988 merged 1 commit into
mainfrom
ci/exclude-oauth-scopes-from-endpoint-check

Conversation

@caohy1988
Copy link
Copy Markdown
Owner

The "Check for hardcoded googleapis.com endpoints" step in .github/workflows/check-file-contents.yml uses

```bash
grep -lE 'https?://[a-zA-Z0-9.-]+.googleapis.com'
```

to find files that should also declare an `.mtls.googleapis.com` counterpart for dynamic endpoint selection. The regex matches any `googleapis.com` URL — including OAuth 2.0 scope URLs like `https://www.googleapis.com/auth/cloud-platform\` and `.../auth/bigquery` — which are identity strings, not API endpoints. They don't have mTLS counterparts and never will. Any file that legitimately declares an OAuth scope (very common for ADK plugins integrating Google APIs) trips the gate even when no real endpoint is hardcoded.

Surfaced on #2 (the BQAA Storage Write regional routing fix): the plugin file already declares https://www.googleapis.com/auth/bigquery for the BigQuery API scope. A one-line bug fix touching that file triggers the whole-file scan, which then demands a fake `.mtls.` URL be added to a place where it doesn't belong.

Fix

Add a second pass that filters the candidate set down to files that have at least one `googleapis.com` URL outside the OAuth scope namespace (i.e. not matching `googleapis.com/auth/`). The mTLS check runs only against that filtered set.

File Before After
Only OAuth scopes flagged ❌ ignored ✅
Endpoint, no mTLS flagged ❌ flagged ❌ (intended)
Endpoint + mTLS passes ✅ passes ✅
Mixed (OAuth + endpoint, no mTLS) flagged ❌ flagged ❌ (intended)

Verification

Ran the patched logic against four synthesized test files locally and confirmed the truth table above. The intent of the check (real hardcoded endpoints must declare their `.mtls` counterpart) is preserved; only the false-positive case is silenced.

Scope

Workflow-only. No source-code changes. No effect on the sibling checks (logger pattern, `from future import annotations`, cli imports) — all three live in separate steps with independent regexes.

Why this is its own PR

Splitting per #2 review feedback — keep the bug fix and the workflow-policy fix on independent commits so each can be reviewed on its own merits, and so the workflow fix can land first and unblock #2 cleanly.

Refs

Test plan

The "Check for hardcoded googleapis.com endpoints" step in
.github/workflows/check-file-contents.yml uses

  grep -lE 'https?://[a-zA-Z0-9.-]+\.googleapis\.com'

to find files that should also declare an `.mtls.googleapis.com`
counterpart for dynamic endpoint selection. The regex matches any
googleapis.com URL — including OAuth 2.0 scope URLs like
https://www.googleapis.com/auth/cloud-platform and
.../auth/bigquery — which are identity strings, not API endpoints.
They don't have mTLS counterparts and never will. Any file that
legitimately declares an OAuth scope (very common for ADK plugins
integrating Google APIs) trips the gate even when no real endpoint
is hardcoded.

Fix: add a second pass that filters the candidate set down to files
that have at least one googleapis.com URL OUTSIDE the OAuth scope
namespace (i.e. not matching `googleapis.com/auth/`). The mTLS check
runs only against that filtered set.

Verified against four synthesized cases:

  only_oauth.py            (only OAuth scopes)        → ignored ✓
  real_endpoint.py         (endpoint, no mTLS)        → flagged ✓
  real_endpoint_with_mtls  (endpoint + mTLS)          → passes  ✓
  mixed.py                 (OAuth + endpoint, no mTLS)→ flagged ✓

No effect on the surrounding `logger`, `from __future__`, or
`cli` import checks. CI policy intent unchanged: real hardcoded
googleapis.com endpoints still must declare their `.mtls`
counterpart.

Refs:
  - #2 (the BQAA Storage Write regional routing
    fix that surfaced this false positive)
  - GoogleCloudPlatform/BigQuery-Agent-Analytics-SDK#262
@caohy1988 caohy1988 merged commit 1d83cfe into main Jun 1, 2026
9 of 10 checks passed
@caohy1988 caohy1988 deleted the ci/exclude-oauth-scopes-from-endpoint-check branch June 1, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant