Nginx container needs allowPrivilegeEscalation: true otherwise OPA is throwing an error, marking allowPrivilegeEscalation: false will result in unix:/var/run/nginx/nginx-config-version.sock failed (98: Address in use), 0.0.0.0:443 failed (13: Permission denied) in Nginx container #1957 #1961
Replies: 3 comments 7 replies
-
Privilege escalation is required by nginx to bind to ports under 1024, since these are considered privileged ports. |
Beta Was this translation helpful? Give feedback.
-
In the original post I see: |
Beta Was this translation helpful? Give feedback.
-
@sja-commit nginx is reloaded and configured with the ports defined in the Gateway resource. The service ports live only on the service and do not affect nginx configuration. They just need to have their |
Beta Was this translation helpful? Give feedback.
-
As I discussed before I tried to recreate the nginx-gateway without adding any extra security in it but OPA gatekeeper throwing an error on nginx container.
I can see there are 2 containers in the nginx gateway installation one is nginx-gateway and another is nginx.
nginx-gateway container has below security context in the yaml manifest, so I understand by default this container doesn't require privileges.
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
drop:
But Nginx container has below security context which doesn't specify the privilege as false.
securityContext:
capabilities:
add:
drop:
When I install using this setup my OPA gatekeeper is throwing error "Error creating: admission webhook "validation.gatekeeper.sh" denied the request: [Policy name] Privilege escalation container is not allowed: nginx
So I tried to add allowPrivilegeEscalation: false in the nginx container security context as well, which works and pods get created but problem starts when I create gateway with ssl termination and http route. Below is the sample gateway and http route I tried and I am getting error in nginx reload:
2024/05/13 08:52:29 [notice] 20#20: signal 1 (SIGHUP) received from 7, reconfiguring
2024/05/13 08:52:29 [notice] 20#20: reconfiguring
2024/05/13 08:52:29 [emerg] 20#20: bind() to unix:/var/run/nginx/nginx-config-version.sock failed (98: Address in use)
2024/05/13 08:52:29 [emerg] 20#20: bind() to unix:/var/lib/nginx/nginx-502-server.sock failed (98: Address in use)
2024/05/13 08:52:29 [emerg] 20#20: bind() to unix:/var/lib/nginx/nginx-500-server.sock failed (98: Address in use)
2024/05/13 08:52:29 [emerg] 20#20: bind() to 0.0.0.0:443 failed (13: Permission denied)
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: demo
namespace: demo
spec:
gatewayClassName: nginx
listeners:
name: https
port: 443
protocol: HTTPS
tls:
mode: Terminate
certificateRefs:
kind: Secret
name: demo-tls
namespace: demo
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: demo
namespace: demo
spec:
parentRefs:
name: demo
sectionName: https
hostnames:
"example.com"
rules:
matches:
path:
type: PathPrefix
value: /
backendRefs:
name: demo #service name
port: 8080
Does nginx requires privilege container access?
Beta Was this translation helpful? Give feedback.
All reactions