Go NFTables Manager is a Golang project that automates and manages nftables
rules based on services registered in Consul. It retrieves the list of services from Consul and applies predefined firewall rules using nftables.
nftables
based on the retrieved servicesnftables
sets for different environments (metrics, backups, app, logs)Consul
API calls in case of failuresnftables
packageGo
programming language (version 1.20 or later)nftables
installed on the systemConsul
server running and accessibleClone the repository:
git clone https://github.com/siddarthkay/go-nftables-manager.git
Change to the project directory:
cd go-nftables-manager
Build the project:
go build
The project uses the following constants for configuration:
consulAddress
: The address of the Consul server (default: "http://localhost:8500")serviceName
: The name of the service to fetch from Consul (default: "wireguard")envValues
: An array of environment values (default: ["metrics", "logs", "backups", "app"])stageValues
: An array of stage values (default: ["prod", "test"])You can modify these constants in the main.go
file to match your specific setup.
Ensure that the Consul server is running and accessible.
Run the project:
./go-nftables-manager
The project will fetch the services from Consul based on the configured service name and filter criteria, and apply the corresponding firewall rules using nftables.
Check the logs for any errors or success messages.
The project includes a test suite for the nftables
package.
You can preview the generated rules by running the TestGenerateRulesFile
like this :
go test -run TestGenerateRulesFile ./nftables
This will generate a nftables.rules
file in the current directory.
You can then test applying those rules via the TestUpdateFirewallRules
like this :
go test -run TestUpdateFirewallRules ./nftables
The tests use a sample services.json
file located in the testdata
directory to simulate the services retrieved from Consul.
Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request.
This project is licensed under the MIT License.
For any questions or inquiries, please contact siddarthkay@gmail.com.