<p>A worked example of using <a href="https://spinframework.dev/v3/writing-apps#using-component-dependencies">component dependencies</a> to keep credentials out of a Spin component. The app has one HTTP handler that needs an API key. Instead of reading it from a variable, it imports <code>seekrit:secrets/store</code> from a dependency that fetches and decrypts on its behalf.</p> <h2>spin.toml</h2> <pre><code class="language-toml">spin_manifest_version = 2 [application] name = &quot;seekrit-spin-example&quot; version = &quot;0.1.0&quot; [variables] seekrit_token = { required = true } [[trigger.http]] route = &quot;/...&quot; component = &quot;app&quot; [component.app] source = &quot;target/wasm32-wasip2/release/seekrit_spin_example.wasm&quot; allowed_outbound_hosts = [&quot;https://api.seekrit.dev&quot;] dependencies_inherit_configuration = true [component.app.variables] seekrit_token = &quot;\{{ seekrit_token }}&quot; [component.app.dependencies] &quot;seekrit:secrets/store&quot; = { version = &quot;0.3.0&quot;, package = &quot;seekritdev:secrets-spin&quot;, registry = &quot;ghcr.io&quot; } [component.app.build] command = &quot;cargo build --target wasm32-wasip2 --release&quot; watch = [&quot;src/**/*.rs&quot;, &quot;Cargo.toml&quot;] </code></pre> <h2>src/lib.rs</h2> <pre><code class="language-rust">use spin_sdk::http::{IntoResponse, Request, Response}; use spin_sdk::http_service; // Bindings for the interface named in `[component.app.dependencies]`. Spin // plugs the dependency into it at load time, so nothing here names a package // or a registry. spin_sdk::dependencies!(); use seekrit::secrets::store; #[http_service] async fn handle_seekrit_example(_req: Request) -&gt; anyhow::Result&lt;impl IntoResponse&gt; { // Names carry no values, so this is safe to return. let names = match store::list_names() { Ok(names) =&gt; names, Err(e) =&gt; return Ok(text(503, &amp;format!(&quot;{e:?}&quot;))), }; // The value stays inside this component; report its length, not the value. let api_key = match store::get(&quot;STRIPE_API_KEY&quot;) { Ok(Some(v)) =&gt; format!(&quot;{} bytes&quot;, v.len()), Ok(None) =&gt; &quot;not in scope&quot;.to_string(), Err(e) =&gt; return Ok(text(503, &amp;format!(&quot;{e:?}&quot;))), }; Ok(text(200, &amp;format!(&quot;in scope: {}\nSTRIPE_API_KEY: {api_key}\n&quot;, names.join(&quot;, &quot;)))) } fn text(status: u16, body: &amp;str) -&gt; impl IntoResponse { Response::builder() .status(status) .header(&quot;content-type&quot;, &quot;text/plain&quot;) .body(body.to_string()) } </code></pre> <h2>Running it</h2> <pre><code class="language-bash">export SPIN_VARIABLE_SEEKRIT_TOKEN=&quot;skt_...&quot; spin build spin up curl localhost:3000 </code></pre> <pre><code>in scope: DATABASE_URL, STRIPE_API_KEY STRIPE_API_KEY: 32 bytes </code></pre> <p>For a deployment, declare a Spin variables provider in <code>runtime-config.toml</code> and point <code>seekrit_token</code> at it; nothing in the component or the manifest changes. What that provider holds is one revocable, read-only token scoped to a single environment — not the secrets.</p> <h2>What is worth copying from this</h2> <p>The pattern generalises past secrets. A dependency component is a way to give one component a capability without giving it the credential the capability needs, and three manifest details make or break it:</p> <ul> <li><code>dependencies_inherit_configuration = true</code>, because Spin grants a dependency none of the parent’s permissions by default. Without it the dependency can neither call out nor read a variable.</li> <li>The dependency package must import the exact <code>wasi:config</code> version Spin registers (<code>0.2.0-draft-2024-09-27</code>). wasmtime gives pre-release versions no semver-compatible matching, so a component built against <code>0.2.0-draft</code> is a different import name and fails at instantiation rather than at a call site.</li> <li>Secrets belong in <code>[component.*.variables]</code>, not <code>component.*.environment</code> — manifest expressions are not supported in <code>environment</code>, so it can only hold a literal.</li> </ul> <p>Verified against Spin 4.1.0.</p> <p>Full walkthrough: <a href="https://seekrit.dev/docs/guides/spin">seekrit.dev/docs/guides/spin</a>.</p>