-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(host-runtime): wire WASM secret-exists to staged credentials (#7307) #7329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+533
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
crates/kernel/ironclaw_host_runtime/src/services/wasm_secrets.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| //! Production backing for the WASM guest `secret-exists` host import. | ||
| //! | ||
| //! Guests (including third-party registry/ironhub tools such as `attio`) use | ||
| //! `secret-exists` as their only credential probe: they abort with a | ||
| //! "credential not configured" failure when it returns `false`. Historically | ||
| //! every production invocation ran with [`WasmHostSecrets`] left at the | ||
| //! [`DenyWasmHostSecrets`] default, so the probe returned `false` even when a | ||
| //! real, staged credential was available — every such tool failed with an | ||
| //! opaque `operation_failed` before ever issuing a request. | ||
| //! | ||
| //! This implementation answers the probe from the per-invocation staged | ||
| //! secret injection store ([`RuntimeSecretInjectionStore`]): authorization | ||
| //! stages granted secret material under `(scope, capability_id, handle)` (see | ||
| //! `obligations/handler.rs`), so `exists` reports `true` exactly when a | ||
| //! non-empty credential for this invocation was actually leased and consumed | ||
| //! — not merely because a manifest declares the handle. | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use ironclaw_host_api::{ | ||
| ids::{CapabilityId, SecretHandle}, | ||
| resource::ResourceScope, | ||
| }; | ||
| use ironclaw_wasm::WasmHostSecrets; | ||
| use secrecy::ExposeSecret; | ||
|
|
||
| use crate::obligations::RuntimeSecretInjectionStore; | ||
|
|
||
| /// Per-invocation `secret-exists` view over the staged secret injection store. | ||
| /// | ||
| /// The store is keyed by the invocation's scope, capability, and the slot | ||
| /// handle the guest is expected to probe, so the view is closed over exactly | ||
| /// those three values. Material is read non-destructively | ||
| /// (`clone_material`) — answering the probe must not consume the one-shot | ||
| /// staged secret that the HTTP egress still needs. | ||
| #[derive(Debug)] | ||
| pub(crate) struct StagedWasmHostSecrets { | ||
| store: Arc<RuntimeSecretInjectionStore>, | ||
| scope: ResourceScope, | ||
| capability_id: CapabilityId, | ||
| } | ||
|
|
||
| impl StagedWasmHostSecrets { | ||
| pub(crate) fn new( | ||
| store: Arc<RuntimeSecretInjectionStore>, | ||
| scope: ResourceScope, | ||
| capability_id: CapabilityId, | ||
| ) -> Self { | ||
| Self { | ||
| store, | ||
| scope, | ||
| capability_id, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl WasmHostSecrets for StagedWasmHostSecrets { | ||
| fn exists(&self, name: &str) -> bool { | ||
| let Ok(handle) = SecretHandle::new(name) else { | ||
| // A guest probing a malformed handle name gets a truthful `false`. | ||
| return false; | ||
| }; | ||
| match self | ||
| .store | ||
| .clone_material(&self.scope, &self.capability_id, &handle) | ||
| { | ||
| // Fail closed: an empty staged credential is not a usable | ||
| // credential — the guest must surface its own re-auth path rather | ||
| // than send an empty key. | ||
| Ok(Some(material)) => !material.expose_secret().is_empty(), | ||
| // No staged material for this invocation (or a poisoned store | ||
| // lock) means the credential was never authorized for this call. | ||
| Ok(None) | Err(_) => false, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use ironclaw_host_api::ids::InvocationId; | ||
|
|
||
| fn store() -> Arc<RuntimeSecretInjectionStore> { | ||
| Arc::new(RuntimeSecretInjectionStore::new()) | ||
| } | ||
|
|
||
| fn scope() -> ResourceScope { | ||
| ResourceScope { | ||
| tenant_id: ironclaw_host_api::ids::TenantId::new("test-tenant").unwrap(), | ||
| user_id: ironclaw_host_api::ids::UserId::new("test-user").unwrap(), | ||
| agent_id: None, | ||
| project_id: None, | ||
| mission_id: None, | ||
| thread_id: None, | ||
| invocation_id: InvocationId::new(), | ||
| } | ||
| } | ||
|
|
||
| fn capability() -> CapabilityId { | ||
| CapabilityId::new("attio.invoke").unwrap() | ||
| } | ||
|
|
||
| fn secrets() -> StagedWasmHostSecrets { | ||
| StagedWasmHostSecrets::new(store(), scope(), capability()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn exists_true_for_staged_non_empty_material() { | ||
| let store = store(); | ||
| let scope = scope(); | ||
| let handle = SecretHandle::new("attio_api_key").unwrap(); | ||
| store | ||
| .insert( | ||
| &scope, | ||
| &capability(), | ||
| &handle, | ||
| ironclaw_secrets::SecretMaterial::from("att-123"), | ||
| ) | ||
| .expect("staging should succeed"); | ||
| let secrets = StagedWasmHostSecrets::new(store, scope, capability()); | ||
| assert!(secrets.exists("attio_api_key")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn exists_false_for_staged_empty_material() { | ||
| let store = store(); | ||
| let scope = scope(); | ||
| let handle = SecretHandle::new("attio_api_key").unwrap(); | ||
| store | ||
| .insert( | ||
| &scope, | ||
| &capability(), | ||
| &handle, | ||
| ironclaw_secrets::SecretMaterial::from(""), | ||
| ) | ||
| .expect("staging should succeed"); | ||
| let secrets = StagedWasmHostSecrets::new(store, scope, capability()); | ||
| assert!(!secrets.exists("attio_api_key")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn exists_false_without_staged_material() { | ||
| assert!(!secrets().exists("attio_api_key")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn exists_false_for_other_capability_or_scope() { | ||
| let store = store(); | ||
| let scope = scope(); | ||
| let handle = SecretHandle::new("attio_api_key").unwrap(); | ||
| store | ||
| .insert( | ||
| &scope, | ||
| &capability(), | ||
| &handle, | ||
| ironclaw_secrets::SecretMaterial::from("att-123"), | ||
| ) | ||
| .expect("staging should succeed"); | ||
| let other_capability = CapabilityId::new("other.invoke").unwrap(); | ||
| assert!( | ||
| !StagedWasmHostSecrets::new(Arc::clone(&store), scope.clone(), other_capability) | ||
| .exists("attio_api_key") | ||
| ); | ||
| assert!(!StagedWasmHostSecrets::new(store, scope, capability()).exists("other_secret")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn exists_false_for_malformed_handle() { | ||
| assert!(!secrets().exists("not a valid handle")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn exists_reads_do_not_consume_staged_material() { | ||
| let store = store(); | ||
| let scope = scope(); | ||
| let handle = SecretHandle::new("attio_api_key").unwrap(); | ||
| store | ||
| .insert( | ||
| &scope, | ||
| &capability(), | ||
| &handle, | ||
| ironclaw_secrets::SecretMaterial::from("att-123"), | ||
| ) | ||
| .expect("staging should succeed"); | ||
| let secrets = StagedWasmHostSecrets::new(store, scope, capability()); | ||
| assert!(secrets.exists("attio_api_key")); | ||
| // The HTTP egress still needs the staged material after the probe. | ||
| assert!(secrets.exists("attio_api_key")); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Test a mismatched invocation scope.
exists_false_for_other_capability_or_scopedoes not create anotherResourceScope. It tests a different capability and handle only.Add an assertion with a fresh scope. This verifies that one invocation cannot observe staged credential presence from another invocation.
Proposed test addition
let other_capability = CapabilityId::new("other.invoke").unwrap(); assert!( !StagedWasmHostSecrets::new(Arc::clone(&store), scope.clone(), other_capability) .exists("attio_api_key") ); + let other_scope = scope(); + assert!( + !StagedWasmHostSecrets::new(Arc::clone(&store), other_scope, capability()) + .exists("attio_api_key") + ); assert!(!StagedWasmHostSecrets::new(store, scope, capability()).exists("other_secret"));As per coding guidelines, credentials must be resolved and injected at the narrowest egress boundary.
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines