File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/sbin/nft -f
2+
3+ flush ruleset
4+
5+ table inet imds_protection {
6+ chain output {
7+ type filter hook output priority 0; policy accept;
8+
9+ # Allow root to access IMDS
10+ meta skuid 0 ip daddr 169.254.169.254 accept
11+ meta skuid 0 ip6 daddr fd00:ec2::254 accept
12+
13+ # Block all other users from accessing IMDS
14+ ip daddr 169.254.169.254 drop
15+ ip6 daddr fd00:ec2::254 drop
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ [Unit]
2+ Description =Block non-root access to EC2 instance metadata
3+ DefaultDependencies =no
4+ Before =network-pre.target
5+ Wants =network-pre.target
6+
7+ [Service]
8+ Type =oneshot
9+ ExecStart =/bin/sh -c ' grep -qi amazon /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null && nft -f /etc/nftables.conf || true'
10+
11+ [Install]
12+ WantedBy =multi-user.target
Original file line number Diff line number Diff line change @@ -112,4 +112,11 @@ usermod --append --groups cert_readers prometheus
112112echo " [setup_base.sh] Restricting su to sudo group..."
113113echo -e ' \nauth required pam_wheel.so group=sudo\n' | tee -a /etc/pam.d/su
114114
115+ echo " === [setup_base.sh] Setting up IMDS protection ==="
116+
117+ apt-get install -y nftables
118+ cp /tmp/common/assets/imds-protection.nftables.conf /etc/nftables.conf
119+ cp /tmp/common/assets/imds-protection.service /etc/systemd/system/imds-protection.service
120+ systemctl enable imds-protection.service
121+
115122echo " === [setup_base.sh] Complete ==="
You can’t perform that action at this time.
0 commit comments