cfn-vpn 0.4.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) 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/Dockerfile +26 -0
  6. data/Gemfile.lock +30 -38
  7. data/README.md +1 -224
  8. data/cfn-vpn.gemspec +3 -3
  9. data/docs/README.md +44 -0
  10. data/docs/certificate-users.md +89 -0
  11. data/docs/getting-started.md +87 -0
  12. data/docs/modifying.md +67 -0
  13. data/docs/routes.md +82 -0
  14. data/docs/scheduling.md +32 -0
  15. data/docs/sessions.md +27 -0
  16. data/lib/cfnvpn.rb +32 -24
  17. data/lib/cfnvpn/{client.rb → actions/client.rb} +11 -8
  18. data/lib/cfnvpn/actions/embedded.rb +110 -0
  19. data/lib/cfnvpn/actions/init.rb +130 -0
  20. data/lib/cfnvpn/actions/modify.rb +149 -0
  21. data/lib/cfnvpn/actions/params.rb +73 -0
  22. data/lib/cfnvpn/{revoke.rb → actions/revoke.rb} +10 -8
  23. data/lib/cfnvpn/actions/routes.rb +144 -0
  24. data/lib/cfnvpn/{sessions.rb → actions/sessions.rb} +7 -6
  25. data/lib/cfnvpn/{share.rb → actions/share.rb} +10 -10
  26. data/lib/cfnvpn/actions/subnets.rb +78 -0
  27. data/lib/cfnvpn/certificates.rb +70 -21
  28. data/lib/cfnvpn/clientvpn.rb +34 -68
  29. data/lib/cfnvpn/compiler.rb +23 -0
  30. data/lib/cfnvpn/config.rb +34 -77
  31. data/lib/cfnvpn/{cloudformation.rb → deployer.rb} +48 -20
  32. data/lib/cfnvpn/globals.rb +16 -0
  33. data/lib/cfnvpn/log.rb +26 -26
  34. data/lib/cfnvpn/s3.rb +13 -3
  35. data/lib/cfnvpn/string.rb +29 -0
  36. data/lib/cfnvpn/templates/helper.rb +14 -0
  37. data/lib/cfnvpn/templates/vpn.rb +344 -0
  38. data/lib/cfnvpn/version.rb +1 -1
  39. metadata +56 -40
  40. data/lib/cfnvpn/cfhighlander.rb +0 -49
  41. data/lib/cfnvpn/init.rb +0 -107
  42. data/lib/cfnvpn/modify.rb +0 -102
  43. data/lib/cfnvpn/routes.rb +0 -83
  44. 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: fc2272c2d2579de34fa1ae63db688ae1ae2a91ea2345004e3dac0a1aa992bfa7
4
- data.tar.gz: e570c13a3af81fc161bf01c18bbad24498bff8620527994a1b43846f9b25732d
3
+ metadata.gz: 15da75354bf027cc2140fab12465e6cb9ff6090cd26eb11495ba63546a476eb0
4
+ data.tar.gz: b6058447275663117acc7b473960cb28bc524886e5d9771f944b6e835dc8b04c
5
5
  SHA512:
