cfn-vpn 0.5.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build-gem.yml +25 -0
  3. data/.github/workflows/release-gem.yml +31 -0
  4. data/.github/workflows/release-image.yml +33 -0
  5. data/Gemfile.lock +30 -38
  6. data/README.md +1 -247
  7. data/cfn-vpn.gemspec +3 -2
  8. data/docs/README.md +44 -0
  9. data/docs/certificate-users.md +89 -0
  10. data/docs/getting-started.md +87 -0
  11. data/docs/modifying.md +67 -0
  12. data/docs/routes.md +82 -0
  13. data/docs/scheduling.md +32 -0
  14. data/docs/sessions.md +27 -0
  15. data/lib/cfnvpn.rb +31 -27
  16. data/lib/cfnvpn/{client.rb → actions/client.rb} +5 -6
  17. data/lib/cfnvpn/{embedded.rb → actions/embedded.rb} +15 -15
  18. data/lib/cfnvpn/actions/init.rb +130 -0
  19. data/lib/cfnvpn/actions/modify.rb +149 -0
  20. data/lib/cfnvpn/actions/params.rb +73 -0
  21. data/lib/cfnvpn/{revoke.rb → actions/revoke.rb} +6 -6
  22. data/lib/cfnvpn/actions/routes.rb +144 -0
  23. data/lib/cfnvpn/{sessions.rb → actions/sessions.rb} +5 -5
  24. data/lib/cfnvpn/{share.rb → actions/share.rb} +10 -10
  25. data/lib/cfnvpn/actions/subnets.rb +78 -0
  26. data/lib/cfnvpn/certificates.rb +5 -5
  27. data/lib/cfnvpn/clientvpn.rb +34 -68
  28. data/lib/cfnvpn/compiler.rb +23 -0
  29. data/lib/cfnvpn/config.rb +34 -78
  30. data/lib/cfnvpn/{cloudformation.rb → deployer.rb} +47 -19
  31. data/lib/cfnvpn/log.rb +26 -26
  32. data/lib/cfnvpn/s3.rb +4 -4
  33. data/lib/cfnvpn/string.rb +29 -0
  34. data/lib/cfnvpn/templates/helper.rb +14 -0
  35. data/lib/cfnvpn/templates/vpn.rb +344 -0
  36. data/lib/cfnvpn/version.rb +1 -1
  37. metadata +55 -22
  38. data/lib/cfnvpn/cfhighlander.rb +0 -49
  39. data/lib/cfnvpn/init.rb +0 -109
  40. data/lib/cfnvpn/modify.rb +0 -103
  41. data/lib/cfnvpn/routes.rb +0 -84
  42. data/lib/cfnvpn/templates/cfnvpn.cfhighlander.rb.tt +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a41e3f9d96119e2dd991397c46dd76a4b2a3512b96019ca0a26882423ffd4d58
4
- data.tar.gz: ed90e797f95c1a36cdbc740102bd8f764f1168b3fa13cfb0b30cd76b57d857dd
3
+ metadata.gz: 15da75354bf027cc2140fab12465e6cb9ff6090cd26eb11495ba63546a476eb0
4
+ data.tar.gz: b6058447275663117acc7b473960cb28bc524886e5d9771f944b6e835dc8b04c
5
5
  SHA512:
6
- metadata.gz: 739c501d83e59f546eff20f0e6e5f1e4cbe521ee744b469eaa686209738c561c8fc06168354ad110647525e6074919387b8fe46bce6d652d5a52a583d787d0f2
7
- data.tar.gz: 7ec851a23a53e3f6d670fde5fd7348fe4f23f3b01c372efb3bc1487682514555a57a9b173f273e46b3808c8878b4589a6350ce7fc6c2471c5c5273139fbb437c
6
+ metadata.gz: e61cef4dfc247340ebc639871d053dac6319ce8d658afb5551f3fe1901b533860a43b44ac036e2721478db013e81e3c4aa182adb1bf87cc96c10206b9670b2f9
7
+ data.tar.gz: 75c182953a0538329d57d669c73e5d7943bea388072b0ce0a010ac2dd4ba86f484978fe51164ef6a43e36a3f0809a0999c0493bac792c530783ef4cadc69667f
@@ -0,0 +1,25 @@
1
+ name: test and build gem
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+
8
+ jobs:
9
+ build:
10
+ name: test + build
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: set up ruby 2.6
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.6.x
19
+ - name: rspec
20
+ run: |
21
+ gem install rspec
22
+ rspec
23
+ - name: build gem
24
+ run: |
25
+ gem build cfn-vpn.gemspec
@@ -0,0 +1,31 @@
1
+ name: release gem
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish Gem
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Check out the repo
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6.x
20
+
21
+ - name: Publish Gem to Github Packages Respository
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build cfn-vpn.gemspec
28
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
31
+ OWNER: ${{ github.repository_owner }}
@@ -0,0 +1,33 @@
1
+ name: release docker image
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish Container Image
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: Check out the repo
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Docker Buildx
17
+ uses: docker/setup-buildx-action@v1
18
+
19
+ - name: Login to GitHub Container Repository
20
+ uses: docker/login-action@v1
21
+ with:
22
+ registry: ghcr.io
23
+ username: ${{ github.repository_owner }}
24
+ password: ${{ secrets.GHCR_PUSH_TOKEN }}
25
+
26
+ - name: Build and push Container Image to GitHub Container Repository
27
+ uses: docker/build-push-action@v2
28
+ with:
29
+ context: .
30
+ file: ./Dockerfile
31
+ push: true
32
+ tags: ghcr.io/base2services/cfnvpn:${{ github.event.release.tag_name }}
33
+ build-args: CFNVPN_VERSION=${{ github.event.release.tag_name }}
data/Gemfile.lock CHANGED
@@ -1,66 +1,58 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cfn-vpn (0.2.0)
4
+ cfn-vpn (1.0.0)
5
5
  aws-sdk-acm (~> 1, < 2)
6
6
  aws-sdk-cloudformation (~> 1, < 2)
7
7
  aws-sdk-ec2 (~> 1.95, < 2)
8
8
  aws-sdk-s3 (~> 1, < 2)
9
- cfhighlander (~> 0.9, < 1)
10
- cfndsl (~> 0.17, < 1)
9
+ aws-sdk-ssm (~> 1, < 2)
10
+ cfndsl (~> 1, < 2)
11
+ netaddr (= 2.0.4)
11
12
  terminal-table (~> 1, < 2)
12
13
  thor (~> 0.20)
13
14
 
14
15
  GEM
15
16
  remote: https://rubygems.org/
16
17
  specs:
17
- aws-eventstream (1.0.3)
18
- aws-partitions (1.253.0)
19
- aws-sdk-acm (1.23.0)
20
- aws-sdk-core (~> 3, >= 3.56.0)
18
+ aws-eventstream (1.1.0)
19
+ aws-partitions (1.390.0)
20
+ aws-sdk-acm (1.38.0)
21
+ aws-sdk-core (~> 3, >= 3.109.0)
21
22
  aws-sigv4 (~> 1.1)
22
- aws-sdk-cloudformation (1.29.0)
23
- aws-sdk-core (~> 3, >= 3.71.0)
23
+ aws-sdk-cloudformation (1.44.0)
24
+ aws-sdk-core (~> 3, >= 3.109.0)
24
25
  aws-sigv4 (~> 1.1)
25
- aws-sdk-core (3.85.1)
26
- aws-eventstream (~> 1.0, >= 1.0.2)
26
+ aws-sdk-core (3.109.2)
27
+ aws-eventstream (~> 1, >= 1.0.2)
27
28
  aws-partitions (~> 1, >= 1.239.0)
28
29
  aws-sigv4 (~> 1.1)
29
30
  jmespath (~> 1.0)
30
- aws-sdk-ec2 (1.124.0)
31
- aws-sdk-core (~> 3, >= 3.71.0)
31
+ aws-sdk-ec2 (1.208.0)
32
+ aws-sdk-core (~> 3, >= 3.109.0)
32
33
  aws-sigv4 (~> 1.1)
33
- aws-sdk-kms (1.27.0)
34
- aws-sdk-core (~> 3, >= 3.71.0)
34
+ aws-sdk-kms (1.39.0)
35
+ aws-sdk-core (~> 3, >= 3.109.0)
35
36
  aws-sigv4 (~> 1.1)
36
- aws-sdk-s3 (1.59.0)
37
- aws-sdk-core (~> 3, >= 3.83.0)
37
+ aws-sdk-s3 (1.84.0)
38
+ aws-sdk-core (~> 3, >= 3.109.0)
38
39
  aws-sdk-kms (~> 1)
39
40
  aws-sigv4 (~> 1.1)
