Skip to content

Commit cff7672

Browse files
tsgTudor Golubenco
authored and
Tudor Golubenco
committed
Fix modules yml files permission on Deb (elastic#3879)
The fix in elastic#3645 had a bug (chmod executed on the wrong folder). This fixes the fix and also adds permissions checks to the tests. (cherry picked from commit 37ae2fc)
1 parent 76f5873 commit cff7672

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

dev-tools/package_test.go

+45-5
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import (
2121
)
2222

2323
const (
24-
expectedConfigMode = os.FileMode(0600)
25-
expectedConfigUID = 0
26-
expectedConfigGID = 0
24+
expectedConfigMode = os.FileMode(0600)
25+
expectedManifestMode = os.FileMode(0644)
26+
expectedConfigUID = 0
27+
expectedConfigGID = 0
2728
)
2829

2930
var (
30-
configFilePattern = regexp.MustCompile(`.*beat\.yml`)
31+
configFilePattern = regexp.MustCompile(`.*beat\.yml`)
32+
manifestFilePattern = regexp.MustCompile(`manifest.yml`)
3133
)
3234

3335
var (
@@ -73,6 +75,9 @@ func checkRPM(t *testing.T, file string) {
7375
}
7476

7577
checkConfigPermissions(t, p)
78+
checkConfigOwner(t, p)
79+
checkManifestPermissions(t, p)
80+
checkManifestOwner(t, p)
7681
}
7782

7883
func checkDeb(t *testing.T, file string, buf *bytes.Buffer) {
@@ -84,6 +89,8 @@ func checkDeb(t *testing.T, file string, buf *bytes.Buffer) {
8489

8590
checkConfigPermissions(t, p)
8691
checkConfigOwner(t, p)
92+
checkManifestPermissions(t, p)
93+
checkManifestOwner(t, p)
8794
}
8895

8996
func checkTar(t *testing.T, file string) {
@@ -95,6 +102,7 @@ func checkTar(t *testing.T, file string) {
95102

96103
checkConfigPermissions(t, p)
97104
checkConfigOwner(t, p)
105+
checkManifestPermissions(t, p)
98106
}
99107

100108
func checkZip(t *testing.T, file string) {
@@ -105,6 +113,7 @@ func checkZip(t *testing.T, file string) {
105113
}
106114

107115
checkConfigPermissions(t, p)
116+
checkManifestPermissions(t, p)
108117
}
109118

110119
// Verify that the main configuration file is installed with a 0600 file mode.
@@ -115,7 +124,7 @@ func checkConfigPermissions(t *testing.T, p *packageFile) {
115124
mode := entry.Mode.Perm()
116125
if expectedConfigMode != mode {
117126
t.Errorf("file %v has wrong permissions: expected=%v actual=%v",
118-
entry.Mode, expectedConfigMode, mode)
127+
entry.File, expectedConfigMode, mode)
119128
}
120129
return
121130
}
@@ -141,6 +150,37 @@ func checkConfigOwner(t *testing.T, p *packageFile) {
141150
})
142151
}
143152

153+
// Verify that the modules manifest.yml files are installed with a 0644 file mode.
154+
func checkManifestPermissions(t *testing.T, p *packageFile) {
155+
t.Run(p.Name+" manifest file permissions", func(t *testing.T) {
156+
for _, entry := range p.Contents {
157+
if manifestFilePattern.MatchString(entry.File) {
158+
mode := entry.Mode.Perm()
159+
if expectedManifestMode != mode {
160+
t.Errorf("file %v has wrong permissions: expected=%v actual=%v",
161+
entry.File, expectedManifestMode, mode)
162+
}
163+
}
164+
}
165+
})
166+
}
167+
168+
// Verify that the manifest owner is root
169+
func checkManifestOwner(t *testing.T, p *packageFile) {
170+
t.Run(p.Name+" manifest file owner", func(t *testing.T) {
171+
for _, entry := range p.Contents {
172+
if manifestFilePattern.MatchString(entry.File) {
173+
if expectedConfigUID != entry.UID {
174+
t.Errorf("file %v should be owned by user %v, owner=%v", entry.File, expectedConfigGID, entry.UID)
175+
}
176+
if expectedConfigGID != entry.GID {
177+
t.Errorf("file %v should be owned by group %v, group=%v", entry.File, expectedConfigGID, entry.GID)
178+
}
179+
}
180+
}
181+
})
182+
}
183+
144184
// Helpers
145185

146186
type packageFile struct {

libbeat/scripts/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ install-home:
342342
if [ -d _meta/module.generated ]; then \
343343
install -d -m 755 ${HOME_PREFIX}/module; \
344344
rsync -av _meta/module.generated/ ${HOME_PREFIX}/module/; \
345-
chmod -R go-w _meta/module.generated; \
345+
chmod -R go-w ${HOME_PREFIX}/module/; \
346346
fi
347347

348348
# Prepares for packaging. Builds binaries and creates homedir data

0 commit comments

Comments
 (0)