Skip to content

Commit 4538f15

Browse files
feat: Add support for NGINX Agent v3 (#43)
1 parent f224f49 commit 4538f15

File tree

2 files changed

+80
-48
lines changed

2 files changed

+80
-48
lines changed

nginx/docker-image-builder/container/start.sh

Lines changed: 76 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,59 @@ sleep 2
1616
if [[ "$NGINX_AGENT_ENABLED" == "true" ]]; then
1717
PARM=""
1818

19-
yq -i '
20-
.server.host=strenv(NGINX_AGENT_SERVER_HOST) |
21-
.server.grpcPort=strenv(NGINX_AGENT_SERVER_GRPCPORT) |
22-
.tls.enable=true |
23-
.tls.skip_verify=true |
24-
.tls.cert="" |
25-
.tls.key=""
26-
' /etc/nginx-agent/nginx-agent.conf
27-
28-
if [[ ! -z "$NGINX_AGENT_INSTANCE_GROUP" ]]; then
29-
PARM="${PARM} --instance-group $NGINX_AGENT_INSTANCE_GROUP"
30-
fi
31-
32-
if [[ ! -z "$NGINX_AGENT_TAGS" ]]; then
33-
PARM="${PARM} --tags $NGINX_AGENT_TAGS"
34-
fi
35-
36-
if [[ ! -z "$NGINX_AGENT_SERVER_TOKEN" ]]; then
37-
yq -i '
38-
.server.token=strenv(NGINX_AGENT_SERVER_TOKEN)
39-
' /etc/nginx-agent/nginx-agent.conf
40-
fi
41-
42-
if [[ ! -z "$NGINX_AGENT_LOG_LEVEL" ]]; then
43-
yq -i '
44-
.log.level=strenv(NGINX_AGENT_LOG_LEVEL)
45-
' /etc/nginx-agent/nginx-agent.conf
46-
fi
19+
NGINX_AGENT_VERSION=`nginx-agent -v | awk '{print $3}' | awk -F\. '{print $1}'`
20+
21+
case "$NGINX_AGENT_VERSION" in
22+
"v2")
23+
yq -i '
24+
.server.host=strenv(NGINX_AGENT_SERVER_HOST) |
25+
.server.grpcPort=strenv(NGINX_AGENT_SERVER_GRPCPORT) |
26+
.tls.enable=true |
27+
.tls.skip_verify=true |
28+
.tls.cert="" |
29+
.tls.key=""
30+
' /etc/nginx-agent/nginx-agent.conf
31+
32+
if [[ ! -z "$NGINX_AGENT_INSTANCE_GROUP" ]]; then
33+
PARM="${PARM} --instance-group $NGINX_AGENT_INSTANCE_GROUP"
34+
fi
35+
36+
if [[ ! -z "$NGINX_AGENT_TAGS" ]]; then
37+
PARM="${PARM} --tags $NGINX_AGENT_TAGS"
38+
fi
39+
40+
if [[ ! -z "$NGINX_AGENT_SERVER_TOKEN" ]]; then
41+
yq -i '
42+
.server.token=strenv(NGINX_AGENT_SERVER_TOKEN)
43+
' /etc/nginx-agent/nginx-agent.conf
44+
fi
45+
46+
if [[ ! -z "$NGINX_AGENT_LOG_LEVEL" ]]; then
47+
yq -i '
48+
.log.level=strenv(NGINX_AGENT_LOG_LEVEL)
49+
' /etc/nginx-agent/nginx-agent.conf
50+
fi
51+
;;
52+
"v3")
53+
PARM="${PARM} --command-server-host ${NGINX_AGENT_SERVER_HOST} --command-server-port ${NGINX_AGENT_SERVER_GRPCPORT} --command-tls-skip-verify"
54+
55+
if [[ ! -z "$NGINX_AGENT_INSTANCE_GROUP" ]]; then
56+
PARM="${PARM} --labels config-sync-group=${NGINX_AGENT_INSTANCE_GROUP}"
57+
fi
58+
59+
if [[ ! -z "$NGINX_AGENT_TAGS" ]]; then
60+
PARM="${PARM} --labels ${NGINX_AGENT_TAGS}"
61+
fi
62+
63+
if [[ ! -z "$NGINX_AGENT_SERVER_TOKEN" ]]; then
64+
PARM="${PARM} --command-auth-token ${NGINX_AGENT_SERVER_TOKEN}"
65+
fi
66+
67+
if [[ ! -z "$NGINX_AGENT_LOG_LEVEL" ]]; then
68+
PARM="${PARM} --log-level ${NGINX_AGENT_LOG_LEVEL}"
69+
fi
70+
;;
71+
esac
4772
fi
4873

