One of the iRules LX projects I’ve been working on is the ability to dynamically open firewall rules based upon a user’s APM Access Session. In this example the user is external trying to access internal server resources but is blocked by AFM’s default firewall policies. The user then logs into an APM policy and upon successful login AFM allows that external user access to internal resources. See the video below for a demo:
iRules do not have direct access to control plane settings. So prior to TMOS 12.1 this wasn’t easily doable without some serious iRule foo around sideband connections. However, with the introduction of iRules LX we can leverage Node.js to help us interact with the control plane via API calls.
So how does it work?
So what does this look like?
Your iRules do not change much except for the addition of the ILX commands:
- ILX::init – invokes the specified node methods
- ILX::call – establishes a communication path from an iRules to the node process
- ILX::notify – sends a message to the specified node method but does not wait for a response
As an example I’ve included the iRule used in the AFM/APM dynamic firewall rule project below:
Notice the ILX::init on line 7 – this is configured with the iRules LX plugin name and the iRules LX extension inside our workspace.
What about Node.js
Next, you provide the Node.js methods your iRule calls in the index.js file
Not too hard and it offers a world of possibilities with the inclusion of NPM modules.
Where’s the rest of the code?
For a complete view of the iRules LX code please visit the Github repository.