Skip to content
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

Setup iptables block for EC2 #234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions modules/profile/manifests/jenkins/agent.pp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@
require => Class[docker],
}

package { 'iptables-persistent':
ensure => 'installed',
}

# docker versions < 19.03.3 don't provide the DOCKER-USER chain
exec { 'setup_docker_iptables_chain':
user => 'root',
unless => '/sbin/iptables -nL DOCKER-USER',
command => '/sbin/iptables -A DOCKER-USER -j RETURN && /sbin/iptables -I FORWARD -j DOCKER-USER && /sbin/iptables -N DOCKER-USER',
before => Exec['setup_iptables_ec2_block_for_docker'],
require => Class[docker],
}

exec { 'setup_iptables_ec2_block_for_docker':
user => 'root',
unless => '/sbin/iptables -nL DOCKER-USER | grep REJECT.*169.254.169.254',
command => '/sbin/iptables --insert DOCKER-USER --destination 169.254.169.254 --jump REJECT',
before => Exec['save_iptables_rule'],
require => Exec['setup_docker_iptables_chain'],
}

exec { 'save_iptables_rule':
user => 'root',
command => '/sbin/iptables-save > /etc/iptables/rules.v4',
require => [Exec['setup_iptables_ec2_block_for_docker'], Package['iptables-persistent']],
}

# required by cleanup_docker script
python::pip { 'docker':
Expand Down