40
- aws-sigv4 (1.1.0)
41
- aws-eventstream (~> 1.0, >= 1.0.2)
42
- cfhighlander (0.10.7)
43
- aws-sdk-cloudformation (~> 1, < 2)
44
- aws-sdk-core (~> 3, < 4)
45
- aws-sdk-ec2 (~> 1, < 2)
46
- aws-sdk-s3 (~> 1, < 2)
47
- cfndsl (= 0.17.2)
48
- duplicate (~> 1.1)
49
- git (~> 1.4, < 2)
50
- highline (>= 1.7.10, < 1.8)
51
- rubyzip (>= 2.0.0, < 3)
52
- thor (~> 0.20, < 1)
53
- cfndsl (0.17.2)
54
- duplicate (1.1.1)
55
- git (1.5.0)
56
- highline (1.7.10)
41
+ aws-sdk-ssm (1.97.0)
42
+ aws-sdk-core (~> 3, >= 3.109.0)
43
+ aws-sigv4 (~> 1.1)
44
+ aws-sigv4 (1.2.2)
45
+ aws-eventstream (~> 1, >= 1.0.2)
46
+ cfndsl (1.2.0)
47
+ hana (~> 1.3)
48
+ hana (1.3.6)
57
49
  jmespath (1.4.0)
58
- rake (10.5.0)
59
- rubyzip (2.0.0)
50
+ netaddr (2.0.4)
51
+ rake (13.0.1)
60
52
  terminal-table (1.8.0)
61
53
  unicode-display_width (~> 1.1, >= 1.1.1)
62
54
  thor (0.20.3)
63
- unicode-display_width (1.6.0)
55
+ unicode-display_width (1.7.0)
64
56
 
65
57
  PLATFORMS
66
58
  ruby
@@ -68,7 +60,7 @@ PLATFORMS
68
60
  DEPENDENCIES
69
61
  bundler (~> 2.0)
70
62
  cfn-vpn!
71
- rake (~> 10.0)
63
+ rake (~> 13.0)
72
64
 
73
65
  BUNDLED WITH
74
66
  2.0.1
data/README.md CHANGED
@@ -1,252 +1,6 @@
1
1
  # CfnVpn
2
2
 
