Skip to content

Commit c34ec20

Browse files
committed
refactor(providers): localize GCP metadata environment keys
Replace obsolete shared project and service-account email alias arrays with constants local to the metadata emulator, their sole consumer. Document the emulator's required environment destinations, token precedence, and missing-value responses. Specify gateway and profile upgrades before supervisor upgrades to preserve metadata discovery during upgrades from 0.1.x. Validation: all 23 focused metadata emulator tests passed. Rust formatting and git diff --check passed. Fern documentation and navigation checks passed with zero errors and three existing warnings. Signed-off-by: Philippe Martin <phmartin@redhat.com>
1 parent e24c0ad commit c34ec20

4 files changed

Lines changed: 33 additions & 15 deletions

File tree

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@ pub fn is_metadata_destination(destination: std::net::SocketAddr) -> bool {
2121
destination == std::net::SocketAddr::from(([127, 0, 0, 1], 8174))
2222
}
2323

24-
// ── Metadata environment keys ───────────────────────────────────────────────
25-
26-
/// Env vars that carry the GCP project ID inside sandboxes.
27-
pub const PROJECT_ID_ENV_VARS: &[&str] = &["GCP_PROJECT_ID", "GOOGLE_CLOUD_PROJECT"];
28-
29-
/// Env vars that carry the GCP service account email inside sandboxes.
30-
pub const SERVICE_ACCOUNT_EMAIL_ENV_VARS: &[&str] = &["GCP_SERVICE_ACCOUNT_EMAIL"];
31-
3224
// ── Token search order ──────────────────────────────────────────────────────
3325

3426
/// GCP token env vars searched in priority order by the metadata emulator.

‎crates/openshell-supervisor-network/src/google_cloud_metadata.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ const PATH_SCOPES: &str = "/computeMetadata/v1/instance/service-accounts/default
3232
const PATH_ALIASES: &str = "/computeMetadata/v1/instance/service-accounts/default/aliases";
3333
const PATH_PROJECT_ID: &str = "/computeMetadata/v1/project/project-id";
3434

35-
const ENV_GCP_PROJECT_ID: &str = openshell_core::google_cloud::PROJECT_ID_ENV_VARS[0];
36-
const ENV_GCP_SERVICE_ACCOUNT_EMAIL: &str =
37-
openshell_core::google_cloud::SERVICE_ACCOUNT_EMAIL_ENV_VARS[0];
35+
const ENV_GCP_PROJECT_ID: &str = "GCP_PROJECT_ID";
36+
const ENV_GCP_SERVICE_ACCOUNT_EMAIL: &str = "GCP_SERVICE_ACCOUNT_EMAIL";
3837

3938
const METADATA_FLAVOR_HEADER: &str = "metadata-flavor";
4039
const METADATA_FLAVOR_VALUE: &str = "Google";

‎docs/how-it-works/providers/google.mdx‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,28 @@ Requests to the host's cloud metadata service remain blocked; the emulator does
160160

161161
### Injected Environment Variables
162162

163-
The provider automatically injects these into the sandbox. Non-secret
164-
vars are resolved to real values at process spawn time; token vars stay
165-
as placeholders for proxy-time resolution.
163+
The `google-cloud` example profile declares these environment variables.
164+
Non-secret values come from `environment.config` or `environment.fixed` and
165+
resolve at process spawn time. Declare token destinations in credential
166+
`env_vars`; token values remain placeholders for proxy-time resolution.
166167

167168
| Variable | Value | Purpose |
168169
|----------|-------|---------|
169170
| `GCE_METADATA_HOST` | `127.0.0.1:8174` | GCP SDK metadata discovery (supervisor emulator) |
170171
| `GCE_METADATA_IP` | `127.0.0.1:8174` | Python google-auth ping detection |
171172
| `METADATA_SERVER_DETECTION` | `assume-present` | Node.js gcp-metadata skip detection |
172-
| `GCP_PROJECT_ID` | from `project_id` config | GCP SDK project |
173+
| `GCP_PROJECT_ID` | from `project_id` config | Metadata project-ID endpoint and GCP SDK project |
173174
| `GOOGLE_CLOUD_PROJECT` | from `project_id` config | Alternative project var |
174175
| `CLOUD_ML_REGION` | from `region` config | GCP region |
175176
| `GCP_LOCATION` | from `region` config | Alternative region var |
177+
| `GCP_SERVICE_ACCOUNT_EMAIL` | from `service_account_email` config | Optional metadata service-account email |
178+
| `GCP_SA_ACCESS_TOKEN` | Credential placeholder | Preferred metadata access token |
179+
| `GCP_ADC_ACCESS_TOKEN` | Credential placeholder | Metadata access token when no usable service-account token is available |
180+
181+
Custom profiles must use these exact names for the metadata project-ID, email,
182+
and token endpoints. A project or email key unavailable as a non-secret value
183+
makes its endpoint return HTTP `404`. Mapping the project only to
184+
`GOOGLE_CLOUD_PROJECT` does not supply the metadata project-ID endpoint.
176185

177186
For each non-secret variable, a sandbox create-time value overrides its template
178187
value, which overrides the provider default. The metadata project-ID endpoint

‎docs/upgrade/0-2-0.mdx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ your role before upgrading from OpenShell 0.1.x to 0.2.0.
1414

1515
If you run OpenShell for a team, start here.
1616

17+
### Upgrade gateways before supervisors
18+
19+
Use this order when your sandboxes use Google Cloud metadata discovery.
20+
21+
1. Export and edit existing profiles as described in
22+
[Migrate Google Cloud and Vertex AI profiles](#migrate-google-cloud-and-vertex-ai-profiles).
23+
2. Upgrade the gateway to 0.2.0 and apply the updated profiles.
24+
3. Upgrade supervisors to 0.2.0. The updated metadata settings work with 0.1.x
25+
supervisors during the rollout.
26+
27+
A 0.1.x gateway sends `GCE_METADATA_HOST=gcp.metadata.openshell.internal`.
28+
Older supervisors rewrite it to `127.0.0.1:8174` and add `GCE_METADATA_IP` and
29+
`METADATA_SERVER_DETECTION`. Supervisors in 0.2.0 use profile-declared settings
30+
without this rewrite or these additions. Upgrading supervisors first breaks
31+
clients that dial the metadata host directly and SDK detection in Python
32+
`google-auth` and Node.js `gcp-metadata`, even while requests through the proxy
33+
can continue to work.
34+
1735
### Migrate Google Cloud and Vertex AI profiles
1836

1937
In OpenShell 0.1.x, the gateway recognized the Google profile IDs and added SDK

0 commit comments

Comments
 (0)