-
Couldn't load subscription status.
- Fork 1.3k
Description
Describe the issue
CKV_K8S_21
The check does report that the default namespace is used when in fact Helm install uses a custom namespace when deploying to k8s.
Examples
Check: CKV_K8S_21: "The default namespace should not be used"
FAILED for resource: ServiceAccount.default.release-name-hello-kubernetes
File: /hello-kubernetes/templates/sa.yaml:3-13
Guide: https://docs.bridgecrew.io/docs/bc_k8s_20
3 | apiVersion: v1
4 | kind: ServiceAccount
5 | metadata:
6 | name: release-name-hello-kubernetes
7 | namespace: default
8 | labels:
9 | app.kubernetes.io/name: hello-kubernetes
10 | helm.sh/chart: hello-kubernetes-1.0.24
11 | app.kubernetes.io/instance: release-name
12 | app.kubernetes.io/managed-by: Helm
13 | app.kubernetes.io/version: "1.4"
As per Helm best practices here helm/helm#5465 (comment) it's not recommended to hardcode the namespace as helm uses the parameter -namespace at installation time which namespace to deploy to.
So the below template for ServiceAccount, from helm perspective is completely valid.
cat sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "hello-kubernetes.fullname" . }}
labels: {{- include "hello-kubernetes.labels" . | nindent 4 }}Version (please complete the following information):
- version: 2.2.80
Additional context
Even if I add namespace to metadata, it still reports as FAILED.
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "hello-kubernetes.fullname" . }}
namespace: {{ .Release.Namespace }}
labels: {{- include "hello-kubernetes.labels" . | nindent 4 }}I'm running checkov in container in Jenkins like described here https://www.checkov.io/4.Integrations/Jenkins.html.
stage('Static code analysis') {
agent {
docker {
image 'bridgecrew/checkov:2.2.80'
args "--entrypoint=''"
}
}
steps {
sh "checkov -d ${env.DIRECTORY} --framework helm"
}
}
My k8s default context has no namespace defined and probably that's why being picked up as default.
I'm wondering if there is a way to tell checkov what namespace to infer when calling helm ?
I couldn't find documented here https://www.checkov.io/7.Scan%20Examples/Helm.html how to do this.