Skip to content

Support Secret env sources in ActorTemplate containers #15

Closed

Description

Summary

ActorTemplate container env currently accepts Kubernetes corev1.EnvVar in the CRD schema, so users can write valueFrom.configMapKeyRef and valueFrom.secretKeyRef in manifests. At runtime, Substrate flattens env vars into its atelet workload protobuf, which historically carried only literal name/value pairs. That means valueFrom entries are accepted by the API but are not usable by actors.

Add support for resolving valueFrom.configMapKeyRef and valueFrom.secretKeyRef for ActorTemplate container env before handing the workload spec to atelet.

Why this matters

  • Secret-backed env vars are the standard Kubernetes pattern for API keys and credentials. Without this, demos and real workloads either inline secrets as plain env values in rendered manifests or need custom workaround scripts.
  • ConfigMap-backed env vars are the standard Kubernetes pattern for non-secret runtime configuration.
  • The current behavior is surprising because the CRD schema exposes Kubernetes EnvVar, including valueFrom, but Substrate silently loses the source and sends an empty literal value to atelet.
  • Supporting these two common valueFrom sources makes ActorTemplate behavior closer to what Kubernetes users expect while keeping unsupported sources explicit.

Proposed scope

  • Support literal env.value as before.
  • Support env.valueFrom.configMapKeyRef from the ActorTemplate namespace.
  • Support env.valueFrom.secretKeyRef from the ActorTemplate namespace.
  • Preserve Kubernetes optional: true behavior by skipping the env var if the referenced object or key is missing.
  • Return a clear error for missing required objects/keys.
  • Return a clear error for unsupported sources such as fieldRef, resourceFieldRef, and fileKeyRef.

Security / design note

Resolving Secret and ConfigMap references in ate-api means ate-api needs read access to those resources. The straightforward implementation grants the ate-api service account get access to ConfigMaps and Secrets so ActorTemplates work without custom per-namespace RBAC. This is a conscious tradeoff for now, but it should remain a security TODO/design choice.

Possible future designs include per-namespace delegated RBAC, admission-time validation/materialization, or another scoped credential model that avoids broad Secret read access in the control plane.

Acceptance criteria

  • ActorTemplate env with valueFrom.secretKeyRef reaches the actor process with the referenced Secret value.
  • ActorTemplate env with valueFrom.configMapKeyRef reaches the actor process with the referenced ConfigMap value.
  • Missing required refs fail clearly instead of becoming empty env vars.
  • Optional missing refs are skipped.
  • Unsupported valueFrom sources fail clearly.
  • Docs call out supported sources and the security/design tradeoff.

Activity

  1. thockin commented on May 20, 2026

    @thockin
    Collaborator

    Thank you for citing the security concern. It's pretty significant, IMO

  2. EItanya commented on May 20, 2026

    @EItanya
    CollaboratorAuthor

    Thank you for citing the security concern. It's pretty significant, IMO

    I also addressed this in the PR I created. I think both approaches have potential downsides. Either we send these over the wire, or we allow all runners to read all secrets. This design could also have overlap with your namespace issue as you could force the runner to coexist with the secrets.

    Has there been prior thinking done on this from your side, I definitely want to get this right, but I'll also say that this is an incredibly important thing to add ASAP

  3. thockin commented on May 20, 2026

    @thockin
    Collaborator

    Taahir Ahmed (@ahmedtd) and Michael Taufen (@mtaufen) probably done the most thinking on this

  4. added
    kind/feature
    on May 21, 2026
  5. mtaufen commented on May 21, 2026

    @mtaufen
    Collaborator

    The industry is broadly converging on a pattern of injecting credentials on the wire to prevent them from ending up in the agent context/being leaked by agents who have access to the env and filesystem. I'd like substrate to natively support this, or be easy to plug in the proxy of your choice.

    We may still want some kind of secret support in the future for actors that run agent loops but aren't giving LLMs direct access to the local filesystem or env vars, for example to make it easier for those actors to connect to LLM APIs. But we need to be careful that our approach doesn't just encourage plumbing secrets to where agents also see them.

    Finally, NOT supporting secrets is guaranteed to lead to ugly things like putting them in plaintext because "there was no other way to do it" (and agents especially will do this if they feel they have to get a job done), so +1 it's VERY important we address this gap.

  6. ahmedtd commented on May 21, 2026

    @ahmedtd
    Collaborator

    Embedding the Kubernetes EnvVar type directly was something I did in the rush for launch --- I will send a PR to replace it with an equivalent substrate-specific type that only has the fields for the things we actively support.

    I agree, though, that we need this feature.

    We can either have ate-api-server read the ConfigMap / Secret, or atelet. Ideally, if we have atelet read the ConfigMap, we can find some way to piggyback on the actor identity (similar to node isolation in Kubernetes). I can't immediately think of a way to make it work by building on the node restriction plugin / node authorizer because the ActorTemplate is not necessarily in the same namespace as the worker pod (if it were, then atelet could impersonate kubelet and get access to the ConfigMap / Secret via node authorizer).

    Probably the design that makes the most sense for now is to make sure that ate-api-server has permission to read all relevant ConfigMaps and Secrets, and interpolate the values into the RPC call to atelet. ate-api-server is already highly privileged, and all of the RPC calls are going to be protected with mTLS.

  7. ahmedtd commented on May 21, 2026

    @ahmedtd
    Collaborator

    One open question I have is: if the environment variable values change on resume (because we read them again from the configmap, and the configmap was updated), does that break the gVisor snapshot?

    They definitely won't be updated in the memory of the running snapshot, but I don't know what is safe to change in the OCI bundle vs what is not when restoring from a snapshot.

  8. ahmedtd commented on May 21, 2026

    @ahmedtd
    Collaborator

    nybidari or Fabricio Voznika (@fvoznika) Do you know the answer to the above?

  9. EItanya commented on May 22, 2026

    @EItanya
    CollaboratorAuthor

    Probably the design that makes the most sense for now is to make sure that ate-api-server has permission to read all relevant ConfigMaps and Secrets, and interpolate the values into the RPC call to atelet. ate-api-server is already highly privileged, and all of the RPC calls are going to be protected with mTLS.

    This is the design I went with for #20, I left it draft only because I wanted to continue the discussion but the implementation should be ok.

    Finally, NOT supporting secrets is guaranteed to lead to ugly things like putting them in plaintext because "there was no other way to do it" (and agents especially will do this if they feel they have to get a job done), so +1 it's VERY important we address this gap.

    I couldn't agree with this more.

    I think in the long-term saying that secrets can never be injected into actors directly may be overly restrictive, but for agents of course injecting on the wire is much more secure. I wonder if an API that allows for either/or could be the most flexible and allow for the most security in the long-term.

  10. fvoznika commented on May 22, 2026

    @fvoznika
    Collaborator

    We decided to allow changes in environment variables between save/restore sessions, especially to support golden images and fork cases where parts of the environment changes. However, environment variables are stored in a memory block in the user mode processes and can't be changed by the kernel. So upon restore, the new environment variables are placed in /proc/gvisor/spec_environ and the application must refresh them to get the new values. More details here.

  11. mtaufen commented on May 22, 2026

    @mtaufen
    Collaborator

    Probably the design that makes the most sense for now is to make sure that ate-api-server has permission to read all relevant ConfigMaps and Secrets, and interpolate the values into the RPC call to atelet. ate-api-server is already highly privileged, and all of the RPC calls are going to be protected with mTLS.

    We need to think about scalability here. Is the intent that these sources be per-template or per-actor?

  12. mtaufen commented on May 22, 2026

    @mtaufen
    Collaborator

    Not to mention security - ate-api-server still runs in the cluster, so this is giving a handful of K8s nodes access to many/most secrets. Now I wish we'd done a real authorizer for ReferenceGrant. https://github.com/kubernetes/enhancements/tree/master/keps/sig-auth/3766-referencegrant

  13. mtaufen commented on May 22, 2026

    @mtaufen
    Collaborator

    interpolate the values into the RPC call to atelet. ate-api-server is already highly privileged, and all of the RPC calls are going to be protected with mTLS

    Do we log RPC arguments today? Can we tag this data as sensitive for redaction before any RPC logs are printed?

  14. mtaufen commented on May 27, 2026

    @mtaufen
    Collaborator

    Another thing to consider: substrate doesn't have its own concept of namespaces yet (not to mention noderestriction), so does Secret support let you mount anyone else's secret by default? Need to plan a path forward that doesn't prevent us from adding that isolation later.

  15. ahmedtd commented on May 27, 2026

    @ahmedtd
    Collaborator

    Another thing to consider: substrate doesn't have its own concept of namespaces yet (not to mention noderestriction), so does Secret support let you mount anyone else's secret by default? Need to plan a path forward that doesn't prevent us from adding that isolation later.

    The PR treats this the same as Kubernetes does --- the secret/configmap needs to be in the same k8s namespace as the actortemplate. That seems like a reasonable level of access restriction to me.

  16. 16 remaining items

  17. ahmedtd commented on Jun 2, 2026

    @ahmedtd
    Collaborator

    If the OCI image changes, we can't restore memory. If the gVisor version changes, we can't restore memory.

    We don't allow you to change these things (or we won't, as soon as ActorTemplate is immutable). For a given actor lifecycle, right now, you can be confident that memory snapshots are in use.

    Process snapshotting at this point of the project is an optimization - we need an SLO to describe it, and the SLO can't be 100%.

    If the SLO is not 100%, then the feature seems useless? If the snapshot is not recoverable, then the actor should be considered dead (and maybe, eventually, when we figure out how to port an actor between actor templates, you might need to run that process to get a new cold boot and memory state0.

    Memory snapshots are not an optimization if they cannot reliably hold state, since as an application developer you will be forced to write to a DB on disk, or a remote data store. At that point it's just the ADK multitenant model with extra steps.

  18. ahmedtd commented on Jun 2, 2026

    @ahmedtd
    Collaborator

    What drives the need to configure a secret or configmap at the ActorTemplate level

    People expect to plumb in API keys via environment variables. If we do not provide this feature, they will instead embed the secret in the ActorTemplate's environment variable definition.

    Projected volumes are definitely the "correct" way to put this stuff in (or even better, figure out how to use your Actor Identity JWT to authenticate to whichever remote API you are calling). But we need to meet people (and LLM APIs) where they're at.

    (Update): For this use case of people plumbing in static API keys, rotation is already assumed to be a pain, and basically unhandled. That's why I think it's fine to read it once at cold boot (typically, during the golden snapshot process), and keep that value frozen.

  19. thockin commented on Jun 2, 2026

    @thockin
    Collaborator

    We don't allow you to change these things (or we won't, as soon as ActorTemplate is immutable). For a given actor lifecycle, right now, you can be confident that memory snapshots are in use.

    I don't buy that as a durable property. Actor upgrades are almost certainly a thing we need to tackle without destroying actors.

  20. ahmedtd commented on Jun 2, 2026

    @ahmedtd
    Collaborator

    I don't buy that as a durable property. Actor upgrades are almost certainly a thing we need to tackle without destroying actors.

    Sure, but it will need to be something where an human operator or controller explicitly marshals the actor through a process:

    • Signal the actor that it needs to write everything it cares about to its durable storage directory.
    • Detach the actor from ActorTemplate A (discarding all extant snapshots for the actor)
    • At this point, the substrate state of the actor is basically just the data directory, whether that's in NFS, GCS, or some other storage system.
    • Attach the actor to ActorTemplate B
    • Resume the actor (either cold booting with the workload spec from B, or resuming from the golden snapshot of B).
  21. thockin commented on Jun 2, 2026

    @thockin
    Collaborator

    I agree with the possible exception of "Signal the actor" - since it is as-yet undefined, we're just hand-waving.

    I agree with the API key use-case and constraints. I am trying to understand if there are more use-cases, in particular for ConfigMaps, and in very particular cases that would need mutability.

  22. EItanya commented on Jun 2, 2026

    @EItanya
    CollaboratorAuthor

    I agree with the possible exception of "Signal the actor" - since it is as-yet undefined, we're just hand-waving.

    I agree with the API key use-case and constraints. I am trying to understand if there are more use-cases, in particular for ConfigMaps, and in very particular cases that would need mutability.

    Without wading too much into the deeper argument here, I do think that at the very least we can start here with ONLY Secret support and leave ConfigMaps for another day. Potentially only supporting mounted volumes for those. What do yall think?

  23. thockin commented on Jun 2, 2026

    @thockin
    Collaborator

    Starting with the things we know we need is the correct path. I was hoping to solve multiple things in one movement, but it seems we can't, so let's do the parts we understand. secretKeyRef which is set upon the first resume SGTM. We don't want to serialize that into any API, so it COULD change value if the actor's memory state is lost for any reason.

  24. EItanya commented on Jun 2, 2026

    @EItanya
    CollaboratorAuthor

    Starting with the things we know we need is the correct path. I was hoping to solve multiple things in one movement, but it seems we can't, so let's do the parts we understand. secretKeyRef which is set upon the first resume SGTM. We don't want to serialize that into any API, so it COULD change value if the actor's memory state is lost for any reason.

    Just to be 100% clear, you're saying we SHOULD NOT restart the actor if the env vars change

  25. thockin commented on Jun 2, 2026

    @thockin
    Collaborator

    I think that's correct. Doing so might be surprising (in a bad way) and we don't KNOW we need it yet, so we can't reason about the implications.

  26. EItanya commented on Jun 2, 2026

    @EItanya
    CollaboratorAuthor

    Implemented the narrowed scope from this thread in PR #20 at commit EItanya/substrate@6945caa.

    This keeps ActorTemplate env support to literal values plus secretKeyRef only, removes ConfigMap env support, removes the public last_resolved_env_* API fields, and removes env-change snapshot invalidation/restart behavior. Secret values are still resolved by ate-api and sent to atelet on the cold/spec path, with existing RPC redaction retained.

  27. changed the title [-]Support ConfigMap and Secret env sources in ActorTemplate containers[/-] [+]Support Secret env sources in ActorTemplate containers[/+] on Jun 8, 2026
  28. added a commit that references this issue on Jun 8, 2026
    0076b20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/apiarea/api-machineryarea/nodearea/securitykind/featureprio/P0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions