-
Notifications
You must be signed in to change notification settings - Fork 2
Add iptables to http-proxy docker images #658
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
Open
AGMETEOR
wants to merge
10
commits into
main
Choose a base branch
from
iptables-in-docker
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c7c060f
Add iptables to http-proxy docker images
AGMETEOR 611aefe
Add servermasq set up script
AGMETEOR 53cb841
Add servermasq set up script comment
AGMETEOR 4e0dd49
.
AGMETEOR bbc9046
Fix permissions for iptables
AGMETEOR 2cd8a3a
Fix permissions for iptables
AGMETEOR c147d5e
Fix iptables commands
AGMETEOR 80c44cd
Fix perms
AGMETEOR 22275da
Fix servermasq rules
AGMETEOR 53780c4
Fix typo
AGMETEOR 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
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,49 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| echo "[+] Setting up LANTERN_SERVERMASQ iptables chain..." | ||
|
|
||
| PROXY_ADDR=$(hostname -i | awk '{print $1}') | ||
|
|
||
| if [ -z "$PROXY_ADDR" ] || [ -z "$PROXY_PORT" ] || [ -z "$MASQ_ADDR" ]; then | ||
| echo "[~] Required environment variables not set, skipping iptables setup" | ||
| exec "$@" | ||
| fi | ||
|
|
||
| # The iptables rules can be explained as follows: | ||
| # 1. Create a new chain called LANTERN_SERVERMASQ. | ||
| # 2. Add a rule to the LANTERN_SERVERMASQ chain that matches packets destined for the proxy address | ||
| # (PROXY_ADDR) that are not destined for the proxy port (PROXY_PORT), and redirects them to the MASQ_ADDR. | ||
| # It is important to understand the context in which this docker container is running and this determines the | ||
| # value of PROXY_ADDR. PROXY_ADDR is the container's internal IP address. See flow of traffic below: | ||
|
|
||
| # [ External Client (public internet) ] | ||
| # | | ||
| # v | ||
| # [ Public IP of cloud provider ] | ||
| # | | ||
| # (NAT to private IP) | ||
| # | | ||
| # v | ||
| # [ VM Private IP (e.g., 10.52.x.x) ] | ||
| # | | ||
| # (Host port → Container port binding) | ||
| # | | ||
| # (Docker NAT to container IP) | ||
| # | | ||
| # v | ||
| # [ Docker Container IP (e.g., 172.17.x.x) ] | ||
|
|
||
| # 3. Add a rule to the PREROUTING chain that matches packets destined for the proxy address (PROXY_ADDR) | ||
| # and redirects them to the LANTERN_SERVERMASQ chain. | ||
| # 4. Add a rule to the POSTROUTING chain that matches packets destined for the MASQ_ADDR and masquerades them in order for responses to be sent back correctly to container. | ||
|
|
||
| iptables -t nat -N LANTERN_SERVERMASQ 2>/dev/null || true | ||
| iptables -t nat -F LANTERN_SERVERMASQ 2>/dev/null || true | ||
|
|
||
| iptables -t nat -A LANTERN_SERVERMASQ -d "$PROXY_ADDR" -p tcp ! --dport "$PROXY_PORT" -j DNAT --to-destination "$MASQ_ADDR" | ||
| iptables -t nat -A PREROUTING -d "$PROXY_ADDR" -j LANTERN_SERVERMASQ | ||
| iptables -t nat -A POSTROUTING -d "$MASQ_ADDR" -j MASQUERADE | ||
|
|
||
| echo "[+] LANTERN_SERVERMASQ setup complete: $@" | ||
| exec su-exec lantern "$@" |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining why
iptablesis required in this image to help future maintainers understand this dependency.