Skip to content

Commit

Permalink
Set default egress IP from ifconfig.me (#454)
Browse files Browse the repository at this point in the history
* Set default egress IP from ifconfig.me

* Try consume attributes
  • Loading branch information
jamilbk committed Feb 12, 2022
1 parent 7588884 commit 70350d4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions omnibus/cookbooks/firezone/recipes/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,26 @@
include_recipe 'line::default'

require 'mixlib/shellout'
require 'net/http'

# Use ip route for finding default egress interface
awk_path = "#{node['firezone']['install_directory']}/embedded/bin/awk"
egress_int_cmd = Mixlib::ShellOut.new("ip route show default 0.0.0.0/0 | grep -oP '(?<=dev ).*' | cut -f1 -d' '")
egress_interface = egress_int_cmd.run_command.stdout.chomp
# Set default endpoint ip to default egress ip
egress_addr_cmd = "ip address show dev #{egress_interface} | grep 'inet ' | #{awk_path} '{print $2}'"
egress_ip = Mixlib::ShellOut.new(egress_addr_cmd)
egress_ip.run_command

node.default['firezone']['wireguard']['endpoint'] ||= egress_ip.stdout.chomp.gsub(%r{/.*}, '')
node.default['firezone']['egress_interface'] = egress_interface
unless node['firezone']['wireguard']['endpoint']
# Figure out a sane default endpoint IP address
egress_ip =
begin
Net::HTTP.get('ifconfig.me', '/')
rescue StandardError
nil
end
node.consume_attributes('firezone' => { 'wireguard' => { 'endpoint' => egress_ip } })
end

unless node['firezone']['egress_interface']
node.consume_attributes('firezone' => { 'egress_interface' => egress_interface })
end

replace_or_add 'IPv4 packet forwarding' do
path '/etc/sysctl.conf'
Expand Down

0 comments on commit 70350d4

Please sign in to comment.