forked from resmo/nip.io
-
Notifications
You must be signed in to change notification settings - Fork 1
Limit access to target IPs to IP ranges of EC2 servers #1
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
mfittko
wants to merge
54
commits into
mfittko:master
Choose a base branch
from
sofatutor:master
base: master
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
54 commits
Select commit
Hold shift + click to select a range
8031dc8
add whitelist, docker-compose
mfittko 6d85d80
add preview
mfittko ea89c49
trigger workflow
mfittko b40d48f
trigger workflow
mfittko eaeb17a
master
mfittko 128576f
on master yeah
mfittko 2e92ff0
use previews.sofatutor.de
mfittko a3a6b96
use remote IP
mfittko fb6b476
update IP
mfittko a1ef09a
apply whitelist
mfittko 3a2477c
Revert "apply whitelist"
mfittko d2cc54d
Update README.md
mfittko 55adc3f
Update backend.conf.example
mfittko 06af284
Update backend.conf.example
mfittko 253eeb1
Merge branch 'master' into master
mfittko 5d88fa3
add dev container and related config
mfittko db3d126
add required changes values from upstream
mfittko 5668e97
Merge remote-tracking branch 'origin/master'
mfittko b44476d
update preview action
mfittko 4647bad
use preview action again
mfittko a909bba
Revert "use preview action again"
mfittko acba55f
change dns
mfittko 275c4e7
parameterize DOMAIN and IP
mfittko b418550
use sofatutor version again
mfittko 1c67b5e
add gitignore
mfittko c93e0b2
pass in IP and DOMAIN
mfittko ca34edf
pass in DOMAIN directly
mfittko 3bf75ed
use owner name
mfittko 8f4ed15
pin ubuntu version
mfittko e924c2c
update from branch
mfittko 29609b9
fix www cname
mfittko a170c6f
always restart
mfittko 88bdfc5
add cleanup action
mfittko 28442d0
use env var for DNS domain
mfittko 614571f
add config for previews
mfittko 3632c4b
use PULLPREVIEW_ENV_VARS
mfittko 3b9ca3a
fix yml
mfittko 5ddd26d
default to env
mfittko b4bc974
fix
mfittko f26eda9
revert
mfittko 1366b09
try protection rule
mfittko 9f8587d
use env var again
mfittko 5d90fbf
parameterize sofatutor dns
mfittko e8c43cf
Merge remote-tracking branch 'origin/master' into sofatutor
mfittko c5e23bb
try default
mfittko d2dc6cd
use top level env
mfittko a95141c
set explicitly
mfittko 9679f6c
enable debugging
mfittko 2d942fc
parameterize nameserver subdomain
mfittko 732e8e7
pass in ID instead
mfittko ad0def2
re-order args
mfittko fb9dac0
add dnstools
mfittko 3e344d8
Merge remote-tracking branch 'origin/master'
mfittko f819deb
implement whitelist check
mfittko 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,35 @@ | ||
| # Use Ubuntu 22.04 as the base image | ||
| FROM ubuntu:22.04 | ||
|
|
||
| # Set environment variables | ||
| ENV DEBIAN_FRONTEND=noninteractive | ||
|
|
||
| # Update the package index and install common dependencies | ||
| RUN apt-get update && apt-get install -y \ | ||
| build-essential \ | ||
| curl \ | ||
| git \ | ||
| vim \ | ||
| python3 \ | ||
| python3-dev \ | ||
| python3-pip \ | ||
| zsh \ | ||
| awscli \ | ||
| software-properties-common \ | ||
| dnsutils | ||
|
|
||
| # Install starship prompt | ||
| RUN sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- --force \ | ||
| && echo 'eval "$(starship init zsh)"' >> /root/.zshrc \ | ||
| && mkdir -p /root/.config | ||
|
|
||
| COPY starship.toml /root/.config/ | ||
|
|
||
| # Install docker | ||
| RUN curl -fsSL https://get.docker.com | sh | ||
|
|
||
| # Add environment variable for the prompt | ||
| ENV SHELL /usr/bin/zsh | ||
|
|
||
| # Set the default command to start a ZSH shell | ||
| CMD ["zsh"] |
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,21 @@ | ||
| { | ||
| "name": "PowerDNS Python Backend Dev Container", | ||
| "dockerFile": "Dockerfile", | ||
| "extensions": [ | ||
| "ms-python.python", | ||
| "amazonwebservices.aws-toolkit-vscode", | ||
| "ms-python.pylance-release", | ||
| "ms-python.vscode-pylance", | ||
| "gmemstr.cloudformation", | ||
| "ms-python.python-testing", | ||
| "ms-python.linting-flake8", | ||
| "ms-vsliveshare.vsliveshare", | ||
| ], | ||
| "mounts": [ | ||
| "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" | ||
| ], | ||
| "postCreateCommand": "apt-get update && apt-get install -y git && ( curl -fsSL https://get.docker.com | sh )", | ||
| "remoteEnv": { | ||
| "GIT_SSL_NO_VERIFY": "1" | ||
| } | ||
| } |
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,4 @@ | ||
| format = "🐳 $all" | ||
|
|
||
| [container] | ||
| disabled = true |
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,2 @@ | ||
| .git | ||
| .github |
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,43 @@ | ||
| name: preview | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - sofatutor | ||
| pull_request: | ||
| types: [labeled, unlabeled, synchronize, closed, reopened] | ||
|
|
||
| env: | ||
| DNS: 'p.sofatutor-sandbox.de' | ||
| ID: '1' | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-22.04 | ||
| if: github.event_name == 'push' || github.event.label.name == 'preview' || contains(github.event.pull_request.labels.*.name, 'preview') | ||
| timeout-minutes: 10 | ||
|
|
||
| steps: | ||
| - name: Optionally override DNS | ||
| run: | | ||
| SOFATUTOR_DNS="${{ vars.SOFATUTOR_DNS }}" | ||
| if [[ $GITHUB_REF == 'refs/heads/sofatutor' && -n "$SOFATUTOR_DNS" ]]; then | ||
| echo "DNS=$SOFATUTOR_DNS" >> "$GITHUB_ENV" | ||
| fi | ||
| - uses: actions/checkout@v2 | ||
| - uses: sofatutor/pullpreview@sofatutor | ||
| with: | ||
| admins: mfittko | ||
| always_on: master,sofatutor | ||
| app_path: . | ||
| instance_type: nano_2_0 | ||
| dns: ${{env.DNS}} | ||
| ports: 53/tcp,53/udp | ||
| registries: docker://index.docker.io/v1 | ||
| compose_files: docker-compose.yml | ||
| env: | ||
| AWS_REGION: eu-central-1 | ||
| PULLPREVIEW_ENV_VARS: IP="$(ec2-metadata | grep public-ipv4 | cut -d ' ' -f2)",DOMAIN=${{ env.DNS }},ID=${{ env.ID }} | ||
| PULLPREVIEW_LAUNCH_COMMAND: docker-compose up -d --build --force-recreate | ||
| AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" | ||
| AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" |
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,18 @@ | ||
| name: Preview Cleanup | ||
| on: | ||
| pull_request: | ||
| types: [unlabeled, closed] | ||
|
|
||
| jobs: | ||
| destroy: | ||
| if: github.event.label.name == 'preview' || contains(github.event.pull_request.labels.*.name, 'preview') | ||
| name: Destroy | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 60 | ||
| steps: | ||
| - uses: sofatutor/pullpreview@sofatutor | ||
| continue-on-error: true | ||
| env: | ||
| AWS_ACCESS_KEY_ID: "${{ secrets.AWS_ACCESS_KEY_ID }}" | ||
| AWS_SECRET_ACCESS_KEY: "${{ secrets.AWS_SECRET_ACCESS_KEY }}" | ||
| AWS_REGION: "eu-central-1" |
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 |
|---|---|---|
| @@ -1,9 +1,19 @@ | ||
| FROM bitnami/minideb:latest | ||
|
|
||
| RUN install_packages python pdns-server pdns-backend-pipe | ||
| ADD src/backend.conf.example /usr/local/bin/backend.conf | ||
| RUN install_packages python pdns-server pdns-backend-pipe curl jq gettext | ||
|
|
||
| ARG ID=${ID:-1} | ||
| ARG IP=${IP:-127.0.0.1} | ||
| ARG DOMAIN=${DOMAIN:-example.com} | ||
|
|
||
| ADD src/backend.conf.example /var/ | ||
| ADD src/nip.py /usr/local/bin/nip | ||
| ADD docker/pdns.conf /etc/pdns/pdns.conf | ||
| ADD src/add_ec2_ip_ranges.sh /usr/local/bin/ | ||
|
|
||
| EXPOSE 53/udp 53/tcp | ||
|
|
||
| COPY src/entrypoint.sh /usr/local/bin/entrypoint | ||
| RUN chmod +x /usr/local/bin/entrypoint | ||
| ENTRYPOINT ["entrypoint"] | ||
| CMD ["pdns_server", "--master", "--daemon=no", "--local-address=0.0.0.0", "--config-dir=/etc/pdns/"] |
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,15 @@ | ||
| version: '3.6' | ||
|
|
||
| services: | ||
| nipio: | ||
| container_name: nipio | ||
| build: | ||
| context: . | ||
| restart: always | ||
| environment: | ||
| ID: "${ID:-1}" | ||
| IP: "${IP:-127.0.0.1}" | ||
| DOMAIN: "${DOMAIN:-example.com}" | ||
| ports: | ||
| - "53:53/udp" | ||
| - "53:53/tcp" |
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,10 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| ip_ranges=($(curl -sk https://ip-ranges.amazonaws.com/ip-ranges.json | jq -c '.prefixes[] | select(.region=="eu-central-1" and .ip_prefix and .service == "EC2") | .ip_prefix')) | ||
| whitelist=$(for i in "${!ip_ranges[@]}"; do echo "ec2_eu_central_1_$i = ${ip_ranges[$i]}"; done | sed 's/"//g') | ||
|
|
||
| if [ -f /usr/local/bin/backend.conf ]; then | ||
| echo "$whitelist" >> /usr/local/bin/backend.conf | ||
| else | ||
| echo "$whitelist" | ||
| fi | ||
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 |
|---|---|---|
| @@ -1,32 +1,36 @@ | ||
| [main] | ||
| # main domain | ||
| domain=example.com | ||
| domain=$DOMAIN | ||
|
|
||
| # default ttl | ||
| ttl=432000 | ||
|
|
||
| # default IP address for non-wildcard entries | ||
| ipaddress=127.0.0.1 | ||
|
|
||
| ipaddress=$IP | ||
|
|
||
| # SOA | ||
| [soa] | ||
| # serial number | ||
| id=1 | ||
| id=$ID | ||
| # Hostmaster email address | ||
| hostmaster=hostmaster@example.com | ||
| hostmaster=hostmaster@$DOMAIN | ||
| # Name server | ||
| ns=ns1.example.com | ||
| ns=ns$ID.$DOMAIN | ||
| refresh=10800 | ||
| retry=3600 | ||
| expire=604800 | ||
| minimum=3600 | ||
|
|
||
| # nameservers | ||
| [nameservers] | ||
| ns1.example.com=127.0.0.1 | ||
| ns2.example.com=127.0.0.1 | ||
| ns$ID.$DOMAIN=$IP | ||
|
|
||
| [additional_cnames] | ||
| _acme-challenge=xyz.auth.example.com. | ||
| www=business.example.com | ||
| _acme-challenge=xyz.auth.$DOMAIN. | ||
| www=www.$DOMAIN. | ||
|
|
||
| [whitelist] | ||
| loopback = 127.0.0.0/8 | ||
| private_net_10 = 10.0.0.0/8 | ||
| private_net_172_16 = 172.16.0.0/12 | ||
| private_net_192_168 = 192.168.0.0/16 |
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,4 @@ | ||
| #!/bin/bash | ||
| envsubst < /var/backend.conf.example > /usr/local/bin/backend.conf # replace config placeholders with env vars | ||
| add_ec2_ip_ranges.sh # add ec2 ip addresses to whitelist section | ||
| "$1" "${@:2}" |
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
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.
use $AWS_REGION env variable. make sure it's available here.