Skip to content
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

[Feature] allow kubernetes auth method for hashivault:// KMS in imageVerify #4274

Open
2 tasks done
rubroboletus opened this issue Jul 29, 2022 · 10 comments
Open
2 tasks done
Assignees
Labels
end user This label is used to track the issue that is raised by the end user. enhancement New feature or request imageVerify Image verification support

Comments

@rubroboletus
Copy link

Problem Statement

Kyverno allows to use hashivault:// keys for image verrification, but the vault token and vault addr must be set. Why not to use vault kubernetes authentication method (https://www.vaultproject.io/docs/auth/kubernetes)?

Solution Description

Kyverno runs inside Kubernetes, Vault supports Kubernetes authentication, why not connect this two features together for using Vault from Kyverno in imageVerify hashivault:// checks. Get short living vault token when needed using kubernetes authentication method and then use it for KMS.

Alternatives

No response

Additional Context

No response

Slack discussion

No response

Research

  • I have read and followed the documentation AND the troubleshooting guide.
  • I have searched other issues in this repository and mine is not recorded.
@rubroboletus rubroboletus added enhancement New feature or request triage Default label assigned to all new issues indicating label curation is needed to fully organize. labels Jul 29, 2022
@chipzoller chipzoller added imageVerify Image verification support and removed triage Default label assigned to all new issues indicating label curation is needed to fully organize. labels Aug 4, 2022
@chipzoller chipzoller added the end user This label is used to track the issue that is raised by the end user. label Aug 4, 2022
@jessequinn
Copy link

agreed. useful. I do not see a viable way of having Vault as a KMS for Kyverno with having to set the token manually and restarting the pod. Tokens have a TTL of 30 days, I believe, in Vault.

@developer-guy
Copy link
Contributor

we (w/@Dentrax) just tested this Vault KMS with Kyverno and I can truly say that everything worked as we expected, yay! As a result, we are going to write a blog post to explain everything in detail, stay tuned 🙈

@chipzoller
Copy link
Member

Can you give us a hint so we can add something to the documentation?

@developer-guy
Copy link
Contributor

developer-guy commented Oct 9, 2023

Firstly, we have added two environment variables to the kyverno-admission-controller: VAULT_ADDR and VAULT_TOKEN.

Then we created a image verification policy like the following:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: check-image
spec:
  validationFailureAction: Enforce
  background: false
  webhookTimeoutSeconds: 30
  failurePolicy: Fail
  rules:
    - name: check-image
      match:
        any:
        - resources:
            kinds:
              - Pod
      verifyImages:
      - imageReferences:
        - "*"
        attestors:
        - count: 1
          entries:
          - keys:
              kms: hashivault://cosign

The cosign is the name of the key we used during the signing/verifying of the container images. Before then we already signed our container image with the following command:

cosign sign --key hashivault://cosign <image>

After we applied the policy above, we expected to verify the signature by Kyverno and all worked as we expected.

We even tried key rotation to see how things would go. We simply rotated the key with which we signed container images then once again we signed container images with the new key, thanks to the VAULT_KEY_PREFIX environment variable, we set it as vault:v2: to the deployment variables and everything worked as we expected again, the container images which we signed with the old key are failed but the ones we signed with the new key are passed.

PTAL @Dentrax

@Lerentis
Copy link
Contributor

Lerentis commented Oct 9, 2023

I guess this is only a valid solution if you are using static tokens in vault. Utilizing the vault in k8s login as stated in the creation of the ticket would be a more desirable solution imo

@developer-guy
Copy link
Contributor

yes it might be but it requires development effort on both sides Kyverno and Sigstore to support that.

@developer-guy
Copy link
Contributor

developer-guy commented Oct 16, 2023

do you want me to add these details to the doc @chipzoller?

@chipzoller
Copy link
Member

Since what you're doing isn't really what this issue describes, maybe just point to the Vault docs if they exist?

@ambis
Copy link

ambis commented Apr 12, 2024

It would be super helpful if we were able to use Vault's kubernetes auth with kyverno.

@angapov
Copy link

angapov commented Apr 22, 2024

I would add that using static Vault token goes against security best practices. Static Vault tokens are long-lived and are susceptible to theft, whereas Kubernetes auth method uses short-lived service account tokens (1 hour TTL by default). I strongly believe Kubernetes auth method should be implemented as a default one by Kyverno.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
end user This label is used to track the issue that is raised by the end user. enhancement New feature or request imageVerify Image verification support
Projects
None yet
Development

No branches or pull requests

8 participants