Kubernetes Agent + Ingress Controller + Module
- English
- 日本語
In this example, the Next-Gen WAF agent is installed as a Docker sidecar, communicating with the Next-Gen WAF dynamic module for NGINX installed on an ingress-nginx Kubernetes ingress controller.
NOTE: The upstream ingress-nginx repository has been archived. Fastly's ingress controller image is now built on the Chainguard-maintained fork, which provides continued security maintenance. The installation steps remain the same.
Integrating the Next-Gen WAF agent into an ingress controller
In addition to installing the Next-Gen WAF per application, it is also possible to install the Next-Gen WAF into a Kubernetes ingress controller that will receive all external traffic to your applications. Doing this is similar to installing into an application with a Next-Gen WAF module:
- Install and configure the Next-Gen WAF module into the ingress controller.
- Add the
sigsci-agentcontainer to the ingress pod and mount a sigsci-agent volume. - Add an
emptyDir{}volume as a place for thesigsci-agentto write temporary data.
Kubernetes NGINX ingress controller
The Kubernetes NGINX Ingress Controller is an NGINX based implementation for the ingress API. Next-Gen WAF supports a dynamic module for NGINX. This enables you to easily wrap the existing ingress-nginx controller to install the Next-Gen WAF module.
Wrap the base nginx-ingress-controller to install the Next-Gen WAF module
Wrapping the nginx-ingress-controller is done by using the base controller and installing the Next-Gen WAF dynamic NGINX module. A prebuilt container can be pulled from Docker Hub with: docker pull signalsciences/sigsci-nginx-ingress-controller-chainguard:latest
Installation
There are two methods for installing:
Prerequisites
Copy the agent keys for the site that you want the agent to be able to access. You will use the agent keys when configuring the Next-Gen WAF agent package.
Install via Helm using overrides
The following steps cover installing sigsci-nginx-ingress-controller-chainguard + sigsci-agent via the official ingress-nginx charts with an override file.
Add the
ingress-nginxrepository:$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginxIn the sigsci-values.yaml file, add the agent keys as
SIGSCI_ACCESSKEYIDandSIGSCI_SECRETACCESSKEY.Install with the release name
my-ingressin thedefaultnamespace:$ helm install -f values-sigsci.yaml my-ingress ingress-nginx/ingress-nginxYou can specify a namespace with
-nflag:$ helm install -n NAMESPACE -f values-sigsci.yaml my-ingress ingress-nginx/ingress-nginxAfter a few minutes, the agent will be listed on the Agents page in the Next-Gen WAF control panel and the Deployment page in the Fastly control panel.
Create an Ingress resource. This step will vary depending on setup and supports a lot of configurations. Official documentation can be found regarding Basic usage - host based routing.
Here is an example Ingress file:
1234567891011121314151617181920apiVersion: networking.k8s.io/v1kind: Ingressmetadata:annotations:kubernetes.io/ingress.class: nginxnginx.ingress.kubernetes.io/rewrite-target: /name: hello-kubernetes-ingress#namespace: SET THIS IF NOT IN DEFAULT NAMESPACEspec:rules:- host: example.comhttp:paths:- pathType: Prefixpath: /testpathbackend:service:name: NAME OF SERVICEport:number: 80
Helm upgrade with override file
In the sigsci-values.yaml file, update the
sigsci-nginx-ingress-controllerto the latest version to update theingress-nginxcharts:controller:# Replaces the default nginx-controller image with a custom image that contains the Next-Gen WAF NGINX moduleimage:repository: signalsciences/sigsci-nginx-ingress-controller-chainguardtag: "latest"pullPolicy: IfNotPresentRun
helm upgradewith the override file. This example is running helm upgrade against themy-ingressrelease created in the previous section:$ helm upgrade -f sigsci-values.yaml my-ingress ingress-nginx/ingress-nginxor
$ helm upgrade -f sigsci-nginxinc-values.yaml my-ingress ingress-nginx/ingress-nginxIf ingress is not in default namespace, use
-nto specify namespace:$ helm upgrade -n NAMESPACE -f sigsci-values.yaml my-ingress ingress-nginx/ingress-nginxor
$ helm upgrade -n NAMESPACE -f sigsci-nginxinc-values.yaml my-ingress ingress-nginx/ingress-nginx
Uninstall release
Uninstall release
my-ingress.$ helm uninstall my-ingressIf it's not in the default namespace, use
-nto specify the namespace:$ helm uninstall -n NAMESPACE my-ingress
Install with custom file
Integrating the Next-Gen WAF agent
Refer to the Agent container image integration.
The NGINX ingress controller is installed with the mandatory.yaml file. This file contains a modified template of the Generic Ingress Controller Deployment. The main additions are:
Change the ingress container to load the custom ingress container and add Volume mounts for socket file communication between the Module/ingress container and Agent sidecar container:
123456789...containers:- name: nginx-ingress-controllerimage: signalsciences/sigsci-nginx-ingress-controller-chainguard:latest...volumeMounts:- name: sigsci-tmpmountPath: /sigsci/tmp...Load the Next-Gen WAF module in the NGINX configuration file (
nginx.conf) viaConfigMap:1234567891011kind: ConfigMapapiVersion: v1data:main-snippet: load_module /usr/lib/nginx/modules/ngx_http_sigsci_nxo_module-1.17.7.so;http-snippet: sigsci_agent_host unix:/sigsci/tmp/sigsci.sock;metadata:name: nginx-configurationnamespace: ingress-nginxlabels:app.kubernetes.io/name: ingress-nginxapp.kubernetes.io/part-of: ingress-nginxAdd a container for the Next-Gen WAF agent:
12345678910111213141516171819202122232425262728...containers:...# Next-Gen WAF agent running in default RPC mode- name: sigsci-agentimage: signalsciences/sigsci-agent:latestimagePullPolicy: IfNotPresentenv:- name: SIGSCI_ACCESSKEYIDvalueFrom:secretKeyRef:# This secret needs added (see docs on sigsci secrets)name: sigsci.my-site-name-herekey: accesskeyid- name: SIGSCI_SECRETACCESSKEYvalueFrom:secretKeyRef:# This secret needs added (see docs on sigsci secrets)name: sigsci.my-site-name-herekey: secretaccesskeysecurityContext:# The sigsci-agent container should run with its root filesystem read onlyreadOnlyRootFilesystem: truevolumeMounts:# Default volume mount location for sigsci-agent writeable data (do not change mount path)- name: sigsci-tmpmountPath: /sigsci/tmp...Define the volume used above:
...volumes:# Define a volume where sigsci-agent will write temp data and share the socket file,# which is required with the root filesystem is mounted read only- name: sigsci-tmpemptyDir: {}...
Setup
The mandatory.yaml file creates the resources in the ingress-nginx namespace. If using Kubernetes Secrets to store the agent access keys, you will need to create the namespace and access keys before running the mandatory.yaml file.
Set the name for the secrets for the agent keys in
mandatory.yaml.123456789101112131415...env:- name: SIGSCI_ACCESSKEYIDvalueFrom:secretKeyRef:# This secret needs added (see docs on sigsci secrets)name: sigsci.my-site-name-herekey: accesskeyid- name: SIGSCI_SECRETACCESSKEYvalueFrom:secretKeyRef:# This secret needs added (see docs on sigsci secrets)name: sigsci.my-site-name-herekey: secretaccesskey...Pull or build the NGINX ingress + Signal Sciences Module container. Set any preferred registry and repository name, and set the image to match in
mandatory.yaml:$ docker pull signalsciences/sigsci-nginx-ingress-controller-chainguard:latestDeploy using modified Generic Deployment:
$ kubectl apply -f mandatory.yamlCreate the service to expose the Ingress Controller. The steps necessary are dependent on your cloud provider. Official instructions can be found at https://kubernetes.github.io/ingress-nginx/deploy/#environment-specific-instructions.
Below is an example
service.yamlfile:1234567891011121314151617kind: ServiceapiVersion: v1metadata:name: ingress-nginxnamespace: ingress-nginxspec:externalTrafficPolicy: Clusterselector:app.kubernetes.io/name: ingress-nginxtype: LoadBalancerports:- name: httpport: 80targetPort: http- name: httpsport: 443targetPort: httpsCreate the Ingress Resource. Below is an example Ingress Resource:
123456789101112131415apiVersion: extensions/v1kind: Ingressmetadata:name: test-ingressnamespace: ingress-nginxannotations:nginx.ingress.kubernetes.io/rewrite-target: /spec:rules:- http:paths:- path: /testpathbackend:serviceName: nginxservicePort: 80