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

Kyverno's default restrict-automount-sa-token policy denies the installation of policy-reporter #155

Closed
Dentrax opened this issue Jun 16, 2022 · 11 comments

Comments

@Dentrax
Copy link

Dentrax commented Jun 16, 2022

Shouldn't we set automountServiceAccountToken: "false" in deployment manifest? Any ideas why we set it to true instead?

$ helm install policy-reporter policy-reporter/policy-reporter --set kyvernoPlugin.enabled=true --set ui.enabled=true --set ui.plugins.kyverno=true  -n policy-reporter --create-namespace

Error: INSTALLATION FAILED: admission webhook "validate.kyverno.svc-fail" denied the request:

resource Deployment/policy-reporter/policy-reporter-kyverno-plugin was blocked due to the following policies

restrict-automount-sa-token:
  autogen-validate-automountServiceAccountToken: 'validation error: Auto-mounting
    of Service Account tokens is not allowed. Rule autogen-validate-automountServiceAccountToken
    failed at path /spec/template/spec/automountServiceAccountToken/'

Rule:

spec:
  background: true
  rules:
  - match:
      any:
      - resources:
          kinds:
          - Pod
    name: validate-automountServiceAccountToken
    validate:
      message: Auto-mounting of Service Account tokens is not allowed.
      pattern:
        spec:
          automountServiceAccountToken: "false"
  validationFailureAction: enforce

cc @developer-guy

@Dentrax
Copy link
Author

Dentrax commented Jun 16, 2022

If i set automountServiceAccountToken: "false" in deployment, pod falling back to crash with the following error:

Error: open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directory

Any ideas how to make it run without setting it true?

@fjogeleit
Copy link
Member

fjogeleit commented Jun 16, 2022

The SA is required to get permissions for accessing the K8s API. Thats because it is set to true. There is no really work around for it. Only possible solution could be to add a manual volume and volumeMount instead the automount feature.

@Dentrax
Copy link
Author

Dentrax commented Jun 16, 2022

So it's something we can fix in the deployment manifests? I prefer to handle all that manual stuff in the helm side during installation.

Currently, it's unable to run this project with Kyverno's default policy enforcement, which decreases the UX a bit in the first place.

@fjogeleit
Copy link
Member

fjogeleit commented Jun 16, 2022

But you will have the same problem with all tools that access the K8s API in some case, the Policy description also says that the intention is to prevent automount for pods that are not interacting with the K8s API.

Kubernetes automatically mounts ServiceAccount credentials in each Pod.
The ServiceAccount may be assigned roles allowing Pods to access API resources.
Blocking this ability is an extension of the least privilege best practice and should
be followed if Pods do not need to speak to the API server to function.
This policy ensures that mounting of these ServiceAccount tokens is blocked.

Because the SA secret name has a dynamic suffix like policy-reporter-token-vdt6m, the manual mount is not really an option because I don't know the secret name before it is created.

@fjogeleit
Copy link
Member

You could add an exclude label and add this label to the policy-reporter pods and other K8s API related tools.

Would it make sense to add some kind of exclusion (e.g. label) to the Kyverno Policy directly @chipzoller @realshuting?

@chipzoller
Copy link
Member

Sure, should it exclude by name?

@fjogeleit
Copy link
Member

If you want to add a policy-reporter specific exclude I would suggest the label app.kubernetes.io/part-of: policy-reporter. Its currently only added on the deployment but I can create a minor version which also add it on pod level. So we don't need multiple values for the different components.

@chipzoller
Copy link
Member

Glad to accept a PR to the policy if one is made.

@fjogeleit
Copy link
Member

Thanks @chipzoller . I will open one

@fjogeleit
Copy link
Member

fjogeleit commented Jun 16, 2022

I created kyverno/policies#348 which should resolve your issue and the Policy should no longer the Policy Reporter deployment.

@fjogeleit
Copy link
Member

The updated Policy has now an exclude filter for Policy Reporter (kyverno/policies#348) which should fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants