Merge ~gary-wzl77/snappy-hwe-snaps/+git/easy-openvpn:natdevice into ~snappy-hwe-team/snappy-hwe-snaps/+git/easy-openvpn:master

Proposed by Gary.Wang
Status: Merged
Approved by: Alfonso Sanchez-Beato
Approved revision: 4e1618e9e80532cacd3b4fd6ead1ea93cc09cda7
Merged at revision: 11512981311832c762e0ce8a456967462a772948
Proposed branch: ~gary-wzl77/snappy-hwe-snaps/+git/easy-openvpn:natdevice
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/easy-openvpn:master
Diff against target: 180 lines (+76/-10)
8 files modified
README.md (+12/-0)
bin/configure (+6/-0)
bin/help (+5/-1)
spread/main/add_client/task.yaml (+2/-2)
spread/main/change_natdevice/task.yaml (+42/-0)
spread/main/hooks/task.yaml (+4/-0)
spread/main/monitor_status/task.yaml (+3/-5)
spread/main/setup_server/task.yaml (+2/-2)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Alfonso Sanchez-Beato Approve
Simon Fels Approve
Review via email: mp+330328@code.launchpad.net

Commit message

Support to specify natdevice via configure hook.

Description of the change

Support to specify natdevice via configure hook.
Note: 1. I don't bump up snap version since we didn't release 2.3.10-2 yet officially.
      2. I'll create another MP with a proper docs structure.

To post a comment you must log in.
Revision history for this message
Simon Fels (morphis) wrote :

One more general comment inline but otherwise LGTM

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

One small nit

review: Needs Fixing
Revision history for this message
Gary.Wang (gary-wzl77) :
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

