Skip to content

Commit b59e45c

Browse files
Add a feature toggle
1 parent 557ffd0 commit b59e45c

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

changelog/fragments/1757633911-Add-agent_policy_id-and-policy_revision_idx-to-checkin-requests.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ description: |
2222
policy. These details will replace the need for an ack on
2323
policy_change actions, and will be used to determine when to send a
2424
policy change when there is a new revision available, or when the
25-
agent is reassigned to a different policy.
25+
agent is reassigned to a different policy. Add a server setting under
26+
feature_flags.ignore_checkin_policy_id that disables this behavour and
27+
restores the previous approach.
2628
2729
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
2830
component: fleet-server

fleet-server.reference.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ fleet:
270270
# upstream_url: "https://artifacts.elastic.co/GPG-KEY-elastic-agent"
271271
# # By default dir is the directory containing the fleet-server executable (following symlinks) joined with elastic-agent-upgrade-keys
272272
# dir: ./elastic-agent-upgrade-keys
273+
#
274+
# # Toggles to enable new behaviour or restore old behaviour.
275+
# feature_flags:
276+
# // ignore agent_policy_id and policy_revision_idx attributes that may be present in the checkin request bodies.
277+
# // POLICY_CHANGE actions need an explicit ack if this is set.
278+
# ignore_checkin_policy_id: false
279+
#
273280
# # monitor options are advanced configuration and should not be adjusted is most cases
274281
# monitor:
275282
# fetch_size: 1000 # The number of documents that each monitor may fetch at once

internal/pkg/api/handleCheckin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@ func calcPollDuration(zlog zerolog.Logger, pollDuration, setupDuration, jitterDu
11471147
// The API keys will be managed if the agent reports a new policy id from its last checkin, or if the revision is different than what the last checkin reported.
11481148
// It returns the revision idx that should be used when subscribing for new POLICY_CHANGE actons and optional args to use when doing the non-tick checkin.
11491149
func (ct *CheckinT) processPolicyDetails(ctx context.Context, zlog zerolog.Logger, agent *model.Agent, req *CheckinRequest) (int64, []checkin.Option, error) {
1150-
// no details specified
1151-
if req == nil || req.PolicyRevisionIdx == nil || req.AgentPolicyId == nil {
1150+
// no details specified or attributes are ignored by config
1151+
if ct.cfg.Features.IgnoreCheckinPolicyID || req == nil || req.PolicyRevisionIdx == nil || req.AgentPolicyId == nil {
11521152
return agent.PolicyRevisionIdx, nil, nil
11531153
}
11541154
policyID := *req.AgentPolicyId

internal/pkg/api/handleCheckin_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,4 +1319,28 @@ func TestProcessPolicyDetails(t *testing.T) {
13191319
pm.AssertExpectations(t)
13201320
})
13211321
}
1322+
1323+
t.Run("IgnoreCheckinPolicyID flag is set", func(t *testing.T) {
1324+
logger := testlog.SetLogger(t)
1325+
checkin := &CheckinT{
1326+
cfg: config.Server{
1327+
Features: config.FeatureFlags{
1328+
IgnoreCheckinPolicyID: true,
1329+
},
1330+
},
1331+
}
1332+
revIDX, opts, err := checkin.processPolicyDetails(t.Context(), logger,
1333+
&model.Agent{
1334+
PolicyID: policyID,
1335+
PolicyRevisionIdx: 1,
1336+
},
1337+
&CheckinRequest{
1338+
AgentPolicyId: &policyID,
1339+
PolicyRevisionIdx: &revIDX2,
1340+
},
1341+
)
1342+
assert.NoError(t, err)
1343+
assert.Equal(t, int64(1), revIDX)
1344+
assert.Empty(t, opts)
1345+
})
13221346
}

internal/pkg/config/input.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type (
7777
StaticPolicyTokens StaticPolicyTokens `config:"static_policy_tokens"`
7878
PGP PGP `config:"pgp"`
7979
PDKDF2 PBKDF2 `config:"pdkdf2"`
80+
Features FeatureFlags `config:"feature_flags"`
8081
}
8182

8283
StaticPolicyTokens struct {
@@ -91,6 +92,13 @@ type (
9192
TokenKey string `config:"token_key"`
9293
PolicyID string `config:"policy_id"`
9394
}
95+
96+
// FeatureFlags contains toggles to enable new behaviour, or restore old behaviour.
97+
FeatureFlags struct {
98+
// IgnoreCheckinPolicyID when true will ignore the agent_policy_id and policy_revision_idx attributes in checkin request bodies.
99+
// This setting restores previous behaviour where all POLICY_CHANGE actions need an explicit ack.
100+
IgnoreCheckinPolicyID bool `config:"ignore_checkin_policy_id"`
101+
}
94102
)
95103

96104
// InitDefaults initializes the defaults for the configuration.

0 commit comments

Comments
 (0)