Commit 3450cdd
committed
Set file mode explicitly for regular files
* As shown in the following code snippet, the function `ensureFiles`
checks the file mode for both regular files and secret files.
https://github.com/nginxinc/nginx-gateway-fabric/blob/6d4cfd7f0de32e9f98dae358cb6cec93529109a5/internal/mode/static/nginx/file/manager_test.go#L43-L47
* The function `ReplaceFiles` in `nginx/file/manager.go` creates files
by internally calling [os.Create](https://pkg.go.dev/os#Create), which,
by default, creates files with mode 0666 (before applying `umask`). See
the [source
code](https://github.com/golang/go/blob/de5b418bea70aaf27de1f47e9b5813940d1e15a4/src/os/file.go#L357-L364)
of `os.Create` for more details.
* The function `writeFile` changes the mode of secret files to 0640 by
calling `chmod`, but does nothing for regular files. Hence, the check
`Expect(info.Mode()).To(Equal(os.FileMode(0o644))) ` in
`nginx/file/manager_test.go` only passes for `umask` with specific
values.
* In my environment, the `umask` value is 002. Therefore, the mode for
regular files will be 0666 - 0002 = 0664, causing the unit test to fail.
In the following screenshot, 420 is 0o644, and 436 is 0o664.

* Solution: This PR sets the file mode explicitly.1 parent 6d4cfd7 commit 3450cdd
1 file changed
+13
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
136 | 138 | | |
137 | 139 | | |
138 | 140 | | |
139 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
140 | 149 | | |
141 | | - | |
| 150 | + | |
142 | 151 | | |
143 | 152 | | |
| 153 | + | |
| 154 | + | |
144 | 155 | | |
145 | 156 | | |
146 | 157 | | |
| |||
0 commit comments