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

Manual backport of #2905 into release/1.2.x #2923

Merged
merged 4 commits into from
Sep 11, 2023
Merged
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
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.
```
11 changes: 1 addition & 10 deletions charts/consul/templates/server-config-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,7 @@ data:
"sink": {
{{- range $index, $element := .Values.server.auditLogs.sinks }}
{{- if ne $index 0 }},{{end}}
"{{ $element.name }}": {
{{- $firstKeyValuePair := false }}
{{- range $k, $v := $element }}
{{- if ne $k "name" }}
{{- if ne $firstKeyValuePair false }},{{end}}
{{- $firstKeyValuePair = true }}
"{{ $k }}": "{{ $v }}"
{{- end }}
{{- end }}
}
"{{ get $element "name" }}": {{ omit $element "name" | toJson }}
{{- end }}
}
}
Expand Down
27 changes: 25 additions & 2 deletions 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,19 +1165,23 @@ 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_bytes=12445' \
--set 'server.auditLogs.sinks[2].rotate_duration=18h' \
--set 'server.auditLogs.sinks[2].path=/tmp/audit-3.json' \
. | tee /dev/stderr |
Expand All @@ -1179,6 +1193,9 @@ load _helpers
local actual=$(echo $object | jq -r .audit.sink.MySink3.path | tee /dev/stderr)
[ "${actual}" = "/tmp/audit-3.json" ]

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.MySink2.path | tee /dev/stderr)
[ "${actual}" = "/tmp/audit-2.json" ]

Expand All @@ -1191,11 +1208,17 @@ load _helpers
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 All @@ -1217,4 +1240,4 @@ load _helpers
yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr)

[ "${configmap}" = "DEBUG" ]
}
}