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

feat(clamav): Make config files dict values #536

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion charts/clamav/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
description: An Open-Source antivirus engine for detecting trojans, viruses, malware & other malicious threats. Using Mailu docker image.
name: clamav
version: 3.2.0
version: 3.3.0
appVersion: "1.4.1"
home: https://www.clamav.net
icon: https://www.clamav.net/assets/clamav-trademark.png
Expand Down
2 changes: 2 additions & 0 deletions charts/clamav/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ The command removes all the Kubernetes components associated with the chart and
The configurable parameters of the ClamAV chart and
their descriptions can be seen in `values.yaml`. The [full documentation](https://www.clamav.net/documents/clam-antivirus-0-101-0-user-manual) contains more information about running ClamAV in docker.

The config files themselves can either be specified as a plain text value or composed from a dict. In case they are specified via dict, if you give one key a list as a value, the option will be repeated for each value in the list.

> **Tip**: You can use the default [values.yaml](values.yaml)

## Memory Usage
Expand Down
12 changes: 12 additions & 0 deletions charts/clamav/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,15 @@ app.kubernetes.io/instance: {{ .Release.Name }}
/init-unprivileged
{{- end -}}
{{- end -}}

{{- define "clamav.dictToConfig" -}}
{{- range $key, $value := . -}}
{{- if kindIs "slice" $value -}}
{{- range $value -}}
{{ $key }} {{ . }}
{{ end }}
{{- else -}}
{{ $key }} {{ $value }}
{{ end }}
{{- end }}
{{- end -}}
10 changes: 7 additions & 3 deletions charts/clamav/templates/clamd-configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.clamdConfig -}}
{{- if or .Values.clamdConfig .Values.clamdConfigDict -}}
kind: ConfigMap
apiVersion: v1
metadata:
Expand All @@ -9,6 +9,10 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
clamd.conf:
{{- toYaml .Values.clamdConfig | nindent 4 }}
clamd.conf: |
{{- if .Values.clamdConfig }}
{{- .Values.clamdConfig | nindent 4 }}
{{- else }}
{{- include "clamav.dictToConfig" .Values.clamdConfigDict | nindent 4 }}
{{- end }}
{{- end }}
10 changes: 7 additions & 3 deletions charts/clamav/templates/freshclam-configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.freshclamConfig -}}
{{- if or .Values.freshclamConfig .Values.clamdConfigDict -}}
kind: ConfigMap
apiVersion: v1
metadata:
Expand All @@ -9,6 +9,10 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
freshclam.conf:
{{- toYaml .Values.freshclamConfig | nindent 4 }}
freshclam.conf: |
{{- if .Values.freshclamConfig }}
{{- .Values.freshclamConfig | nindent 4 }}
{{- else }}
{{- include "clamav.dictToConfig" .Values.freshclamConfigDict | nindent 4 }}
{{- end }}
{{- end }}
8 changes: 4 additions & 4 deletions charts/clamav/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ spec:
volumeMounts:
- name: clamav-data
mountPath: /data
{{- if .Values.freshclamConfig }}
{{- if or .Values.freshclamConfig .Values.freshclamConfigDict }}
- name: freshclam-config-volume
mountPath: /etc/clamav/freshclam.conf
subPath: freshclam.conf
{{- end }}
{{- if .Values.clamdConfig }}
{{- if or .Values.clamdConfig .Values.clamdConfigDict }}
- name: clamd-config-volume
mountPath: /etc/clamav/clamd.conf
subPath: clamd.conf
Expand Down Expand Up @@ -116,12 +116,12 @@ spec:
- name: clamav-data
emptyDir: {}
{{- end }}
{{- if .Values.freshclamConfig }}
{{- if or .Values.freshclamConfig .Values.freshclamConfigDict }}
- name: freshclam-config-volume
configMap:
name: {{ include "clamav.fullname" . }}-freshclam
{{- end }}
{{- if .Values.clamdConfig }}
{{- if or .Values.clamdConfig .Values.clamdConfigDict }}
- name: clamd-config-volume
configMap:
name: {{ include "clamav.fullname" . }}-clamd
Expand Down
48 changes: 46 additions & 2 deletions charts/clamav/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,41 @@
"clamdConfig": {
"type": ["string"]
},
"clamdConfigDict": {
"type": "object",
"patternProperties": {
".*": {
"anyOf": [
{ "type": ["string", "integer" ] },
{
"type": "array",
"items":[
{ "type": ["string", "integer" ] }
]
}
]
}
}
},
"freshclamConfig": {
"type": ["string"]
},
"freshclamConfigDict": {
"type": "object",
"patternProperties": {
".*": {
"anyOf": [
{ "type": ["string", "integer" ] },
{
"type": "array",
"items":[
{ "type": ["string", "integer" ] }
]
}
]
}
}
},
"resources": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -285,8 +317,6 @@
"fullnameOverride",
"service",
"ingress",
"clamdConfig",
"freshclamConfig",
"resources",
"podLabels",
"nodeSelector",
Expand All @@ -299,5 +329,19 @@
"extraVolumes",
"extraVolumeMounts",
"persistentVolume"
],
"allOf":[
{
"anyOf":[
{ "required": ["clamdConfig"] },
{ "required": ["clamdConfigDict"] }
]
},
{
"anyOf":[
{ "required": ["freshclamConfig"] },
{ "required": ["freshclamConfigDict"] }
]
}
]
}
105 changes: 49 additions & 56 deletions charts/clamav/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,87 +66,80 @@ ingress:

