---
title: "Component Configuration and Secrets | Cosmonic"
description: "Configure Wasm components with inline values, Kubernetes ConfigMaps, Secrets, and network allowlists on Cosmonic Control."
canonical: "https://cosmonic.com/docs/operations/component-configuration/"
---

# Component Configuration and Secrets

Wasm components running on Cosmonic Control receive configuration and secrets through fields on the `WorkloadDeployment` manifest. For an HTTP workload, that is the `WorkloadDeployment` an [`HTTPTrigger`](https://cosmonic.com/docs/custom-resources/#httptrigger) routes to; the trigger itself carries no component configuration. Values are delivered to the component via the [`wasi:config`](https://github.com/WebAssembly/wasi-config) interface and read at runtime.

This page covers all configuration mechanisms available to a component: inline key-value pairs, references to Kubernetes ConfigMaps and Secrets, outbound network allowlisting, and private OCI registries for component images.

## Inline configuration

Pass static key-value pairs directly in the manifest using `localResources.environment.config`:

```yaml
apiVersion: runtime.wasmcloud.dev/v1alpha1
kind: WorkloadDeployment
metadata:
  name: my-app
  namespace: default
spec:
  replicas: 1
  template:
    spec:
      hostInterfaces:
        - namespace: wasi
          package: http
          interfaces:
            - incoming-handler
          config:
            host: my-app.localhost.cosmonic.sh
      components:
        - name: app
          image: ghcr.io/my-org/my-app:1.0.0
          localResources:
            environment:
              config:
                LOG_LEVEL: info
                CACHE_TTL: "300"
                FEATURE_FLAG_DARK_MODE: "true"
```

Keys and values are arbitrary strings. The component reads them at runtime via `wasi:config/runtime`.

## Configuration from a ConfigMap

Reference a Kubernetes ConfigMap to supply configuration without embedding it in the manifest. All keys in the ConfigMap are merged into the component's configuration:

```shell
kubectl create configmap my-app-config \
  --from-literal=LOG_LEVEL=info \
  --from-literal=CACHE_TTL=300 \
  -n default
```

```yaml
spec:
  template:
    spec:
      components:
        - name: app
          image: ghcr.io/my-org/my-app:1.0.0
          localResources:
            environment:
              configFrom:
                - name: my-app-config
```

Multiple ConfigMaps may be listed. If the same key appears in more than one, the last entry in the list wins.

You can combine `configFrom` with inline `config`. Inline values are merged alongside the referenced ConfigMaps. In case of key conflicts, the last source in declaration order wins:

```yaml
localResources:
  environment:
    config:
      FEATURE_FLAG_DARK_MODE: "true"   # inline override
    configFrom:
      - name: my-app-config            # base config from ConfigMap
      - name: my-app-config-overrides  # additional overrides
```

## Secrets

Reference a Kubernetes Secret to inject sensitive values. Secret values are base64-decoded and UTF-8 decoded before being delivered to the component:

```shell
kubectl create secret generic my-app-secrets \
  --from-literal=DATABASE_URL=postgres://user:password@db.internal:5432/mydb \
  --from-literal=API_KEY=supersecretkey \
  -n default
```

```yaml
spec:
  template:
    spec:
      components:
        - name: app
          image: ghcr.io/my-org/my-app:1.0.0
          localResources:
            environment:
              secretFrom:
                - name: my-app-secrets
```

Multiple Secrets may be listed. If the same key appears in more than one, the last entry takes precedence.

`configFrom` and `secretFrom` may be combined freely. All referenced ConfigMaps and Secrets are merged into a single flat key-value map delivered to the component:

```yaml
localResources:
  environment:
    config:
      LOG_LEVEL: info
    configFrom:
      - name: my-app-config
    secretFrom:
      - name: my-app-secrets
```

> **Note**
>
> The operator service account has `get`, `list`, and `watch` access to Secrets cluster-wide by default (see [Kubernetes RBAC](https://cosmonic.com/docs/operations/deploying-to-cosmonic-control/#kubernetes-rbac)). Ensure your namespace RBAC restricts which tenants can create or read Secrets in each namespace.

## Host interface configuration

Some host interfaces require their own configuration — for example, an outbound HTTP interface that needs a base URL, or a blobstore interface that needs a bucket name. These are separate from component configuration and are passed to the capability layer via `hostInterfaces[].config`:

```yaml
spec:
  template:
    spec:
      components:
        - name: app
          image: ghcr.io/my-org/my-app:1.0.0
      hostInterfaces:
        - namespace: wasi
          package: blobstore
          version: 0.2.0-draft
          interfaces:
            - blobstore
          config:
            bucket: my-bucket
          secretFrom:
            - name: blobstore-credentials
```

`hostInterfaces` supports the same `config`, `configFrom`, and `secretFrom` fields as component `localResources`.

## Named host interfaces

A workload can declare the same `namespace:package` more than once under distinct `name`s, with each entry carrying its own `config` and secrets. As of Cosmonic Control v0.7.0 (wasmCloud v2.5.1 hosts), the `name` is a routing identity: the host resolves a component's named `(implements <name>)` imports by it, so two imports of the same interface can land on different backends — for example, a NATS-backed cache and a Redis session store both speaking `wasi:keyvalue`:

```yaml
spec:
  template:
    spec:
      components:
        - name: app
          image: ghcr.io/my-org/my-app:1.0.0
      hostInterfaces:
        - namespace: wasi
          package: keyvalue
          version: 0.2.0-draft
          name: cache
          interfaces:
            - store
          config:
            backend: nats
        - namespace: wasi
          package: keyvalue
          version: 0.2.0-draft
          name: sessions
          interfaces:
            - store
          config:
            backend: redis
```

The `backend` key selects the backing store the host's multiplexed keyvalue plugin uses for each named import: `in-memory`, `filesystem`, `redis`, or `nats`. Bucket names are still chosen by the component at runtime via `store::open(...)`, and each open call is scoped to the backend its import routes to.

Where each backend lives (`url`, plus `root` and `prefix`) belongs to the HostGroup, not the workload. Since v0.14.0 a workload that sets one of those keys on a named binding, in `config` or through `secretFrom`, is refused under the default `workloadConfig: deny`. Declare them on a source-less `hostPlugins` entry, keyed by the binding's `name`:

```yaml
# hostgroup-values.yaml
hostPlugins:
  - id: wasi-keyvalue-multiplexed
    bindings:
      cache:
        config:
          url: nats://workload-nats.shared.svc.cluster.local:4222
      sessions:
        secretFrom:
          - sessions-redis # a Secret whose `url` key holds redis://... with credentials
```

Once an entry declares any `bindings`, it lists every binding name its plugin accepts: a workload that uses a name the entry doesn't list is refused, even if that binding only sets `backend`. Add every name your workloads use, such as `cache` and `sessions` above, or run with `workloadConfig: warn` until the list is complete.

`redis` and `nats` need a `url`. Named `wasi:blobstore` bindings (`wasi-blobstore-multiplexed`, host-owned `url` and `root`) and `wasmcloud:messaging` bindings (`wasmcloud-messaging-multiplexed`, host-owned `url`) follow the same rule. See [Named bindings take their backend address from the HostGroup](https://cosmonic.com/docs/operations/upgrading/#named-bindings-take-their-backend-address-from-the-hostgroup) for the full list of plugin ids and the `warn` and `allow` settings.

The v0.7.0 CRDs enforce two invariants at admission time:

- No two `hostInterfaces` entries may be exact duplicates (the same `namespace`, `package`, `name`, and `version`).
- At most one entry of a given `namespace:package` may be unnamed. The unnamed entry is the default route — components importing the interface without a named import resolve to it — and it cannot be shared. Give every additional entry of the same package a distinct `name`.

Entries that share a `namespace`, `package`, and `name` merge when their versions are semver-compatible (the highest wins, per the component model's canonical-version rules); semver-incompatible versions of the same package coexist as distinct interfaces.

## Outbound network access

By default, Wasm components have no outbound network access. Use `allowedHosts` to explicitly permit outbound HTTP calls to specific hosts:

```yaml
localResources:
  allowedHosts:
    - https://api.example.com
    - https://auth.example.com
```

Calls to any host not in `allowedHosts` will be denied at the runtime level. Use the most specific URLs you can — preferring `https://api.example.com` over `https://*`.

> **Note**
>
> `allowedHosts` controls outbound HTTP access from within the component (via `wasi:http/outgoing-handler`). It does not affect inbound traffic, which is controlled by the `HTTPTrigger` that routes to the workload.

### Name resolution

Components that open sockets directly resolve hostnames through `wasi:sockets/ip-name-lookup`. Name resolution is governed separately from `allowedHosts` by its own allowlist, `allowedIpNameLookups` (available in Cosmonic Control 0.8.x and later):

```yaml
localResources:
  allowedHosts:
    - https://api.example.com
  allowedIpNameLookups:
    - api.example.com
    - '*.internal.example.com'
```

Like `allowedHosts`, name resolution is deny-by-default: an empty or absent `allowedIpNameLookups` blocks every lookup, which the component sees as a `permanent-resolver-failure`. To allow any name, set `allowedIpNameLookups: ['*']` explicitly. Each entry is a name, not a URL — no scheme, port, path, query string, or fragment. Entries take one of four forms:

- `*` — resolve any name
- `*.suffix` — any subdomain of a suffix, e.g. `*.wasmcloud.io`
- `host` — a single name, e.g. `api.wasmcloud.io`
- a literal IP address, e.g. `10.0.0.1` or `::1`

> **Note**
>
> `allowedHosts` governs outbound *connections* (via `wasi:http/outgoing-handler`); `allowedIpNameLookups` governs *name resolution* (via `wasi:sockets/ip-name-lookup`). A component that only makes outbound HTTP calls needs just `allowedHosts` — the runtime resolves those hosts as part of the request. `allowedIpNameLookups` applies when a component resolves names itself, typically before opening a raw socket with `wasi:sockets`.

## Private component registries

If your component image is in a private OCI registry, create a `docker-registry` pull secret and reference it on the component spec:

```shell
kubectl create secret docker-registry component-pull-secret \
  --docker-server=my-registry.corp.com \
  --docker-username=<username> \
  --docker-password=<password> \
  -n default
```

```yaml
spec:
  template:
    spec:
      components:
        - name: app
          image: my-registry.corp.com/my-org/my-app:1.0.0
          imagePullSecret:
            name: component-pull-secret
```

Each component in a workload can reference a different pull secret if images come from different registries.

> **Note**
>
> This secret is per-component, not per-HostGroup pod. The HostGroup itself does not need access to your application component registries — only the operator does, to resolve and distribute the component image.

## Volumes and volume mounts

Workloads can request a volume on the host pod and mount it into one or more components. The most common use is sharing data between a long-running `service` and the per-request components colocated with it on the same host (see [Service-plus-component workloads](https://cosmonic.com/docs/operations/ingress-and-workloads/#service-plus-component-workloads)).

Declare the volume once on `template.spec.volumes`, then mount it on each side via `localResources.volumeMounts`:

```yaml
spec:
  template:
    spec:
      volumes:
        - name: data
          ephemeral: {}
      service:
        image: ghcr.io/example/index-service:0.1.0
        localResources:
          volumeMounts:
            - name: data
              mountPath: /data
      components:
        - name: api
          image: ghcr.io/example/api:0.1.0
          localResources:
            volumeMounts:
              - name: data
                mountPath: /data
```

Volumes default to read-write. Set `readOnly: true` on a `volumeMount` to mount it read-only on that side; omit the field for the default read-write behavior.

`ephemeral: {}` requests a per-host scratch volume that is created with the host pod and destroyed when the pod terminates — its lifetime matches the workload's. Persistent volumes mounted in this way are not part of the v0.4.x surface.

A `hostPath` volume instead mounts a directory that already exists in the host pod. Since v0.14.0 the host accepts one only inside a directory its HostGroup lists in `hostVolumes.allowedHostPaths`, which is empty by default; otherwise the workload fails to start. See [`hostPath` volumes](https://cosmonic.com/docs/operations/host-groups/#hostpath-volumes).

## NATS messaging subscriptions

Components that export `wasmcloud:messaging/handler@0.2.0` receive inbound messages from NATS subjects subscribed by the host on their behalf. Configure the subjects via the `config.subscriptions` field on the messaging entry under `hostInterfaces`:

```yaml
spec:
  template:
    spec:
      hostInterfaces:
        - namespace: wasmcloud
          package: messaging
          version: '0.2.0'
          interfaces:
            - handler
            - consumer
            - types
          config:
            subscriptions: tasks.worker
      components:
        - name: task-worker
          image: ghcr.io/example/task-worker:0.1.0
```

Inbound messages on `tasks.worker` invoke the component's `handle_message` export. To reply, the handler reads `msg.reply_to` and publishes a response on it via `wasmcloud:messaging/consumer.publish`. If the handler returns `Err` without publishing, no reply is sent and the requester sees its own client-side timeout.

The hostgroup chart's `nexus.requestTimeoutSeconds` value (default `300` since chart 0.4.1) bounds how long any single `wasmcloud:messaging/consumer.request` call will wait for a reply. Lower it explicitly to fall back to a tighter ceiling, or set it to `null` to use the async-nats client default of 10 seconds.

## Reference

All configuration fields are available under `spec.template.spec.components[].localResources` on `WorkloadDeployment` and `WorkloadReplicaSet` (under `spec.components[].localResources` on a `Workload`):

| Field | Type | Description |
| --- | --- | --- |
| `localResources.environment.config` | `map[string]string` | Inline key-value configuration delivered to the component |
| `localResources.environment.configFrom` | `[]LocalObjectReference` | References to ConfigMaps; all keys are merged |
| `localResources.environment.secretFrom` | `[]LocalObjectReference` | References to Secrets; values are base64+UTF-8 decoded |
| `localResources.allowedHosts` | `[]string` | Allowlist of outbound HTTP hosts |
| `localResources.allowedIpNameLookups` | `[]string` | Allowlist of names resolvable via `wasi:sockets/ip-name-lookup` (deny-by-default) |
| `localResources.volumeMounts` | `[]VolumeMount` | Mounts a volume declared in `template.spec.volumes` into the component or service |
| `imagePullSecret` | `LocalObjectReference` | Pull secret for the component's OCI image |
| `hostInterfaces[].name` | `string` | Routing identity for [named host interfaces](https://cosmonic.com/docs/operations/component-configuration/#named-host-interfaces); required when multiple entries share a `namespace:package` |
| `hostInterfaces[].config` | `map[string]string` | Inline config for a host interface (e.g. `subscriptions` for `wasmcloud:messaging/handler@0.2.0`) |
| `hostInterfaces[].configFrom` | `[]LocalObjectReference` | ConfigMap references for a host interface |
| `hostInterfaces[].secretFrom` | `[]LocalObjectReference` | Secret references for a host interface |

Last updated on **Nov 10, 2026** by **Liam Randall**
