Skip to content

Commit

Permalink
feat: azure workload identity support (aquasecurity#1267)
Browse files Browse the repository at this point in the history
* feat: azure workload identity support

Signed-off-by: chenk <hen.keinan@gmail.com>

* feat: azure workload identity support

Signed-off-by: chenk <hen.keinan@gmail.com>

* feat: azure workload identity support

Signed-off-by: chenk <hen.keinan@gmail.com>

* feat: azure workload identity support

Signed-off-by: chenk <hen.keinan@gmail.com>

* feat: azure workload identity support

Signed-off-by: chenk <hen.keinan@gmail.com>

* feat: workload identity support

Signed-off-by: chenk <hen.keinan@gmail.com>

---------

Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan authored Jun 8, 2023
1 parent c86f7e1 commit 63b6dd9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions deploy/helm/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ data:
{{- with .Values.nodeCollector.excludeNodes }}
nodeCollector.excludeNodes: {{ . | quote }}
{{- end }}
{{- if .Values.trivyOperator.azureWorkloadIdentity }}
scanJob.podTemplateLabels: {{ printf "azure.workload.identity/use=true,%s" .Values.trivyOperator.scanJobPodTemplateLabels | quote }}
{{- else }}
{{- with .Values.trivyOperator.scanJobPodTemplateLabels }}
scanJob.podTemplateLabels: {{ . | quote }}
{{- end }}
{{- end }}
{{- with .Values.trivyOperator.additionalReportLabels }}
report.additionalLabels: {{ . | quote }}
{{- end }}
Expand Down
14 changes: 13 additions & 1 deletion deploy/helm/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ metadata:
namespace: {{ include "trivy-operator.namespace" . }}
labels:
{{- include "trivy-operator.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
{{- if .Values.trivyOperator.azureWorkloadIdentity}}
{{- range $name, $value := .Values.trivyOperator.azureWorkloadIdentityUseLabel }}
{{ $name }}: {{ $value | quote }}
{{- end -}}
{{- end }}
{{- if or .Values.serviceAccount.annotations .Values.trivyOperator.azureWorkloadIdentity }}
annotations:
{{- end }}
{{- with .Values.serviceAccount.annotations }}
{{- . | toYaml | nindent 4 }}
{{- end }}
{{- if .Values.trivyOperator.azureWorkloadIdentity}}
{{- range $name, $value := .Values.trivyOperator.azureWorkloadIdentityAnnotation }}
{{ $name }}: {{ $value | quote }}
{{- end -}}
{{- end }}
{{- end }}

{{- if .Values.rbac.create }}
Expand Down
7 changes: 7 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ trivyOperator:
# labeled with. Example: `foo=bar,env=stage` will labeled the reports with the labels `foo: bar` and `env: stage`
additionalReportLabels: ""

# azureWorkloadIdentity if enable azure workload identity annotation and labels wil be added to trivy-operator service account and scan job must be used with azureWorkloadIdentityClientID, azurerkloadIdentityTenantID and azureWorkloadIdentityUseAnnotation
azureWorkloadIdentity: false
# azureWorkloadIdentityAnnotation annotation to be added to trivy-operator service account it is required to update the values of : <tenant-id> and <client-id>
azureWorkloadIdentityAnnotation: {azure.workload.identity/client-id: client-id, azure.workload.identity/tenant-id: tenant-id}
# azureWorkloadIdentityUseLabel label to be added to trivy-operator service account
azureWorkloadIdentityUseLabel: {azure.workload.identity/use: true}

trivy:
# createConfig indicates whether to create config objects
createConfig: true
Expand Down
3 changes: 2 additions & 1 deletion pkg/trivyoperator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ func (c ConfigData) GetScanJobPodTemplateLabels() (labels.Set, error) {
}

scanJobPodTemplateLabelsMap := map[string]string{}
for _, annotation := range strings.Split(scanJobPodTemplateLabelsStr, ",") {
labelParts := strings.Split(strings.TrimSuffix(scanJobPodTemplateLabelsStr, ","), ",")
for _, annotation := range labelParts {
sepByEqual := strings.Split(annotation, "=")
if len(sepByEqual) != 2 {
return labels.Set{}, fmt.Errorf("failed parsing incorrectly formatted custom scan pod template labels: %s", scanJobPodTemplateLabelsStr)
Expand Down
10 changes: 10 additions & 0 deletions pkg/trivyoperator/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,16 @@ func TestConfigData_GetScanJobPodTemplateLabels(t *testing.T) {
expected labels.Set
expectError string
}{
{
name: "scan job template labels with additional comma at the end can be fetched successfully",
config: trivyoperator.ConfigData{
"scanJob.podTemplateLabels": "a.b=c.d/e,foo=bar,",
},
expected: labels.Set{
"foo": "bar",
"a.b": "c.d/e",
},
},
{
name: "scan job template labels can be fetched successfully",
config: trivyoperator.ConfigData{
Expand Down

0 comments on commit 63b6dd9

Please sign in to comment.