Skip to content

Commit d30c2f4

Browse files
committed
fix(providers): import restored GCP metadata profiles in E2E
Allow standard non-Windows E2E lanes to import profiles requiring the restored supervisor metadata adapter. Keep the GCP token-response tests and remove unused compiled environment catalogs now declared by profiles. Signed-off-by: Philippe Martin <phmartin@redhat.com>
1 parent d576c53 commit d30c2f4

7 files changed

Lines changed: 122 additions & 88 deletions

File tree

Lines changed: 5 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Shared GCP constants for the metadata emulator, provider env injection,
5-
//! and credential resolution.
4+
//! Shared destinations and environment keys used by the GCP metadata emulator.
65
//!
7-
//! This module is the single source of truth for GCP naming: env var aliases,
8-
//! provider config keys, token search order, and Vertex-specific env vars.
9-
//! `openshell-server`, `openshell-providers`, and `openshell-sandbox`
10-
//! import from here.
6+
//! Provider environment defaults and discovery keys belong to imported
7+
//! profiles; this module holds only the names required by the supervisor's
8+
//! metadata protocol.
119
1210
// ── Metadata emulator ───────────────────────────────────────────────────────
1311

@@ -23,72 +21,24 @@ pub fn is_metadata_destination(destination: std::net::SocketAddr) -> bool {
2321
destination == std::net::SocketAddr::from(([127, 0, 0, 1], 8174))
2422
}
2523

26-
// ── Env var alias arrays ────────────────────────────────────────────────────
24+
// ── Metadata environment keys ───────────────────────────────────────────────
2725

2826
/// Env vars that carry the GCP project ID inside sandboxes.
2927
pub const PROJECT_ID_ENV_VARS: &[&str] = &["GCP_PROJECT_ID", "GOOGLE_CLOUD_PROJECT"];
3028

31-
/// Env vars that carry the GCP region/location inside sandboxes.
32-
pub const REGION_ENV_VARS: &[&str] = &["CLOUD_ML_REGION", "GCP_LOCATION"];
33-
3429
/// Env vars that carry the GCP service account email inside sandboxes.
3530
pub const SERVICE_ACCOUNT_EMAIL_ENV_VARS: &[&str] = &["GCP_SERVICE_ACCOUNT_EMAIL"];
3631

37-
// ── Provider config keys ────────────────────────────────────────────────────
38-
39-
/// Config key for project ID in `gcp` providers.
40-
pub const GCP_PROJECT_ID_CONFIG_KEY: &str = "project_id";
41-
42-
/// Config key for region in `gcp` providers.
43-
pub const GCP_REGION_CONFIG_KEY: &str = "region";
44-
45-
/// Config key for service account email in `gcp` providers.
46-
pub const GCP_SERVICE_ACCOUNT_EMAIL_CONFIG_KEY: &str = "service_account_email";
47-
4832
// ── Token search order ──────────────────────────────────────────────────────
4933

5034
/// GCP token env vars searched in priority order by the metadata emulator.
5135
/// SA token wins over ADC if both are configured, matching GCP's own
5236
/// credential precedence.
5337
pub const TOKEN_ENV_KEYS: &[&str] = &["GCP_SA_ACCESS_TOKEN", "GCP_ADC_ACCESS_TOKEN"];
5438

