Skip to content

Commit cabc2ee

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 6503084 commit cabc2ee

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
@@ -2789,6 +2789,108 @@ mod tests {
27892789
);
27902790
}
27912791

2792+
#[test]
2793+
fn gcp_token_response_returns_sa_over_adc() {
2794+
let state = ProviderCredentialState::from_environment(
2795+
1,
2796+
HashMap::from([
2797+
("GCP_SA_ACCESS_TOKEN".to_string(), "sa-tok".to_string()),
2798+
("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string()),
2799+
]),
2800+
HashMap::new(),
2801+
HashMap::new(),
2802+
);
2803+
let (placeholder, _) = state.gcp_token_response().expect("should find token");
2804+
assert_eq!(
2805+
placeholder, "openshell:resolve:env:v1_GCP_SA_ACCESS_TOKEN",
2806+
"metadata must return the current revision-scoped SA placeholder"
2807+
);
2808+
}
2809+
2810+
#[test]
2811+
fn gcp_token_response_falls_back_to_adc() {
2812+
let state = ProviderCredentialState::from_environment(
2813+
1,
2814+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2815+
HashMap::new(),
2816+
HashMap::new(),
2817+
);
2818+
let (placeholder, _) = state.gcp_token_response().expect("should find ADC token");
2819+
assert_eq!(
2820+
placeholder, "openshell:resolve:env:v1_GCP_ADC_ACCESS_TOKEN",
2821+
"metadata must return the current revision-scoped ADC placeholder"
2822+
);
2823+
}
2824+
2825+
#[test]
2826+
fn gcp_token_response_returns_none_without_gcp() {
2827+
let state = ProviderCredentialState::from_environment(
2828+
1,
2829+
HashMap::from([("GITHUB_TOKEN".to_string(), "ghp_abc".to_string())]),
2830+
HashMap::new(),
2831+
HashMap::new(),
2832+
);
2833+
assert!(state.gcp_token_response().is_none());
2834+
}
2835+
2836+
#[test]
2837+
fn gcp_token_response_defaults_expires_in_to_3600() {
2838+
let state = ProviderCredentialState::from_environment(
2839+
1,
2840+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2841+
HashMap::new(),
2842+
HashMap::new(),
2843+
);
2844+
let (_, expires_in) = state.gcp_token_response().unwrap();
2845+
assert_eq!(
2846+
expires_in, 3600,
2847+
"should default to 3600 when no expiry set"
2848+
);
2849+
}
2850+
2851+
#[test]
2852+
fn gcp_token_response_calculates_remaining() {
2853+
let now_ms = i64::try_from(
2854+
std::time::SystemTime::now()
2855+
.duration_since(std::time::UNIX_EPOCH)
2856+
.unwrap()
2857+
.as_millis(),
2858+
)
2859+
.unwrap();
2860+
let state = ProviderCredentialState::from_environment(
2861+
1,
2862+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2863+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), now_ms + 120_000)]),
2864+
HashMap::new(),
2865+
);
2866+
let (_, expires_in) = state.gcp_token_response().unwrap();
2867+
assert!(
2868+
(110..=120).contains(&expires_in),
2869+
"expected ~120s remaining, got {expires_in}"
2870+
);
2871+
}
2872+
2873+
#[test]
2874+
fn gcp_token_response_handles_already_expired_token_without_panic() {
2875+
let now_ms = i64::try_from(
2876+
std::time::SystemTime::now()
2877+
.duration_since(std::time::UNIX_EPOCH)
2878+
.unwrap()
2879+
.as_millis(),
2880+
)
2881+
.unwrap();
2882+
let state = ProviderCredentialState::from_environment(
2883+
1,
2884+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), "adc-tok".to_string())]),
2885+
HashMap::from([("GCP_ADC_ACCESS_TOKEN".to_string(), now_ms - 1_000)]),
2886+
HashMap::new(),
2887+
);
2888+
assert!(
2889+
state.gcp_token_response().is_none(),
2890+
"expired token should be skipped rather than panic"
2891+
);
2892+
}
2893+
27922894
#[test]
27932895
fn child_env_with_non_secret_resolved_resolves_vertex_vars_without_metadata_host() {
27942896
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
@@ -849,11 +849,10 @@ impl ProviderTypeProfile {
849849
/// provides GCP metadata for non-Windows sandbox runtimes.
850850
pub fn ensure_platform_adapter_available(&self) -> Result<(), crate::ProviderError> {
851851
match self.required_platform_adapter.as_str() {
852-
"" => Ok(()),
853852
"gcp-metadata" if cfg!(windows) => {
854853
Err(crate::ProviderError::UnavailableGcpMetadataAdapter)
855854
}
856-
"gcp-metadata" => Ok(()),
855+
"" | "gcp-metadata" => Ok(()),
857856
_ => Err(crate::ProviderError::UnknownPlatformAdapter),
858857
}
859858
}

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

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

5657-
// Existing stored profiles and interceptor-vended profiles must also
5658-
// fail at attachment, even when they did not pass this build's import.
5657+
// Existing stored and interceptor-vended profiles must pass the same
5658+
// capability check at attachment as profiles imported in this build.
56595659
state
56605660
.store
56615661
.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)