6
- metadata.gz: 7a447e1385f39c171e7f5a16c5af5e913855d52fb1f1838220dd00e96c954cfd5258707c9dd389b256aaaf4a776fca5d9bf72cd39870b92cd0d02297ccc9568b
7
- data.tar.gz: 52f82b3f55c856542e6c431613f64f6bae9d9b69378a84042c759da3cb620ee270f0cdd067b49e7564a1ebc490249896941db829a6836570af246c5a8278a911
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/Dockerfile ADDED
@@ -0,0 +1,26 @@
1
+ FROM ruby:2.7-alpine
2
+
3
+ RUN apk add --no-cache easy-rsa git \
4
+ # Hack until easy-rsa 3.0.7 is released https://github.com/OpenVPN/easy-rsa/issues/261
5
+ && sed -i 's/^RANDFILE\s*=\s\$ENV.*/#&/' /usr/share/easy-rsa/openssl-easyrsa.cnf \
6
+ && ln -s /usr/share/easy-rsa/easyrsa /usr/bin/
7
+
8
+ ENV EASYRSA=/usr/share/easy-rsa
9
+ ENV EASYRSA_BATCH=yes
10
+
11
+ ARG CFNVPN_VERSION="0.5.0"
12
+
13
+ COPY . /src
14
+
15
+ WORKDIR /src
16
+
17
+ RUN gem build cfn-vpn.gemspec \
18
+ && gem install cfn-vpn-${CFNVPN_VERSION}.gem \
19
+ && rm -rf /src
20
+
21
+ RUN addgroup -g 1000 cfnvpn && \
22
+ adduser -D -u 1000 -G cfnvpn cfnvpn
23
+
24
+ USER cfnvpn
25
+
26
+ RUN cfndsl -u 9.0.0
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,229 +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
- Install [docker](https://docs.docker.com/install/)
20
-
21
- Docker is required to generate the certificates required for the client vpn.
22
- 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)
23
-
24
- 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.
25
-
26
- ```bash
27
- export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXXXXXXX"
28
- export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXXXXXXX"
29
- export AWS_SESSION_TOKEN="XXXXXXXXXXXXXXXXXXXXX"
30
- ```
31
-
32
- Optionally export the AWS region if not providing `--region` flag
33
-
34
- ```bash
35
- export AWS_REGION="us-east-1"
36
- ```
37
-
38
- ## Scenarios
39
-
40
- For further AWS documentation please visit https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/scenario.html
41
-
42
- ### SplitTunnel
43
-
44
- 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.
45
-
46
- ### Public subnet with Internet Access
47
-
48
- 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.
49
- Please read the AWS [documentation](https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/scenario-internet.html) for troubleshooting any networking issues
50
-
51
- ### Private subnet with Internet Access
52
-
53
- 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.
54
-
55
- ```bash
56
- cfn-vpn init myvpn --bucket mybucket --server-cn myvpn.domain.tld --subnet-id subnet-123456ab --dns-servers 10.0.0.2
57
- ```
58
-
59
- 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:
60
-
61
- ```bash
62
- dig @10.0.0.2 google.com
63
- ```
64
-
65
- ## Usage
66
-
67
- ```bash
68
- Commands:
69
- cfn-vpn --version, -v # print the version
70
- cfn-vpn client [name] --bucket=BUCKET --client-cn=CLIENT_CN # Create a new client certificate
71
- cfn-vpn config [name] --bucket=BUCKET --client-cn=CLIENT_CN # Retrieve the config for the AWS Client VPN
72
- cfn-vpn help [COMMAND] # Describe available commands or one specific command
73
- cfn-vpn init [name] --bucket=BUCKET --server-cn=SERVER_CN --subnet-id=SUBNET_ID # Create a AWS Client VPN
74
- cfn-vpn modify [name] # Modify your AWS Client VPN
75
- cfn-vpn revoke [name] --bucket=BUCKET --client-cn=CLIENT_CN # Revoke a client certificate
76
- cfn-vpn routes [name] # List, add or delete client vpn routes
77
- cfn-vpn sessions [name] # List and kill current vpn connections
78
- cfn-vpn share [name] --bucket=BUCKET --client-cn=CLIENT_CN # Provide a user with a s3 signed download for certificates and config
79
- ```
80
-
81
- Global options
82
-
83
- ```bash
84
- p, [--profile=PROFILE] # AWS Profile
85
- r, [--region=REGION] # AWS Region
86
- # Default: ENV['AWS_REGION']
87
- [--verbose], [--no-verbose] # set log level to debug
88
- ```
89
-
90
-
91
- ### Create a new AWS Client VPN
92
-
93
- This will create a new client vpn endpoint, associates it with a subnet and sets up a route to the internet.
94
- 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.
95
- These keys are bundled in a tar and stored encrypted in your provided s3 bucket.
96
-
97
- ```bash
98
- cfn-vpn init myvpn --bucket mybucket --server-cn myvpn.domain.tld --subnet-id subnet-123456ab
99
- ```
100
-
101
- *Optional:*
102
-
103
- ```bash
104
- [--cidr=CIDR] # cidr from which to assign client IP addresses
105
- # Default: 10.250.0.0/16
106
- [--dns-servers=DNS_SERVERS] # DNS Servers to push to clients.
107
- [--split-tunnel], [--no-split-tunnel] # only push routes to the client on the vpn endpoint
108
- [--internet-route], [--no-internet-route] # create a default route to the internet
109
- # Default: true
110
- [--protocol=PROTOCOL] # set the protocol for the vpn connections
111
- # Default: udp
112
- # Possible values: udp, tcp
113
- ```
114
-
115
- ### Create a new client
116
-
117
- This will generate a new client certificate and key against the CA generated in the `init`.
118
- It will be bundled into a tar and stored encrypted in your provided s3 bucket.
119
-
120
- `cfn-vpn client myvpn --client-cn user1 --bucket mybucket`
121
-
122
-
123
- ### Revoke a client
124
-
125
- This will revoke the client certificate and apply to the client VPN endpoint.
126
- Note this wont terminate the session but will stop the client from reconnecting using the certificate.
127
-
128
- `cfn-vpn revoke myvpn --client-cn user1 --bucket mybucket`
129
-
130
-
131
- ### Download the config file
132
-
133
- This will download the client certificate bundle from s3 and the Client VPN config file from the endpoint.
134
- The config will be modified to include the local path of the client cert and key.
135
-
136
- `cfn-vpn config myvpn --client-cn user1 --bucket mybucket`
137
-
138
-
139
- ### Modify the Client VPN config
140
-
141
- This will modify some attributes of the client vpn endpoint.
142
-
143
- `cfn-vpn config myvpn --dns-servers 8.8.8.8,8.8.4.4`
144
-
145
- *Options:*
146
-
147
- ```bash
148
- [--cidr=CIDR] # cidr from which to assign client IP addresses
149
- # Default: 10.250.0.0/16
150
- [--dns-servers=DNS_SERVERS] # DNS Servers to push to clients.
151
- [--split-tunnel], [--no-split-tunnel] # only push routes to the client on the vpn endpoint
152
- [--internet-route], [--no-internet-route] # create a default route to the internet
153
- # Default: true
154
- [--protocol=PROTOCOL] # set the protocol for the vpn connections
155
- # Default: udp
156
- # Possible values: udp, tcp
157
- ```
158
-
159
-
160
- ### Share client certificates with a user
161
-
162
- This will generate a presigned url for the client's certificate and config file to allow them to download them to their local computer.
163
-
164
- `cfn-vpn share myvpn --client-cn user1 --bucket mybucket`
165
-
166
- You can then share the output with your user
167
-
168
- ```
169
- Download the certificates and config from the bellow presigned URLs which will expire in 1 hour.
170
-
171
- Certificate:
172
- <presigned url>
173
-
174
- Config:
175
- <presigned url>
176
-
177
- Extract the certificates from the tar and place into a safe location.
178
- tar xzfv user1.tar.gz -C <path>
179
-
180
- Modify base2-ciinabox.config.ovpn to include the full location of your extracted certificates
181
- echo "key /<path>/user1.key" >> myvpn.config.ovpn
182
- echo "cert /<path>/user1.crt" >> myvpn.config.ovpn
183
-
184
- Open myvpn.config.ovpn with your favourite openvpn client.
185
- ```
186
-
187
-
188
- ### Show and Kill Current Connections
189
-
190
- This is show a table of current connections on the vpn. You can then kill sessions by using the connection id.
191
-
192
- ```bash
193
- $ cfn-vpn sessions myvpn
194
- +-------------+---------------------+--------+-------------+-----------------------------------+---------------+--------------+
195
- | Common Name | Connected (UTC) | Status | IP Address | Connection ID | Ingress Bytes | Egress Bytes |
196
- +-------------+---------------------+--------+-------------+-----------------------------------+---------------+--------------+
197
- | user1 | 2019-06-28 04:58:19 | active | 10.250.0.98 | cvpn-connection-05bcc579cb3fdf9a3 | 3000 | 2679 |
198
- +-------------+---------------------+--------+-------------+-----------------------------------+---------------+--------------+
199
- ```
200
-
201
- Specify the `--kill` flag with the connection id to kill the session.
202
-
203
- `cfn-vpn sessions myvpn --kill cvpn-connection-05bcc579cb3fdf9a3`
204
-
205
-
206
- ### Show, Add and Remove Routes
207
-
208
- This will display the route table from the Client VPN.
209
-
210
- ```bash
211
- +---------------+-----------------------+--------+-----------------+------+-----------+
212
- | Route | Description | Status | Target | Type | Origin |
213
- +---------------+-----------------------+--------+-----------------+------+-----------+
214
- | 10.0.0.0/16 | Default Route | active | subnet-123456ab | Nat | associate |
215
- | 0.0.0.0/0 | Route to the internet | active | subnet-123456ab | Nat | add-route |
216
- +---------------+-----------------------+--------+-----------------+------+-----------+
217
- ```
218
-
219
- to add a new route specify the `--add` flag with the cidr and a description with the `--desc` flag.
220
-
221
- `cfn-vpn routes myvpn --add 10.10.0.0/16 --desc "route to peered vpc"`
222
-
223
- to delete a route specify the `--del` flag with the cidr you want to delete.
224
-
225
- `cfn-vpn routes myvpn --del 10.10.0.0/16`
226
-
3
+ Click [here](docs/README.md) to view the documentation and getting started guide.
227
4
 
228
5
  ## Contributing
229
6