3
- Manages the resources required to create a [client vpn](https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/what-is.html) in AWS.
4
- Uses cloudformation to manage the state of the vpn resources.
5
-
6
- ## Platforms
7
-
8
- - osx
9
- - linux
10
-
11
- ## Installation
12
-
13
- Install `cfn-vpn` gem
14
-
15
- ```bash
16
- gem install cfn-vpn
17
- ```
18
-
19
- ### easy-rsa
20
-
21
- **Option 1 - Docker**
22
-
23
- Install [docker](https://docs.docker.com/install/)
24
-
25
- Docker is required to generate the certificates required for the client vpn.
26
- The gem uses [openvpn/easy-rsa](https://github.com/OpenVPN/easy-rsa) project in [base2/aws-client-vpn](https://hub.docker.com/r/base2/aws-client-vpn) docker image. [repo](https://github.com/base2Services/ciinabox-containers/tree/master/easy-rsa)
27
-
28
- **Option 1 - local**
29
-
30
- If you would rather setup easy-rsa than install docker, you can use the `--easyrsa-local` flag when running the commands to use a local copy of easy-rsa, the binary just needs to be available in the `$PATH`. Install from [openvpn/easy-rsa](https://github.com/OpenVPN/easy-rsa)
31
-
32
-
33
- ### AWS Credentials
34
-
35
- Setup your [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html) by either setting a profile or exporting them as environment variables.
36
-
37
- ```bash
38
- export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXXXXXXX"
39
- export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXXXXXXX"
40
- export AWS_SESSION_TOKEN="XXXXXXXXXXXXXXXXXXXXX"
41
- ```
42
-
43
- Optionally export the AWS region if not providing `--region` flag
44
-
45
- ```bash
46
- export AWS_REGION="us-east-1"
47
- ```
48
-
49
- ## Docker Image
50
-
51
- [base2/cfn-vpn](https://hub.docker.com/r/base2/cfn-vpn) docker image for usage in a pipeline which comes pre packaged with all dependencies.
52
-
53
- ## Scenarios
54
-
55
- For further AWS documentation please visit https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/scenario.html
56
-
57
- ### SplitTunnel
58
-
59
- Split tunnel when enabled will only push the routes defined on the client vpn. This is useful if you only want to push routes from your vpc through the vpn.
60
-
61
- ### Public subnet with Internet Access
62
-
63
- This can be setup with default options selected. This will push all routes from through the vpn including all internet traffic. The ENI attached to the vpn client attaches a public IP which is used for natting between the vpn and the internet. This must be placed inside a public subnet with a internet gateway attached to the vpc.
64
- Please read the AWS [documentation](https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/scenario-internet.html) for troubleshooting any networking issues
65
-
66
- ### Private subnet with Internet Access
67
-
68
- This is the same as above but the vpn attached to a subnet in a private subnet with the public route being routed through a nat gateway. **NOTE** the dns on the vpn must be set to the dns server of the vpc you've attached the vpn to, the reserved IP address at the base of the VPC IPv4 network range plus two. For example if you VPC cidr is 10.0.0.0/16 then the dns server for that vpc is 10.0.0.2.
69
-
70
- ```bash
71
- cfn-vpn init myvpn --bucket mybucket --server-cn myvpn.domain.tld --subnet-id subnet-123456ab --dns-servers 10.0.0.2
72
- ```
73
-
74
- If you are experiencing issue connecting to the internet check to see if your local dns configurations are overriding the ones set by the vpn. You can test this by using `dig` to query a domain from the vpc dns server. For example:
75
-
76
- ```bash
77
- dig @10.0.0.2 google.com
78
- ```
79
-
80
- ## Usage
81
-
82
- ```bash
83
- Commands:
84
- cfn-vpn --version, -v # print the version
85
- cfn-vpn client [name] --bucket=BUCKET --client-cn=CLIENT_CN # Create a new client certificate
86
- cfn-vpn config [name] --bucket=BUCKET --client-cn=CLIENT_CN # Retrieve the config for the AWS Client VPN
87
- cfn-vpn embedded [name] --bucket=BUCKET --client-cn=CLIENT_CN # Embed client certs into config and generate S3 presigned URL
88
- cfn-vpn help [COMMAND] # Describe available commands or one specific command
89
- cfn-vpn init [name] --bucket=BUCKET --server-cn=SERVER_CN --subnet-id=SUBNET_ID # Create a AWS Client VPN
90
- cfn-vpn modify [name] # Modify your AWS Client VPN
91
- cfn-vpn revoke [name] --bucket=BUCKET --client-cn=CLIENT_CN # Revoke a client certificate
92
- cfn-vpn routes [name] # List, add or delete client vpn routes
93
- cfn-vpn sessions [name] # List and kill current vpn connections
94
- cfn-vpn share [name] --bucket=BUCKET --client-cn=CLIENT_CN # Provide a user with a s3 signed download for certificates and config
95
- ```
96
-
97
- Global options
98
-
99
- ```bash
100
- p, [--profile=PROFILE] # AWS Profile
101
- r, [--region=REGION] # AWS Region
102
- # Default: ENV['AWS_REGION']
103
- [--verbose], [--no-verbose] # set log level to debug
104
- ```
105
-
106
-
107
- ### Create a new AWS Client VPN
108
-
109
- This will create a new client vpn endpoint, associates it with a subnet and sets up a route to the internet.
110
- During this process a new CA and certificate and keys are generated using [openvpn/easy-rsa](https://github.com/OpenVPN/easy-rsa) and uploaded to ACM.
111
- These keys are bundled in a tar and stored encrypted in your provided s3 bucket.
112
-
113
- ```bash
114
- cfn-vpn init myvpn --bucket mybucket --server-cn myvpn.domain.tld --subnet-id subnet-123456ab
115
- ```
116
-
117
- *Optional:*
118
-
119
- ```bash
120
- [--cidr=CIDR] # cidr from which to assign client IP addresses
121
- # Default: 10.250.0.0/16
122
- [--dns-servers=DNS_SERVERS] # DNS Servers to push to clients.
123
- [--split-tunnel], [--no-split-tunnel] # only push routes to the client on the vpn endpoint
124
- [--internet-route], [--no-internet-route] # create a default route to the internet
125
- # Default: true
126
- [--protocol=PROTOCOL] # set the protocol for the vpn connections
127
- # Default: udp
128
- # Possible values: udp, tcp
129
- ```
130
-
131
- ### Create a new client
132
-
133
- This will generate a new client certificate and key against the CA generated in the `init`.
134
- It will be bundled into a tar and stored encrypted in your provided s3 bucket.
135
-
136
- `cfn-vpn client myvpn --client-cn user1 --bucket mybucket`
137
-
138
-
139
- ### Revoke a client
140
-
141
- This will revoke the client certificate and apply to the client VPN endpoint.
142
- Note this wont terminate the session but will stop the client from reconnecting using the certificate.
143
-
144
- `cfn-vpn revoke myvpn --client-cn user1 --bucket mybucket`
145
-
146
-
147
- ### Download the config file
148
-
149
- This will download the client certificate bundle from s3 and the Client VPN config file from the endpoint.
150
- The config will be modified to include the local path of the client cert and key.
151
-
152
- `cfn-vpn config myvpn --client-cn user1 --bucket mybucket`
153
-
154
-
155
- ### Modify the Client VPN config
156
-
157
- This will modify some attributes of the client vpn endpoint.
158
-
159
- `cfn-vpn config myvpn --dns-servers 8.8.8.8,8.8.4.4`
160
-
161
- *Options:*
162
-
163
- ```bash
164
- [--cidr=CIDR] # cidr from which to assign client IP addresses
165
- # Default: 10.250.0.0/16
166
- [--dns-servers=DNS_SERVERS] # DNS Servers to push to clients.
167
- [--split-tunnel], [--no-split-tunnel] # only push routes to the client on the vpn endpoint
168
- [--internet-route], [--no-internet-route] # create a default route to the internet
169
- # Default: true
170
- [--protocol=PROTOCOL] # set the protocol for the vpn connections
171
- # Default: udp
172
- # Possible values: udp, tcp
173
- ```
174
-
175
-
176
- ### Share client certificates with a user
177
-
178
- This will generate a presigned url for the client's certificate and config file to allow them to download them to their local computer.
179
-
180
- `cfn-vpn share myvpn --client-cn user1 --bucket mybucket`
181
-
182
- You can then share the output with your user
183
-
184
- ```
185
- Download the certificates and config from the bellow presigned URLs which will expire in 1 hour.
186
-
187
- Certificate:
188
- <presigned url>
189
-
190
- Config:
191
- <presigned url>
192
-
193
- Extract the certificates from the tar and place into a safe location.
194
- tar xzfv user1.tar.gz -C <path>
195
-
196
- Modify base2-ciinabox.config.ovpn to include the full location of your extracted certificates
197
- echo "key /<path>/user1.key" >> myvpn.config.ovpn
198
- echo "cert /<path>/user1.crt" >> myvpn.config.ovpn
199
-
200
- Open myvpn.config.ovpn with your favourite openvpn client.
201
- ```
202
-
203
-
204
- ### Show and Kill Current Connections
205
-
206
- This is show a table of current connections on the vpn. You can then kill sessions by using the connection id.
207
-
208
- ```bash
209
- $ cfn-vpn sessions myvpn
210
- +-------------+---------------------+--------+-------------+-----------------------------------+---------------+--------------+
211
- | Common Name | Connected (UTC) | Status | IP Address | Connection ID | Ingress Bytes | Egress Bytes |
212
- +-------------+---------------------+--------+-------------+-----------------------------------+---------------+--------------+
213
- | user1 | 2019-06-28 04:58:19 | active | 10.250.0.98 | cvpn-connection-05bcc579cb3fdf9a3 | 3000 | 2679 |
214
- +-------------+---------------------+--------+-------------+-----------------------------------+---------------+--------------+
215
- ```
216
-
217
- Specify the `--kill` flag with the connection id to kill the session.
218
-
219
- `cfn-vpn sessions myvpn --kill cvpn-connection-05bcc579cb3fdf9a3`
220
-
221
-
222
- ### Show, Add and Remove Routes
223
-
224
- This will display the route table from the Client VPN.
225
-
226
- ```bash
227
- +---------------+-----------------------+--------+-----------------+------+-----------+
228
- | Route | Description | Status | Target | Type | Origin |
229
- +---------------+-----------------------+--------+-----------------+------+-----------+
230
- | 10.0.0.0/16 | Default Route | active | subnet-123456ab | Nat | associate |
231
- | 0.0.0.0/0 | Route to the internet | active | subnet-123456ab | Nat | add-route |
232
- +---------------+-----------------------+--------+-----------------+------+-----------+
233
- ```
234
-
235
- to add a new route specify the `--add` flag with the cidr and a description with the `--desc` flag.
236
-
237
- `cfn-vpn routes myvpn --add 10.10.0.0/16 --desc "route to peered vpc"`
238
-
239
- to delete a route specify the `--del` flag with the cidr you want to delete.
240
-
241
- `cfn-vpn routes myvpn --del 10.10.0.0/16`
242
-
243
-
244
- ### Embed client certificates into config file and share
245
-
246
- This will pull the clients certificate and key archives from S3 and embed them into the config file, upload it back to S3 and generate a presigned URL for the user.
247
- This allows the you to download or share a single, ready to import config file into a OpenVPN client.
248
-
249
- `cfn-vpn embedded myvpn --client-cn user1 --bucket mybucket`
3
+ Click [here](docs/README.md) to view the documentation and getting started guide.
250
4
 
251
5
  ## Contributing
252
6