55-
// ── Vertex-specific env vars ────────────────────────────────────────────────
56-
57-
/// Env var injected to signal Vertex AI usage to Goose.
58-
pub const GOOSE_PROVIDER_ENV_VAR: &str = "GOOSE_PROVIDER";
59-
60-
/// Env var for Anthropic Vertex project ID (consumed by Claude Code SDK).
61-
pub const ANTHROPIC_VERTEX_PROJECT_ID_ENV_VAR: &str = "ANTHROPIC_VERTEX_PROJECT_ID";
62-
63-
/// Env var for Vertex location (consumed by Claude Code SDK).
64-
pub const VERTEX_LOCATION_ENV_VAR: &str = "VERTEX_LOCATION";
65-
66-
/// Non-secret GCP/Vertex config vars that must be resolved to real values
67-
/// in the child environment. Everything else stays as placeholders for
68-
/// proxy-time resolution.
69-
///
70-
/// This list MUST be the union of all alias arrays above plus all
71-
/// Vertex-specific env vars. If you add an alias to `PROJECT_ID_ENV_VARS`,
72-
/// `REGION_ENV_VARS`, or a Vertex constant, add it here too.
73-
pub const STATIC_CONFIG_KEYS: &[&str] = &[
74-
// project_id aliases
75-
"GCP_PROJECT_ID",
76-
"GOOGLE_CLOUD_PROJECT",
77-
// region aliases
78-
"CLOUD_ML_REGION",
79-
"GCP_LOCATION",
80-
// service account email
81-
"GCP_SERVICE_ACCOUNT_EMAIL",
82-
// Vertex-specific non-secret config
83-
GOOSE_PROVIDER_ENV_VAR,
84-
ANTHROPIC_VERTEX_PROJECT_ID_ENV_VAR,
85-
VERTEX_LOCATION_ENV_VAR,
86-
];
87-
8839
#[cfg(test)]
8940
mod tests {
9041
use super::*;
91-
use std::collections::HashSet;
9242

9343
#[test]
9444
fn metadata_destination_matches_only_reserved_loopback_endpoint() {
@@ -104,28 +54,4 @@ mod tests {
10454
assert!(!is_metadata_destination(address.parse().unwrap()));
10555
}
10656
}
107-
108-
#[test]
109-
fn static_config_keys_matches_alias_arrays_and_vertex_vars() {
110-
let expected: HashSet<&str> = PROJECT_ID_ENV_VARS
111-
.iter()
112-
.chain(REGION_ENV_VARS)
113-
.chain(SERVICE_ACCOUNT_EMAIL_ENV_VARS)
114-
.copied()
115-
.chain([
116-
GOOSE_PROVIDER_ENV_VAR,
117-
ANTHROPIC_VERTEX_PROJECT_ID_ENV_VAR,
118-
VERTEX_LOCATION_ENV_VAR,
119-
])
120-
.collect();
121-
let actual: HashSet<&str> = STATIC_CONFIG_KEYS.iter().copied().collect();
122-
assert_eq!(
123-
expected,
124-
actual,
125-
"STATIC_CONFIG_KEYS must be the union of all alias arrays + Vertex vars. \
126-
Missing: {:?}, Extra: {:?}",
127-
expected.difference(&actual).collect::<Vec<_>>(),
128-
actual.difference(&expected).collect::<Vec<_>>(),
129-
);
130-
}
13157
}

‎crates/openshell-core/src/provider_credentials.rs‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,108 @@ mod tests {
23252325
);
23262326
}
23272327

