发布时间: 2024-7-24 文章作者: myluzh 分类名称: Kubernetes 朗读文章
mkdir -p "/data/safeline"2、下载编排脚本
cd "/data/safeline" wget "https://waf-ce.chaitin.cn/release/latest/compose.yaml"3、配置变量
cd "/data/safeline" touch ".env" # 使用文本编辑器打开 .env 文件,写入下方的内容。根据你的实际情况修改配置文件中的 {safeline-dir} 和 {postgres-password} 字段 SAFELINE_DIR=/data/safeline IMAGE_TAG=latest MGT_PORT=9443 POSTGRES_PASSWORD=Aa87654321 SUBNET_PREFIX=172.22.222 IMAGE_PREFIX=swr.cn-east-3.myhuaweicloud.com/chaitin-safeline4、下载镜像包并载入
cd "/data/safeline" wget https://demo.waf-ce.chaitin.cn/image.tar.gz # 载入镜像 cat image.tar.gz | gzip -d | docker load5、启动雷池
cd "/data/safeline" docker compose up -d6、初始化管理员账户
docker exec safeline-mgt resetadmin
vi /data/safeline/resources/detector/detector.yml bind_addr: 0.0.0.0 listen_port: 80002、编辑compose.yaml
vi /data/safeline/compose.yaml ...... detect: ...... ports: - 8000:8000 ......3、启动雷池waf
cd "/data/safeline" docker compose down docker compose up -d4、测试是否生效
tcping 172.30.233.87 8000 172.30.233.87:8000 - Connected - 40.317ms
# safeline.yaml apiVersion: v1 kind: ConfigMap metadata: name: safeline namespace: ingress-nginx data: host: "172.30.233.87" # 雷池检测引擎的地址 port: "8000" #检测引擎的端口 # 创建ConfigMap kubectl create namespace ingress-nginx kubectl apply -f safeline.yaml2、注入环境变量
# ingress-nginx-controller-deployment.yaml ... env: - name: SAFELINE_HOST valueFrom: configMapKeyRef: name: safeline key: host - name: SAFELINE_PORT valueFrom: configMapKeyRef: name: safeline key: port3、制作集成了waf的ingress-nginx镜像
FROM rancher/nginx-ingress-controller:nginx-0.49.3-rancher1 USER root RUN apk add --no-cache make gcc unzip wget RUN wget https://luarocks.org/releases/luarocks-3.11.0.tar.gz && \ tar zxpf luarocks-3.11.0.tar.gz && \ cd luarocks-3.11.0 && \ ./configure && \ make && \ make install && \ cd .. && \ rm -rf luarocks-3.11.0 luarocks-3.11.0.tar.gz RUN luarocks install ingress-nginx-safeline && \ ln -s /usr/local/share/lua/5.1/safeline /etc/nginx/lua/plugins/safeline USER www-data
# 根据上面的dockerfile 构建带有waf插件的镜像 docker build -t nginx-ingress-controller-waf:nginx-1.1.0-rancher1 .4、替换原来的镜像
# kubectl edit daemonset nginx-ingress-controller -n ingress-nginx ... image: nginx-ingress-controller-waf:nginx-1.1.0-rancher1 ...5、测试
# curl "http://xxxxx.com/login?user=admin%27or%201%3D1" {"code": 403, "success":false, "message": "blocked by Chaitin SafeLine Web Application Firewall", "event_id": "cd4642c861834b58991f883916ffe73e"}
cd /data/safeline rm -f image.tar.gz wget https://demo.waf-ce.chaitin.cn/image.tar.gz docker compose down --remove-orphans docker load -i image.tar.gz docker compose up -d
# kubectl logs nginx-ingress-controller-rhvnl -n ingress-nginx或者直接进入nginx-ingress-controller 输出下环境变量看看有没有读取到检测引擎的地址跟端口:
# kubectl get pod -n ingress-nginx NAME READY STATUS RESTARTS AGE nginx-ingress-controller-rhvnl 1/1 Running 0 4d17h nginx-ingress-controller-wkc4j 1/1 Running 1 4d17h # kubectl exec -it nginx-ingress-controller-rhvnl -n ingress-nginx -- bash bash-5.1$ echo $SAFELINE_HOST 172.30.233.87 bash-5.1$ echo $SAFELINE_PORT 8000
标签: k8s Ingress waf ingress-nginx 雷池 safeline
发表评论