-
Notifications
You must be signed in to change notification settings - Fork 2
nftables formula #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tacerus
wants to merge
12
commits into
openSUSE:main
Choose a base branch
from
tacerus:new/nftables
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
nftables formula #61
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
80e10ac
Initialize nftables formula
tacerus 85dd5cb
Use list based nftables rules
tacerus bfb3e8d
Last mako version
tacerus 96573f3
Refactor
tacerus 045bb85
Move logic to macros, improve includes
tacerus 43e488a
Drop mako template
tacerus 1eee500
Support vmaps
tacerus 93886ae
Support maps
tacerus 3240740
Support multiple includes
tacerus 605572e
Make table type optional
tacerus e121717
Support multiple chain jumps
tacerus 730c448
Support counter and log in chains
tacerus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ## Write simple and set variables | ||
| % for variable, contents in config.get('variables', {}).items(): | ||
| define ${variable} = \ | ||
| % if isinstance(contents, str): | ||
| ${contents} | ||
| % elif isinstance(contents, list): | ||
| { | ||
| % for value in contents: | ||
| ${value}, | ||
| % endfor | ||
| } | ||
| % endif | ||
| % endfor | ||
|
|
||
| ## Write tables | ||
| % for table, table_config in config.get('tables', {}).items(): | ||
| table ${table} ${table_config['type']} { | ||
| % for chain, chain_config in table_config.get('chains', {}).items(): | ||
| chain ${chain} { | ||
| % if 'policy' in chain_config: | ||
| policy ${chain_config['policy']} | ||
| % endif | ||
| ## Establish correct rule order based on priority key | ||
| <% | ||
| combined_chain_config = {} | ||
| combined_chain_config.update(chain_config.get('rules', {})) | ||
| combined_chain_config.update(chain_config.get('meta', {})) | ||
| for entry in sorted(combined_chain_config, key=lambda lowentry: combined_chain_config[lowentry].get('priority', 100)): | ||
| combined_chain_config[entry] = combined_chain_config.pop(entry) | ||
| %> | ||
| % for entry, entry_config in combined_chain_config.items(): | ||
| ${entry}${entry_config.get(' action','')} | ||
| % endfor | ||
| } | ||
| % endfor | ||
| } | ||
| % endfor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| {%- from 'nftables/map.jinja' import nft, dir %} | ||
|
|
||
| #nftables_packages: | ||
| # pkg.installed: | ||
| # - pkgs: | ||
| # - nftables-service | ||
|
|
||
| nftables_directory: | ||
| file.directory: | ||
| - name: {{ dir }} | ||
| - makedirs: true | ||
|
|
||
| nftables_config_base: | ||
| file.managed: | ||
| - name: /etc/nftables.conf | ||
| - contents: | | ||
| #!/usr/sbin/nft -f | ||
| include "{{ dir }}/*.conf" | ||
|
|
||
| {%- for category, config in nft.items() %} | ||
|
|
||
| nftables_config_{{ category }}: | ||
| file.managed: | ||
| - name: | ||
| {%- set file = category ~ '.conf' -%} | ||
| {%- if 'priority' in config -%} | ||
| {%- set file = config['priority'] ~ '_' ~ file -%} | ||
| {%- endif -%} | ||
| {{ ' ' ~ dir }}/{{ file }} | ||
| - template: mako | ||
| - source: salt://{{ slspath }}/files/nftables.mako | ||
| - context: | ||
| config: {{ config }} | ||
| {%- endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| {%- set mypillar = salt['pillar.get']('nftables', {}) -%} | ||
| {%- set nft = mypillar.get('config', {}) -%} | ||
| {%- set dir = '/etc/nftables.conf.d/salt' %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| nftables: | ||
| config: | ||
| variables: | ||
| priority: 01 | ||
| variables: | ||
| vpn_ranges: | ||
| - 192.168.0.0/24 | ||
| - 192.168.1.0/24 | ||
| myhost: 192.168.0.1/32 | ||
| tables: | ||
| priority: 02 | ||
| tables: | ||
| inet: | ||
| type: filter | ||
| chains: | ||
| input: | ||
| policy: drop | ||
| rules: | ||
| 'ct state established, related': | ||
| priority: 201 | ||
| action: accept | ||
| 'ct state invalid': | ||
| priority: 202 | ||
| action: drop | ||
| meta: | ||
| 'iif external jump input_external': | ||
| priority: 101 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.