## Ref: https://linux.die.net/man/5/clamd.conf
## Note: will completely override default clamd.conf file at https://github.com/Mailu/Mailu/tree/master/optional/clamav/conf
clamdConfig: |
clamdConfigDict:
###############
# General
###############

DatabaseDirectory /data
TemporaryDirectory /tmp
LogTime yes
DatabaseDirectory: /data
TemporaryDirectory: /tmp
LogTime: "yes"
# CUSTOM: Use pid file in tmp
PidFile /tmp/clamd.pid
LocalSocket /tmp/clamd.sock
TCPSocket 3310
Foreground yes
PidFile: /tmp/clamd.pid
LocalSocket: /tmp/clamd.sock
TCPSocket: 3310
Foreground: "yes"

###############
# Results
###############

DetectPUA yes
ExcludePUA NetTool
ExcludePUA PWTool
HeuristicAlerts yes
Bytecode yes
DetectPUA: "yes"
ExcludePUA:
- NetTool
- PWTool
HeuristicAlerts: "yes"
Bytecode: "yes"

###############
# Scan
###############

ScanPE yes
DisableCertCheck yes
ScanELF yes
AlertBrokenExecutables yes
ScanOLE2 yes
ScanPDF yes
ScanSWF yes
ScanMail yes
PhishingSignatures yes
PhishingScanURLs yes
ScanHTML yes
ScanArchive yes

###############
# Scan
###############

MaxScanSize 150M
MaxFileSize 30M
MaxRecursion 10
MaxFiles 15000
MaxEmbeddedPE 10M
MaxHTMLNormalize 10M
MaxHTMLNoTags 2M
MaxScriptNormalize 5M
MaxZipTypeRcg 1M
MaxPartitions 128
MaxIconsPE 200
PCREMatchLimit 10000
PCRERecMatchLimit 10000
ScanPE: "yes"
DisableCertCheck: "yes"
ScanELF: "yes"
AlertBrokenExecutables: "yes"
ScanOLE2: "yes"
ScanPDF: "yes"
ScanSWF: "yes"
ScanMail: "yes"
PhishingSignatures: "yes"
PhishingScanURLs: "yes"
ScanHTML: "yes"
ScanArchive: "yes"

MaxScanSize: 150M
MaxFileSize: 30M
MaxRecursion: 10
MaxFiles: 15000
MaxEmbeddedPE: 10M
MaxHTMLNormalize: 10M
MaxHTMLNoTags: 2M
MaxScriptNormalize: 5M
MaxZipTypeRcg: 1M
MaxPartitions: 128
MaxIconsPE: 200
PCREMatchLimit: 10000
PCRERecMatchLimit: 10000

## Ref: https://linux.die.net/man/5/freshclam.conf
## Note: will completely override default clamd.conf file at https://github.com/Mailu/Mailu/tree/master/optional/clamav/conf
freshclamConfig: |
freshclamConfigDict:
###############
# General
###############

DatabaseDirectory /data
LogTime yes
DatabaseDirectory: /data
LogTime: "yes"
# CUSTOM: Use pid file in tmp
PidFile /tmp/freshclam.pid
PidFile: /tmp/freshclam.pid
# CUSTOM: Set defined user
DatabaseOwner 2000
DatabaseOwner: "2000"

###############
# Updates
###############

DatabaseMirror database.clamav.net
ScriptedUpdates yes
NotifyClamd /etc/clamav/clamd.conf
Bytecode yes
DatabaseMirror: database.clamav.net
ScriptedUpdates: "yes"
NotifyClamd: /etc/clamav/clamd.conf
Bytecode: "yes"

# Use freshclamConfig to define the content of /etc/clamav/freshclam.conf. Example:
# freshclamConfig: |
Expand Down