Skip to content

Commit 0dc6851

Browse files
authored
Merge branch 'main' into fix/sync-replace
2 parents 01eb4a9 + a2dced9 commit 0dc6851

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

.mergify.yml

+13
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ pull_request_rules:
374374
labels:
375375
- "backport"
376376
title: "[{{ destination_branch }}](backport #{{ number }}) {{ title }}"
377+
- name: backport patches to 9.0 branch
378+
conditions:
379+
- merged
380+
- label=backport-9.0
381+
actions:
382+
backport:
383+
assignees:
384+
- "{{ author }}"
385+
branches:
386+
- "9.0"
387+
labels:
388+
- "backport"
389+
title: "[{{ destination_branch }}](backport #{{ number }}) {{ title }}"
377390

378391
- name: backport patches to all active minor branches for the 8 major.
379392
conditions:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Fix secret_paths redaction along complex paths
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: elastic-agent
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
pr: https://github.com/elastic/elastic-agent/pull/6710
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

internal/pkg/diagnostics/diagnostics.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ func redactKey(k string) bool {
398398
strings.Contains(k, "passphrase") ||
399399
strings.Contains(k, "password") ||
400400
strings.Contains(k, "token") ||
401-
strings.Contains(k, "key")
401+
strings.Contains(k, "key") ||
402+
strings.Contains(k, "secret")
402403
}
403404

404405
func zipLogs(zw *zip.Writer, ts time.Time, topPath string, excludeEvents bool) error {
@@ -593,19 +594,23 @@ func RedactSecretPaths(mapStr map[string]any, errOut io.Writer) map[string]any {
593594
fmt.Fprintln(errOut, "No output redaction: secret_paths attribute is not a list.")
594595
return mapStr
595596
}
596-
cfg := ucfg.MustNewFrom(mapStr)
597+
cfg := ucfg.MustNewFrom(mapStr, ucfg.PathSep("."))
597598
for _, v := range arr {
598599
key, ok := v.(string)
599600
if !ok {
600601
fmt.Fprintf(errOut, "No output redaction for %q: expected type string, is type %T.\n", v, v)
601602
continue
602603
}
603604

604-
if ok, _ := cfg.Has(key, -1, ucfg.PathSep(".")); ok {
605+
if ok, err := cfg.Has(key, -1, ucfg.PathSep(".")); err != nil {
606+
fmt.Fprintf(errOut, "Error redacting secret path %q: %v.\n", key, err)
607+
} else if ok {
605608
err := cfg.SetString(key, -1, REDACTED, ucfg.PathSep("."))
606609
if err != nil {
607610
fmt.Fprintf(errOut, "No output redaction for %q: %v.\n", key, err)
608611
}
612+
} else {
613+
fmt.Fprintf(errOut, "Unable to find secret path %q for redaction.\n", key)
609614
}
610615
}
611616
result, err := config.MustNewConfigFrom(cfg).ToMapStr()

internal/pkg/diagnostics/diagnostics_test.go

+40-1
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,55 @@ secret_paths:
248248
- inputs.0.redactKey
249249
- inputs.1.missingKey
250250
- outputs.default.redactOtherKey
251+
`,
252+
}, {
253+
name: "path in nested list",
254+
input: []byte(`id: test-policy
255+
inputs:
256+
- type: httpjson
257+
data_stream:
258+
namespace: default
259+
streams:
260+
- config_version: "2"
261+
request.transforms:
262+
- set:
263+
target: header.Authorization
264+
value: SSWS this-should-be-redacted
265+
- set:
266+
target: url.params.limit
267+
value: "1000"
268+
secret_paths:
269+
- inputs.0.streams.0.request.transforms.0.set.value
270+
`),
271+
expect: `id: test-policy
272+
inputs:
273+
- data_stream:
274+
namespace: default
275+
streams:
276+
- config_version: "2"
277+
request:
278+
transforms:
279+
- set:
280+
target: header.Authorization
281+
value: <REDACTED>
282+
- set:
283+
target: url.params.limit
284+
value: "1000"
285+
type: httpjson
286+
secret_paths:
287+
- inputs.0.streams.0.request.transforms.0.set.value
251288
`,
252289
}}
253290

254291
for _, tc := range tests {
255292
t.Run(tc.name, func(t *testing.T) {
256293
file := client.DiagnosticFileResult{Content: tc.input, ContentType: "application/yaml"}
257294
var out bytes.Buffer
258-
err := writeRedacted(io.Discard, &out, "testPath", file)
295+
var errOut bytes.Buffer
296+
err := writeRedacted(&errOut, &out, "testPath", file)
259297
require.NoError(t, err)
260298

299+
t.Logf("Error output: %s", errOut.String())
261300
assert.Equal(t, tc.expect, out.String())
262301
})
263302
}

0 commit comments

Comments
 (0)