Simulates connectivity failures in a controlled manner
491
Caltrops is an application for simulating connectivity failures in a controlled manner- by allowing external management of iptables rules around proxy connections between software client/edge and server/platform.
The Caltrops application runs in a container alongside instances of the Squid proxy server, and legacy iptables. Web endpoints are exposed using flask to allow iptables rules to be managed via requested issued from a command-line application like curl or wget, or with your REST library of choice, and test how your client/edge and/or server/platform reacts to varieties of connectivity loss.
By default, 20 ports (13128 through 13148, inclusive) are served by the squid instance for client connections. The intention is that one application connection policy should be used per proxy port on caltrops. An implication of this is that the iptables rule ordering should not affect connectivity for a client/edge application.
The client/edge device must support proxy connections with basic authentication.
Developed for testing IoT connectivity- specifically when operating virtual ThingWorx IoT Edge aircraft in project thingworx-flightgear-edge
Caltrops can run standalone as a python application, but is intended to run in a docker container.
Retrieve the container from docker hub:
docker pull jas0ndiamond/caltrops
Start Caltrops by executing:
docker run --name jas0ndiamond/caltrops --privileged=true -p 15000:15000
If Caltrops expects to handle external traffic, the proxy ports must also be published when running the container:
docker pull jas0ndiamond/caltrops
docker run --name jas0ndiamond/caltrops --privileged=true -p 15000:15000 -p 13128-13148:13128-13148
Caltrops must be run in privileged mode. This is required by iptables.
The Caltrops UI is available at http://caltrops_host:15000, which will display a simple readout of the iptables rules in place.
Connect your device to the proxy port. The default target for the proxy ports is ACCEPT, so a connection attempt should succeed. The proxy is configured by default with Basic auth in the Dockerfile, with user myproxyuser, and password myproxypass
Connections through caltrops can also be tested with curl:
curl -i --proxy "http://myproxyuser:myproxypass@caltrops_host:13128" "https://www.github.com"
Affect the traffic judgments of the ports by issuing the following REST requests.
For inbound traffic, specifically traffic originating from the client to Caltrops, use the following endpoints:
For example, to DROP traffic inbound from the client connected to caltrops on port 13131, the relevant rule can be set either with the following curl command, or with your REST library of choice:
curl -i "http://caltrops_host:15000/drop_inbound?port=13131"
An HTTP 200 will be returned on success, with field change set accordingly:
SUCCESS - the rule changed was successfully appliedSKIP - the rule was successfully determined to not need changing (i.e. attempting to apply an ACCEPT target to a rule already with an ACCEPT target)FAIL - the rule change failed, likely due to an invalid/malformed port, or a port not served by the underlying squid instance.An HTTP 500 will be returned on an internal failure. Please report instances of this.
For outbound traffic, specifically traffic originating from the server to Caltrops, use the following endpoints:
For example, to REJECT traffic inbound from the client connected to caltrops on port 13131, the relevant rule can be set either with the following curl command, or with your REST library of choice:
curl -i "http://caltrops_host:15000/reject_outbound?port=13131"
An HTTP 200 will be returned on success, with field change set accordingly:
SUCCESS - the rule changed was successfully appliedSKIP - the rule was successfully determined to not need changing (i.e. attempting to apply an ACCEPT target to a rule already with an ACCEPT target)FAIL - the rule change failed, likely due to an invalid/malformed port, or a port not served by the underlying squid instance.An HTTP 500 will be returned on an internal failure. Please report instances of this.
Rules can be reset to the startup default by issuing a request to http://caltrops_host:15000/reset_rules
The default proxy ports can be changed by modifying the container's squid config file, and the caltrops.py python application. Ensure that the new port range is published when the container is run.
Basic tests can be executed from the project root directory by running:
#ensure your caltrops container is running first!
python3 -m unittest test/caltrops_test.py
docker pull jas0ndiamond/caltrops:latest