ukcloud-vpn 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3502c84be2bf3e2d7f051af0dfb09485c554621
4
+ data.tar.gz: 3c5bc2c4c497296e05684c92436736bc302d0d56
5
+ SHA512:
6
+ metadata.gz: 8095033a2b267c862dd4bb7e0184b325f5805e2c4e352ca1dc309c96619b361eb4ca93cd377788d6185c9a12708ac633f6ae4a9dbbbd86833d1c7bb189eae798
7
+ data.tar.gz: 50787b78bdf41c4349b3a7d724efaadf847f5399e9c21cfb819d90072fb4310e14dbcd70830238d3a6929ad9a1805adae4447c5ffe35f1b27e4b79c6462ff3e5
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ukcloud-vpn.gemspec
4
+ gemspec
@@ -0,0 +1,149 @@
1
+ #UKCloud IPSec VPN Configuration Tool
2
+
3
+ This command line tool allows UKCloud customers using vShield Edge firewalls to configure IPSec tunnels using a configuration file written in "YAML"
4
+ For more information on YAML and it's syntax see: https://en.wikipedia.org/wiki/YAML
5
+
6
+
7
+
8
+ ## Installation
9
+
10
+ First ensure Ruby is installed on your machine.
11
+
12
+ To check you can run:
13
+
14
+ ```batchfile
15
+ >ruby -v
16
+ ruby 2.0.0p247 (2013-06-27) [i386-mingw32]
17
+ ```
18
+
19
+ The tool was built using Ruby 2.0.0p247 but other versions may work.
20
+
21
+ And then install the gem using:
22
+ ```batchfile
23
+ >gem install ukcloud-vpn
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ Once installed the tool can be run by executing the following:
29
+
30
+ ```batchfile
31
+ >ukcloud-vpn apply <path to yaml file>
32
+ ```
33
+
34
+ For example:
35
+
36
+ ```batchfile
37
+ >ukcloud-vpn apply c:\tmp\firewalls.yml
38
+ ```
39
+
40
+ Or for Linux:
41
+
42
+ ```batchfile
43
+ $ ukcloud-vpn apply /tmp/firewalls.yml
44
+ ```
45
+
46
+
47
+ ## Configuration File
48
+
49
+ The configuration file uses YAML as a format and defines one or more vShield Edge Firewalls to be configured.
50
+ The file has the following syntax:
51
+
52
+ ```yaml
53
+ Firewalls:
54
+ - Name: Firewall_1
55
+ Service:
56
+ IsEnabled: true
57
+ Creds:
58
+ User: xxx.xxxx.xxx
59
+ Password: xxxxxxxxxxxx
60
+ Org: x-x-xx-xxxx
61
+ Url: api.vcd.portal.ukcloudcloud.com
62
+ Edge: nftxxxxxx-x
63
+ GatewayIpsecVpnService:
64
+ IsEnabled: true
65
+ Tunnel:
66
+ - Name: west-to-east
67
+ IpsecVpnLocalPeerId:
68
+ IpsecVpnLocalPeerName:
69
+ PeerIpAddress: 111.111.111.111
70
+ PeerId: 111.111.111.111
71
+ LocalIpAddress: 222.222.222.222
72
+ LocalId: 222.222.222.222
73
+ LocalSubnet:
74
+ - Name: DMZ
75
+ Gateway: 10.0.1.1
76
+ Netmask: 255.255.255.0
77
+ PeerSubnet:
78
+ - Name: DMZ
79
+ Gateway: 10.0.10.1
80
+ Netmask: 255.255.255.0
81
+ SharedSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
82
+ EncryptionProtocol: AES256
83
+ Mtu: 1400
84
+ IsEnabled: true
85
+ - Name: Firewall_2
86
+ Creds:
87
+ User: xxx.xxxx.xxx
88
+ Password: xxxxxxxxxxxx
89
+ Org: x-x-xx-xxxx
90
+ Url: api.vcd.portal.ukcloudcloud.com
91
+ Edge: nftxxxxxx-x
92
+ GatewayIpsecVpnService:
93
+ IsEnabled: true
94
+ Tunnel:
95
+ - Name: east-to-west
96
+ IpsecVpnLocalPeerId:
97
+ IpsecVpnLocalPeerName:
98
+ PeerIpAddress: 222.222.222.222
99
+ PeerId: 222.222.222.222
100
+ LocalIpAddress: 111.111.111.111
101
+ LocalId: 111.111.111.111
102
+ PeerSubnet:
103
+ - Name: DMZ
104
+ Gateway: 10.0.1.1
105
+ Netmask: 255.255.255.0
106
+ LocalSubnet:
107
+ - Name: DMZ
108
+ Gateway: 10.0.10.1
109
+ Netmask: 255.255.255.0
110
+ SharedSecret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
111
+ EncryptionProtocol: AES256
112
+ Mtu: 1400
113
+ IsEnabled: true
114
+ ```
115
+
116
+
117
+ Note that a hyphen ( - ) in YAML represents an array item (an item which can appear one or more times).
118
+ Hopefully it is clear from the example file above the the file supports:
119
+ * One or more vShield firewalls per file
120
+ * One or more tunnels per vShield firewall
121
+ * One or more local subnet per tunnel
122
+ * One or more peer subnet per tunnel
123
+
124
+
125
+ **PeerIpAddress** & **PeerId** should be set to the public IP address of the remote vShield Firewall
126
+ **LocalIpAddress** & **LocalId** should be set to the public IP address of the local vShield Firewall
127
+
128
+
129
+ The file can be created in any text editor (notepad etc) and is usually saved with a ".yml" file extension although this is not required by the tool.
130
+
131
+ ## Contributing
132
+
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ukcloud-cloud-services/ukcloud-vpn.
134
+ Please ensure that the tests run successfully before creating a PR and consider increasing the coverage if adding new features.
135
+
136
+ The project has unit tests using Rspec which can be run using:
137
+
138
+ ```batchfile
139
+ >bundle exec rspec
140
+ ```
141
+
142
+ The CLI tests are written using Cucumber & Aruba and can be run using:
143
+
144
+ ```batchfile
145
+ >bundle exec cucumber
146
+ ```
147
+
148
+ Note: Cucumber tests do not appear to work on Windows
149
+
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require 'cucumber'
4
+ require 'cucumber/rake/task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ Cucumber::Rake::Task.new(:features) do |t|
8
+ t.cucumber_opts = "features --format pretty"
9
+ end
10
+
11
+ task :default => :spec
12
+ task :test => :spec
13
+ task :test => :features
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+ require 'cli'
4
+ UKCloud::Vcloud::Ipsec::Cli.start(ARGV)
@@ -0,0 +1,28 @@
1
+ require 'thor'
2
+ require 'main'
3
+ require 'version'
4
+
5
+ module UKCloud
6
+ module Vcloud
7
+ module Ipsec
8
+ class Cli < Thor
9
+ desc "version", "Print ukcloud-vpn version"
10
+
11
+
12
+ def version
13
+ puts UKCloud::Vcloud::Ipsec::VERSION
14
+ end
15
+
16
+
17
+ desc "apply <location>", "Begin configuration of IPSec tunnels"
18
+ def apply(path)
19
+ begin
20
+ UKCloud::Vcloud::Ipsec::Main.new(path)
21
+ rescue Exception => e
22
+ puts e.message
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,51 @@
1
+ require 'yaml'
2
+
3
+ module UKCloud
4
+ module Vcloud
5
+ module Ipsec
6
+ class Configuration
7
+ attr_accessor :file_location, :full_config, :firewalls
8
+ def initialize(file_location = "#{Dir.pwd}/firewalls.yml")
9
+ @file_location = file_location
10
+ raise("Configuration File Not Found At #{file_location}") unless File.exists?(file_location)
11
+
12
+ @full_config = load_yaml
13
+ @firewalls = parse_config
14
+ end
15
+
16
+ def load_yaml
17
+ file = File.open(@file_location)
18
+ conf = YAML.load(file)
19
+ file.close
20
+
21
+ symbolize(conf) unless conf == false
22
+ end
23
+
24
+ def parse_config
25
+ raise("No firewalls In Config File: #{@file_location}") unless @full_config.is_a?(Hash) && @full_config[:Firewalls]
26
+ raise("No firewalls In Config File: #{@file_location}") unless @full_config[:Firewalls].is_a?(Array) && @full_config[:Firewalls].length > 0
27
+ #To Do: Add Config Schema?
28
+ @full_config[:Firewalls]
29
+
30
+
31
+ end
32
+
33
+ private
34
+
35
+ def symbolize(obj)
36
+ return obj.reduce({}) do |memo, (k, v)|
37
+ memo.tap { |m| m[k.to_sym] = symbolize(v) }
38
+ end if obj.is_a? Hash
39
+
40
+ return obj.reduce([]) do |memo, v|
41
+ memo << symbolize(v); memo
42
+ end if obj.is_a? Array
43
+
44
+ obj
45
+ end
46
+
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,83 @@
1
+ require 'fog'
2
+ require 'configuration'
3
+
4
+
5
+ module UKCloud
6
+ module Vcloud
7
+ module Ipsec
8
+ class Main
9
+ attr_accessor :config
10
+ def initialize(config_file)
11
+ @config = UKCloud::Vcloud::Ipsec::Configuration.new(config_file)
12
+ configure_firewalls(@config.firewalls)
13
+
14
+ end
15
+
16
+ def configure_firewalls(firewalls)
17
+ firewalls.each do |firewall|
18
+ configure_firewall(firewall)
19
+ end
20
+ end
21
+
22
+ def configure_firewall(firewall)
23
+ creds = firewall[:Creds]
24
+ connection = vcloud_login(creds)
25
+ edge_id = get_edge_href(creds[:Edge],connection).split('/').last
26
+
27
+ puts "Configuring VPN Service For Firewall: #{creds[:Edge]}"
28
+ task = connection.post_configure_edge_gateway_services(edge_id,firewall).body
29
+ monitor_task(task[:href].split('/').last,connection)
30
+ puts "Finished Configuring VPN Service For Firewall: #{creds[:Edge]}"
31
+
32
+ #TO DO: SUPPORT MERGING CONFIG WITH EXISTING
33
+ #current_config = get_current_config(edge_href,connection)
34
+ #new_config = merge_configs(current_config, new_config)
35
+
36
+ end
37
+
38
+ def vcloud_login(creds)
39
+ puts "Connecting to vCloud Director API"
40
+ connection = Fog::Compute::VcloudDirector.new(
41
+ :vcloud_director_username => "#{creds[:User]}@#{creds[:Org]}",
42
+ :vcloud_director_password => creds[:Password],
43
+ :vcloud_director_host => creds[:Url],
44
+ :vcloud_director_show_progress => true, # task progress bar on/off
45
+ :connection_options => {
46
+ :omit_default_port => true
47
+ }
48
+ )
49
+ puts "Connected to vCloud Director API"
50
+
51
+ connection
52
+ end
53
+
54
+ def get_edge_href(edge_name, connection)
55
+ puts "Getting vShield Edge HREF From Query"
56
+ results = connection.get_execute_query(type="edgeGateway", :filter => "name==#{edge_name}").body
57
+
58
+ raise "Edge #{edge_name} Not Found!" unless results[:total] == "1"
59
+ raise "Edge Name #{edge_name} Not Unique!" if results[:total].to_i > 1
60
+ puts "Finished Getting vShield Edge HREF From Query"
61
+ result = results[:EdgeGatewayRecord][:href]
62
+ end
63
+
64
+ def get_current_config(edge_href,connection)
65
+ configuration = connection.get_edge_gateway(edge_href.split('/').last).body
66
+
67
+ vpn_service = configuration[:Configuration][:EdgeGatewayServiceConfiguration][:GatewayIpsecVpnService]
68
+ end
69
+
70
+ def monitor_task(task_id,connection)
71
+ task = connection.get_task(task_id).body
72
+ while(task[:status] == "running") do
73
+ puts " Task: #{task[:operation]} Still Running"
74
+ task = connection.get_task(task_id).body
75
+ sleep(3)
76
+ end
77
+
78
+ puts " Task: #{task[:operation]} Completed With Status: #{task[:status]}"
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ module UKCloud
2
+ module Vcloud
3
+ module Ipsec
4
+ VERSION = "0.0.6"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ukcloud-vpn"
8
+ spec.version = UKCloud::Vcloud::Ipsec::VERSION
9
+ spec.authors = ["Tim Lawrence"]
10
+ spec.email = ["tlawrence@ukcloudcloud.com"]
11
+
12
+ spec.summary = %q{Configure vCloud Director IPSec VPNs}
13
+ spec.homepage = "https://github.com/ukcloud-cloud-services"
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
19
+ else
20
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.bindir = "bin"
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.10"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "aruba"
32
+
33
+ spec.add_runtime_dependency 'fog', '>=1.26.0'
34
+ spec.add_runtime_dependency 'thor'
35
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ukcloud-vpn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Tim Lawrence
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aruba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fog
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.26.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.26.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - tlawrence@ukcloudcloud.com
100
+ executables:
101
+ - ukcloud-vpn
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - bin/ukcloud-vpn
112
+ - lib/cli.rb
113
+ - lib/configuration.rb
114
+ - lib/main.rb
115
+ - lib/version.rb
116
+ - ukcloud-vpn.gemspec
117
+ homepage: https://github.com/ukcloud-cloud-services
118
+ licenses: []
119
+ metadata:
120
+ allowed_push_host: https://rubygems.org
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.5.1
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Configure vCloud Director IPSec VPNs
141
+ test_files: []