2328+
#[test]
2329+
fn gcp_token_response_returns_sa_over_adc() {
2330+
let state = ProviderCredentialState::from_environment(
2331+
1,
2332+
HashMap::from([
2333+
("GCP_SA_ACCESS_TOKEN".to_string(), "sa-tok".to_string()),
2334+
("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string()),
2335+
]),
2336+
HashMap::new(),
2337+
HashMap::new(),
2338+
);
2339+
let (placeholder, _) = state.gcp_token_response().expect("should find token");
2340+
assert_eq!(
2341+
placeholder, "openshell:resolve:env:v1_GCP_SA_ACCESS_TOKEN",
2342+
"metadata must return the current revision-scoped SA placeholder"
2343+
);
2344+
}
2345+
2346+
#[test]
2347+
fn gcp_token_response_falls_back_to_adc() {
2348+
let state = ProviderCredentialState::from_environment(
2349+
1,
2350+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2351+
HashMap::new(),
2352+
HashMap::new(),
2353+
);
2354+
let (placeholder, _) = state.gcp_token_response().expect("should find ADC token");
2355+
assert_eq!(
2356+
placeholder, "openshell:resolve:env:v1_GCP_ADC_ACCESS_TOKEN",
2357+
"metadata must return the current revision-scoped ADC placeholder"
2358+
);
2359+
}
2360+
2361+
#[test]
2362+
fn gcp_token_response_returns_none_without_gcp() {
2363+
let state = ProviderCredentialState::from_environment(
2364+
1,
2365+
HashMap::from([("GITHUB_TOKEN".to_string(), "ghp_abc".to_string())]),
2366+
HashMap::new(),
2367+
HashMap::new(),
2368+
);
2369+
assert!(state.gcp_token_response().is_none());
2370+
}
2371+
2372+
#[test]
2373+
fn gcp_token_response_defaults_expires_in_to_3600() {
2374+
let state = ProviderCredentialState::from_environment(
2375+
1,
2376+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2377+
HashMap::new(),
2378+
HashMap::new(),
2379+
);
2380+
let (_, expires_in) = state.gcp_token_response().unwrap();
2381+
assert_eq!(
2382+
expires_in, 3600,
2383+
"should default to 3600 when no expiry set"
2384+
);
2385+
}
2386+
2387+
#[test]
2388+
fn gcp_token_response_calculates_remaining() {
2389+
let now_ms = i64::try_from(
2390+
std::time::SystemTime::now()
2391+
.duration_since(std::time::UNIX_EPOCH)
2392+
.unwrap()
2393+
.as_millis(),
2394+
)
2395+
.unwrap();
2396+
let state = ProviderCredentialState::from_environment(
2397+
1,
2398+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2399+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), now_ms + 120_000)]),
2400+
HashMap::new(),
2401+
);
2402+
let (_, expires_in) = state.gcp_token_response().unwrap();
2403+
assert!(
2404+
(110..=120).contains(&expires_in),
2405+
"expected ~120s remaining, got {expires_in}"
2406+
);
2407+
}
2408+
2409+
#[test]
2410+
fn gcp_token_response_handles_already_expired_token_without_panic() {
2411+
let now_ms = i64::try_from(
2412+
std::time::SystemTime::now()
2413+
.duration_since(std::time::UNIX_EPOCH)
2414+
.unwrap()
2415+
.as_millis(),
2416+
)
2417+
.unwrap();
2418+
let state = ProviderCredentialState::from_environment(
2419+
1,
2420+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2421+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), now_ms - 1_000)]),
2422+
HashMap::new(),
2423+
);
2424+
assert!(
2425+
state.gcp_token_response().is_none(),
2426+
"expired token should be skipped rather than panic"
2427+
);
2428+
}
2429+
23282430
#[test]
23292431
fn child_env_with_non_secret_resolved_resolves_vertex_vars_without_metadata_host() {
23302432
let state = ProviderCredentialState::from_bound_environment(

‎crates/openshell-providers/src/environment_tests.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ fn platform_adapter_availability_and_unknown_adapter_errors() {
252252
let mut profile = profile();
253253
let availability = profile.ensure_platform_adapter_available();
254254
if cfg!(windows) {
255-
assert!(availability.unwrap_err().to_string().contains("unavailable"));
255+
assert!(
256+
availability
257+
.unwrap_err()
258+
.to_string()
259+
.contains("unavailable")
260+
);
256261
} else {
257262
assert!(availability.is_ok());
258263
}

‎crates/openshell-providers/src/profiles.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,11 +845,10 @@ impl ProviderTypeProfile {
845845
/// provides GCP metadata for non-Windows sandbox runtimes.
846846
pub fn ensure_platform_adapter_available(&self) -> Result<(), crate::ProviderError> {
847847
match self.required_platform_adapter.as_str() {
848-
"" => Ok(()),
849848
"gcp-metadata" if cfg!(windows) => {
850849
Err(crate::ProviderError::UnavailableGcpMetadataAdapter)
851850
}
852-
"gcp-metadata" => Ok(()),
851+
"" | "gcp-metadata" => Ok(()),
853852
_ => Err(crate::ProviderError::UnknownPlatformAdapter),
854853
}
855854
}

‎crates/openshell-server/src/grpc/provider.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5617,8 +5617,8 @@ mod tests {
56175617
assert!(response.imported, "{:?}", response.diagnostics);
56185618
}
56195619

5620-
// Existing stored profiles and interceptor-vended profiles must also
5621-
// fail at attachment, even when they did not pass this build's import.
5620+
// Existing stored and interceptor-vended profiles must pass the same
5621+
// capability check at attachment as profiles imported in this build.
56225622
state
56235623
.store
56245624
.put_message(&stored_provider_profile(profile))

‎e2e/support/gateway-common.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ e2e_import_example_provider_profiles() {
242242
echo "Importing example provider profiles from ${root}/providers..."
243243
for profile in "${root}"/providers/*.yaml; do
244244
adapter="$(yq -r '.required_platform_adapter // ""' "${profile}")" || return 1
245-
# The standard test runtimes provide no platform adapters. Specialized
246-
# suites must provision the capability before importing a profile needing it.
247-
if [ -n "${adapter}" ]; then
245+
# The standard Linux test runtimes provide the supervisor GCP metadata
246+
# adapter. Other platform adapters need a specialized suite.
247+
if [ -n "${adapter}" ] && [ "${adapter}" != "gcp-metadata" ]; then
248248
echo "Skipping ${profile}: requires platform adapter ${adapter}"
249249
continue
250250
fi

‎tasks/scripts/test-e2e-provider-profiles.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ trap 'rm -rf "${PROFILE_WORK}"' EXIT
1313
mkdir -p "${PROFILE_WORK}/providers"
1414
printf 'id: google-cloud\n' > "${PROFILE_WORK}/providers/google-cloud.yaml"
1515
printf 'id: acme\nrequired_platform_adapter: gcp-metadata\n' > "${PROFILE_WORK}/providers/acme.yaml"
16+
printf 'id: future\nrequired_platform_adapter: future-adapter\n' > "${PROFILE_WORK}/providers/future.yaml"
1617

1718
capture_profile_import() {
1819
printf '%s\n' "$*" >> "${PROFILE_WORK}/imports"
1920
}
2021

2122
e2e_import_example_provider_profiles capture_profile_import "${PROFILE_WORK}"
22-
expected="provider profile import --file ${PROFILE_WORK}/providers/google-cloud.yaml --global"
23+
expected="provider profile import --file ${PROFILE_WORK}/providers/acme.yaml --global
24+
provider profile import --file ${PROFILE_WORK}/providers/google-cloud.yaml --global"
2325
if [ "$(cat "${PROFILE_WORK}/imports")" != "${expected}" ]; then
2426
echo "FAIL: profile selection must follow adapter declarations, independent of ID" >&2
2527
exit 1

0 commit comments

Comments
 (0)