coreruleset / modsecurity-crs-docker

Official ModSecurity Docker + Core Rule Set (CRS) images
https://coreruleset.org
Apache License 2.0
241 stars 63 forks source link

Latest nginx build not working #201

Closed guidugli closed 5 months ago

guidugli commented 5 months ago

I was reinstalling a server and noticed that the latest image is not working. Doing some tests I noticed that running the command below on a 3 month old image works, but it fails with the latest one.

podman run --name abc -p 8080:8080 -p 8443:443 -ti -e PROXY=0 -e ALLOWED_METHODS="GET POST PUT" -e MODSEC_RULE_ENGINE=Off --rm docker.io/owasp/modsecurity-crs:nginx

The error happens on both arm and x64.

Here is the log when running the latest image:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-generate-certificate.sh /usr/local/bin/generate-certificate: generating new certificate Warning: No -copy_extensions given; ignoring any extensions in the request /usr/local/bin/generate-certificate: generated /etc/nginx/conf/server.key and /etc/nginx/conf/server.crt /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template to /etc/nginx/modsecurity.d/modsecurity-override.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/modsecurity.d/setup.conf.template to /etc/nginx/modsecurity.d/setup.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/conf.d/default.conf.template to /etc/nginx/conf.d/default.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/conf.d/logging.conf.template to /etc/nginx/conf.d/logging.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/conf.d/modsecurity.conf.template to /etc/nginx/conf.d/modsecurity.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/includes/location_common.conf.template to /etc/nginx/includes/location_common.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/includes/proxy_backend.conf.template to /etc/nginx/includes/proxy_backend.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/includes/proxy_backend_ssl.conf.template to /etc/nginx/includes/proxy_backend_ssl.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/nginx.conf.template to /etc/nginx/nginx.conf /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/90-copy-modsecurity-config.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/91-update-resolver.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/92-update-real_ip.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/93-update-proxy-ssl-config.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/94-activate-plugins.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/95-activate-rules.sh /docker-entrypoint.sh: Configuration complete; ready for start up 2024/02/13 02:11:34 [warn] 1#1: "ssl_stapling" ignored, issuer certificate not found for certificate "/etc/nginx/conf/server.crt" nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/etc/nginx/conf/server.crt" 2024/02/13 02:11:34 [notice] 1#1: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/924/0) 2024/02/13 02:11:34 [emerg] 1#1: bind() to 0.0.0.0:80 failed (13: Permission denied) nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

guidugli commented 5 months ago

It seems that the difference between the image that works and the one that does not is that the latest one executes the entrypoint as nginx, so probably that is why it is failing.

If I start with --user root, the latest image works too.

podman run --user root -p 8080:8080 -p 8443:443 -ti -e PROXY=0 -e ALLOWED_METHODS="GET POST PUT" -e

MODSEC_RULE_ENGINE=Off --rm docker.io/owasp/modsecurity-crs:nginx /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-generate-certificate.sh /usr/local/bin/generate-certificate: generating new certificate Warning: No -copy_extensions given; ignoring any extensions in the request /usr/local/bin/generate-certificate: generated /etc/nginx/conf/server.key and /etc/nginx/conf/server.crt /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/modsecurity.d/modsecurity-override.conf.template to /etc/nginx/modsecurity.d/modsecurity-override.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/modsecurity.d/setup.conf.template to /etc/nginx/modsecurity.d/setup.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/conf.d/default.conf.template to /etc/nginx/conf.d/default.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/conf.d/logging.conf.template to /etc/nginx/conf.d/logging.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/conf.d/modsecurity.conf.template to /etc/nginx/conf.d/modsecurity.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/includes/location_common.conf.template to /etc/nginx/includes/location_common.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/includes/proxy_backend.conf.template to /etc/nginx/includes/proxy_backend.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/includes/proxy_backend_ssl.conf.template to /etc/nginx/includes/proxy_backend_ssl.conf 20-envsubst-on-templates.sh: Running envsubst on /etc/nginx/templates/nginx.conf.template to /etc/nginx/nginx.conf /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/90-copy-modsecurity-config.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/91-update-resolver.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/92-update-real_ip.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/93-update-proxy-ssl-config.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/94-activate-plugins.sh /docker-entrypoint.sh: Launching /docker-entrypoint.d/95-activate-rules.sh /docker-entrypoint.sh: Configuration complete; ready for start up 2024/02/13 02:22:54 [warn] 1#1: "ssl_stapling" ignored, issuer certificate not found for certificate "/etc/nginx/conf/server.crt" nginx: [warn] "ssl_stapling" ignored, issuer certificate not found for certificate "/etc/nginx/conf/server.crt" 2024/02/13 02:22:54 [notice] 1#1: ModSecurity-nginx v1.0.3 (rules loaded inline/local/remote: 0/924/0)

fzipi commented 5 months ago

Thanks for the report, I'll take a look soon.

wolffberg commented 5 months ago

We were also hit by this after our image caches were flushed. We worked around it by using non-standard ports.

env:
- name: PORT
  value: "8080"
  name: SSL_PORT
  value: "8443"
fzipi commented 5 months ago

Should be fixed by #202, we are going to release probably tomorrow with CRS v4.0 🎉

theseion commented 5 months ago

@fzipi do you want to close this issue?

fzipi commented 5 months ago

I would wait until we release and people say it is fixed for them.

fzipi commented 5 months ago

@guidugli We released a new version yesterday, can you pull it and see if it fixed the problem?

guidugli commented 5 months ago

It is working now. Thank you.

theseion commented 5 months ago

Thanks for the feedback.