security(vertex): route credential/project/region resolution through the profile secret scope

agent/vertex_adapter.py resolved VERTEX_CREDENTIALS_PATH,
GOOGLE_APPLICATION_CREDENTIALS, VERTEX_PROJECT_ID, and VERTEX_REGION via raw
os.environ.get() instead of the profile-scoped get_secret() every other
credential lookup in hermes_cli/runtime_provider.py uses. In a multiplex
gateway serving several profiles from one process, os.environ still holds
whichever profile's .env python-dotenv loaded at boot — so a raw read here
let one profile's turn silently mint a Vertex OAuth2 token from, and get
billed against, a different profile's GCP service account. No error, no
fail-closed guard: the multiplex UnscopedSecretError protection was bypassed
entirely because these reads never went through get_secret().

- _resolve_credentials_path/_resolve_project_override/_resolve_region now
  call agent.secret_scope.get_secret(), matching the _getenv() pattern
  already used for every other provider's credentials.
- get_vertex_credentials()'s ADC fallback (google.auth.default()) reads
  GOOGLE_APPLICATION_CREDENTIALS from os.environ internally, bypassing
  get_secret() entirely — closed with a narrow guard: when multiplexing is
  active and this profile's scope has no Vertex credentials of its own, but
  os.environ still carries a value (left by a different profile's boot-time
  dotenv load), refuse ADC rather than silently authenticate as a stranger.
- Zero behavior change for single-profile installs: get_secret() falls
  through to os.environ transparently whenever multiplexing is off.

Same bug class as the already-fixed _HERMES_OAUTH_FILE/_AUTH_JSON_PATH/
HOOKS_DIR cross-profile leaks, now closed for Vertex's OAuth2 credential
path.
This commit is contained in:
srojk34
2026-07-02 02:16:13 +03:00
committed by kshitij
parent 2f7c51a3e2
commit 7f64cce96d
2 changed files with 92 additions and 3 deletions
+29 -3
View File
@@ -21,6 +21,8 @@ import os
import time
from typing import Optional, Tuple
from agent.secret_scope import get_secret as _get_secret, is_multiplex_active
# Ensure google-auth is installed before importing. The [vertex] extra is no
# longer in [all] per the lazy-install policy added 2026-05-12 — lazy_deps
# handles on-demand installation so the Vertex provider still works for users
@@ -65,7 +67,7 @@ def _resolve_region(explicit: Optional[str] = None) -> str:
"""Region precedence: explicit arg > VERTEX_REGION env > config.yaml > default."""
if explicit:
return explicit
env_region = os.environ.get("VERTEX_REGION", "").strip()
env_region = (_get_secret("VERTEX_REGION") or "").strip()
if env_region:
return env_region
cfg_region = str(_vertex_config().get("region") or "").strip()
@@ -78,7 +80,7 @@ def _resolve_project_override() -> Optional[str]:
Returns None when neither is set (the credentials' embedded project_id
is used in that case).
"""
env_project = os.environ.get("VERTEX_PROJECT_ID", "").strip()
env_project = (_get_secret("VERTEX_PROJECT_ID") or "").strip()
if env_project:
return env_project
cfg_project = str(_vertex_config().get("project_id") or "").strip()
@@ -88,8 +90,14 @@ def _resolve_project_override() -> Optional[str]:
def _resolve_credentials_path(explicit: Optional[str]) -> Optional[str]:
if explicit and os.path.exists(explicit):
return explicit
# Routed through get_secret (not a raw os.environ read): in a multiplex
# gateway serving several profiles from one process, os.environ reflects
# whichever profile's .env happened to be loaded at boot, not the profile
# the current turn belongs to. Reading it directly here would let one
# profile mint Vertex tokens from — and get billed against — a different
# profile's service-account file. See agent/secret_scope.py.
for env_var in ("VERTEX_CREDENTIALS_PATH", "GOOGLE_APPLICATION_CREDENTIALS"):
path = os.environ.get(env_var)
path = _get_secret(env_var)
if path and os.path.exists(path):
return path
return None
@@ -123,6 +131,24 @@ def get_vertex_credentials(credentials_path: Optional[str] = None) -> Tuple[Opti
)
project_id = creds.project_id
else:
# google.auth.default() reads GOOGLE_APPLICATION_CREDENTIALS
# straight from os.environ internally — it has no notion of
# the profile secret scope. _resolve_credentials_path already
# confirmed (via get_secret) that *this* profile doesn't
# define the var, but python-dotenv's load_dotenv() mutates
# os.environ at boot for whichever profile happened to load
# first, so a raw os.environ read here can still pick up a
# different profile's service-account path. Refuse rather
# than silently authenticating under a stranger's identity.
if is_multiplex_active() and os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
logger.warning(
"Vertex ADC skipped for this profile: "
"GOOGLE_APPLICATION_CREDENTIALS is set in the process "
"environment (from another profile's .env) but not in "
"this profile's own config. Set VERTEX_CREDENTIALS_PATH "
"in this profile's .env instead of relying on ADC."
)
return None, None
creds, project_id = google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)