Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(installer): Make policy metadata files root-owned & world-readable #32356

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions pkg/fleet/internal/cdn/cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,17 @@ func (c *CDN) Close() error {
}

// writePolicyMetadata writes the policy metadata to the given directory
// and makes it readable to dd-agent
// and makes it world-readable
func writePolicyMetadata(config Config, dir string) error {
ddAgentUID, ddAgentGID, err := getAgentIDs()
if err != nil {
return fmt.Errorf("error getting dd-agent user and group IDs: %w", err)
}

state := config.State()
stateBytes, err := json.Marshal(state)
if err != nil {
return fmt.Errorf("could not marshal state: %w", err)
}
err = os.WriteFile(filepath.Join(dir, policyMetadataFilename), stateBytes, 0440)
err = os.WriteFile(filepath.Join(dir, policyMetadataFilename), stateBytes, 0444)
if err != nil {
return fmt.Errorf("could not write %s: %w", policyMetadataFilename, err)
}
if runtime.GOOS != "windows" {
err = os.Chown(filepath.Join(dir, policyMetadataFilename), ddAgentUID, ddAgentGID)
if err != nil {
return fmt.Errorf("could not chown %s: %w", policyMetadataFilename, err)
}
}
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions test/new-e2e/tests/installer/unix/upgrade_scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ func (s *upgradeScenarioSuite) TestConfigUpgradeSuccessful() {
state.AssertDirExists("/etc/datadog-agent/managed/datadog-agent", 0755, "root", "root")
state.AssertSymlinkExists("/etc/datadog-agent/managed/datadog-agent/stable", "/etc/datadog-agent/managed/datadog-agent/e94406c45ae766b7d34d2793e4759b9c4d15ed5d5e2b7f73ce1bf0e6836f728d", "root", "root")
// Verify metadata
state.AssertFileExists("/etc/datadog-agent/managed/datadog-agent/e94406c45ae766b7d34d2793e4759b9c4d15ed5d5e2b7f73ce1bf0e6836f728d/policy.metadata", 0440, "dd-agent", "dd-agent")
file := s.Env().RemoteHost.MustExecute("sudo cat /etc/datadog-agent/managed/datadog-agent/e94406c45ae766b7d34d2793e4759b9c4d15ed5d5e2b7f73ce1bf0e6836f728d/policy.metadata")
state.AssertFileExists("/etc/datadog-agent/managed/datadog-agent/e94406c45ae766b7d34d2793e4759b9c4d15ed5d5e2b7f73ce1bf0e6836f728d/policy.metadata", 0444, "root", "root")
file := s.Env().RemoteHost.MustExecute("cat /etc/datadog-agent/managed/datadog-agent/e94406c45ae766b7d34d2793e4759b9c4d15ed5d5e2b7f73ce1bf0e6836f728d/policy.metadata")
policiesState := &pbgo.PoliciesState{}
err := json.Unmarshal([]byte(file), policiesState)
require.NoError(s.T(), err)
Expand Down
Loading