vagrant-proxyconf 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,47 @@
1
+ FROM centos:7
2
+
3
+ ENV CI_USERNAME vagrant
4
+ ENV CI_PASSWORD vagrant
5
+ ENV CI_HOMEDIR /home/vagrant
6
+ ENV CI_SHELL /bin/bash
7
+
8
+ EXPOSE 8888
9
+
10
+ RUN yum clean all && \
11
+ yum makecache fast && \
12
+ yum -y install epel-release && \
13
+ yum clean expire-cache && \
14
+ yum -y install \
15
+ curl \
16
+ initscripts \
17
+ openssh-clients \
18
+ openssh-server \
19
+ sudo \
20
+ tinyproxy
21
+
22
+ RUN /usr/sbin/sshd-keygen && \
23
+ mkdir -p /var/run/sshd && \
24
+ rm -f /usr/lib/tmpfiles.d/systemd-nologin.conf
25
+
26
+ RUN if ! getent passwd $CI_USERNAME; then \
27
+ useradd -m -d ${CI_HOMEDIR} -s ${CI_SHELL} $CI_USERNAME; \
28
+ fi && \
29
+ echo "${CI_USERNAME}:${CI_PASSWORD}" | chpasswd && \
30
+ echo "${CI_USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
31
+ mkdir -p /etc/sudoers.d && \
32
+ echo "${CI_USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/${CI_USERNAME} && \
33
+ chmod 0440 /etc/sudoers.d/${CI_USERNAME} && \
34
+ mkdir -p ${CI_HOMEDIR}/.ssh && \
35
+ chown -R ${CI_USERNAME}:${CI_USERNAME} ${CI_HOMEDIR}/.ssh && \
36
+ chmod 0700 ${CI_HOMEDIR}/.ssh && \
37
+ curl -L https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub > ${CI_HOMEDIR}/.ssh/vagrant.pub && \
38
+ touch ${CI_HOMEDIR}/.ssh/authorized_keys && \
39
+ grep -q "$(cat ${CI_HOMEDIR}/.ssh/vagrant.pub | awk '{print $2}')" ${CI_HOMEDIR}/.ssh/authorized_keys || cat ${CI_HOMEDIR}/.ssh/vagrant.pub >> ${CI_HOMEDIR}/.ssh/authorized_keys && \
40
+ chown ${CI_USERNAME}:${CI_USERNAME} ${CI_HOMEDIR}/.ssh/authorized_keys && \
41
+ chmod 0600 ${CI_HOMEDIR}/.ssh/authorized_keys
42
+
43
+ COPY tinyproxy.conf /etc/tinyproxy/tinyproxy.conf
44
+ COPY entrypoint.sh /entrypoint.sh
45
+
46
+ ENTRYPOINT ["/entrypoint.sh"]
47
+ CMD [ "start" ]
@@ -0,0 +1,31 @@
1
+ Tests
2
+ -----
3
+
4
+ If you are testing the current release of this plugin via bundler
5
+
6
+ ```
7
+ bundle exec vagrant up default
8
+ ```
9
+
10
+ ## Expect
11
+
12
+
13
+ ### Box `default`
14
+
15
+ - The box `default` is a docker container that will be a reverse
16
+ proxy. It should provision itself and work without errors.
17
+
18
+ - You can check that the proxy is working by
19
+ `tail -f /var/log/tinyproxy/tinyproxy.log` inside the container
20
+
21
+ - **NOTE**: You'll need to use `docker exec <hash> -it bash` to get into the container
22
+
23
+
24
+ ### Box `apt_host`
25
+
26
+ - Vagrant should automatically instally docker-ce.
27
+ - The box should come up and provision itself with the proxy settings
28
+ configured in your Vagrantfile.
29
+
30
+
31
+ - **NOTE**: You can use `ssh` to connect to this container.
@@ -0,0 +1,27 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :spec => 'spec:all'
5
+ task :default => :spec
6
+
7
+ namespace :spec do
8
+ targets = []
9
+ Dir.glob('./spec/*').each do |dir|
10
+ next unless File.directory?(dir)
11
+ target = File.basename(dir)
12
+ target = "_#{target}" if target == "default"
13
+ targets << target
14
+ end
15
+
16
+ task :all => targets
17
+ task :default => :all
18
+
19
+ targets.each do |target|
20
+ original_target = target == "_default" ? target[1..-1] : target
21
+ desc "Run serverspec tests to #{original_target}"
22
+ RSpec::Core::RakeTask.new(target.to_sym) do |t|
23
+ ENV['TARGET_HOST'] = original_target
24
+ t.pattern = "spec/#{original_target}/*_spec.rb"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,74 @@
1
+ # this should be the IP address of the :default box
2
+ $PROXY_HOST ="10.0.2.2"
3
+ $PROXY_PORT="8888"
4
+ $PROXY_NO_PROXY=[
5
+ 'localhost',
6
+ ]
7
+
8
+ ENV['HTTP_PROXY'] = ENV.fetch('HTTP_PROXY', "http://#{$PROXY_HOST}:#{$PROXY_PORT}")
9
+ ENV['HTTPS_PROXY'] = ENV.fetch('HTTPS_PROXY', "https://#{$PROXY_HOST}:#{$PROXY_PORT}")
10
+ ENV['NO_PROXY'] = ENV.fetch('NO_PROXY', $PROXY_NO_PROXY.join(","))
11
+
12
+ puts "HTTP_PROXY = '#{ENV["HTTP_PROXY"]}'"
13
+ puts "HTTPS_PROXY = '#{ENV["HTTPS_PROXY"]}'"
14
+ puts "NO_PROXY = '#{ENV["NO_PROXY"]}'"
15
+
16
+ puts "vagrant-proxyconf is installed? #{Vagrant.has_plugin?('vagrant-proxyconf')}"
17
+
18
+ $APT_PROXY_ENABLED = ENV.fetch("VAGRANT_APT_PROXY_ENABLED", "true")
19
+
20
+ if $APT_PROXY_ENABLED == "false"
21
+ $APT_PROXY_ENABLED = false
22
+ else
23
+ $APT_PROXY_ENABLED = true
24
+ end
25
+
26
+ Vagrant.configure("2") do |config|
27
+
28
+ config.vm.define 'default' do |c|
29
+ c.vm.box = nil
30
+
31
+ if Vagrant.has_plugin?('vagrant-proxyconf')
32
+ c.proxy.enabled = false
33
+ end
34
+
35
+ c.vm.provider "docker" do |d|
36
+ d.build_dir = "."
37
+ d.has_ssh = true
38
+ d.ports = [
39
+ "#{$PROXY_PORT}:#{$PROXY_PORT}",
40
+ ]
41
+ end
42
+ end
43
+
44
+ config.vm.define 'apt_host' do |c|
45
+ c.vm.box = "bento/ubuntu-18.04"
46
+
47
+ # ENV['VAGRANT_APT_VERIFY_HOST'] = "true"
48
+ # ENV['VAGRANT_APT_VERIFY_PEER'] = "false"
49
+
50
+ if Vagrant.has_plugin?('vagrant-proxyconf')
51
+ c.proxy.http = ENV['HTTP_PROXY']
52
+ c.proxy.https = ENV['HTTPS_PROXY']
53
+ c.proxy.no_proxy = ENV['NO_PROXY']
54
+ # uncomment the following to test different behaviors
55
+ # c.apt_proxy.verify_host = "true"
56
+ # c.apt_proxy.verify_peer = "false"
57
+ c.proxy.enabled = {
58
+ :apt => {
59
+ :enabled => $APT_PROXY_ENABLED,
60
+ :skip => false,
61
+ },
62
+ :env => {
63
+ :enabled => false,
64
+ :skip => false,
65
+ },
66
+ :git => {
67
+ :enabled => false,
68
+ :skip => false,
69
+ }
70
+ }
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,50 @@
1
+ #!/bin/bash
2
+ set -ex
3
+
4
+ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
5
+
6
+ start() {
7
+ # start ssh if sshd is installed
8
+ if [ -f /usr/sbin/sshd ]; then
9
+
10
+ /usr/sbin/sshd-keygen
11
+ /usr/sbin/sshd -t
12
+ /usr/sbin/sshd
13
+
14
+ else
15
+
16
+ true
17
+
18
+ fi
19
+
20
+ # start tinyproxy
21
+ /usr/sbin/tinyproxy \
22
+ -d \
23
+ -c "/etc/tinyproxy/tinyproxy.conf"
24
+ }
25
+
26
+ stop() {
27
+
28
+ pgrep -f 'sshd' | while read _pid
29
+ do
30
+ kill -9 $_pid
31
+ done
32
+
33
+ pgrep -f 'tinyproxy' | while read _pid
34
+ do
35
+ kill -9 $_pid
36
+ done
37
+
38
+ }
39
+
40
+ case "${1}" in
41
+
42
+ start)
43
+ start
44
+ ;;
45
+
46
+ stop)
47
+ stop
48
+ ;;
49
+
50
+ esac
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ PROXY_HOST = "10.0.2.2"
4
+
5
+ context 'when proxy is enabled' do
6
+
7
+ before(:context) do
8
+ ENV['HTTP_PROXY'] = "http://#{PROXY_HOST}:8888"
9
+ ENV['HTTPS_PROXY'] = "https://#{PROXY_HOST}:8888"
10
+ ENV['NO_PROXY'] = "*.example.com"
11
+
12
+ `vagrant provision #{ENV['TARGET_HOST']}`
13
+ `sleep 3`
14
+ end
15
+
16
+ describe file('/etc/apt/apt.conf.d/01proxy') do
17
+ let(:expected_content) do
18
+ <<-EOS.gsub(/^\s+/, '')
19
+ Acquire::http::Proxy "http://10.0.2.2:8888";
20
+ Acquire::https::Proxy "https://10.0.2.2:8888";
21
+ EOS
22
+ end
23
+
24
+ its(:content) do
25
+ should eq(expected_content)
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ context 'when VAGRANT_APT_VERIFY_PEER="false"' do
32
+
33
+ before(:context) do
34
+ ENV['HTTP_PROXY'] = "http://#{PROXY_HOST}:8888"
35
+ ENV['HTTPS_PROXY'] = "https://#{PROXY_HOST}:8888"
36
+ ENV['NO_PROXY'] = "*.example.com"
37
+ ENV['VAGRANT_APT_VERIFY_PEER'] = "false"
38
+
39
+ `vagrant provision #{ENV['TARGET_HOST']}`
40
+ `sleep 3`
41
+ end
42
+
43
+ describe file('/etc/apt/apt.conf.d/01proxy') do
44
+ let(:expected_content) do
45
+ <<-EOS.gsub(/^\s+/, '')
46
+ Acquire::http::Proxy "http://10.0.2.2:8888";
47
+ Acquire::https::Proxy "https://10.0.2.2:8888";
48
+ Acquire::https::Verify-Peer "false";
49
+ EOS
50
+ end
51
+
52
+ its(:content) do
53
+ should eq(expected_content)
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ context 'when VAGRANT_APT_VERIFY_PEER="true" and VAGRANT_APT_VERIFY_HOST="false"' do
60
+
61
+ before(:context) do
62
+ ENV['HTTP_PROXY'] = "http://#{PROXY_HOST}:8888"
63
+ ENV['HTTPS_PROXY'] = "https://#{PROXY_HOST}:8888"
64
+ ENV['NO_PROXY'] = "*.example.com"
65
+ ENV['VAGRANT_APT_VERIFY_PEER'] = "true"
66
+ ENV['VAGRANT_APT_VERIFY_HOST'] = "false"
67
+
68
+ `vagrant provision #{ENV['TARGET_HOST']}`
69
+ `sleep 3`
70
+ end
71
+
72
+ describe file('/etc/apt/apt.conf.d/01proxy') do
73
+ let(:expected_content) do
74
+ <<-EOS.gsub(/^\s+/, '')
75
+ Acquire::http::Proxy "http://10.0.2.2:8888";
76
+ Acquire::https::Proxy "https://10.0.2.2:8888";
77
+ Acquire::https::Verify-Peer "true";
78
+ Acquire::https::Verify-Host "false";
79
+ EOS
80
+ end
81
+
82
+ its(:content) do
83
+ should eq(expected_content)
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ context 'when VAGRANT_APT_VERIFY_PEER="" and VAGRANT_APT_VERIFY_HOST=""' do
90
+
91
+ before(:context) do
92
+ ENV['HTTP_PROXY'] = "http://#{PROXY_HOST}:8888"
93
+ ENV['HTTPS_PROXY'] = "https://#{PROXY_HOST}:8888"
94
+ ENV['NO_PROXY'] = "*.example.com"
95
+ ENV['VAGRANT_APT_VERIFY_PEER'] = ""
96
+ ENV['VAGRANT_APT_VERIFY_HOST'] = ""
97
+
98
+ `vagrant provision #{ENV['TARGET_HOST']}`
99
+ `sleep 3`
100
+ end
101
+
102
+ describe file('/etc/apt/apt.conf.d/01proxy') do
103
+ let(:expected_content) do
104
+ <<-EOS.gsub(/^\s+/, '')
105
+ Acquire::http::Proxy "http://10.0.2.2:8888";
106
+ Acquire::https::Proxy "https://10.0.2.2:8888";
107
+ EOS
108
+ end
109
+
110
+ its(:content) do
111
+ should eq(expected_content)
112
+ end
113
+ end
114
+
115
+ end
116
+
117
+ context 'when VAGRANT_APT_VERIFY_PEER="true" and VAGRANT_APT_VERIFY_HOST="true" but proxy is disabled' do
118
+
119
+ before(:context) do
120
+ ENV['HTTP_PROXY'] = "http://#{PROXY_HOST}:8888"
121
+ ENV['HTTPS_PROXY'] = "https://#{PROXY_HOST}:8888"
122
+ ENV['NO_PROXY'] = "*.example.com"
123
+ ENV['VAGRANT_APT_VERIFY_PEER'] = "true"
124
+ ENV['VAGRANT_APT_VERIFY_HOST'] = "true"
125
+ ENV['VAGRANT_APT_PROXY_ENABLED'] = "false"
126
+
127
+ `vagrant provision #{ENV['TARGET_HOST']}`
128
+ `sleep 3`
129
+ end
130
+
131
+ describe file('/etc/apt/apt.conf.d/01proxy') do
132
+ it { should_not exist }
133
+ end
134
+
135
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe package('tinyproxy') do
4
+ it { should be_installed }
5
+ end
6
+
7
+ describe service('tinyproxy') do
8
+ it { should be_enabled }
9
+ it { should be_running }
10
+ end
11
+
12
+
13
+ describe port(8888) do
14
+ it { should be_listening }
15
+ end
@@ -0,0 +1,52 @@
1
+ require 'serverspec'
2
+ require 'net/ssh'
3
+ require 'tempfile'
4
+
5
+ set :backend, :ssh
6
+
7
+ if ENV['ASK_SUDO_PASSWORD']
8
+ begin
9
+ require 'highline/import'
10
+ rescue LoadError
11
+ fail "highline is not available. Try installing it."
12
+ end
13
+ set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
14
+ else
15
+ set :sudo_password, ENV['SUDO_PASSWORD'] || "vagrant"
16
+ end
17
+
18
+ host = ENV['TARGET_HOST']
19
+
20
+ `vagrant up #{host}`
21
+
22
+ config = Tempfile.new('', Dir.tmpdir)
23
+ config.write(`vagrant ssh-config #{host}`)
24
+ config.close
25
+
26
+ options = Net::SSH::Config.for(host, [config.path])
27
+
28
+ options[:user] ||= Etc.getlogin
29
+
30
+ set :host, options[:host_name] || host
31
+ set :ssh_options, options
32
+
33
+ # Disable sudo
34
+ # set :disable_sudo, true
35
+
36
+
37
+ # Set environment variables
38
+ set :env,
39
+ :LANG => 'C',
40
+ :LC_MESSAGES => 'C'
41
+
42
+ # Set PATH
43
+ # set :path, '/sbin:/usr/local/sbin:$PATH'
44
+ set :path, [
45
+ '/usr/local/bin',
46
+ '/usr/local/sbin',
47
+ '/usr/bin',
48
+ '/usr/sbin',
49
+ '/bin',
50
+ '/sbin',
51
+ '$PATH',
52
+ ].join(':')