4974
if [[ "$NAP_WAF" == "true" ]]; then
@@ -53,22 +78,25 @@ if [[ "$NAP_WAF" == "true" ]]; then
5378
/opt/app_protect/bin/bd_agent &
5479
/usr/share/ts/bin/bd-socket-plugin tmm_count 4 proc_cpuinfo_cpu_mhz 2000000 total_xml_memory 471859200 total_umu_max_size 3129344 sys_max_account_id 1024 no_static_config &
5580

56-
yq -i '
57-
.nap_monitoring.collector_buffer_size=50000 |
58-
.nap_monitoring.processor_buffer_size=50000 |
59-
.nap_monitoring.syslog_ip=strenv(FQDN) |
60-
.nap_monitoring.syslog_port=10514 |
61-
.extensions += ["nginx-app-protect","nap-monitoring"]
62-
' /etc/nginx-agent/nginx-agent.conf
63-
81+
if [[ "$NGINX_AGENT_VERSION" == "v2" ]]; then
82+
yq -i '
83+
.nap_monitoring.collector_buffer_size=50000 |
84+
.nap_monitoring.processor_buffer_size=50000 |
85+
.nap_monitoring.syslog_ip=strenv(FQDN) |
86+
.nap_monitoring.syslog_port=10514 |
87+
.extensions += ["nginx-app-protect","nap-monitoring"]
88+
' /etc/nginx-agent/nginx-agent.conf
89+
fi
6490
else
65-
yq -i '
66-
.nap_monitoring.collector_buffer_size=50000 |
67-
.nap_monitoring.processor_buffer_size=50000 |
68-
.nap_monitoring.syslog_ip=strenv(FQDN) |
69-
.nap_monitoring.syslog_port=514 |
70-
.extensions += ["nginx-app-protect","nap-monitoring"]
71-
' /etc/nginx-agent/nginx-agent.conf
91+
if [[ "$NGINX_AGENT_VERSION" == "v2" ]]; then
92+
yq -i '
93+
.nap_monitoring.collector_buffer_size=50000 |
94+
.nap_monitoring.processor_buffer_size=50000 |
95+
.nap_monitoring.syslog_ip=strenv(FQDN) |
96+
.nap_monitoring.syslog_port=514 |
97+
.extensions += ["nginx-app-protect","nap-monitoring"]
98+
' /etc/nginx-agent/nginx-agent.conf
99+
fi
72100

73101
su - nginx -s /bin/bash -c "/opt/app_protect/bin/bd_agent &"
74102
su - nginx -s /bin/bash -c "/usr/share/ts/bin/bd-socket-plugin tmm_count 4 proc_cpuinfo_cpu_mhz 2000000 total_xml_memory 471859200 total_umu_max_size 3129344 sys_max_account_id 1024 no_static_config &"
@@ -82,9 +110,11 @@ if [[ "$NAP_WAF" == "true" ]]; then
82110
chown nginx:nginx /opt/app_protect/pipe/*
83111

84112
if [[ "$NAP_WAF_PRECOMPILED_POLICIES" == "true" ]]; then
85-
yq -i '
86-
.nginx_app_protect.precompiled_publication=true
87-
' /etc/nginx-agent/nginx-agent.conf
113+
if [[ "$NGINX_AGENT_VERSION" == "v2" ]]; then
114+
yq -i '
115+
.nginx_app_protect.precompiled_publication=true
116+
' /etc/nginx-agent/nginx-agent.conf
117+
fi
88118
fi
89119

90120
fi

nginx/docker-image-builder/manifests/nginx-manifest.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ spec:
4949
# The Instance Group (NGINX Instance Manager) / Config Sync Group (NGINX One Console)
5050
value: "lab"
5151
- name: NGINX_AGENT_TAGS
52-
# Comma-separated list of tags for the NGINX instance
53-
value: "preprod,devops"
52+
# Comma-separated list of tags for the NGINX instance - Agent v2 syntax
53+
#value: "preprod,devops"
54+
# Comma-separated list of tags for the NGINX instance - Agent v3 syntax
55+
#value: "tenant=preprod,subtenant=datacentre1"
5456
- name: NGINX_AGENT_LOG_LEVEL
5557
# NGINX Agent loglevel - default is "info"
5658
value: "info"

0 commit comments

Comments
 (0)