LGTM

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2index 120c043..e5c7630 100644
3--- a/README.md
4+++ b/README.md
5@@ -26,6 +26,18 @@ Commands subject to change as I refine things, but here goes:
6
7 ## Configure
8
9+Enable IP forwarding firstly. Note: On ubuntu core, IP forwarding is disabled by default.
10+
11+ $ sudo sysctl -w net.ipv4.ip_forward=1
12+
13+If internet connection is over ethernet, you can skip natdevice setup since default natdevice value is 'eth0'.
14+While a wireless connection is established, you need to set it to 'wlan0' accordingly.
15+Note: This fits the scenario where people usually setup a wireless connection on ubuntu core at the first boot.
16+
17+ $ sudo snap set easy-openvpn natdevice=wlan0
18+
19+Setup an openvpn server with host machine IP address
20+
21 $ sudo easy-openvpn.setup -u udp://<public ip>
22
23 You'll be prompted to set a passphrase for your CA. This passphrase will be
24diff --git a/bin/configure b/bin/configure
25index 8ef9823..d1b6d0f 100755
26--- a/bin/configure
27+++ b/bin/configure
28@@ -28,6 +28,11 @@ if ! nopasswd=$(snapctl get nopasswd); then
29 exit 1
30 fi
31
32+if ! natdevice=$(snapctl get natdevice); then
33+ echo "Failed to get natdevice option."
34+ exit 1
35+fi
36+
37 cat << EOF > $PROFILE
38 export OPENVPN=$SNAP_DATA/openvpn
39 export EASYRSA=$SNAP/usr/local/easyrsa
40@@ -36,6 +41,7 @@ export EASYRSA_VARS_FILE=$SNAP_DATA/openvpn/vars
41 export PATH=$SNAP/usr/local/easyrsa:$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
42 export DEBUG=$debug
43 export NOPASSWD=$nopasswd
44+export OVPN_NATDEVICE=$natdevice
45 EOF
46
47 # Set default domain common name and call easy-rsa explicitly in batch mode.
48diff --git a/bin/help b/bin/help
49index 0375715..c2b7cc1 100755
50--- a/bin/help
51+++ b/bin/help
52@@ -18,13 +18,17 @@ source ${SNAP_DATA}/easy-openvpn.profile
53
54 DEFAULT_DEBUG=0
55 DEFAULT_NOPASSWD=0
56+DEFAULT_OVPN_NATDEVICE=eth0
57
58 SNAPPY_DEBUG=debug
59 SNAPPY_NOPASSWD=nopasswd
60+SNAPPY_OVPN_NATDEVICE=natdevice
61
62-KEYS=("DEBUG" "NOPASSWD")
63+KEYS=("DEBUG" "NOPASSWD" "OVPN_NATDEVICE")
64 DESC_DEBUG="Enable debug mode in OpenVPN server if it's set to 1."
65 DESC_NOPASSWD="Enable generating private key without a passphrase during server setup if it's set to 1"
66+DESC_OVPN_NATDEVICE="Support to specify nat device, typically it could be eth0(default) or wlan0 if you
67+ connect to server over wireless connection"
68
69 cat << 'EOF'
70 OpenVPN snap with management scripts that simplify PKI
71diff --git a/spread/main/add_client/task.yaml b/spread/main/add_client/task.yaml
72index 1d0b480..989ef52 100644
73--- a/spread/main/add_client/task.yaml
74+++ b/spread/main/add_client/task.yaml
75@@ -14,11 +14,11 @@ execute: |
76
77 # check if foo exists in the client list
78 client_name=$(sudo easy-openvpn.clients | awk -F',' '{if(NR>1)print $1}')
79- [ "${client_name}" = foo ] || exit 1
80+ test "${client_name}" = "foo"
81
82 # test client config
83 sudo easy-openvpn.show-client foo > tmp.ovpn
84 ! cmp --silent foo.ovpn tmp.ovpn
85
86 # test duplicated client
87- sudo easy-openvpn.add-client foo > foo.ovpn && exit 1 || exit 0
88+ ! sudo easy-openvpn.add-client foo > foo.ovpn
89diff --git a/spread/main/change_natdevice/task.yaml b/spread/main/change_natdevice/task.yaml
90new file mode 100644
91index 0000000..6bbdf50
92--- /dev/null
93+++ b/spread/main/change_natdevice/task.yaml
94@@ -0,0 +1,42 @@
95+summary: Test change natdevice to 'wlan0'.
96+
97+execute: |
98+ . $TESTSLIB/utilities.sh
99+ # so enable to setup server in non-interactive mode
100+ sudo snap set easy-openvpn nopasswd=1
101+
102+ # change natdevice to 'eth0'.
103+ # It should be set to 'wlan0' while connecting to a wireless network
104+ sudo snap set easy-openvpn natdevice='eth0'
105+
106+ # setup openvpn server
107+ sudo easy-openvpn.setup -u "udp://${SERVER_IP}"
108+
109+ # launch openvpn server
110+ sudo service ${SERVICE_UNIT} start
111+
112+ # wait openvpn server to launch
113+ wait_for_systemd_service ${SERVICE_UNIT}
114+ sudo journalctl -n 10 --no-pager -u ${SERVICE_UNIT} | MATCH 'Initialization Sequence Completed'
115+
116+ # add a client
117+ sudo easy-openvpn.add-client foo > foo.ovpn
118+
119+ # change foo.ovpn owner to avoid dac_override denied in snappy world.
120+ sudo chown root.root foo.ovpn
121+
122+ # run openvpn client as daemon to connect server
123+ sudo easy-openvpn.connect-server foo.ovpn --daemon
124+
125+ # check currrent client connection status
126+ sleep 90
127+ sudo nohup easy-openvpn.status &>status_log &
128+
129+ sleep 1
130+ client_info=$(sed '/^Common/,/^ROUTING/{//!b};d;//d' status_log)
131+ name=$(echo "${client_info}" | awk -F',' '{print $1}')
132+ rx=$(echo "${client_info}" | awk -F',' '{print $3}')
133+ tx=$(echo "${client_info}" | awk -F',' '{print $4}')
134+ test "${name}" = "foo"
135+ test "${rx}" -gt "0"
136+ test "${tx}" -gt "0"
137diff --git a/spread/main/hooks/task.yaml b/spread/main/hooks/task.yaml
138index 53c3fe1..f849977 100644
139--- a/spread/main/hooks/task.yaml
140+++ b/spread/main/hooks/task.yaml
141@@ -11,3 +11,7 @@ execute: |
142 # set 'nopasswd' to 1 and check the value in help command
143 sudo snap set easy-openvpn nopasswd=1
144 sudo easy-openvpn.help | MATCH "'nopasswd' current value set to: '1'.*"
145+
146+ # set 'natdevice' to 'wlan0' and check the value in help command
147+ sudo snap set easy-openvpn natdevice=wlan0
148+ sudo easy-openvpn.help | MATCH "'natdevice' current value set to: 'wlan0'.*"
149diff --git a/spread/main/monitor_status/task.yaml b/spread/main/monitor_status/task.yaml
150index d73a647..0574a89 100644
151--- a/spread/main/monitor_status/task.yaml
152+++ b/spread/main/monitor_status/task.yaml
153@@ -32,12 +32,10 @@ execute: |
154 sudo nohup easy-openvpn.status &>status_log &
155
156 sleep 1
157- cat status_log
158 client_info=$(sed '/^Common/,/^ROUTING/{//!b};d;//d' status_log)
159- echo $client_info
160 name=$(echo "${client_info}" | awk -F',' '{print $1}')
161 rx=$(echo "${client_info}" | awk -F',' '{print $3}')
162 tx=$(echo "${client_info}" | awk -F',' '{print $4}')
163- [ "${name}" = "foo" ] || exit 1
164- [ "${rx}" -gt "0" ] || exit 1
165- [ "${tx}" -gt "0" ] || exit 1
166+ test "${name}" = "foo"
167+ test "${rx}" -gt "0"
168+ test "${tx}" -gt "0"
169diff --git a/spread/main/setup_server/task.yaml b/spread/main/setup_server/task.yaml
170index 77bf55b..0b1b0c4 100644
171--- a/spread/main/setup_server/task.yaml
172+++ b/spread/main/setup_server/task.yaml
173@@ -14,5 +14,5 @@ execute: |
174
175 # to check if ca keypairs are generated successfully
176 SNAP_DATA="/var/snap/easy-openvpn/current"
177- [ -f "${SNAP_DATA}/openvpn/pki/private/${SERVER_IP}.key" ] || exit 1
178- [ -f "${SNAP_DATA}/openvpn/pki/private/ca.key" ] || exit 1
179+ test -f "${SNAP_DATA}/openvpn/pki/private/${SERVER_IP}.key"
180+ test -f "${SNAP_DATA}/openvpn/pki/private/ca.key"

Subscribers

People subscribed via source and target branches

to all changes: