Skip to content

Proposal: out-of-tree encryption backends #2016

Open

Description

@ndrpnt

This proposal explores ways to enable out-of-tree encryption backends in SOPS. The goal is to make it easy to add new encryption backends, including private ones.

Other components that could benefit from out-of-tree extensibility, such as stores and publishing backends, are out of scope.

Related PRs:

As stated multiple times, maintainers are open to a plugin system for encryption backends. This avoids adding dependencies and responsibilities to core SOPS. In the future, moving even core providers out-of-tree would make evolving (and forking) them a lighter process.

I've explored two approaches, and I'm looking for maintainer feedback before investing more time.

Option 1: build on the existing key service infrastructure

This approach was discussed in #481, but I don't think it went anywhere.

I Hacked together sops-generic-keyservice, a proof-of-concept key service server compatible with Scaleway Key Manager and OVH Key Management Service. For a lack of better alternative, it currently piggybacks on AWS' --kms flag to pass arbitrary configuration to the KMS.

I believe this approach can get us far without requiring major/breaking changes in SOPS. Some backward-compatible improvements are needed to make "Generic KMS" a first class backend:

  1. Add support for generic_key in the key service API:
    message Key {
      oneof key_type {
        ...
        GenericKey generic_key = 7; // or google.protobuf.Struct ?
      }
    }
    
    message GenericKey {
      // Allow key service servers to filter only the requests they can handle.
      string kms_id = 1;
    
      map<string, google.protobuf.Value> configuration = 2;
    }
  2. Add the corresponding flags, e.g --generic-kms '{"kms_id": "mykms", "configuration": {"foo": "bar"}}'. Passing a JSON object is inelegant but straightforward. One can also look at how Terraform handles complex dynamic values through flags and environment variables.
  3. Add the corresponding configuration options
    creation_rules:
      - generic_kms:
          - kms_id: mykms
            configuration:
              foo: bar

Option 2: build a plugin system

A fully fledged plugin system:

  • Offers a sleeker user experience, without the need to start services and export environment variables before running SOPS.
  • Offers a cleaner API than the keyservice one, purpose-built for providers to implement.
  • Lays the groundwork to make other components pluggable, like stores and publishing backends.
  • Requires more upfront design, and more coding effort.

This option is not exclusive with option 1: we may rely on a generic key service to interate on the KMS plugin API without affecting core SOPS. Once the API is stable enough, and providers exist for multiple backends (including core ones), we can merge it into SOPS.

I did not invest time in pursuing that option. Maybe PluginRPC would be a good fit, but it leaves installing the executable up to the user.

Next Steps

I'd appreciate feedback from maintainers on pursuing option 1. I can work on a draft PR if this direction sounds reasonable.

