@@ -21,13 +21,15 @@ import (
21
21
)
22
22
23
23
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
27
28
)
28
29
29
30
var (
30
- configFilePattern = regexp .MustCompile (`.*beat\.yml` )
31
+ configFilePattern = regexp .MustCompile (`.*beat\.yml` )
32
+ manifestFilePattern = regexp .MustCompile (`manifest.yml` )
31
33
)
32
34
33
35
var (
@@ -73,6 +75,9 @@ func checkRPM(t *testing.T, file string) {
73
75
}
74
76
75
77
checkConfigPermissions (t , p )
78
+ checkConfigOwner (t , p )
79
+ checkManifestPermissions (t , p )
80
+ checkManifestOwner (t , p )
76
81
}
77
82
78
83
func checkDeb (t * testing.T , file string , buf * bytes.Buffer ) {
@@ -84,6 +89,8 @@ func checkDeb(t *testing.T, file string, buf *bytes.Buffer) {
84
89
85
90
checkConfigPermissions (t , p )
86
91
checkConfigOwner (t , p )
92
+ checkManifestPermissions (t , p )
93
+ checkManifestOwner (t , p )
87
94
}
88
95
89
96
func checkTar (t * testing.T , file string ) {
@@ -95,6 +102,7 @@ func checkTar(t *testing.T, file string) {
95
102
96
103
checkConfigPermissions (t , p )
97
104
checkConfigOwner (t , p )
105
+ checkManifestPermissions (t , p )
98
106
}
99
107
100
108
func checkZip (t * testing.T , file string ) {
@@ -105,6 +113,7 @@ func checkZip(t *testing.T, file string) {
105
113
}
106
114
107
115
checkConfigPermissions (t , p )
116
+ checkManifestPermissions (t , p )
108
117
}
109
118
110
119
// Verify that the main configuration file is installed with a 0600 file mode.
@@ -115,7 +124,7 @@ func checkConfigPermissions(t *testing.T, p *packageFile) {
115
124
mode := entry .Mode .Perm ()
116
125
if expectedConfigMode != mode {
117
126
t .Errorf ("file %v has wrong permissions: expected=%v actual=%v" ,
118
- entry .Mode , expectedConfigMode , mode )
127
+ entry .File , expectedConfigMode , mode )
119
128
}
120
129
return
121
130
}
@@ -141,6 +150,37 @@ func checkConfigOwner(t *testing.T, p *packageFile) {
141
150
})
142
151
}
143
152
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
+
144
184
// Helpers
145
185
146
186
type packageFile struct {
0 commit comments