Skip to content

Commit 1890ea0

Browse files
Merge remote-tracking branch 'upstream/8.18' into mergify/bp/8.18/pr-9662
2 parents 522a322 + 75457aa commit 1890ea0

File tree

8 files changed

+627
-370
lines changed

8 files changed

+627
-370
lines changed

.package-version

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"version": "8.18.6-SNAPSHOT",
3-
"build_id": "8.18.6-a4a77cad",
4-
"manifest_url": "https://snapshots.elastic.co/8.18.6-a4a77cad/manifest-8.18.6-SNAPSHOT.json",
5-
"summary_url": "https://snapshots.elastic.co/8.18.6-a4a77cad/summary-8.18.6-SNAPSHOT.html",
6-
"core_version": "8.18.6",
7-
"stack_build_id": "8.18.6-a4a77cad-SNAPSHOT"
2+
"version": "8.18.7-SNAPSHOT",
3+
"build_id": "8.18.7-4f6bc48f",
4+
"manifest_url": "https://snapshots.elastic.co/8.18.7-4f6bc48f/manifest-8.18.7-SNAPSHOT.json",
5+
"summary_url": "https://snapshots.elastic.co/8.18.7-4f6bc48f/summary-8.18.7-SNAPSHOT.html",
6+
"core_version": "8.18.7",
7+
"stack_build_id": "8.18.7-4f6bc48f-SNAPSHOT"
88
}
Lines changed: 32 additions & 0 deletions
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: security
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: redact secrets from pre-config, computed-config, components-expected, and components-actual files in diagnostics archive
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/9560
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/agent/application/coordinator/coordinator.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ type Coordinator struct {
322322
// run a ticker that checks to see if we have a new PID.
323323
componentPIDTicker *time.Ticker
324324
componentPidRequiresUpdate *atomic.Bool
325+
326+
// Abstraction for diagnostics AddSecretMarkers function for testability
327+
secretMarkerFunc func(*logger.Logger, *config.Config) error
325328
}
326329

327330
// The channels Coordinator reads to receive updates from the various managers.
@@ -442,7 +445,8 @@ func New(
442445
componentPIDTicker: time.NewTicker(time.Second * 30),
443446
componentPidRequiresUpdate: &atomic.Bool{},
444447

445-
fleetAcker: fleetAcker,
448+
fleetAcker: fleetAcker,
449+
secretMarkerFunc: diagnostics.AddSecretMarkers,
446450
}
447451
// Setup communication channels for any non-nil components. This pattern
448452
// lets us transparently accept nil managers / simulated events during
@@ -1296,6 +1300,10 @@ func (c *Coordinator) generateAST(cfg *config.Config) (err error) {
12961300
return err
12971301
}
12981302