Activity

  1. felixfontein commented on Dec 13, 2025

    @felixfontein
    Contributor

    From a user point of view, Option 2 is easier to use, and also to set-up. Especially if you need to use multiple different encryption backends at once. But I haven't spent that much time thinking about it so far, so this is just a first reaction :)

    CC @getsops/maintainers any opinions?

  2. felixfontein commented on Dec 13, 2025

    @felixfontein
    Contributor

    Maybe PluginRPC would be a good fit, but it leaves installing the executable up to the user.

    PluginRPC sounds (on a first glance) similar to what I was thinking about when I thought about plugins before. I'm not sure whether that specific project is a good idea though, it doesn't seem to be very actively developed, doesn't seem to have a big community, and might require a CLA (pluginrpc/pluginrpc#1 (comment) seems to indicate it, I didn't found something elsewhere).

    It might also be a good idea to look closer at what age is doing - it also supports plugins, and its maintainer has a lot of experience with Go and security, so what they use can't be a too bad choice.

  3. kuzaxak commented on Dec 22, 2025

    @kuzaxak

    @felixfontein Maybe worth to consider the Helm way with wasm: wazero or the same as Helm extism runtime?

    Proposal from Helm is here

    UPD: Extism is using Wazero, sorry for confusion.

    Extism's underlying Go tooling, Wazero

  4. kuzaxak commented on Dec 23, 2025

    @kuzaxak

    @felixfontein Maybe worth to consider the Helm way with wasm: wazero or the same as Helm extism runtime?

    Proposal from Helm is here

    UPD: Extism is using Wazero, sorry for confusion.

    Extism's underlying Go tooling, Wazero

    Not possible as. unfortunately, wasm runtime don't have crypto and network access.

    Maybe the Hashicorp gRPC to the local approach would be a good start?

    It might also be a good idea to look closer at what age is doing - it also supports plugins, and its maintainer has a lot of experience with Go and security, so what they use can't be a too bad choice.

    Age is using subprocess and passing data via stdin\out

  5. gokselk commented on Dec 24, 2025

    @gokselk

    I've worked on plugin systems before and they're a hassle to get right.

    Here's my take on this. Age uses subprocess + stdin/stdout which seems like the simplest path. They use a custom multi-line text format called stanzas (same format as their encrypted files), but for SOPS plain JSON should work:

    $ echo '{"key_id":"...","plaintext":"base64..."}' | sops-kms-example --sops-plugin=v1
    {"ciphertext":"base64..."}
    
    $ echo '{"key_id":"...","ciphertext":"base64..."}' | sops-kms-example --sops-plugin=v1
    {"plaintext":"base64..."}
    

    Operation is inferred from the request (plaintext = encrypt, ciphertext = decrypt). The --sops-plugin=v1 flag prevents accidental execution and gives room for protocol changes later. Plugins handle their own credentials via env vars or config files.

    Errors return {"error": "message"}.

    KMS calls are network bound anyway so subprocess overhead shouldn't matter.

    Just a rough draft, happy to hear thoughts.

  6. felixfontein commented on Dec 24, 2025

    @felixfontein
    Contributor

    I think an RPC interface similar to what age uses makes more sense, as it allows to reuse connections for example if multiple identities are used with the same KMS. I guess both JSON or Protobuf are fine; Protobuf has the advantage that we already use it for communication with keyservices, while JSON is simpler and would allow to implement plugins without having to use Protobuf.

    I think the most important thing is that the protocol is well-documented (the age plugin protocol is not really well documented, or at least I couldn't find any documentation on it - I had to read the code to understand how it works).

  7. gokselk commented on Dec 24, 2025

    @gokselk

    Looking at the existing backends, the protocol seems pretty minimal, so JSON would probably be enough. But I'm fine with either approach.

    I think an RPC interface similar to what age uses makes more sense, as it allows to reuse connections for example if multiple identities are used with the same KMS.

    Good point about connection reuse. Keeping the plugin process alive with newline delimited JSON over stdin/stdout would handle that nicely IMO.

  8. ndrpnt commented on Dec 29, 2025

    @ndrpnt
    Author

    I'm also in favor of a simple communication protocol via stdin/stdout (and maybe forward flags and/or environment variables). I believe spinning up a gRPC server would make plugin lifecycle management more complex.

    I would prefer JSON over protobuf, to enable writing simple adhoc plugins. For example shell scripts that wrap a CLI. Protobuf forces plugin authors to install the toolchain and have some know-how just to generate stubs. Sure SOPS could distribute a plugin SDK/library (like Terraform does), but that seems overkill for a few RPCs.

    Plugin discovery can be done by searching the PATH for executables named sops-* (or sops-kms-* if we want to differentiate plugin types), similar to what kubectl does. I think it is reasonable to leave plugin installation up to the user.


    Thinking more about it, a plugin system still requires adding a GenericKey type to the key service API, right?
    That change being rather limited in scope, I'd love to see it land soon as to: integrate SOPS with new encryption backends, iterate on the plugin API out of tree, and gather feedback on the key service API with real usecases at hand.

    What about adding an ExperimentalGenericKeyV1 type with (obviously) no backward compatibility guarantee?


    [Thinking out loud] We may want to invoke the same plugin with different configurations.
    We could do that by forwarding --generic-kms-<kms_id>-* flags and SOPS_GENERIC_KMS_<KMS_ID>_* environment variables to plugin subprocesses after stripping the prefix.

    For example, to run the sops-aws plugin with different AWS profiles depending on the key, one could write:

    # .sops.yaml
    creation_rules:
      - generic_kms:
          - kms_id: aws-foo
            configuration:
              plugin: aws
              ...
          - kms_id: aws-bar
            configuration:
              plugin: aws
              ...

    And then run:

    SOPS_GENERIC_KMS_AWS_FOO_AWS_PROFILE=profile-1
    SOPS_GENERIC_KMS_AWS_BAR_AWS_PROFILE=profile-2
    sops ...
  9. ndrpnt commented on Dec 31, 2025

    @ndrpnt
    Author

    it allows to reuse connections for example if multiple identities are used with the same KMS

    Correct me if I'm wrong, multiple identities mean multiple requests to the keyservice, which would make keeping a plugin running awkward.

  10. felixfontein commented on Feb 26, 2026

    @felixfontein
    Contributor

    I recently had to think of this thread when I was thinking about stores and store plugins (similar to encryption plugins). The data structure that store plugins need to handle are potentially better handled as Protobuf data than JSON, especially since JSON is known to cause a lot of problems for certain data types (numbers: precision loss and being able to distinguish between integers and floats) and doesn't support other data types like timestamps or dates.

    Obviously one can work around this (use objects instead of simple values and store all kind of data in strings insead of JSON native data types), but it's more annoying in JSON than Protobuf.

  11. reneleonhardt commented on Feb 27, 2026

    @reneleonhardt
    Contributor

    For human-readable configuration, YAML 1.2 seems to be best option currently (decimals instead of float precision loss, ISO timestamps, more secure, less ambiguous, explicit typing if needed, no recursive entity expansion).

  12. felixfontein commented on Feb 28, 2026

    @felixfontein
    Contributor

    @reneleonhardt I'm not sure how that relates to a format for inter-process communication that's written and read by machines?

  13. devx commented on Mar 27, 2026

    @devx

    I spent some time and working towards an ADR for the plugin as disscused in this thread I do have few questions and would love some guidance.

    1. Should new plugin-backed files preserve the legacy "single key group as
      top-level arrays" format, or should plugins be stored only in key_groups
      going forward and use the top-level form only for backward-compatibility when
      reading old data?
    • Supporting both shapes keeps behavior consistent with existing metadata, but it
      also duplicates schema and serialization logic for a brand-new key type.
    1. Is key_ref truly opaque, or will SOPS standardize common fields?
    • opaque object plus generic CLI input, or partially standardized schema plus
      friendlier dedicated flags.
    1. Should retries be handled by SOPS or by the plugin?
    • Current SOPS key handling is relatively direct and does not add retry logic at
      this abstraction layer.
    • Automatic retries in core can be helpful for transient network failures, but
      they can also hide plugin-side bugs or interact badly with non-idempotent
      backends.
    1. How should timeouts be configured?
    • hard-coded defaults only
    • global CLI flags
    • environment variables
    • .sops.yaml
    1. Is instance_id mandatory for all plugin-backed keys?
    • Requiring it makes lifecycle and config routing explicit.
    • Allowing omission makes simple cases easier but introduces another naming rule
      that must remain stable over time.
    1. Should environment-variable compatibility drive instance_id validation?
    • This couples two separate concerns:
      stable plugin instance identity and environment prefix generation.
    • An alternative would be to allow a broader instance_id and derive a safe env
      prefix separately, for example by normalization plus hashing.
    1. What is the intended stability level of the keyservice bridge?
    • introducing either ExperimentalGenericKeyV1 or
      PluginKey in keyservice.
    • The implementation path strongly benefits from a local bridge.
    • The long-term compatibility story depends on whether that bridge is documented
      as experimental, local-only, or fully supported.
    1. How much plugin execution detail should SOPS expose in logs and errors?The proposal suggests surfacing plugin name, instance ID, exit code, stderr, andresolved plugin path in failure cases.
    • Rich diagnostics are useful for debugging plugin deployment problems.
    • Raw stderr may contain backend-specific details that are noisy or, in the
      worst case, too revealing. It may need truncation and redaction rules.
  14. ndrpnt commented on May 30, 2026

    @ndrpnt
    Author

    Some related issues that, I think, would be covered by a plugin system:

    I hope to have time to work on that this summer

  15. Dexmachi commented on Jun 29, 2026

    @Dexmachi

    I hope to have time to work on that this summer

    I've been working on an interface for this for a while
    I don't have that much experience, but I tried to do a general enough solution, it can be found in #2210

    I'd love to get comments on this, as this would open up a lot of opportunities for SOPS

  16. deblasis commented on Aug 28, 2026

    @deblasis

    TL;DR: An implementation exists: out-of-process plugins, working branch + spec + reference plugin which is the OCI-KMS from my PR #1226

    I've followed this thread (and #2210) for a while, then I moved onto other things but yesterday I was reminded about this so I put something together.
    Obviously I used my judgement as a veteran (old) software engineer to steer a couple of LLMs in a loop. Happy to provide details if interested.

    I hope this is received the right way. It seems that the discussion has been going in circles on design questions that are hard to settle in the abstract, I went and built a complete implementation on a branch, to turn the questions into ones with evidence attached. Not opening a PR yet, this post is asking for a steer first.

    What's built (branch plugin-system on my fork, ~53 commits over main, zero new core dependencies):

    • Wire protocol, spec'd in full: JSON lines over stdio, one process per plugin binary reused across key operations, lockstep request/response, handshake with version negotiation, frozen v1 error taxonomy. Deliberately modeled on age's plugin protocol, since @felixfontein noted earlier in this thread that "an RPC interface similar to what age uses makes more sense". I had more experience with go-plugin but it was nice to learn more about the inner workings of age.
      That comment is what convinced me this direction had maintainer support, and the spec is written so a plugin is ballpark 80 lines in any language (the appendix contains a complete minimal Python plugin).
    • Security model: repository content can never cause execution. Binary resolution is PATH-only (never cwd, never a repo-relative path), and every spawn passes an allowlist in a local config (~/.sops.yaml or SOPS_LOCAL_CONFIG) that never ships in the repo. No allowlist, no execution, fail closed. Opt-in SHA-256 pinning per binary.
    • Conformance tooling: sops plugins list and sops plugins verify (handshake, roundtrip with anti-cheater probes, error-shape check, respawn check).
    • A real backend ported: PR ocikms: Oracle Cloud KMS support #1226's ocikms rebuilt as a standalone plugin with zero sops imports, plus fuzzing (1.6M+ execs) and an adversarial scenario battery against a simulated OCI backend (I dogfooded a project of mine)
    • Tests: full suite green including -race, covering the misbehavior matrix (garbage output, hangs, oversized lines, crashes before/after the request, double-apply hazards).

    Full spec: https://github.com/deblasis/sops/blob/plugin-system/docs/plugins/spec.md#the-sops-plugin1-protocol-specification.
    Branch: https://github.com/deblasis/sops/tree/plugin-system.
    Reference plugin: https://github.com/deblasis/sops-plugin-ocikms

    The questions I'd love a maintainer steer on (these are the forks where community members have gone different ways, and I'll happily re-scope to match):

    1. Out-of-process RPC vs in-process Go interface (Proposal/RFC: out-of-tree encryption backends interface #2210)? My read of the age comment above is that RPC is preferred; Proposal/RFC: out-of-tree encryption backends interface #2210 explores the Go-interface route and @Dexmachi has real work there. I think the two can coexist (an interface layer could sit over the wire protocol), but that's a maintainer call, and I've asked it explicitly so Proposal/RFC: out-of-tree encryption backends interface #2210's author gets the same answer I do.
    2. Config shape: my branch groups plugin keys under a plugins: list in creation rules (binary:, optional key_ref, timeout, opaque config:); Proposal/RFC: out-of-tree encryption backends interface #2210 uses per-instance IDs. Both work; which shape would maintainers want?
    3. Metadata and the old-sops boundary: a new metadata key type means old binaries silently drop it on re-save. My branch fails loudly on that path and the spec mandates a version floor, but whether that's acceptable policy is a project decision, not mine.
    4. Governance: the spec includes PROPOSED commitments (anchored deprecation window for v1, dual-stack negotiation) that only bind if maintainers ratify them. I kept protocol MUSTs and project promises explicitly separated in the spec so nothing legislates for upstream without a green light.

    Happy to turn any of this into a stack of piecemeal reviewable cute PRs 😄, or fold the useful parts into whatever shape the project prefers. Credit where due: @devx 's ADR questions and @ndrpnt 's related-issue list (#2170, #2157) shaped the scope, and #2210's instance work informed the config discussion.

  17. Dexmachi commented on Aug 28, 2026

    @Dexmachi

    @deblasis I love this implementation of yours!

    Honestly, I've been a bit bummed that the RFC (#2210) hasn't seen much upstream discussion lately since I've been looking at this closely, but seeing that someone else took the torch and built something this robust is amazing. I'm a relatively newer software engineer compared to you, but I'd love to chime in on a few topics:

    Regarding the implementation points:

    1. The RPC Route: I love that you went with the structured JSON-lines/lockstep RPC approach! My PoC in Proposal/RFC: out-of-tree encryption backends interface #2210 also used a JSON-over-stdio bridge, not an in-process Go interface, but your alignment with the age plugin protocol standard is great. I'm really glad you took a look at my RFC to help shape this
    2. Config Shape: Our implementations are actually very close here. My RFC also uses a plugins list with binary_name, an opaque config block, and a timeout. The main difference is the key_ref vs my approach with an instance_id (and passing an env_prefix down to the plugin). Both definitely achieve the same goal, tho

    I do have a quick architectural question regarding DevEx and the Handshake:
    While handshakes and version negotiation make the protocol much more robust and safer against regressions, I'm curious about how you see this impacting the DevEx for community members creating new (and perhaps simple) plugins, I ask this specifically because I built my RFC with DevEx in mind, so that plugins could be created more easily

    Could you share a bit more on how the handshake is implemented under the hood? I'd love to get a better understanding of how you balanced that extra protocol strictness with keeping the barrier to entry low for plugin creators. (Both to gather more knowledge as a SWE and to see how it operates in your spec)

    Making a quick read through your branch, it is quite impressive what you've done, mine honestly looks like a POC in comparison! I'd love for this to be the selected process, if it gets merged

    really really happy to see this moving forward, and I'd be glad to try and contribute with yours, or to receive contributions on mine!

  18. ndrpnt commented on Sep 1, 2026

    @ndrpnt
    Author

    Hey @Dexmachi, @deblasis, thanks for helping move this forward. I empathize with the urge to have a working implementation.

    I'd be happy if the maintainers want to move forward with one of the proposed implementation. Speaking for myself, I have a hard time engaging with your comments/PRs, sorry. I'm not saying it's slop, but maybe lacking empathy?

    BTW, note that if you really need this, it is already possible—albeit hacky—to integrate stock SOPS with external encryption backends. You can find some examples (OVH, Scaleway, and a simple PluginRPC-based system) in the repository linked in the issue.

  19. deblasis commented on Sep 2, 2026

    @deblasis

    Thanks @Dexmachi, and genuinely, your RFC was one of the inputs I worked from, so "shaped this" is literal. And for what it's worth, the gap between us is is just a few more rounds of iteration. Also, I leveraged your work, you had to come up with something from scratch so... Nicely done!

    ...
    [REDACTED for empathy]
    ...

  20. deblasis commented on Sep 2, 2026

    @deblasis

    Thanks @ndrpnt. I hear that the comments/PRs have been hard to engage with. That's useful to know, and I’ll keep the discussion here on the design tradeoffs.

    I would obviously rework this as "small piecemeal cute reviewable PRs", not shove it like this for review. This is a POC and a conversation opener/resumer.

    I support any decision the maintainers make. I am a guest in someone else's house.
    Happy to reshape the prototype to match whatever direction they pick (in-tree hook vs out-of-tree plugin, protocol, key type, etc.).

    The existing stock-SOPS + external backend examples are good to have documented either way.

  21. rkthtrifork commented on Nov 25, 2026

    @rkthtrifork

    I have created a PoC for a plugin design in this PR #2358

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions