nginx
get source ip from cloudflare
The problem - we log only cf addresses if we not configure nginx properly
curl -s https://www.cloudflare.com/ips-v4/ | awk '{print "set_real_ip_from "$1 ";"}'
curl -s https://www.cloudflare.com/ips-v6/ | awk '{print "set_real_ip_from "$1 ";"}'
http {
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
set_real_ip_from 2a06:98c0::/29;
set_real_ip_from 2c0f:f248::/32;
real_ip_header CF-Connecting-IP;
}
basic-auth
read -p "Enter username: " username && read -sp "Enter password: " password && echo "$username:$(openssl passwd -apr1 $password)" | sudo tee -a /etc/nginx/.htaccess && echo -e "\nCredentials added successfully."
location / {
# Basic authentication setup
auth_basic "Restricted Access";
auth_basic_user_file /etc/nginx/.htaccess ;
}
fix upstream sent too big header
proxy_busy_buffers_size 512k;
proxy_buffers 4 512k;
proxy_buffer_size 256k;
nginx ingress cotroller config snippet
https://ellie.wtf/notes/ingress-nginx-risky-annotations
Today I found myself needing to configure ingress-nginx. I needed to write a bit of nginx config to rewrite status codes for certain routes.
Something like
nginx.ingress.kubernetes.io/configuration-snippet: |-
location /metrics {
return 404;
}
I’ve done this many times in the past, but today I received the following error
Error: UPGRADE FAILED: cannot patch "xyz" with kind Ingress: admission webhook "validate.nginx.ingress.kubernetes.io" denied the request: annotation group ConfigurationSnippet contains risky annotation based on ingress configuration
I already had
allowSnippetAnnotations: true
set, so this was confusing!
It turns out, in a recent release (controller 1.12), annotations are flagged by risk. There’s a table here
You now need to specify
annotations-risk-level: Critical
in the configmap. If you’re using the helm chart, it can be added like so
controller:
config:
annotations-risk-level: Critical
Note that this change is a reaction to a security issue. This is mostly an issue if you’re using a multi-tenant cluster.