-
Notifications
You must be signed in to change notification settings - Fork 5
Scoped credentials for outgoing HTTP — host‑held secrets, guest‑held names #89
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
Open
simongdavies
wants to merge
12
commits into
hyperlight-dev:main
Choose a base branch
from
simongdavies:feat/scoped-credentials
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
13cb610
fix(python-guest): persist module globals across run() calls
simongdavies e471990
Add scoped credentials WIT interface
simongdavies 14136f7
feat(host): stub Credentials trait impl to keep build green
simongdavies 5b4ad0c
feat(credentials): add registry, attach binding, and host API
simongdavies e85d8fa
feat(credentials): hook outgoing-handler to inject credential headers
simongdavies 29c3111
feat(credentials): thread registry through all layers + Python SDK
simongdavies ec07662
build(wasm): set WIT_WORLD via workspace cargo config + detect WIT st…
simongdavies d11996c
feat(credentials): guest-side helper + integration tests (Phase 1)
simongdavies 4616952
build(wasm_sandbox): commit compiled WIT artifact + CI drift check
simongdavies c8fdd2e
fix(wasm_backend): remove buggy local .cargo/config.toml shadowing root
simongdavies 6b8076e
feat(credentials): resolver becomes a per-request callback
simongdavies 9e9ee77
build(wasm_sandbox): strip producers section so WIT artifact is deter…
simongdavies 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # WIT_WORLD is consumed at COMPILE time by: | ||
| # - hyperlight_wasm_macro (proc-macro) -> std::env::var_os("WIT_WORLD").unwrap() | ||
| # - hyperlight_wasm/build.rs -> rerun-if-env-changed=WIT_WORLD | ||
| # - hyperlight_wasm_runtime/build.rs -> emits cfg(component) IFF WIT_WORLD is set | ||
| # | ||
| # Without it, hyperlight_wasm_runtime falls back to the legacy flatbuffer-based | ||
| # host-function ABI, while hyperlight-wasm-sandbox (built with WIT_WORLD via the | ||
| # proc-macro's host_bindgen!) uses the component-model ABI. Mixing the two yields | ||
| # "GuestError: Host function vector parameter missing length" at sandbox start. | ||
| # | ||
| # `just wasm test` exports WIT_WORLD via its recipe, but bare `cargo` invocations | ||
| # (e.g. from an IDE or a developer running `cargo test --manifest-path ...`) | ||
| # would otherwise miss it. Cargo looks for `.cargo/config.toml` by walking up the | ||
| # CWD tree, so we put it at the repo root to cover every workspace cargo call. | ||
| [env] | ||
| WIT_WORLD = { value = "src/wasm_sandbox/wit/sandbox-world.wasm", relative = true } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //! Scoped-credential registry for outgoing HTTP requests. | ||
| //! | ||
| //! A [`CredentialEntry`] binds a logical credential identifier to the | ||
| //! metadata required to inject a token header at request time: | ||
| //! | ||
| //! * `target` — URL-prefix scope. The outgoing-handler only injects | ||
| //! the credential when the request URL starts with this prefix. | ||
| //! * `header` — HTTP header name (e.g. `"Authorization"`). | ||
| //! * `prefix` — Value prefix prepended to the resolved token | ||
| //! (e.g. `"Bearer "`). | ||
| //! * `resolver` — A host-side callback invoked on every credentialed | ||
| //! outgoing request to produce a fresh secret value. The host calls | ||
| //! the resolver synchronously from the WASI HTTP dispatch path, so | ||
| //! implementations should be fast and (where appropriate) memoise | ||
| //! internally. Errors returned by the resolver surface to the guest | ||
| //! as a request-level dispatch failure with a host-redacted message. | ||
| //! | ||
| //! The registry is populated by the host before the guest runs. | ||
| //! Guests bind a credential to a specific outgoing request via WIT | ||
| //! `attach`. | ||
|
|
||
| use std::collections::HashMap; | ||
| use std::fmt; | ||
| use std::sync::{Arc, Mutex}; | ||
|
|
||
| /// Host-side callback that produces the secret token value for a | ||
| /// credential at request-dispatch time. | ||
| /// | ||
| /// The returned `String` is treated as the literal token; the host | ||
| /// prepends [`CredentialEntry::prefix`] to it to form the outgoing | ||
| /// header value. | ||
| /// | ||
| /// On error, the returned diagnostic string is **dropped** by the | ||
| /// outgoing-handler before any guest-visible error is produced — it | ||
| /// is neither sent to the guest nor logged by this crate. The wire | ||
| /// path surfaces only a fixed `"credential resolver failed"` | ||
| /// indication. Resolver authors who need diagnostics should record | ||
| /// them inside the resolver itself (e.g. via the host's own logger) | ||
| /// before returning the `Err`. | ||
| pub type ResolverFn = Arc<dyn Fn() -> Result<String, String> + Send + Sync>; | ||
|
|
||
| /// Metadata for a single scoped credential. | ||
| #[derive(Clone)] | ||
| pub struct CredentialEntry { | ||
| /// URL-prefix scope. Only requests whose URL starts with this | ||
| /// value are eligible for credential injection. | ||
| pub target: String, | ||
|
|
||
| /// HTTP header name to set (e.g. `"Authorization"`). | ||
| pub header: String, | ||
|
|
||
| /// Value prefix prepended to the resolved token | ||
| /// (e.g. `"Bearer "`). May be empty. | ||
| pub prefix: String, | ||
|
|
||
| /// Resolver callback. Invoked on every credentialed outgoing | ||
| /// request; see [`ResolverFn`] for the contract. | ||
| pub resolver: ResolverFn, | ||
| } | ||
|
|
||
| impl fmt::Debug for CredentialEntry { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| // The resolver is a function pointer that may close over secret | ||
| // material; we never want it (or its captures) to appear in a | ||
| // log line, panic message, or `dbg!` output. | ||
| f.debug_struct("CredentialEntry") | ||
| .field("target", &self.target) | ||
| .field("header", &self.header) | ||
| .field("prefix", &self.prefix) | ||
| .field("resolver", &"<callback>") | ||
| .finish() | ||
| } | ||
| } | ||
|
|
||
| impl CredentialEntry { | ||
| /// Build a [`CredentialEntry`] whose resolver returns a fixed | ||
| /// token string on every invocation. | ||
| /// | ||
| /// Convenience constructor for tests, examples, and trivially | ||
| /// short-lived secrets. Production callers that need refresh | ||
| /// behaviour (managed identities, OAuth, …) should construct | ||
| /// the entry directly with a custom [`ResolverFn`]. | ||
| pub fn with_static_resolver( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put this behind a flag or something so its not used except for tests? |
||
| target: impl Into<String>, | ||
| header: impl Into<String>, | ||
| prefix: impl Into<String>, | ||
| token: impl Into<String>, | ||
| ) -> Self { | ||
| let token = token.into(); | ||
| Self { | ||
| target: target.into(), | ||
| header: header.into(), | ||
| prefix: prefix.into(), | ||
| resolver: Arc::new(move || Ok(token.clone())), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Shared, thread-safe credential registry keyed by credential id. | ||
| pub type CredentialRegistry = Arc<Mutex<HashMap<String, CredentialEntry>>>; | ||
|
|
||
| /// Creates an empty credential registry. | ||
| pub fn empty_registry() -> CredentialRegistry { | ||
| Arc::new(Mutex::new(HashMap::new())) | ||
| } | ||
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
This file was deleted.
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.
I am not sure legacy is the right term here? I had this problem too and had to run
hyperlight-sandbox/src/wasm_sandbox/Justfile
Line 34 in 60585dc