Skip to content

Commit e1b4c21

Browse files
authored
Fix permissions on default state sub-directories when Agent runs as container (#2330)
* Set temp dir permissions to 0770 * Set logs dir permissions to 0775 * Adding CHANGELOG entry * Fix kind of change in changelog entry
1 parent 18bc2ad commit e1b4c21

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed
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: Fixes the permissions of the `state/data/tmp` and `state/data/logs` folders when they're setup as part of running `elastic-agent container`.
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; a word indicating the component this changeset affects.
22+
component: 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/2330
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/elastic/elastic-agent/issues/2315

internal/pkg/agent/application/paths/common.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
// AgentLockFileName is the name of the overall Elastic Agent file lock.
2323
AgentLockFileName = "agent.lock"
2424
tempSubdir = "tmp"
25+
tempSubdirPerms = 0770
2526

2627
darwin = "darwin"
2728
)
@@ -85,7 +86,7 @@ func TempDir() string {
8586
tmpDir := filepath.Join(Data(), tempSubdir)
8687
tmpCreator.Do(func() {
8788
// create tempdir as it probably don't exists
88-
_ = os.MkdirAll(tmpDir, 0750)
89+
_ = os.MkdirAll(tmpDir, tempSubdirPerms)
8990
})
9091
return tmpDir
9192
}

internal/pkg/agent/cmd/container.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const (
4343
defaultRequestRetrySleep = "1s" // sleep 1 sec between retries for HTTP requests
4444
defaultMaxRequestRetries = "30" // maximum number of retries for HTTP requests
4545
defaultStateDirectory = "/usr/share/elastic-agent/state" // directory that will hold the state data
46+
47+
logsPathPerms = 0775
4648
)
4749

4850
var (
@@ -150,7 +152,7 @@ func logContainerCmd(streams *cli.IOStreams) error {
150152
logsPath := envWithDefault("", "LOGS_PATH")
151153
if logsPath != "" {
152154
// log this entire command to a file as well as to the passed streams
153-
if err := os.MkdirAll(logsPath, 0755); err != nil {
155+
if err := os.MkdirAll(logsPath, logsPathPerms); err != nil {
154156
return fmt.Errorf("preparing LOGS_PATH(%s) failed: %w", logsPath, err)
155157
}
156158
logPath := filepath.Join(logsPath, "elastic-agent-startup.log")
@@ -795,14 +797,14 @@ func setPaths(statePath, configPath, logsPath string, writePaths bool) error {
795797
if logsPath != "" {
796798
paths.SetLogs(logsPath)
797799
// ensure that the logs directory exists
798-
if err := os.MkdirAll(filepath.Join(logsPath), 0755); err != nil {
800+
if err := os.MkdirAll(filepath.Join(logsPath), logsPathPerms); err != nil {
799801
return fmt.Errorf("preparing LOGS_PATH(%s) failed: %w", logsPath, err)
800802
}
801803
}
802804

803805
// ensure that the internal logger directory exists
804806
loggerPath := filepath.Join(paths.Home(), logger.DefaultLogDirectory)
805-
if err := os.MkdirAll(loggerPath, 0755); err != nil {
807+
if err := os.MkdirAll(loggerPath, logsPathPerms); err != nil {
806808
return fmt.Errorf("preparing internal log path(%s) failed: %w", loggerPath, err)
807809
}
808810

0 commit comments

Comments
 (0)