@@ -215,80 +215,112 @@ pub async fn run_sandbox(
215215 openshell_supervisor_process:: process:: ResolvedProcessIdentity :: default ( ) ;
216216
217217 #[ cfg_attr( not( target_os = "linux" ) , allow( unused_mut) ) ]
218- let ( provider_credentials, mut provider_env) =
219- if let Some ( bootstrap) = sidecar_bootstrap. as_ref ( ) {
220- let provider_credentials = ProviderCredentialState :: from_child_env_snapshot (
221- bootstrap. provider_env_revision ,
222- bootstrap. provider_child_env . clone ( ) ,
223- ) ;
224- ( provider_credentials, bootstrap. provider_child_env . clone ( ) )
225- } else {
226- // Fetch provider environment variables from the server.
227- // This is done after loading the policy so the sandbox can still start
228- // even if provider env fetch fails (graceful degradation).
229- let (
230- provider_env_revision,
231- provider_env,
232- provider_credential_expires_at_ms,
233- dynamic_credentials,
234- ) = if let ( Some ( id) , Some ( endpoint) ) = ( & sandbox_id, & openshell_endpoint) {
235- match openshell_core:: grpc_client:: fetch_provider_environment ( endpoint, id) . await {
236- Ok ( result) => {
237- ocsf_emit ! (
238- ConfigStateChangeBuilder :: new( ocsf_ctx( ) )
239- . severity( SeverityId :: Informational )
240- . status( StatusId :: Success )
241- . state( StateId :: Enabled , "loaded" )
242- . message( format!(
243- "Fetched provider environment [env_count:{}]" ,
244- result. environment. len( )
245- ) )
246- . build( )
247- ) ;
248- (
249- result. provider_env_revision ,
250- result. environment ,
251- result. credential_expires_at_ms ,
252- result. dynamic_credentials ,
253- )
254- }
255- Err ( e) => {
256- ocsf_emit ! (
218+ let ( provider_credentials, mut provider_env) = if let Some ( bootstrap) =
219+ sidecar_bootstrap. as_ref ( )
220+ {
221+ let provider_credentials = ProviderCredentialState :: from_child_env_snapshot (
222+ bootstrap. provider_env_revision ,
223+ bootstrap. provider_child_env . clone ( ) ,
224+ ) ;
225+ ( provider_credentials, bootstrap. provider_child_env . clone ( ) )
226+ } else {
227+ // Fetch provider environment variables from the server.
228+ // This is done after loading the policy so the sandbox can still start
229+ // even if provider env fetch fails (graceful degradation).
230+ let (
231+ provider_env_revision,
232+ provider_env,
233+ provider_credential_expires_at_ms,
234+ dynamic_credentials,
235+ static_credential_bindings,
236+ non_secret_environment_keys,
237+ ) = if let ( Some ( id) , Some ( endpoint) ) = ( & sandbox_id, & openshell_endpoint) {
238+ match openshell_core:: grpc_client:: fetch_provider_environment ( endpoint, id) . await {
239+ Ok ( result) => {
240+ ocsf_emit ! (
241+ ConfigStateChangeBuilder :: new( ocsf_ctx( ) )
242+ . severity( SeverityId :: Informational )
243+ . status( StatusId :: Success )
244+ . state( StateId :: Enabled , "loaded" )
245+ . message( format!(
246+ "Fetched provider environment [env_count:{}]" ,
247+ result. environment. len( )
248+ ) )
249+ . build( )
250+ ) ;
251+ (
252+ result. provider_env_revision ,
253+ result. environment ,
254+ result. credential_expires_at_ms ,
255+ result. dynamic_credentials ,
256+ result. static_credential_bindings ,
257+ result. non_secret_environment_keys ,
258+ )
259+ }
260+ Err ( e) => {
261+ ocsf_emit ! (
257262 ConfigStateChangeBuilder :: new( ocsf_ctx( ) )
258- . severity( SeverityId :: Medium )
263+ . severity( SeverityId :: High )
259264 . status( StatusId :: Failure )
260- . state( StateId :: Other , "degraded " )
265+ . state( StateId :: Disabled , "fail_closed " )
261266 . message( format!(
262- "Failed to fetch provider environment, continuing without : {e}"
267+ "Failed to fetch provider environment; no provider credentials are active : {e}"
263268 ) )
264269 . build( )
265270 ) ;
266- (
267- 0 ,
268- std:: collections:: HashMap :: new ( ) ,
269- std:: collections:: HashMap :: new ( ) ,
270- std:: collections:: HashMap :: new ( ) ,
271- )
272- }
271+ (
272+ 0 ,
273+ std:: collections:: HashMap :: new ( ) ,
274+ std:: collections:: HashMap :: new ( ) ,
275+ std:: collections:: HashMap :: new ( ) ,
276+ std:: collections:: HashMap :: new ( ) ,
277+ Vec :: new ( ) ,
278+ )
273279 }
274- } else {
275- (
276- 0 ,
277- std:: collections:: HashMap :: new ( ) ,
280+ }
281+ } else {
282+ (
283+ 0 ,
284+ std:: collections:: HashMap :: new ( ) ,
285+ std:: collections:: HashMap :: new ( ) ,
286+ std:: collections:: HashMap :: new ( ) ,
287+ std:: collections:: HashMap :: new ( ) ,
288+ Vec :: new ( ) ,
289+ )
290+ } ;
291+
292+ let dynamic_credentials_fallback = dynamic_credentials. clone ( ) ;
293+ let provider_credentials = match ProviderCredentialState :: from_bound_environment (
294+ provider_env_revision,
295+ provider_env,
296+ provider_credential_expires_at_ms,
297+ dynamic_credentials,
298+ static_credential_bindings,
299+ non_secret_environment_keys,
300+ ) {
301+ Ok ( credentials) => credentials,
302+ Err ( error) => {
303+ ocsf_emit ! (
304+ ConfigStateChangeBuilder :: new( ocsf_ctx( ) )
305+ . severity( SeverityId :: High )
306+ . status( StatusId :: Failure )
307+ . state( StateId :: Disabled , "fail_closed" )
308+ . message( format!(
309+ "Rejected provider environment bindings; static provider credentials were revoked; fetched dynamic token grants remain active: {error}"
310+ ) )
311+ . build( )
312+ ) ;
313+ ProviderCredentialState :: from_environment (
314+ provider_env_revision,
278315 std:: collections:: HashMap :: new ( ) ,
279316 std:: collections:: HashMap :: new ( ) ,
317+ dynamic_credentials_fallback,
280318 )
281- } ;
282-
283- let provider_credentials = ProviderCredentialState :: from_environment (
284- provider_env_revision,
285- provider_env,
286- provider_credential_expires_at_ms,
287- dynamic_credentials,
288- ) ;
289- let provider_env = provider_credentials. child_env_with_gcp_resolved ( ) ;
290- ( provider_credentials, provider_env)
319+ }
291320 } ;
321+ let provider_env = provider_credentials. child_env_with_gcp_resolved ( ) ;
322+ ( provider_credentials, provider_env)
323+ } ;
292324
293325 // Shared agent-proposals feature flag. Seed from the same initial settings
294326 // snapshot that produced the policy so networking and process setup agree
@@ -3577,12 +3609,28 @@ async fn run_policy_poll_loop(ctx: PolicyPollLoopContext) -> Result<()> {
35773609 . await
35783610 {
35793611 Ok ( env_result) => {
3580- ctx. provider_credentials . install_environment (
3581- env_result. provider_env_revision ,
3612+ let provider_env_revision = env_result. provider_env_revision ;
3613+ let install_result = ctx. provider_credentials . install_bound_environment (
3614+ provider_env_revision,
35823615 env_result. environment ,
35833616 env_result. credential_expires_at_ms ,
35843617 env_result. dynamic_credentials ,
3618+ env_result. static_credential_bindings ,
3619+ env_result. non_secret_environment_keys ,
35853620 ) ;
3621+ if let Err ( error) = install_result {
3622+ ocsf_emit ! (
3623+ ConfigStateChangeBuilder :: new( ocsf_ctx( ) )
3624+ . severity( SeverityId :: High )
3625+ . status( StatusId :: Failure )
3626+ . state( StateId :: Enabled , "retained_previous_credentials" )
3627+ . message( format!(
3628+ "Rejected provider environment refresh bindings; previous provider credentials remain active: {error}"
3629+ ) )
3630+ . build( )
3631+ ) ;
3632+ continue ;
3633+ }
35863634 let child_env = ctx. provider_credentials . child_env_with_gcp_resolved ( ) ;
35873635 let env_count = child_env. len ( ) ;
35883636 if let Some ( publisher) = ctx. sidecar_control_publisher . as_ref ( ) {
@@ -3591,19 +3639,18 @@ async fn run_policy_poll_loop(ctx: PolicyPollLoopContext) -> Result<()> {
35913639 child_env. clone ( ) ,
35923640 ) ;
35933641 }
3594- current_provider_env_revision = env_result . provider_env_revision ;
3642+ current_provider_env_revision = provider_env_revision;
35953643 ocsf_emit ! (
35963644 ConfigStateChangeBuilder :: new( ocsf_ctx( ) )
35973645 . severity( SeverityId :: Informational )
35983646 . status( StatusId :: Success )
35993647 . state( StateId :: Enabled , "loaded" )
36003648 . unmapped(
36013649 "provider_env_revision" ,
3602- serde_json:: json!( env_result . provider_env_revision)
3650+ serde_json:: json!( provider_env_revision)
36033651 )
36043652 . message( format!(
3605- "Provider environment refreshed [revision:{} env_count:{env_count}]" ,
3606- env_result. provider_env_revision
3653+ "Provider environment refreshed [revision:{provider_env_revision} env_count:{env_count}]"
36073654 ) )
36083655 . build( )
36093656 ) ;
0 commit comments