Skip to content

Feature request: Support decrypting multiple files at a time #945

Open

Description

@patricknelson

It would be awesome if sops supported decrypting multiple files at a time.

Use case: For example, say you have multiple encrypted Kubernetes secrets that you'd like to apply all at once, this could be streamlined as:

sops -d secrets/*.enc.yml | kubectl apply -f -

This would be much easier than having to manually specify each file individually, one at a time. This would also require that sops be able to concatenate each file using the --- document delimiter in the resulting YAML stream.

Activity

  1. jaythamke commented on Nov 1, 2021

    @jaythamke

    Would be nice input and I am also looking forward to it.
    By the way any update here? Thanks

  2. narasimhan-coverwallet commented on Apr 12, 2022

    @narasimhan-coverwallet

    Hello! This is something that would be really nice, for batch operations that include not just for applying on kubernetes. For example, searching en masse when almost all the infra is captured in IaC

  3. LucasVanHaaren commented on Jun 17, 2022

    @LucasVanHaaren

    I agree, it would be very nice to have this feature !

  4. BlacCello commented on Aug 2, 2022

    @BlacCello

    It would be very helpful to have the support for multiple files for sops exec-env as well. Currently, we have to nest multiple exec-env commands which is not very clean.

  5. beejei commented on Apr 13, 2023

    @beejei

    OMG, I started to use SOPS 2 days before, and I think I'm arriving at the right place.
    +1 from my side!
    This will make the usage a lot easier especially when specifying decryption on my package.json script

  6. CyberHippo commented on Jun 9, 2023

    @CyberHippo

    +1 as well, that would be awesome

  7. fnayou commented on Apr 22, 2024

    @fnayou

    +1 that will be really helpful

  8. vring0 commented on Jul 18, 2024

    @vring0

    +1

  9. maulerjan commented on Nov 26, 2024

    @maulerjan

    +1 this would simplify my nx scripts a lot

  10. Cristobal-M commented on Nov 21, 2025

    @Cristobal-M

    +1
    This would help me to, I've multiple projects to manage. I'm using a script to ease management of env variables, that script decrypts recursively a directory into a temporary location and opens a new window of vscode.

    It would do it faster If I can pass a batch of files. I think I may create a local tool with a GUI (inspired from infisical) if I had the time.

  11. jgonera commented on Dec 19, 2025

    @jgonera

    Another benefit: it would probably be faster when using KMS because we don't have to refetch the same key for each file (if they are encrypted with the same one). This would be really beneficial for Cloud Run (and similar platforms) cold starts. Right now I decrypt secrets on container start and this adds a few seconds to cold starts.

  12. felixfontein commented on Dec 20, 2025

    @felixfontein
    Contributor

    Another benefit: it would probably be faster when using KMS because we don't have to refetch the same key for each file (if they are encrypted with the same one). This would be really beneficial for Cloud Run (and similar platforms) cold starts. Right now I decrypt secrets on container start and this adds a few seconds to cold starts.

    Since SOPS doesn't fetch keys, but asks the KMS to decrypt the file's encryption key (which is different for every file), this won't help for the reason you mentioned. But it will help for setting up the connection to the KMS, since it only has to do that (and authenticate) once.

    I guess the main question for this one is how the user interface should look like. I can imagine multiple use cases:

    • Decrypt multiple files to files (with potentially different formats) - this needs complex configuration;
    • Decrypt multiple files to YAML and concatenate the documents (as suggested in the issue itself);
    • Decrypt multiple files, merge them, and dump the result.

    I can imagine that all three cases will be useful (likely for different persons :) ). Also I would not integrate it into the decrypt subcommand, to avoid making it more complex than it needs to be. One or more new subcommands (potentially different ones for the different use-cases) sound like a better idea to me.

  13. jgonera commented on Dec 22, 2025

    @jgonera

    @felixfontein I didn't know the inner workings of KMS, but it completely makes sense that the key would never leave the servers. It would be great to speed this up in any way! Personally, I use JSON so I'd love to see this work for multiple formats.

  14. almaceleste commented on Jul 5, 2026

    @almaceleste

    Another use case is Docker Compose with several services, each requiring its own secrets file - or even several such files.

  15. czxtm commented on Aug 10, 2026

    @czxtm

    @felixfontein for now, if all it did was act like it was called twice, for example:

    sops exec-env file1.yaml file2.yaml 'npm start'
    

    just behaved like:

    sops exec-env file1.yaml 'sops exec-env file2.yaml \'npm start\''
    

    that would probably be very easy to implement and still save me a ton of hassle.

    For the sake of simplicity I suggest that initially, then the more intricate stuff can be implemented over time.

  16. abd-ulbasit commented on Oct 17, 2026

    @abd-ulbasit

    I'm working on the smallest slice of this: sops exec-env with several files, as czxtm proposed above. PR: #2324 (it refs this issue and does not close it).

    Shape: sops exec-env [flags] FILE [FILE...] COMMAND. Every positional argument except the last is a file, and the last is the command, run through the shell as today. Any call with three or more positional arguments currently fails with error: missing file to decrypt, so no working invocation changes meaning. exec-env FILE -- 'cmd' keeps working.

    Behaviour:

    • The files apply in the order given, like nested exec-env calls: on a key collision the later file wins. File values still override the inherited environment, and --pristine and --same-process work as before.
    • All files are decrypted before the command starts. If one fails, the command does not run, and with several files the error names the file. Single-file errors are unchanged.
    • Flags have to come before the files. urfave/cli v1 moves the argument that follows a boolean flag ahead of the other positionals, so exec-env a.yaml --pristine b.yaml cmd reaches sops as b.yaml a.yaml cmd. Today that already breaks exec-env file.yaml --pristine cmd. With several files it would silently flip precedence, so the exec-env help text in the PR says so.

    Not in this PR: exec-file (it substitutes one path for {}, so several files need one placeholder each), decrypt with several files (@felixfontein, you suggested new subcommands for that, so I'm leaving that design to you), and reusing the KMS connection across files.

    One question: this shape takes the positional tail that #1469 asks for. sops exec-env secrets.env -- cat foo would try to decrypt cat, so a later argv mode would need an explicit flag like the --no-shell you suggested in #1626. If you'd rather keep the tail free, I can move the extra files to a repeatable flag.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions