Skip to content

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

Closed
caohy1988 wants to merge 1 commit into
google:mainfrom
caohy1988:upstream/ci-exclude-oauth-scopes
Closed

ci(check-file-contents): exclude OAuth scope URLs from endpoint scan#5931
caohy1988 wants to merge 1 commit into
google:mainfrom
caohy1988:upstream/ci-exclude-oauth-scopes

Conversation

@caohy1988
Copy link
Copy Markdown

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.

Surfaces today on any PR touching src/google/adk/plugins/bigquery_agent_analytics_plugin.py (the file already declares https://www.googleapis.com/auth/bigquery at L2145 for the BigQuery API scope). The same false positive affects any plugin that needs to reference a standard Google API scope.

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.

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

Truth table verified by running the patched logic against four synthesized test files locally.

Scope

Workflow-only. No source-code changes. No effect on the sibling steps in the same workflow (logger pattern, from __future__ import annotations, cli imports) — they live in independent regex blocks.

The check's intent — real hardcoded googleapis.com endpoints must declare their .mtls counterpart — is preserved.

Background

Originated as caohy1988/adk-python#4 where it was reviewed and merged on the fork. Surfaced while preparing a separate Storage Write API regional-routing fix for the BQAA plugin (queued behind this one upstream so the policy gate gives an honest signal on real changes).

Test plan

  • Local truth-table check on four synthesized files
  • Upstream CI on this PR — check-file-contents is filtered to paths: '**.py' and this PR only touches YAML, so the step is skipped on its own diff. Validation runs on follow-up PRs touching .py files (specifically the queued BQAA Storage Write fix).

)

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
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.

2 participants