Description
We have been running ingress-nginx with modsecurity rules in place for over two years. Recently the we have been unable to block geolocations and are getting this error in the debug logs
Database is not open. Use: SecGeoLookupDb directive.
I have the GeoLite2-Country.mmdb mounted using an azure file back PV:
# Create an Azure File StorageClass
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: geoip-country-database-sc
namespace: nginx-ingress-controller
provisioner: kubernetes.io/azure-file
mountOptions:
- dir_mode=0775
- file_mode=0775
- uid=0
- gid=0
- mfsymlinks
- cache=strict
- actimeo=30
parameters:
skuName: Standard_ZRS
allowVolumeExpansion: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: geoip-country-database-pvc
namespace: nginx-ingress-controller
spec:
accessModes:
- ReadWriteMany
storageClassName: geoip-country-database-sc
resources:
requests:
storage: 1Gi
This is my ingress-nginx-controller ConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: ingress-nginx-controller
namespace: nginx-ingress-controller
annotations:
meta.helm.sh/release-name: ingress-nginx
meta.helm.sh/release-namespace: nginx-ingress-controller
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: 1.9.3
helm.sh/chart: ingress-nginx-4.8.2
data:
add-headers: nginx-ingress-controller/ingress-nginx-custom-add-headers
allow-snippet-annotations: "true"
strict-validate-path-type: "true"
enable-modsecurity: 'true'
modsecurity-snippet: |
Include /etc/nginx/modsecurity/modsecurity.conf
proxy-cookie-path: |
$uri "/; HTTPOnly; Secure; SameSite=strict"
extra values:
controller:
extraVolumeMounts:
- name: geoip-country-database
mountPath: "/etc/nginx/geoip/GeoLite2-Country.mmdb"
subPath: GeoLite2-Country.mmdb
- name: modsecurity
mountPath: "/etc/nginx/modsecurity/modsecurity.conf"
subPath: modsecurity.conf
extraVolumes:
- name: geoip-country-database
persistentVolumeClaim:
claimName: geoip-country-database-pvc
- name: modsecurity
configMap:
name: "modsecurity-conf"
Modsecurity Configuration:
SecRuleEngine On
SecRequestBodyAccess On
SecResponseBodyAccess On
SecAuditEngine RelevantOnly
SecAuditLogRelevantStatus "^(?:5|4(?!04))"
SecAuditLogParts ABIFHJKZ
SecAuditLogType Concurrent
SecAuditLog /var/log/modsec_audit.log
SecDebugLog /tmp/modsec_debug.log
SecCookieFormat 0
SecStatusEngine On
SecAuditLogStorageDir /var/log/audit/
SecRule REMOTE_ADDR "@ipMatch 10.180.0.0/16" "phase:1,id:200000001,nolog,allow"
SecGeoLookup /etc/nginx/geoip/GeoLite2-Country.mmdb
SecRule REMOTE_ADDR "@geoLookup" "phase:1,chain,id:22,drop,msg:'Non-allowed country IP address'"
SecRule GEO:COUNTRY_CODE "!@pm US CA BS MX TC TT VC MF LC KN BL AG AI AW BB VG KY CU DM DO GD GP HT JM MQ MS CR GB AU NZ"
ingress-nginx helm chart version 4.8.3
AKS version 1.30.0
ingress-nginx App Version 1.9.4
We have this configuration running in four Kubernetes clusters. Up until recently it was working just fine, then we started getting the above error in the logs.
I have tried restarting the ingress-nginx-controller deployments, and that helped in our development clusters, for a little while, then we started seeing the error message again, and I was able to reach all sites from a blocked country.
I have tried upgrading the helm chart from 4.8.2 to 4.8.3 in all clusters, which oddly worked for one replica in one of our production clusters (there are two replicas running in each cluster) but not any of the others.
This also fixed one of or dev clusters for a few days, but it has started giving the above error message again.
I expect the configuration to be able to find the database and use it when I set SecGeoLookupDb to the correct file path, everytime.
Not sure what else to try to resolve this, and find it odd that it sometimes works, and other times does not.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status