|
| 1 | +Enable API discovery for Nginx |
| 2 | +============================== |
| 3 | + |
| 4 | +In the previous lab, we learnt how F5 Distributed Cloud can discover API Endpoints on traffic handled by BIG-IP. |
| 5 | + |
| 6 | +In this lab, you will replicate the same use case but with Nginx as a Dataplane instead of BIG-IP. You will learn how to ``onboard`` a Nginx into F5XC, in order to enable the API Discovery feature on this Nginx. |
| 7 | + |
| 8 | +Key take aways before jumping into the lab: |
| 9 | + |
| 10 | +* Out of Band Discovery |
| 11 | +* CE required on Nginx Network |
| 12 | +* CE collects and anonymises logs from Nginx |
| 13 | +* F5XC runs API Discovery engine in F5XC infrastructure |
| 14 | +* Outcomes |
| 15 | + |
| 16 | + * Inventory |
| 17 | + * Security Insights risks |
| 18 | + * Compliance |
| 19 | + * Authentication state |
| 20 | + * Sensitive Data |
| 21 | + |
| 22 | +.. image:: ../pictures/nginx-apid-archi.png |
| 23 | + :align: left |
| 24 | + |
| 25 | +.. note:: If you have already run the lab 7 (API Discovery for BIG-IP), you can reuse the same CE and skip to the sections "Deploy and Register CE". If not, please follow the instructions below to deploy and register a new CE in order to connect your Nginx to F5XC. |
| 26 | + |
| 27 | + |
| 28 | +Deploy and register Customer Edge (CE) |
| 29 | +-------------------------------------- |
| 30 | + |
| 31 | +The CE (Customer Edge) is not yet registered. But it is already deployed in your UDF environment. |
| 32 | +The CE is deployed with 2 NICs |
| 33 | + |
| 34 | +* NIC Outside in charge of IPSEC tunnels between CE and RE |
| 35 | +* NIC Inside in charge of configuring BIG-IP and collect logs from BIG-IP |
| 36 | + |
| 37 | +.. note:: In a nutshell, F5XC will configure the BIG-IP to collect request logs from the Virtual Server, and send those logs to the CE. Then the CE will anonymize the logs and send them to the F5XC infrastructure to render the API Discovery endpoints and insights. |
| 38 | + |
| 39 | +Register the CE |
| 40 | +^^^^^^^^^^^^^^^ |
| 41 | + |
| 42 | +In UDF environment, connect to the Customer Edge (CE) UI with credentials below |
| 43 | + |
| 44 | +* Creds : ``admin`` / ``Volterra123`` |
| 45 | +* Update credentials, you can reuse the same password ``Volterra123`` |
| 46 | +* Click on ``Configure Now`` button |
| 47 | + |
| 48 | +.. image:: ../pictures/configure-ce.png |
| 49 | + :align: left |
| 50 | + |
| 51 | +* Token (copy paste using the copy button below) |
| 52 | + |
| 53 | +.. code-block:: none |
| 54 | +
|
| 55 | + $$smsv2Token$$ |
| 56 | +
|
| 57 | +* Cluster Name: ``$$smsv2SiteName$$`` |
| 58 | +* Hostmane: ``master0`` |
| 59 | + |
| 60 | +* Click ``Save Configuration`` |
| 61 | + |
| 62 | +Wait 15min to see the CE registered in the F5 Distributed Cloud Console. |
| 63 | + |
| 64 | + |
| 65 | +Check Registration on the F5 Distributed Cloud Console |
| 66 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 67 | + |
| 68 | +In F5 Distributed Cloud Console |
| 69 | + |
| 70 | +* Go to Multi-Cloud Network Connect > Overview > Infrastructure > Sites |
| 71 | +* Search for your site ``$$smsv2SiteName$$`` |
| 72 | +* Click on it |
| 73 | +* Refresh the page till upgrades are finished and every flag is green |
| 74 | + |
| 75 | +.. image:: ../pictures/site-view.png |
| 76 | + :align: left |
| 77 | + |
| 78 | +.. note:: Your CE is up and running and ready to connect to the BIG-IP in order to collect logs. |
| 79 | + |
| 80 | + |
| 81 | +Onboard Nginx instance |
| 82 | +---------------------- |
| 83 | + |
| 84 | +Onboard Nginx is different from onboarding a BIG-IP as Nginx is not natively integrated with F5XC like BIG-IP. This type of integration is called 3rd Party Proxy integration. |
| 85 | +Therefore, we will need to install a lightweight JS module on the Nginx to collect logs and send them to the CE. |
| 86 | + |
| 87 | +The Nginx instance is already up and running in your UDF environment, but it is not yet onboarded to F5XC. To onboard it, you will need to connect to the Nginx instance and make some "changes". |
| 88 | + |
| 89 | +Create the Service Discovery profile |
| 90 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 91 | + |
| 92 | +Create a new Service Discovery configuration for 3rd Parties Services |
| 93 | + |
| 94 | +.. image:: ../pictures/3rd-sd-page.png |
| 95 | + :align: left |
| 96 | + |
| 97 | +* Name : ``nginx-sd`` |
| 98 | +* Site : select your site name ``$$smsv2SiteName$$`` |
| 99 | +* Network type : ``Site Local Inside Network`` |
| 100 | + |
| 101 | +In the discovery section, create an application associated to the Nginx application |
| 102 | + |
| 103 | +* Application Source Name : ``nginx-sentence-app`` |
| 104 | +* Source Subnet IP : ``10.1.0.0/16`` (this is the subnet used by the Nginx) |
| 105 | + |
| 106 | +.. image:: ../pictures/3rd-sd-config.png |
| 107 | + :align: left |
| 108 | + |
| 109 | +Download the certificates |
| 110 | +^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 111 | + |
| 112 | +* Click on Generate button to download the certificates that will be used by the JS module on the Nginx to send logs to the CE securely. |
| 113 | + |
| 114 | +.. image:: ../pictures/3rd-gen-cert.png |
| 115 | + :align: left |
| 116 | + |
| 117 | +* Now, you must upload the zip file into the Nginx instance. |
| 118 | + |
| 119 | + * In UDF portal, on the Nginx instance, there is a Access Method called ``UPLOAD CERTS``. Click on it, it will open a new browser page to an Upload file website. |
| 120 | + |
| 121 | + .. image:: ../pictures/3rd-udf-upload.png |
| 122 | + :align: left |
| 123 | + :scale: 50% |
| 124 | + |
| 125 | + * Upload your zip file from this website. It will be uploaded into the Nginx instance. |
| 126 | + |
| 127 | + .. image:: ../pictures/3rd-upload-site.png |
| 128 | + :align: left |
| 129 | + :scale: 70% |
| 130 | + |
| 131 | + |
| 132 | +Enable API Disovery and Download the token |
| 133 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 134 | + |
| 135 | +* In Web Application and API Protection > Third-Party Applications, enable API Discovery for the application ``nginx-sd-nginx-sentence-app`` |
| 136 | + |
| 137 | + .. image:: ../pictures/3rd-enable-apid.png |
| 138 | + :align: left |
| 139 | + |
| 140 | +* Enable and select your API Definition (created in the previous labs) |
| 141 | +* Enable API Discovery |
| 142 | +* Select also the Sensitive Data Detection Policy created in the previous labs, or keep the Default. |
| 143 | +* Save |
| 144 | + |
| 145 | +* Click on the 3-dots, and ``Generate Token`` |
| 146 | +* Copy and save the token, you will need it to configure the JS module on the Nginx |
| 147 | + |
| 148 | +.. note:: You have finished the configuration on the F5 Distributed Cloud side, now you need to configure the JS module on the Nginx side to start sending logs to the CE and see API Discovery in action. |
| 149 | + |
| 150 | +Configure the Nginx instance |
| 151 | +---------------------------- |
| 152 | + |
| 153 | +.. note:: The Nginx instance is already pre-configured to avoid too many copy-paste between this lab guide and the SSH session. You will just adapt the configuration to collect the logs from Nginx application and forward the logs to the CE. |
| 154 | + |
| 155 | +* SSH or WEBSSH to the Nginx instance |
| 156 | + |
| 157 | + .. image:: ../pictures/3rd-nginx-ssh.png |
| 158 | + :align: left |
| 159 | + :scale: 70% |
| 160 | + |
| 161 | +Copy the certificats |
| 162 | +^^^^^^^^^^^^^^^^^^^^ |
| 163 | + |
| 164 | +* Copy the certificates zip file into /home/ubuntu directory and unzup it |
| 165 | + |
| 166 | + .. code-block:: bash |
| 167 | +
|
| 168 | + sudo cp /var/www/nginx-upload-file/uploads/<your-file-name>.zip /home/ubuntu/certs.zip |
| 169 | + unzip certs.zip |
| 170 | +
|
| 171 | +* Copy the certs and key files into the right directories, and modify the permissions. Those certs+key are use to initiate the MTLS between the Nginx and the CE. |
| 172 | + |
| 173 | + .. code-block:: bash |
| 174 | +
|
| 175 | + sudo cp client.crt /etc/nginx/certs/client.crt |
| 176 | + sudo cp client.key /etc/nginx/certs/client.key |
| 177 | + sudo cp server_ca.crt /etc/nginx/certs/server_ca.crt |
| 178 | +
|
| 179 | + sudo chmod 600 /etc/nginx/certs/client.key |
| 180 | + sudo chmod 644 /etc/nginx/certs/client.crt |
| 181 | + sudo chmod 644 /etc/nginx/certs/server_ca.crt |
| 182 | +
|
| 183 | +Update the nginx configuration |
| 184 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 185 | + |
| 186 | +* Modify the nginx.conf file |
| 187 | + |
| 188 | + .. code-block:: bash |
| 189 | +
|
| 190 | + sudo nano /etc/nginx/nginx.conf |
| 191 | +
|
| 192 | + .. note:: Have a look on the nginx.conf file, and check the blocks that are already configured for you. I added comments so you can understand them. |
| 193 | + |
| 194 | + .. note:: Block Upstream obelix -> this is the CE |
| 195 | + |
| 196 | + .. note:: Block Server 8080 -> website to upload the certificates |
| 197 | + |
| 198 | + .. note:: Block Server 80 -> the Nginx LB proxying the sentence application |
| 199 | + |
| 200 | + .. note:: Block Server 18080 -> the API Discovery configuration to collect the logs, format them, and send them to the CE. |
| 201 | + |
| 202 | + |
| 203 | +* At the end of the file, ``uncomment`` those 5 lines. Ctrl+X to exit, Y to save and Enter to confirm. |
| 204 | + |
| 205 | + .. code-block:: bash |
| 206 | +
|
| 207 | + proxy_ssl_certificate /etc/nginx/certs/client.crt; |
| 208 | + proxy_ssl_certificate_key /etc/nginx/certs/client.key; |
| 209 | + proxy_ssl_trusted_certificate /etc/nginx/certs/server_ca.crt; |
| 210 | + proxy_ssl_verify on; |
| 211 | + proxy_ssl_server_name off; # keep off unless Telemetry_Ingestion_Service cert CN matches host |
| 212 | +
|
| 213 | +* Reload nginx configuration |
| 214 | + |
| 215 | + .. code-block:: bash |
| 216 | +
|
| 217 | + sudo nginx -s reload |
| 218 | +
|
| 219 | +
|
| 220 | +Check your lab |
| 221 | +-------------- |
| 222 | + |
| 223 | +From the Nginx instance |
| 224 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 225 | + |
| 226 | +Now it is time to check if |
| 227 | + |
| 228 | +* Nginx is proxying the sentence application |
| 229 | +* Nginx is sending logs to the CE |
| 230 | + |
| 231 | +To do so, we will simulate some traffic to the sentence application, and check if we can see the logs. |
| 232 | + |
| 233 | +.. note:: A traffic generator script is running every 9 minutes. It is already running, you don't have to run it. |
| 234 | + |
| 235 | +* Connect in SSH or WebSSH to the Nginx instance and run the command below, keep the terminal opened. |
| 236 | + |
| 237 | + .. code-block:: bash |
| 238 | +
|
| 239 | + tail -f /var/log/nginx/location_debug.log |
| 240 | +
|
| 241 | +* Connect in SSH or WebSSH to the Traffic Gen instance. It opens a second terminal |
| 242 | +* Run the command below |
| 243 | + |
| 244 | + .. code-block:: bash |
| 245 | +
|
| 246 | + curl -k --location 'http://10.1.10.10/api/colors' --header 'Host: api.sentence.com' |
| 247 | +
|
| 248 | +* Now, look into the nginx instance terminal, you should see the logs being collected by the nginx and sent to the CE. |
| 249 | + |
| 250 | + .. code-block:: bash |
| 251 | +
|
| 252 | + { "time":"2026-04-30T18:48:56+00:00", "server":"127.0.0.1", "uri":"/logs/third_party_application/access", "method":"POST", "status":500, "token":"", "body":"{\"method\":\"GET\",\"url\":\"http://api.sentence.com/api/colors\",\"client_ip\":\"10.1.10.6\",\"req_headers\":{\"host\":\"api.sentence.com\",\"user-agent\":\"curl/7.81.0\",\"accept\":\"*/*\"},\"request_timestamp\":1777574936841,\"req_payload\":\"\",\"rsp_status\":200,\"rsp_headers\":{\"content-type\":\"application/json; charset=utf-8\",\"content-length\":\"210\",\"x-powered-by\":\"Express\",\"vary\":\"Origin, Accept-Encoding\",\"access-control-allow-credentials\":\"true\",\"cache-control\":\"no-cache\",\"pragma\":\"no-cache\",\"expires\":\"-1\",\"x-content-type-options\":\"nosniff\",\"etag\":\"W/\\\"d2-RfZ0XwcFqRWrzPouuyCT4I7Dhlo\\\"\"},\"response_timestamp\":1777574936841,\"rsp_payload\":\"WwogIHsKICAgICJpZCI6IDEsCiAgICAibmFtZSI6ICJyZWQiCiAgfSwKICB7CiAgICAiaWQiOiAyLAogICAgIm5hbWUiOiAiYmx1ZSIKICB9LAogIHsKICAgICJpZCI6IDMsCiAgICAibmFtZSI6ICJncmVlbiIKICB9LAogIHsKICAgICJuYW1lIjogImJsYWNrIiwKICAgICJpZCI6IDQKICB9LAogIHsKICAgICJuYW1lIjogInllbGxvdyIsCiAgICAiaWQiOiA1CiAgfQpd\",\"req_id\":\"3bc650014be3462ebd99fc8d3f3dd06f\",\"dst\":\"10.1.20.7:31220\",\"rsp_code_details\":\"200\"}" } |
| 253 | +
|
| 254 | +.. note:: you can notice all the datas from the request and also the response is encoded in Base64. You can decode it with https://www.base64decode.org/ |
| 255 | + |
| 256 | + |
| 257 | +From the F5 Distributed Cloud Console |
| 258 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 259 | + |
| 260 | +* Connect to the F5 Distributed Cloud Console, in the WAAP section, and click on the ``Third-Party Applications`` menu on the left |
| 261 | +* Click on the application ``nginx-sd-nginx-sentence-app`` |
| 262 | + |
| 263 | + .. image:: ../pictures/3rd-menu-apid.png |
| 264 | + :align: left |
| 265 | + |
| 266 | +* After 2 hours, or if the trainer can run the job for you, you will find all the outcomes of the API Discovery, such as Inventory, Security Insights, Compliance, Authentication state, Sensitive Data, etc... |
| 267 | + |
| 268 | + .. image:: ../pictures/3rd-apid-outcomes.png |
| 269 | + :align: left |
| 270 | + |
| 271 | + |
| 272 | +.. note:: Congrats, the lab is finished. |
0 commit comments