Skip to content

feat: parallel / de-duplicated secrets decryption  #782

Closed

Description

@travisgroth

Hi,

On larger installs leveraging the helm secrets plugin, a full run of lint, diff and apply can take a long time (I just watched a 3+ minute run). After digging into the code it seems like there's two reasons:

  1. A mutex to avoid two goroutines erasing each other's .dec.yaml files when moving to temp storage. This mutex forces all decrypts to be serial.

  2. No coordination of which secrets have already been decrypted and moved to temp storage. A secrets file is decrypted N times, where N is the number of charts referencing it.

Some implementation ideas:

  1. Allow decrypt to run free unless two routines are operating on the same file.

    a. Use filesystem flock() to shift the locking out of process. This is likely simpler, though may have platform corner cases.

    b. Shift the mutex into some sort of shared map indexed on some representation of a file path, so that locking can occur against file level granularity.

  2. Be able to detect if a secret has already been decrypted and skip it (this also helps item [1]). Like [1], there is a way both on-filesystem and in-memory.

    a. Hash the secret file path/name into a unique and secure value. Use this value as the file name inside the temporary location. Before calling decrypt, check if a file is already present. If it is, the decrypt can be skipped. If we try our new locking before checking for the tempfile, we can avoid any duplicate decrypts.

    b. Using a structure much like [1b], track the files that are already decrypted into temp storage and check if they are already decrypted.

Thoughts? This may have implications in #745

Activity

  1. mumoshu commented on Jul 31, 2019

    @mumoshu
    Collaborator

    @travisgroth Your proposal sounds great! Not sure I can tackle this shortly but it would definitely welcome more ideas and pull requests related to this.

    Also, I was thinking that caching decrypted secrets #444 will also help.

  2. travisgroth commented on Aug 2, 2019

    @travisgroth
    ContributorAuthor

    Question re #444 - I think [2] addresses that without putting them in-memory, which sounds objectively better, but more complicated.

    I can probably take a pass at this in the next week or so.

  3. mumoshu commented on Aug 5, 2019

    @mumoshu
    Collaborator

    Question re #444 - I think [2] addresses that without putting them in-memory, which sounds objectively better, but more complicated.

    I thought #444 can be better in terms of that it doesn't need to keep all the cached credentials on tmpfs until helmfile exits.

    Anyway, I believe we can start with [2] because #444 is an extension of your [2].

    Either way we need to decrypt the secret onto the disk(because that's how helm-secrets works) before saving the result in memory(#444).

  4. travisgroth commented on Aug 5, 2019

    @travisgroth
    ContributorAuthor

    After looking a bit, I think you're right. My conclusion was that the cleanup gets complicated if we cache on disk with the current design.

    Generating a new file from memory for each independent helm exec makes cleanup easier to reason about and shrinks the change scope. A data structure that implements [1] in memory could easily be extended for [2] with some extra fields and a method or two, so that sounds like a reasonable approach.

  5. travisgroth commented on Aug 16, 2019

    @travisgroth
    ContributorAuthor

    Closed in #804

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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions