-
Notifications
You must be signed in to change notification settings - Fork 691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kustomize plugin #167
Comments
Yeah, I ran into the same problem. In my case, I have a For example, given the following
when doing:
If I remove the So, with the new support for plugins (I had to build
where
and #!/bin/bash
temp_dir=$(mktemp -d)
#
# For debugging, uncomment this.
#
#trap "/bin/rm -rf $temp_dir" 0 2 3 1
echo "=======" > ~/plugin.txt
echo "dir=$temp_dir" >> ~/plugin.txt
echo "=======" >> ~/plugin.txt
cat $1 >> ~/plugin.txt
echo "=======" >> ~/plugin.txt
OPTIONS=$(cat $1 | yq -r '.metadata.options')
echo "options: $OPTIONS" >> ~/plugin.txt
echo "=======" >> ~/plugin.txt
cat - > $temp_dir/input.yaml
# Filter secrets
cat $temp_dir/input.yaml | yq -y '.|select(.kind=="Secret")' > $temp_dir/secrets.yaml
# kubeseal strips the kustomize metadata annotation so we have to save it to inject it later.
ANNOTATION=$(cat $temp_dir/secrets.yaml | yq '.metadata.annotations."kustomize.config.k8s.io/id"')
INJECT=".metadata.annotations.\"kustomize.config.k8s.io/id\"=$ANNOTATION"
echo "annotation: $ANNOTATION" >> ~/plugin.txt
echo "=======" >> ~/plugin.txt
echo "inject: $INJECT" >> ~/plugin.txt
echo "=======" >> ~/plugin.txt
# Filter other contents
cat $temp_dir/input.yaml | yq -y '.|select(.kind!="Secret")' > $temp_dir/other.yaml
# Apply kubeseal to secrets
cat $temp_dir/secrets.yaml \
| kubeseal $OPTIONS --format yaml \
> $temp_dir/sealedsecrets.yaml
# Inject the kustomize metadata annotation back (kubeseal stripped it!)
cat $temp_dir/sealedsecrets.yaml \
| yq -y --sort-keys "$INJECT" \
> $temp_dir/sealedsecrets-with-annotation.yaml
# put everything together again
cat $temp_dir/other.yaml > $temp_dir/output.yaml
echo "---" >> $temp_dir/output.yaml
cat $temp_dir/sealedsecrets-with-annotation.yaml >> $temp_dir/output.yaml
# This is the custom-transformed output...
cat $temp_dir/output.yaml The idea here is to apply In principle, we should then be able to do:
But that doesn't work. Just:
produces an error:
And indeed, I see why: https://github.com/kubernetes-sigs/kustomize/blob/master/k8sdeps/kunstruct/hasher.go#L25 Darn! I wonder if the kustomize plugin feature requires relaxing this hashing function to that kustomize could be applied to non-standard resources like |
I'm a little bit confused about this use case. Here is how I think about the problem space (and I might be missing something obvious, so please let me know): If I understand correctly, the secretGenerator kustomize rule literally reads a cleartext file from the FS and encodes it into a k8s Secret resource (like
The goal of sealed-secrets is to avoid checking in the secrets in your version control system. A secondary goal of kustomize is to provide some helpers for common tasks such as constructing config maps or secrets from bits that you have laying around in other files (since you cannot otherwise "import" a value from a file in yaml). That works on the assumption that it's ok to have that information in clear in the filesystem. Perhaps improvements in the usability of the |
For me, the benefit of In terms of how this relates to sealed secrets, it would be useful to have The sealed secret controller would also need to be able to decrypt the renamed sealed secret when it's deployed (hand-waving issues with garbage collection). |
Thanks! This is actually similar to an issue reported with spinnaker: #62 (comment) Perhaps we can find a way to address both issues |
We've also just hit this, and are having to just pass sealed secrets as resources. It'd be nice to be able to declare a
and specify my kubseal cert in my overlay/$env/kustomization.yaml.
Which should give a plugin the data required to seal a new secret and pass it on |
that would require teaching the core secretGenerator plugin about sealed secrets. A possible horrible hack we could do is to literally create a Secret with fake items containing encrypted data e.g.
and have the controller unseal these in-place. Strategic merge patch (supported by kubectl apply and diff) would handle those extra fields. The main downside is that while scheduling pods referencing you'll see errors referring to missing items rather than unavailable secret (which is what you'd expect with sealed-secrets since the unsealing is asynchronous) |
You would still need some method of sealing the secret with Kustomize, before you could pass any secret into the cluster. So you'd need a plugin (or Kustomize) to handle the sealing with certs, and a generator to keep the Kustomize pattern in tact? |
yeah I was glossing over that. We might just put the output of <whatever_you_use_to_generate_your_cleartext_once> | kubeseal >sealedsecret_unseal_here.yaml
this will create a secret with a But, as I said, this looks like a hack. Probably a proper kustomize plugin would be better. I'm wondering if we can write a generic kustomize plugin that deals with these "suffixed references" without having to be specific to sealed-secrets. (EDIT: ideally we should be able to set some labels to the secret, to instruct the sealed secret controller to do this "merge" operation; I don't know how to add labels/annotations with kustomize's |
I agree it's not obvious, but this is how you add labels/annotations to the builtin
would be rendered to
|
@mkmik what would be the label required I'm trying to apply your suggested hack by doing this:
Applying that kustomize manifest deploys the expected secret to the cluster:
but nothing else. No logs on the sealed-controller showing awareness of the wrapped sealed secret. I guess that without that label doing the linking there's no way for the controller to react. Sorry for asking, but has been progress on the non-hacky path for this use case? |
it was just an idea; there is nothing in the controller right now that would act that way. |
I started looking to use SealedSecrets with kustomize as well, and thought it would be relatively simple using the raw option to produce encrypted values and have a sealed secrets generator plugin such that you might do something like:
I haven't actually gone through implementing it, but it seems like getting the automatic versioning and rollout will be blocked because of the hashing problem for custom types that @NicolasRouquette mentioned in #167 (comment). The builtin HashTransformer only supports ConfigMaps and Secrets, so it fails. Maybe the hashing could just be done in the sealedSecretGenerator plugin? Past that, I think the name-reference transformer could be configured for sealed secrets to do appropriate name updates, but again I haven't actually tried it. |
We developed sealed secret hash transformer to add hash to
|
By using the |
This is great @RyosukeCla ! I did validate that the namespace-wide scope works as well. |
Successfully wrote a kustomize transformers that will replace every I also wrote https://github.com/tehmoon/cheatsheet/blob/master/kubernetes/kustomize/plugins/sealed-secrets-install.md to generate installing sealed-secret. Ideal for gitops!!! Generation can be done offline since you can pass the |
@tehmoon hi! Thanks. Can you please describe your wider workflow so I can better understand how this step with kustomize fits in? |
@mkmik of course! I'm installing and operating a kubernetes cluster solely using GitOps with FluxCD. If I take, for example, the way you install the mesh network Linkerd, you have to run This is where
These are a lot of unnecessary steps which can all be avoided using a transformer plugin. It goes without saying that |
Is there a reason why this wouldn't work for a plugin?
|
With Helm you can trigger a pod roll out by changing a secret's manifest without needing to rename the secret by taking advantage of annotations and a bit of templating. You can do something like this in your deployment template: template:
metadata:
annotations:
checksum/secret: {{ include ("shared-lib.secret") . | sha256sum }} In the above case, that's including the contents of a secret template which is a standard Kubernetes secret. It then gets a checksum of the file which results in that annotation having a unique checksum. Re-rolling your secrets will produce a different checksum and that will trigger a rollout of your pods. You can think of it like cache busting your static files but for Kubernetes manifests. Does anyone have any ideas on how to apply this sort of thing with Kustomize? Preferably in a way that works with GitOps (ArgoCD) where you're not having to run anything in CI beforehand, or ideally not having to manually run something locally to change the template before pushing your code up. I think running it locally wouldn't be too hard to pull off in a shell script since all you would have to do is pop in a I am in the process of using sealed secrets (will be migrating to it soon) so I do think there will be a need to have some shell scripting before pushing code to help extract / edit / create a new sealed secret, so maybe the local approach is the way to go since if you're running a local |
This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback. |
As a user of
SealedSecrets is a really good solution, but if it reduces possibilities offered by the standard system, it starts to became a pain and other solution can be investigated, like for example |
Is there any workaround or way to do it? |
Here's one way of doing this with newer versions of kustomize (tested on Input.
├── builtin-config.yaml
├── kustomization.yaml
├── pod.yaml
└── sealedsecret.yaml
1 directory, 4 files ==> builtin-config.yaml <==
nameReference:
- kind: Secret
fieldSpecs:
- kind: SealedSecret
path: metadata/name
- kind: SealedSecret
path: spec/template/metadata/name
==> kustomization.yaml <==
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./pod.yaml
- ./sealedsecret.yaml
secretGenerator:
- name: test
files:
- ./sealedsecret.yaml
options:
annotations:
config.kubernetes.io/local-config: "true"
configurations:
- ./builtin-config.yaml
==> pod.yaml <==
# yaml-language-server: $schema=https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/master-standalone/pod-v1.json
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: something
image: some-image
envFrom:
- secretRef:
name: test
==> sealedsecret.yaml <==
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
name: test
annotations:
sealedsecrets.bitnami.com/namespace-wide: "true"
spec:
encryptedData:
a: "1...."
b: "2..."
c: "3..."
template:
metadata:
name: test
type: Opaque
OutputapiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
annotations:
sealedsecrets.bitnami.com/namespace-wide: "true"
name: test-cm5hd7d6b9
spec:
encryptedData:
a: 1....
b: 2...
c: 3...
template:
metadata:
name: test-cm5hd7d6b9
type: Opaque
---
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- envFrom:
- secretRef:
name: test-cm5hd7d6b9
image: some-image
name: something
The trick is to teach kustomize ( This Finally, to avoid emitting the Obviously, you also need a |
FYI, I got tired of doing the copy-pasta above again and again in every new Kustomization, so I've created a KRM function that can help me out: https://github.com/jashandeep-sohi/krm-fn-sealedsecrets It too is kind of a hack, so your mileage may vary but the UX is much nicer for my use-case. Here's an example of doing something similar to a secretGenerator above, but in a more persistent way: https://github.com/jashandeep-sohi/krm-fn-sealedsecrets/tree/master/examples/kpt-seal-name-ref-kustomization |
On latest version of kustomize, @jashandeep-sohi 's solution no longer works because as soon as I add the Of course I can remove the To work around this, I just gave sealed secrets access to overwrite the applied stub secret instead: - name: test
files:
- ./sealedsecret.yaml
options:
annotations:
sealedsecrets.bitnami.com/managed: "true" This is not ideal, there is a potential race condition, but it works for now unless anyone has any better ideas. |
Hi,
We are using sealed-secrets together with kustomize and it's a bit of pain to handle it for multiple environments right now, since you need a new name of the sealed-secret to trigger the rolling-upgrade of services. I saw that kustomize now supports plugin, would be great if some kind soul could create a plugin for sealed-secrets :) Prbly a lot of people would appreciate it.
https://github.com/kubernetes-sigs/kustomize/blob/master/docs/plugins.md
/ Cheers
The text was updated successfully, but these errors were encountered: