Skip to content

Commit

Permalink
Manual backport of #2905 into release/1.2.x (#2923)
Browse files Browse the repository at this point in the history
* Create 2905.txt

* Update server-config-configmap.yaml

* Update server-config-configmap.bats

* Update server-config-configmap.bats
  • Loading branch information
Ganeshrockz authored Sep 11, 2023
1 parent 025bfc3 commit 1372b85
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
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 @@ -201,16 +201,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 @@ -1189,6 +1189,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 @@ -1201,6 +1203,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 @@ -1214,6 +1222,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 @@ -1232,19 +1242,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 @@ -1256,6 +1270,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 @@ -1268,11 +1285,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 @@ -1294,4 +1317,4 @@ load _helpers
yq -r '.data["server.json"]' | jq -r .log_level | tee /dev/stderr)

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

0 comments on commit 1372b85

Please sign in to comment.