@@ -115,6 +115,14 @@ func (x *hostsStore) Acquire(meta Meta) (err error) {
115
115
return errors .Join (store .ErrSystemFailure , err )
116
116
}
117
117
118
+ // os.WriteFile relies on syscall.Open. Unless there are ACLs, the effective mode of the file will be matched
119
+ // against the current process umask.
120
+ // See https://www.man7.org/linux/man-pages/man2/open.2.html for details.
121
+ // Since we must make sure that these files are world readable, explicitly chmod them here.
122
+ if err = os .Chmod (loc , 0o644 ); err != nil {
123
+ err = errors .Join (store .ErrSystemFailure , err )
124
+ }
125
+
118
126
var content []byte
119
127
content , err = json .Marshal (meta )
120
128
if err != nil {
@@ -176,6 +184,14 @@ func (x *hostsStore) AllocHostsFile(id string, content []byte) (location string,
176
184
err = errors .Join (store .ErrSystemFailure , err )
177
185
}
178
186
187
+ // os.WriteFile relies on syscall.Open. Unless there are ACLs, the effective mode of the file will be matched
188
+ // against the current process umask.
189
+ // See https://www.man7.org/linux/man-pages/man2/open.2.html for details.
190
+ // Since we must make sure that these files are world readable, explicitly chmod them here.
191
+ if err = os .Chmod (loc , 0o644 ); err != nil {
192
+ err = errors .Join (store .ErrSystemFailure , err )
193
+ }
194
+
179
195
return err
180
196
})
181
197
if err != nil {
@@ -333,6 +349,7 @@ func (x *hostsStore) updateAllHosts() (err error) {
333
349
if err != nil {
334
350
log .L .WithError (err ).Errorf ("failed to write hosts file for %q" , entry )
335
351
}
352
+ _ = os .Chmod (loc , 0o644 )
336
353
}
337
354
return nil
338
355
}
0 commit comments