-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add recipe lyraphase_workstation::loopback_alias_ip for re-creating I…
…P alias on lo0 every reboot (For use with Docker for Mac) Use case: Docker container == socks5h:// ==> Alias IP of macOS Host running SSH Tunnel => Bastion Host See diagram: https://gist.github.com/trinitronx/6427d6454fb3b121fc2ab5ca7ac766bc References: - [user-defined networks](https://docs.docker.com/network/bridge/##differences-between-user-defined-bridges-and-the-default-bridge) - [Docker forum thread: Connecting docker container to macOS Host](https://forums.docker.com/t/accessing-host-machine-from-within-docker-container/14248/13) - [Terraform enhancement request for SOCKS5h support and Explanation of Use Case](hashicorp/terraform#17754 (comment))
- Loading branch information
1 parent
298037c
commit c980c68
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
default['lyraphase_workstation']['loopback_alias_ip'] = {} | ||
default['lyraphase_workstation']['loopback_alias_ip']['alias_ip'] = '172.16.222.111' |
This file contains 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,37 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2018 James Cuzella | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
|
||
loopback_alias_ip = nil | ||
if ! node['lyraphase_workstation']['loopback_alias_ip'].nil? && ! node['lyraphase_workstation']['loopback_alias_ip']['alias_ip'].nil? | ||
loopback_alias_ip = node['lyraphase_workstation']['loopback_alias_ip']['alias_ip'] | ||
end | ||
|
||
template "/Library/LaunchDaemons/com.runlevel1.lo0.alias.plist" do | ||
source "com.runlevel1.lo0.alias.plist.erb" | ||
user "root" | ||
group "wheel" | ||
mode "0644" | ||
variables({ loopback_alias_ip: loopback_alias_ip }) | ||
notifies :run, 'execute[load the com.runlevel1.lo0.alias plist into launchd]' | ||
end | ||
|
||
execute "load the com.runlevel1.lo0.alias plist into launchd" do | ||
command "launchctl load -w /Library/LaunchDaemons/com.runlevel1.lo0.alias.plist" | ||
user node['lyraphase_workstation']['user'] | ||
not_if 'launchctl list com.runlevel1.lo0.alias' | ||
end |
This file contains 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,61 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2018 James Cuzella | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
require 'spec_helper' | ||
|
||
describe 'lyraphase_workstation::loopback_alias_ip' do | ||
|
||
let(:launchd_plist) { "/Library/LaunchDaemons/com.runlevel1.lo0.alias.plist" } | ||
let(:loopback_alias_ip) { '172.16.222.111' } | ||
|
||
let(:chef_run) { | ||
klass = ChefSpec.constants.include?(:SoloRunner) ? ChefSpec::SoloRunner : ChefSpec::Runner | ||
klass.new(platform: 'mac_os_x', version: '10.11.1') do |node| | ||
create_singleton_struct "EtcPasswd", [ :name, :passwd, :uid, :gid, :gecos, :dir, :shell, :change, :uclass, :expire ] | ||
node.normal['etc']['passwd']['brubble'] = Struct::EtcPasswd.new('brubble', '********', 501, 20, 'Barney Rubble', '/Users/brubble', '/bin/bash', 0, '', 0) | ||
node.normal['lyraphase_workstation']['user'] = 'brubble' | ||
node.normal['lyraphase_workstation']['home'] = '/Users/brubble' | ||
|
||
stub_command("which git").and_return('/usr/local/bin/git') | ||
|
||
stub_command('launchctl list com.runlevel1.lo0.alias').and_return(true) | ||
end.converge(described_recipe) | ||
} | ||
|
||
it 'installs launchd plist for adding IP alias to loopback network interface lo0' do | ||
expect(chef_run).to create_template(launchd_plist).with( | ||
user: 'root', | ||
group: 'wheel', | ||
mode: '0644' | ||
) | ||
expect(chef_run).to render_file(launchd_plist).with_content(Regexp.new("^\\s+<string>/sbin/ifconfig</string>$")) | ||
expect(chef_run).to render_file(launchd_plist).with_content(Regexp.new("^\\s+<string>#{loopback_alias_ip}</string>$")) | ||
|
||
expect(chef_run.template(launchd_plist)).to notify('execute[load the com.runlevel1.lo0.alias plist into launchd]').to(:run) | ||
end | ||
|
||
context "when launchd plist is already loaded" do | ||
before(:all) do | ||
stub_command('launchctl list com.runlevel1.lo0.alias').and_return(true) | ||
end | ||
|
||
it "skips loading com.runlevel1.lo0.alias launchd plist file" do | ||
expect(chef_run.execute('load the com.runlevel1.lo0.alias plist into launchd')).to do_nothing | ||
end | ||
end | ||
end | ||
|
This file contains 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,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Label</key> | ||
<string>com.runlevel1.lo0.alias</string> | ||
<key>RunAtLoad</key> | ||
<true/> | ||
<key>ProgramArguments</key> | ||
<array> | ||
<string>/sbin/ifconfig</string> | ||
<string>lo0</string> | ||
<string>alias</string> | ||
<string><%= @loopback_alias_ip %></string> | ||
<string>up</string> | ||
</array> | ||
<key>StandardErrorPath</key> | ||
<string>/var/log/loopback-alias.log</string> | ||
<key>StandardOutPath</key> | ||
<string>/var/log/loopback-alias.log</string> | ||
<key>UserName</key> | ||
<string>root</string> | ||
</dict> | ||
</plist> |