1303+
if err = c.secretMarkerFunc(c.logger, cfg); err != nil {
1304+
c.logger.Errorf("failed to add secret markers: %v", err)
1305+
}
1306+
12991307
// perform and verify ast translation
13001308
m, err := cfg.ToMapStr()
13011309
if err != nil {

internal/pkg/agent/application/coordinator/coordinator_unit_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ import (
3737
"github.com/elastic/elastic-agent/pkg/component"
3838
"github.com/elastic/elastic-agent/pkg/component/runtime"
3939
agentclient "github.com/elastic/elastic-agent/pkg/control/v2/client"
40+
"github.com/elastic/elastic-agent/pkg/core/logger"
4041
"github.com/elastic/elastic-agent/pkg/core/logger/loggertest"
4142
"github.com/elastic/elastic-agent/pkg/utils/broadcaster"
4243
)
4344

45+
var testSecretMarkerFunc = func(*logger.Logger, *config.Config) error {
46+
// no-op secret marker function for testing
47+
return nil
48+
}
49+
4450
func TestVarsManagerError(t *testing.T) {
4551
// Set a one-second timeout -- nothing here should block, but if it
4652
// does let's report a failure instead of timing out the test runner.
@@ -470,6 +476,7 @@ func TestCoordinatorReportsInvalidPolicy(t *testing.T) {
470476
vars: emptyVars(t),
471477
ast: emptyAST(t),
472478
componentPIDTicker: time.NewTicker(time.Second * 30),
479+
secretMarkerFunc: testSecretMarkerFunc,
473480
}
474481

475482
// Send an invalid config update and confirm that Coordinator reports
@@ -585,6 +592,7 @@ func TestCoordinatorReportsComponentModelError(t *testing.T) {
585592
vars: emptyVars(t),
586593
ast: emptyAST(t),
587594
componentPIDTicker: time.NewTicker(time.Second * 30),
595+
secretMarkerFunc: testSecretMarkerFunc,
588596
}
589597

590598
// This configuration produces a valid AST but its EQL condition is
@@ -653,7 +661,7 @@ func TestCoordinatorPolicyChangeUpdatesMonitorReloader(t *testing.T) {
653661
// does let's report a failure instead of timing out the test runner.
654662
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
655663
defer cancel()
656-
logger := logp.NewLogger("testing")
664+
log := logp.NewLogger("testing")
657665

658666
configChan := make(chan ConfigChange, 1)
659667

@@ -668,10 +676,16 @@ func TestCoordinatorPolicyChangeUpdatesMonitorReloader(t *testing.T) {
668676
newServerFn := func(*monitoringCfg.MonitoringConfig) (reload.ServerController, error) {
669677
return monitoringServer, nil
670678
}
671-
monitoringReloader := reload.NewServerReloader(newServerFn, logger, monitoringCfg.DefaultConfig())
679+
monitoringReloader := reload.NewServerReloader(newServerFn, log, monitoringCfg.DefaultConfig())
680+
681+
secretMarkerCalled := false
682+
mockSecretMarkerFunc := func(*logger.Logger, *config.Config) error {
683+
secretMarkerCalled = true
684+
return nil
685+
}
672686

673687
coord := &Coordinator{
674-
logger: logger,
688+
logger: log,
675689
agentInfo: &info.AgentInfo{},
676690
stateBroadcaster: broadcaster.New(State{}, 0, 0),
677691
managerChans: managerChans{
@@ -680,6 +694,7 @@ func TestCoordinatorPolicyChangeUpdatesMonitorReloader(t *testing.T) {
680694
runtimeMgr: runtimeManager,
681695
vars: emptyVars(t),
682696
componentPIDTicker: time.NewTicker(time.Second * 30),
697+
secretMarkerFunc: mockSecretMarkerFunc,
683698
}
684699
coord.RegisterMonitoringServer(monitoringReloader)
685700

@@ -700,6 +715,8 @@ inputs:
700715
coord.runLoopIteration(ctx)
701716
assert.True(t, cfgChange.acked, "Coordinator should ACK a successful policy change")
702717

718+
assert.True(t, secretMarkerCalled, "secret marker should be called")
719+
703720
// server is started by default
704721
assert.True(t, monitoringServer.startTriggered)
705722
assert.True(t, monitoringServer.isRunning)
@@ -819,6 +836,7 @@ func TestCoordinatorPolicyChangeUpdatesRuntimeAndOTelManager(t *testing.T) {
819836
otelMgr: otelManager,
820837
vars: emptyVars(t),
821838
componentPIDTicker: time.NewTicker(time.Second * 30),
839+
secretMarkerFunc: testSecretMarkerFunc,
822840
}
823841

824842
// Create a policy with one input and one output (no otel configuration)
@@ -950,6 +968,7 @@ func TestCoordinatorReportsRuntimeManagerUpdateFailure(t *testing.T) {
950968
runtimeMgr: runtimeManager,
951969
vars: emptyVars(t),
952970
componentPIDTicker: time.NewTicker(time.Second * 30),
971+
secretMarkerFunc: testSecretMarkerFunc,
953972
}
954973

955974
// Send an empty policy which should forward an empty component model to
@@ -1011,6 +1030,7 @@ func TestCoordinatorReportsOTelManagerUpdateFailure(t *testing.T) {
10111030
otelMgr: otelManager,
10121031
vars: emptyVars(t),
10131032
componentPIDTicker: time.NewTicker(time.Second * 30),
1033+
secretMarkerFunc: testSecretMarkerFunc,
10141034
}
10151035

10161036
// Send an empty policy which should forward an empty component model to
@@ -1074,6 +1094,7 @@ func TestCoordinatorAppliesVarsToPolicy(t *testing.T) {
10741094
runtimeMgr: runtimeManager,
10751095
vars: emptyVars(t),
10761096
componentPIDTicker: time.NewTicker(time.Second * 30),
1097+
secretMarkerFunc: testSecretMarkerFunc,
10771098
}
10781099

10791100
// Create a policy with one input and one output

internal/pkg/agent/cmd/inspect.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ func inspectConfig(ctx context.Context, cfgPath string, opts inspectConfigOpts,
145145
if err != nil {
146146
return fmt.Errorf("error loading agent config: %w", err)
147147
}
148+
// Ensure secret markers are injected based on secret_paths before redaction.
149+
if err := diagnostics.AddSecretMarkers(l, fullCfg); err != nil {
150+
fmt.Fprintf(streams.Err, "failed to add secret markers: %v\n", err)
151+
}
152+
148153
err = printConfig(fullCfg, streams)
149154
if err != nil {
150155
return fmt.Errorf("error printing config: %w", err)
@@ -228,6 +233,16 @@ func inspectConfig(ctx context.Context, cfgPath string, opts inspectConfigOpts,
228233

229234
}
230235

236+
// Ensure secret markers are injected based on secret_paths before redaction.
237+
rawCfg := config.MustNewConfigFrom(cfg)
238+
if err := diagnostics.AddSecretMarkers(l, rawCfg); err != nil {
239+
fmt.Fprintf(streams.Err, "failed to add secret markers: %v\n", err)
240+
}
241+
cfg, err = rawCfg.ToMapStr()
242+
if err != nil {
243+
return fmt.Errorf("failed to convert config with secret markers: %w", err)
244+
}
245+
231246
return printMapStringConfig(cfg, streams)
232247
}
233248

0 commit comments

Comments
 (0)