feat: add source support #139
Open
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.
Summary
Adds optional source filtering (IP, subnet or "any") to UFW rules created by
ufw-docker
, updates help/usage, and introduces comprehensive test coverage for the new behaviour.Motivation
Users need to restrict allowed traffic to a container by specific source addresses or subnets, not only by destination port/protocol.
It is useful for cases when an application lives behind a proxy (e.g. CloudFlare). I use it with this script:
What’s changed
ufw-docker <list|allow> [docker-instance-id-or-name [source] [port[/tcp|/udp]] [network]]
192.168.1.10
,fd00:cf::42
)192.168.1.0/24
,fd00:cf::/8
)any
ufw route allow proto <tcp|udp> from <SOURCE> to <INSTANCE_IP> [port <PORT>] comment "allow <instance> <SOURCE> <PORT>/<PROTO> [<NETWORK>]"
any
is used as the default when the source is omitted to allow.Implementation note:
source
parameter was added before port to setfrom
and use auto-detection for ports together.Documentation note:
I wrote the Chinese part using a translator, so please do not judge it strictly and check it thoroughly.