This is a continuation of the Secure Gateway Setup Guide.
- How to protect your secure gateway
destination; - How to configure your
java message hub consumerto grant itself access to your destination automatically; - How to clean your destination firewall table;
-
Go to your
gatewaydashboard at your secure gateway service and press on the gray area with your destination title; -
Mark the check box
Restrict cloud access to this destination with iptable rulesand pressUPDATE DESTINATION;
After this point you will not be able to reach your gateway from your browser, the only machines able to reach it will be the ones with the IP and PORT on the iptables list;
Your Message Hub Java Consumer has a yml file with all the properties need to setup your firewall access, they are part of the property SGW_CONFIG. Manifest File
Sample:
SGW_CONFIG: '{
"destination-id":"${YOUR_SECURE_GATEWAY_DESTINATION_ID}",
"api-host":"${YOUR_SECURE_GATEWAY_HOST_URL}",
"gateway-id":"${YOUR_SECURE_GATEWAY_ID}",
"sgw-token":"${YOUR_SECURE_GATEWAY_SECURE_TOKEN}"
}'
⚠️ Observation: this file is very sensitive to tabs and space, if you are having problems when running the Message Hub Consumer ensure you have the same file layout as provided on this sample.
${YOUR_SECURE_GATEWAY_HOST_URL} - Check table below, to know what address to use accordingly your region.
| Region | Value |
|---|---|
| US South | https://sgmanager.ng.bluemix.net |
| Sydney | https://sgmanager.eu-gb.bluemix.net |
| United Kingdom | http://sgmanager.au-syd.bluemix.net |
${YOUR_SECURE_GATEWAY_ID} - To get this property access your gateway dashboard and press the engine icon in the top left, value of the gateway ID will be on the popup opened.
${YOUR_SECURE_GATEWAY_SECURE_TOKEN} -At the same popup you have the gateway ID, you also have your secure token on the line marked by the key icon, just press the clipboard icon to copy it.
${YOUR_SECURE_GATEWAY_DESTINATION_ID} - To get the destination use go back to you gateway dashboard and press over the engine icon of your destination. Then, collect the property at the destination id field.
Once you collect all you can update your manifest.yml, it would be something like this:
SGW_CONFIG: '{
"destination-id":"7XdvxXADqW4_PLC",
"api-host":"https://sgmanager.ng.bluemix.net",
"gateway-id":"7XdvxXADqW4_prod_ng",
"sgw-token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maWd1cmF0aW9uX2lkIjoiN1hkdnhYQURxVzRfcHJvZF9uZyIsInJlZ2lvbiI6InVzLXNvdXRoIiwiaWF0IjoxNDc5NDAyNzA4LCJleHAiOjE0ODcxNzg3MDh9.HWCLA-RbJvq3MT0dg-7IHiaA1fdEjXsPZaR9vdVVSKA"
}'
No that you have your connection properties for you secure gateway API, we can update the Manifest File on your Java Message Hub Consumer.
Just need to replace the place holder variables by your SGW_CONFIG properties.
After data you can do a cf push to run your Message Hub Consumer on bluemix or just update your properties via your bluemix console.
If all worked fine, after java app starts to run on your gateway destination at table of the IPs you will see with a new IP that was set by the Java Message Consumer Consumer App.
⚠️ If you already deployed your message hub consumer previously on your account, following pushes will only update the WAR file, so to update theSGW_CONFIGyou will need to go to your bluemix console at the app properties and update this runtime variable and restart your app.
📝 Check our Java Message Hub Consumer code, it has a special Java code to allow it to add itself on the gateway whitelist. As described here.
📚 To learn more about this access: https://console.ng.bluemix.net/docs/services/SecureGateway/sg_023.html#sg_033 https://console.ng.bluemix.net/apidocs/25?&language=node#introduction
If for some reason you want to wipe out the list of IP/Ports from the Secure Gateway restricted list to prevent all servers to access your endpoint you can run the following command:
curl -X DELETE "https://sgmanager.ng.bluemix.net/v1/sgconfig/$GATEWAY_ID/destinations/$Ddestination_id/ipTableRule?all=true"" -H "Authorization: Bearer $SECURE_TOKEN" -H "Content-type: application/json" -d '{"all":true}' -k
#For exmaple
curl -X DELETE "https://sgmanager.ng.bluemix.net/v1/sgconfig/7XdvxXADqW4_prod_ng/destinations/7XdvxXADqW4_PLC/ipTableRule?all=true" -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maWd1cmF0aW9uX2lkIjoiN1hkdnhYQURxVzRfcHJvZF9uZyIsInJlZ2lvbiI6InVzLXNvdXRoIiwiaWF0IjoxNDc5NDAyNzA4LCJleHAiOjE0ODcxNzg3MDh9.HWCLA-RbJvq3MT0dg-7IHiaA1fdEjXsPZaR9vdVVSKA" -H "Content-type: application/json" -d '{"all":true}' -kBy invoking a DELETE call to "https://sgmanager.ng.bluemix.net/v1/sgconfig/$GATEWAY_ID/destinations/$Ddestination_id/ipTableRule" using your Secure Token as the Bearer token with the payload '{"all":true}' you will ask the selected destination to wipe its list of ips. To information used here it is the same one used on step 3, deploying your SecureGatewayAdapter.
https://console.ng.bluemix.net/apidocs/25?&language=node#introduction







