Skip to content

Commit 5a60b38

Browse files
MK8S-25: Disable HTTP directory listing for RPM repository
Security fix to prevent exposing repository structure on port 8080. - Changed autoindex from on to off in nginx configuration. - Use nginx location directives to return 200 for health checks instead of index files This maintains the original health check functionality while preventing directory structure exposure. The nginx location = / and location = /saltenv/ directives handle health check requests with 200 status, while location / handles all other requests with autoindex off for security. The nginx.conf.j2 template uses the archives variable to generate location directives for each saltenv, but the variable wasn't being passed in the template context. This caused Salt unit tests to fail. The creation of index.html files was tried but it creates a chicken and egg issue during the container startup when the files were not present. Plus this approach is much more simple, no code, not so much salt, only plain configuration. Related: RD-680
1 parent 668c5db commit 5a60b38

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
### Bug Fixes
1919

20+
- Disable HTTP directory listing for RPM repository to improve security
21+
(PR[#4651](https://github.com/scality/metalk8s/pull/4651))
22+
2023
- Fix a Bug where NodeSystemSaturation alert triggers too early after only 15 minutes of high load
2124
(PR[#4641](https://github.com/scality/metalk8s/pull/4641))
2225

salt/metalk8s/repo/configured.sls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Generate repositories nginx configuration:
1515
- defaults:
1616
listening_address: {{ grains.metalk8s.control_plane_ip }}
1717
listening_port: {{ repo.port }}
18+
archives: {{ archives }}
1819
1920
Deploy common container registry nginx configuration:
2021
file.managed:

salt/metalk8s/repo/files/nginx.conf.j2

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@ server {
22
listen {{ listening_address }}:{{ listening_port }};
33
server_name localhost;
44

5+
# Return 200 OK for root path health checks
6+
location = / {
7+
return 200 '';
8+
add_header Content-Type text/plain;
9+
}
10+
11+
# Return 200 OK for saltenv path health checks
12+
{%- for env in archives.keys() %}
13+
location = /{{ env }}/ {
14+
return 200 '';
15+
add_header Content-Type text/plain;
16+
}
17+
{%- endfor %}
18+
519
location / {
620
root /var/www/repositories;
7-
autoindex on;
21+
# Security fix: Disable directory listing to prevent exposing repository structure
22+
autoindex off;
823
}
924

1025
include conf.d/*.inc;

salt/tests/unit/formulas/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,7 @@ metalk8s:
882882
extra_context:
883883
listening_address: "10.0.0.1"
884884
listening_port: 8080
885+
archives: *example_archives
885886

886887
repositories-manifest.yaml.j2:
887888
_cases:

0 commit comments

Comments
 (0)