-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Conversation
This is nice! 🎉 Did you have a cause to exec to the binary instead of linking sops as a library? Is something missing in |
@carlpett I completely missed that. I think I was just too focused on copying the git-secret method. Of course that makes more sense. Will try it. |
@PaulFarver thanks a lot for the effort! 🌹 I need to get familiar with |
The docker build seems to be failing when it has to run the known_hosts.sh. Seems gitlab is having some trouble |
Btw, it might make sense to wait for getsops/sops#566, to get proper versioned modules (and the new import path) |
@PaulFarver it seems that the e2e error was transient (or due to a flaky test, I need to investigate). Good news is it started working again after rebuilding. |
@PaulFarver I really like the shape this is taking! Some comments:
|
@2opremio Sounds good 👍 Working on it now |
|
and ... |
and .. |
How will this play along with Kustomize and other manifest generators? |
Good question! Since the detection is content-based, it will work transparently (i.e. you should be able to generate sops-encrypted content) |
As @2opremio has already stated, it should work transparently. I think you might run into some trouble, though. Sops verifies a file with a checksum in the metadata. The checksum depends on when the file was modified, the values, and key structure. Even the key position. Also that of unencrypted values. As I understand it, manifest generation is run before the yaml files are loaded in flux, which is when the sops decryption takes place. That means you would have to generate the valid sops encrypted file with kustomize build. It might be possible, but I think it would be pretty tedious, and hard to maintain. |
As a side note, |
Exactly this was my concern. It might be feasable to have the secrets not included with kustomize, and just cating them into the generated manifest, if sops only is concerned with the individual documents inside the yaml. |
Sops does have support for yaml multidocs, but you have to encrypt all documents in the file, so I don't think it aligns too well with the kustomize use case. The poc of this feature worked in much the same way as the git-secret feature, where files are decrypted right after a checkout. This would support encryption of patches individually, which seems like a better workflow for people using manifest generation. @2opremio We could pursue decrypt-first functionality, but with the trial-and-error approach suggested by @ajvb. What do you think? |
Decrypt first would be the best, but it would require to resolve all the bases and resources from the kustomize files first, or decrypt any yaml the whole repository, not just those inside the git-path. (The latter wouldn't work if the kustomize files refers to resources outside the repository, but maybe that is an ok limitation.) |
Right... I have another branch, that implements decrypt-first with the trial-and-error approach and the go.mozilla.org/sops library. If that is the way we want to move forward, I will switch the pull request to that branch. |
After thinking about this further it turns out I wasn't completely right (sorry I didn't think it through right away). At the current state of this PR, sops decryption is attempted after reading the files from the filesystem and not when parsing them (which is used both when loading files from disk and by manifest generation). There is an easy fix though. @PaulFarver can you move the Depending on how This will allow you to do manifest generation with sop-encrypted manifests, included in the generation output, like follows:
Where files with suffix Note that the Now I realize this might be what @elzapp was referring to with play along with Kustomize and other manifest generators. A decrypt-first (in-place) approach would indeed solve this problem but I think it's overkill since, as @elzapp mentioned:
Flux doesn't understand This approach wouldn't support external bases including sops-encrypted manifests and it would result in git repositories incompatible with standard Kustomize (which doesn't support sops manifests as input). I think that implementing decrypt-first to solve this problem is just a workaround to compensate for the lack of interoperability between As an alternative, and in addition to the current PR, we could include the sops binary in the Flux container, allowing to explicitly decrypt the files before passing them to Kustomize, as follows
File layout
|
I've cleaned up a bit. I've rebased and squashed, so it should be a little more neatly applied to master, than the other sixty-odd commits😄 I got to thinking... It might be a little neater to split |
Really nice! This is ready to go apart from 3 minor comments. |
Nice, I think this is ready to go. Re-running the tests since they seem to be failing for unrelated reasons. |
Cool! Thanks for the patience @2opremio 🥇 It's been a pleasure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, great job! 💯
I may wait a bit for merging until #2672 is resolved
I may ask you to rebase on top on master when that happens
@PaulFarver would you mind rebasing on top of master and fixing the conflict (it's minor)? |
add the sops v3.5 binary in the flux docker image for use, with pre-processing tools such kustomize Signed-off-by: Paul Farver <[email protected]>
Include sops decrypt library, and use it to decrypt files as they are loaded by flux Signed-off-by: Paul Farver <[email protected]>
add tests, that verify that a set of pre-encrypted files can be imported and automatically decrypted with sops Signed-off-by: Paul Farver <[email protected]>
add the "--sops" flag to switch sops decryption on and off when starting the flux daemon Signed-off-by: Paul Farver <[email protected]>
@2opremio Yep, done! |
@PaulFarver sorry to activate an old thread, but I'm trying to figure out how this works when my file was encrypted with AWS KMS. Would I need to first mount (somehow) a volume into the flux container that contains the It looks like the code here is less about generically "enabling SOPS" and more specifically "enabling sops with GPG". Is that accurate? |
KMS should work, you just need to configure the environment if the Flux container as if you were to invoke the sops binary (which is also included in the Flux image, so it's a good way to test that it works). |
@2opremio that's essentially what I was asking how to do :) ( sops uses the go aws sdk, which expects the credentials file to live at I'm not sure the best way to solve that problem. Unless I'm really misunderstanding something here |
Don’t bother with credentials file. You can just export the variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Set them up as environment variables for your flux container |
@tomjohnburton ... that said, I use helm to install flux. I see ... is it considered secure to pass those secrets in like that? that's what I'm alluding to when I say chicken and egg. I'm just not sure if pushing those in directly as env vars is actually a smart/safe thing to be doing. |
Instead of storing the AWS key in a Kubernetes secret or env vars you should consider using IAM roles for service accounts. With eksctl you could associate an IAM role to Flux service account so that Flux pod can access the KMS API see https://eksctl.io/usage/iamserviceaccounts/ |
ok, perfect! That's very helpful for when I get to the EKS stage. Currently proving everything out locally first. I think helm-secrets has what I need for this layer for now. First am going to push straight into env vars using a temp/throwaway IAM user just to prove out the e2e flow, then will work on improving with helm-secrets/volume mounts, then "harden" once in EKS and switching to the service account/role approach. Thank you for the help guys! |
Would anyone have a running example of eksctl-enabled-flux using sops + KMS key to decrypt files? |
yes, this has been working very well. we use a simple script we named I've kept the stuff in there where we're allowing the script to control setting up multiple instances of flux that each watch a different branch of the repo and a specific path. You may or may not find that part useful, but it's how we are dealing with running multiple flux-enabled CI/CD projects in the same cluster. Obviously change paths and whatnot to match your needs. The important bits are in the helm command
Once setup, this works great. Any SOPS encrypted manifests flux finds in the configured path in the repo, as long as they were encrypted with that same KMS ARN, will be automatically decrypted. Make sure to remember for kubernetes |
And to be clear, there is nothing special about whether your cluster was setup using |
This is a pull request that adds support for sops OOTB as described in #1676
The point of this feature is to let flux decrypt files encrypted with sops. Sops is ideal for encryption of yaml files, and has support for AWS KMS, GCP KMS, Azure Key Vault and PGP. The idea is to get flux to decrypt yaml manifests that have been encrypted with sops.
--sops
is a boolean option for specifying whether sops decryption should be enabled