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

Remote Cluster Configuration for Trivy-Dojo-Report-Operator #84

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ spec:
value: {{ quote .Values.operator.trivyDojoReportOperator.env.reports }}
- name: KUBERNETES_CLUSTER_DOMAIN
value: {{ quote .Values.kubernetesClusterDomain }}
{{- if .Values.remoteClusterKubeconfig }}
- name: KUBECONFIG
value: "/app/.kube/config"
{{- end }}
image: {{ .Values.operator.trivyDojoReportOperator.image.repository }}:{{ .Values.operator.trivyDojoReportOperator.image.tag | default .Chart.AppVersion }}
livenessProbe:
httpGet:
Expand All @@ -110,8 +114,24 @@ spec:
{{- end }}
securityContext: {{- toYaml .Values.operator.trivyDojoReportOperator.containerSecurityContext
| nindent 10 }}
{{- if .Values.remoteClusterKubeconfig }}
volumeMounts:
- name: kubeconfig
mountPath: /app/.kube
{{- end }}
{{- if .Values.remoteClusterKubeconfig }}
volumes:
- name: kubeconfig
secret:
secretName: {{ include "charts.fullname" . }}-defect-dojo-api-credentials
items:
- key: kubeconfig
path: config
{{- end }}
securityContext: {{- toYaml .Values.operator.podSecurityContext | nindent 8 }}
{{- if .Values.createRBAC }}
serviceAccountName: {{ include "charts.fullname" . }}-account
{{- end }}
{{- with .Values.operator.trivyDojoReportOperator.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.createRBAC }}
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down Expand Up @@ -62,3 +63,4 @@ subjects:
- kind: ServiceAccount
name: '{{ include "charts.fullname" . }}-account'
namespace: '{{ .Release.Namespace }}'
{{- end }}
11 changes: 7 additions & 4 deletions charts/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ metadata:
name: {{ include "charts.fullname" . }}-defect-dojo-api-credentials
labels:
{{- include "charts.labels" . | nindent 4 }}
stringData:
data:
apiKey: {{ required "defectDojoApiCredentials.apiKey is required" .Values.defectDojoApiCredentials.apiKey
| quote }}
| b64enc | quote }}
url: {{ required "defectDojoApiCredentials.url is required" .Values.defectDojoApiCredentials.url
| quote }}
type: Opaque
| b64enc | quote }}
{{- if .Values.remoteClusterKubeconfig }}
kubeconfig: {{ .Values.remoteClusterKubeconfig | quote }}
{{- end }}
type: Opaque
3 changes: 3 additions & 0 deletions charts/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defectDojoApiCredentials:
apiKey: "YOUR_DEFECTDOJO_API_KEY"
url: "YOUR_DEFECTDOJO_URL"
# -- Kubeconfig remote cluster already in base64
remoteClusterKubeconfig: ""
kubernetesClusterDomain: cluster.local
account:
serviceAccount:
Expand Down Expand Up @@ -57,3 +59,4 @@ operator:
runAsNonRoot: true
fsGroupChangePolicy: Always
fsGroup: 1000
createRBAC: true
11 changes: 11 additions & 0 deletions deploy/trivy-dojo-report-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ metadata:
stringData:
apiKey: "YOUR_DEFECTDOJO_API_KEY"
url: "YOUR_DEFECTDOJO_URL"
kubeconfig: ""
type: Opaque
---
# Source: trivy-dojo-report-operator/templates/rbac.yaml
Expand Down Expand Up @@ -221,6 +222,16 @@ spec:
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
volumeMounts:
- name: kubeconfig
mountPath: /app/.kube
volumes:
- name: kubeconfig
secret:
secretName: telekom-mms-trivy-dojo-report-operator-defect-dojo-api-credentials
items:
- key: kubeconfig
path: config
securityContext:
fsGroup: 1000
fsGroupChangePolicy: Always
Expand Down
6 changes: 6 additions & 0 deletions src/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def check_allowed_reports(report: str):
)
exit(1)

@kopf.on.login()
def login_fn(**kwargs):
if settings.KUBECONFIG:
return kopf.login_with_kubeconfig(**kwargs)
else:
return kopf.login_via_client(**kwargs)

@kopf.on.startup()
def configure(settings: kopf.OperatorSettings, **_):
Expand Down
1 change: 1 addition & 0 deletions src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO").upper()

REPORTS: list = os.getenv("REPORTS", "vulnerabilityreports").split(",")
KUBECONFIG: str = os.getenv("KUBECONFIG", "")