Skip to content

Commit e0cd96c

Browse files
committed
[ACTP] align monolithic runner with corrupt identity recovery
getRunnerConfig hard-failed on any GetIdentityFromPreviousEnrollment error, so the monolithic runner stayed wedged on a corrupt identity file while split mode recovered from it. Treat ErrIdentityCorrupt as an absent identity there too, and keep aborting on I/O failures.
1 parent 5346df5 commit e0cd96c

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

comp/privateactionrunner/impl/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ dd_agent_go_test(
4848
srcs = ["privateactionrunner_test.go"],
4949
embed = [":impl"],
5050
deps = [
51+
"//comp/core/config",
52+
"//comp/core/hostname/hostnameinterface/mock",
53+
"//comp/core/log/mock",
54+
"//pkg/privateactionrunner/util",
5155
"@com_github_datadog_datadog_go_v5//statsd",
5256
"@com_github_stretchr_testify//assert",
5357
"@com_github_stretchr_testify//require",

comp/privateactionrunner/impl/privateactionrunner.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,12 @@ func (p *PrivateActionRunner) getRunnerConfig(ctx context.Context) (*parconfig.C
208208

209209
persistedIdentity, err := enrollment.GetIdentityFromPreviousEnrollment(ctx, p.coreConfig)
210210
if err != nil {
211-
return nil, fmt.Errorf("failed to get identity: %w", err)
211+
// Corrupt content never fixes itself, so fall back instead of wedging startup.
212+
if !errors.Is(err, enrollment.ErrIdentityCorrupt) {
213+
return nil, fmt.Errorf("failed to get identity: %w", err)
214+
}
215+
p.logger.Warnf("Discarding unusable persisted identity: %v", err)
216+
persistedIdentity = nil
212217
}
213218
if enrollment.ShouldReenroll(agentIdentifier, persistedIdentity) {
214219
persistedIdentity = nil

comp/privateactionrunner/impl/privateactionrunner_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ package privateactionrunnerimpl
77

88
import (
99
"context"
10+
"encoding/base64"
1011
"errors"
12+
"os"
13+
"path/filepath"
1114
"testing"
1215
"time"
1316

1417
"github.com/DataDog/datadog-go/v5/statsd"
1518
"github.com/stretchr/testify/assert"
1619
"github.com/stretchr/testify/require"
20+
21+
coreconfig "github.com/DataDog/datadog-agent/comp/core/config"
22+
hostnamemock "github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface/mock"
23+
logmock "github.com/DataDog/datadog-agent/comp/core/log/mock"
24+
parutil "github.com/DataDog/datadog-agent/pkg/privateactionrunner/util"
1725
)
1826

1927
func TestExecutorIdleTimeout(t *testing.T) {
@@ -32,6 +40,36 @@ func TestExecutorIdleTimeout(t *testing.T) {
3240
}
3341
}
3442

43+
func TestGetRunnerConfigDiscardsCorruptIdentity(t *testing.T) {
44+
// Must match ensure-enrollment: recover instead of wedging startup.
45+
identityPath := filepath.Join(t.TempDir(), "identity.json")
46+
require.NoError(t, os.WriteFile(identityPath, []byte("not-json"), 0o600))
47+
48+
privateJWK, _, err := parutil.GenerateKeys()
49+
require.NoError(t, err)
50+
encodedKey, err := privateJWK.MarshalJSON()
51+
require.NoError(t, err)
52+
urn := parutil.MakeRunnerURN("us1", 123, "test-runner")
53+
54+
hostnameGetter, _ := hostnamemock.NewMock("test-host")
55+
runner := &PrivateActionRunner{
56+
coreConfig: coreconfig.NewMockWithOverrides(t, map[string]interface{}{
57+
"private_action_runner.enabled": true,
58+
"private_action_runner.identity_file_path": identityPath,
59+
"private_action_runner.self_enroll": false,
60+
"private_action_runner.urn": urn,
61+
"private_action_runner.private_key": base64.RawURLEncoding.EncodeToString(encodedKey),
62+
}),
63+
hostnameGetter: hostnameGetter,
64+
logger: logmock.New(t),
65+
}
66+
67+
cfg, err := runner.getRunnerConfig(context.Background())
68+
69+
require.NoError(t, err)
70+
assert.Equal(t, urn, cfg.Urn)
71+
}
72+
3573
func TestStopCleansUpMetricsClient(t *testing.T) {
3674
tests := []struct {
3775
name string

0 commit comments

Comments
 (0)