Block docker access to specific IP

MattyB

I'd like my EC2 instance to have IAM-based permissions, but don't want the docker containers on that instance to have the same permissions. I believe it should be sufficient to block access to the magic IP 169.254.169.254. Is it sufficient to run: iptables -I DOCKER -s 169.254.169.254 -j DROP

Do I also need to configure my docker daemon with --icc=false or --iptables=false?

fotinakis

Finally got this working, you need to add this rule on the host machine:

1) Drop docker bridge packets when outbound to 169.254.169.254 port 80 or 443.

sudo iptables -I FORWARD -i docker0 -d 169.254.169.254 \
  -p tcp -m multiport --dports 80,443 -j DROP

Now, if I try to connect inside the container:

$ sudo docker run -it ubuntu bash
root@8dc525dc5a04:/# curl -I https://www.google.com
HTTP/1.1 200 OK
root@8dc525dc5a04:/# curl -I http://169.254.169.254/
  # <-- hangs indefinitely, which is what we want

Connections to the special IP still work from the host machine, but not from inside containers.

Note: my use case is for Google Compute Engine and prevents Docker containers from accessing the metadata server on 169.254.169.254, while still allowing DNS and other queries against that same IP. Your mileage may vary on AWS.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Block Docker port and access it to few IP addresses

From Dev

Limit Network access but allow a specific IP for a Running Docker Container

From Dev

Block Ping from a specific IP

From Dev

Block write access in a specific folder

From Dev

Block the access of specific! USB devices

From Dev

block ip addresses that request a specific url

From Dev

Firewall to block traffic to a specific IP - troubleshoot

From Dev

How to access guest IP in docker

From Dev

How to block access by IP using .htaccess

From Dev

IIS | Block page specific url except for specific internal IP address

From Dev

block device access on windows docker tool box

From Dev

Restrict Schema Access to Specific IP Address in oracle

From Dev

Restrict access to specific IP in Play Framework (Scala)

From Dev

Allow MongoDB remote access for specific IP

From Dev

Restrict SSH Access to Specific IP for User

From Dev

Restrict SSH Access to Specific IP for User

From Dev

Restrict Schema Access to Specific IP Address in oracle

From Dev

htaccess: file access for specific ip only

From Dev

Limit SSH access to specific clients by IP address

From Dev

How do you block specific IP adress in Ruby on Rails

From Dev

Block certain link on website for a specific IP range using .htaccess

From Dev

Using Windows Firewall to block a specific IP on Windows 10

From Dev

Block website users if their IP address resolves to a specific domain

From Dev

How I can block specific IP's using iptables?

From Dev

iptables block access to all ports except from a partial IP address

From Dev

How to block access to sub-domain by IP address

From Dev

Modem/router seems to block access to NAS box with static IP?

From Dev

Block access from IP address in Apache2

From Dev

Block access to an ip and port using iptables on my routers

Related Related

  1. 1

    Block Docker port and access it to few IP addresses

  2. 2

    Limit Network access but allow a specific IP for a Running Docker Container

  3. 3

    Block Ping from a specific IP

  4. 4

    Block write access in a specific folder

  5. 5

    Block the access of specific! USB devices

  6. 6

    block ip addresses that request a specific url

  7. 7

    Firewall to block traffic to a specific IP - troubleshoot

  8. 8

    How to access guest IP in docker

  9. 9

    How to block access by IP using .htaccess

  10. 10

    IIS | Block page specific url except for specific internal IP address

  11. 11

    block device access on windows docker tool box

  12. 12

    Restrict Schema Access to Specific IP Address in oracle

  13. 13

    Restrict access to specific IP in Play Framework (Scala)

  14. 14

    Allow MongoDB remote access for specific IP

  15. 15

    Restrict SSH Access to Specific IP for User

  16. 16

    Restrict SSH Access to Specific IP for User

  17. 17

    Restrict Schema Access to Specific IP Address in oracle

  18. 18

    htaccess: file access for specific ip only

  19. 19

    Limit SSH access to specific clients by IP address

  20. 20

    How do you block specific IP adress in Ruby on Rails

  21. 21

    Block certain link on website for a specific IP range using .htaccess

  22. 22

    Using Windows Firewall to block a specific IP on Windows 10

  23. 23

    Block website users if their IP address resolves to a specific domain

  24. 24

    How I can block specific IP's using iptables?

  25. 25

    iptables block access to all ports except from a partial IP address

  26. 26

    How to block access to sub-domain by IP address

  27. 27

    Modem/router seems to block access to NAS box with static IP?

  28. 28

    Block access from IP address in Apache2

  29. 29

    Block access to an ip and port using iptables on my routers

HotTag

Archive