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

Fix audit log parse error #2905

Merged
merged 4 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions .changelog/2905.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
audit-log: fix parsing error for some audit log configuration fields fail with uncovertible string to integer errors.
```
4 changes: 4 additions & 0 deletions charts/consul/templates/server-config-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ data:
{{- if ne $k "name" }}
{{- if ne $firstKeyValuePair false }},{{end}}
{{- $firstKeyValuePair = true }}
{{- if or (eq $k "rotate_max_files") (eq $k "rotate_bytes") }}
"{{ $k }}": {{ $v }}
{{- else }}
"{{ $k }}": "{{ $v }}"
{{- end }}
{{- end }}
{{- end }}
}
{{- end }}
Expand Down
25 changes: 24 additions & 1 deletion charts/consul/test/unit/server-config-configmap.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,8 @@ load _helpers
--set 'server.auditLogs.sinks[0].format=json' \
--set 'server.auditLogs.sinks[0].delivery_guarantee=best-effort' \
--set 'server.auditLogs.sinks[0].rotate_duration=24h' \
--set 'server.auditLogs.sinks[0].rotate_max_files=20' \
--set 'server.auditLogs.sinks[0].rotate_bytes=12455355' \
--set 'server.auditLogs.sinks[0].path=/tmp/audit.json' \
. | tee /dev/stderr |
yq -r '.data["audit-logging.json"]' | tee /dev/stderr)
Expand All @@ -1124,6 +1126,12 @@ load _helpers

local actual=$(echo $object | jq -r .audit.sink.MySink.rotate_duration | tee /dev/stderr)
[ "${actual}" = "24h" ]

local actual=$(echo $object | jq -r .audit.sink.MySink.rotate_max_files | tee /dev/stderr)
[ ${actual} = 20 ]

local actual=$(echo $object | jq -r .audit.sink.MySink.rotate_bytes | tee /dev/stderr)
[ ${actual} = 12455355 ]
}

@test "server/ConfigMap: server.auditLogs is enabled with 1 sink input object and it does not contain the name attribute" {
Expand All @@ -1137,6 +1145,8 @@ load _helpers
--set 'server.auditLogs.sinks[0].format=json' \
--set 'server.auditLogs.sinks[0].delivery_guarantee=best-effort' \
--set 'server.auditLogs.sinks[0].rotate_duration=24h' \
--set 'server.auditLogs.sinks[0].rotate_max_files=20' \
--set 'server.auditLogs.sinks[0].rotate_bytes=12455355' \
--set 'server.auditLogs.sinks[0].path=/tmp/audit.json' \
. | tee /dev/stderr |
yq -r '.data["audit-logging.json"]' | jq -r .audit.sink.name | tee /dev/stderr)
Expand All @@ -1155,20 +1165,24 @@ load _helpers
--set 'server.auditLogs.sinks[0].format=json' \
--set 'server.auditLogs.sinks[0].delivery_guarantee=best-effort' \
--set 'server.auditLogs.sinks[0].rotate_duration=24h' \
--set 'server.auditLogs.sinks[0].rotate_max_files=15' \
--set 'server.auditLogs.sinks[0].rotate_bytes=12445' \
--set 'server.auditLogs.sinks[0].path=/tmp/audit.json' \
--set 'server.auditLogs.sinks[1].name=MySink2' \
--set 'server.auditLogs.sinks[1].type=file' \
--set 'server.auditLogs.sinks[1].format=json' \
--set 'server.auditLogs.sinks[1].delivery_guarantee=best-effort' \
--set 'server.auditLogs.sinks[1].rotate_max_files=15' \
--set 'server.auditLogs.sinks[1].rotate_duration=24h' \
--set 'server.auditLogs.sinks[1].rotate_max_files=25' \
--set 'server.auditLogs.sinks[1].rotate_bytes=152445' \
--set 'server.auditLogs.sinks[1].path=/tmp/audit-2.json' \
--set 'server.auditLogs.sinks[2].name=MySink3' \
--set 'server.auditLogs.sinks[2].type=file' \
--set 'server.auditLogs.sinks[2].format=json' \
--set 'server.auditLogs.sinks[2].delivery_guarantee=best-effort' \
--set 'server.auditLogs.sinks[2].rotate_max_files=20' \
--set 'server.auditLogs.sinks[2].rotate_duration=18h' \
--set 'server.auditLogs.sinks[2].rotate_bytes=12445' \
--set 'server.auditLogs.sinks[2].path=/tmp/audit-3.json' \
. | tee /dev/stderr |
yq -r '.data["audit-logging.json"]' | tee /dev/stderr)
Expand All @@ -1185,17 +1199,26 @@ load _helpers
local actual=$(echo $object | jq -r .audit.sink.MySink1.name | tee /dev/stderr)
[ "${actual}" = "null" ]

local actual=$(echo $object | jq -r .audit.sink.MySink1.rotate_max_files | tee /dev/stderr)
[ ${actual} = 15 ]

local actual=$(echo $object | jq -r .audit.sink.MySink3.delivery_guarantee | tee /dev/stderr)
[ "${actual}" = "best-effort" ]

local actual=$(echo $object | jq -r .audit.sink.MySink2.rotate_duration | tee /dev/stderr)
[ "${actual}" = "24h" ]

local actual=$(echo $object | jq -r .audit.sink.MySink2.rotate_bytes | tee /dev/stderr)
[ ${actual} = 152445 ]

local actual=$(echo $object | jq -r .audit.sink.MySink1.format | tee /dev/stderr)
[ "${actual}" = "json" ]

local actual=$(echo $object | jq -r .audit.sink.MySink3.type | tee /dev/stderr)
[ "${actual}" = "file" ]

local actual=$(echo $object | jq -r .audit.sink.MySink3.rotate_max_files | tee /dev/stderr)
[ ${actual} = 20 ]
}

@test "server/ConfigMap: server.logLevel is empty" {
Expand Down
Loading