internal/Anycast-Wiki.md
... ...
@@ -1,241 +0,0 @@
1
-## Distributed wiki sites
2
-
3
-The idea is to deploy the mirrors across dn42 using [anycast](https://en.wikipedia.org/wiki/Anycast) addressing (BGP), thus providing redundancy, load-balancing and improved access times for the site.
4
-The local webserver is monitored with a simple shell script (below) working in conjuction with [ExaBGP](https://github.com/Exa-Networks/exabgp), announcing/withdrawing the assigned route if the service is up/down.
5
-
6
-### Network
7
-
8
- * Install wiki anycast address `172.23.0.80/32` on the system
9
- * Setup tunnel(s) to the dn42 network (routing daemon not required)
10
-
11
-### Setup gollum
12
-
13
- * Install [gollum](https://github.com/gollum/gollum)
14
- * Clone the dn42 wiki repo:
15
-
16
- `git clone ssh://[email protected]/dn42/wiki <path>`
17
-
18
- * Setup cron for periodic pull/push jobs for the repo
19
- * Generate a [CSR](/services/Certificate-Authority) and send to `[email protected]`. Wait for a reply containing internal.dn42/wiki.dn42 certificates.
20
- * Start two gollum instances, read-only and editing on `127.0.0.1`:
21
-
22
- Read/write (SSL access only):
23
- ```
24
-gollum --css <path>/custom.css --gollum-path <path> --host 127.0.0.1 --port 4568
25
- ```
26
- Read-only:
27
- ```
28
-gollum --css <path>/custom.css --gollum-path <path> --host 127.0.0.1 --port 4567 --no-edit
29
- ```
30
-
31
-### Nginx proxy
32
-
33
-##### /etc/nginx/sites-enabled/wiki.dn42:
34
-
35
-```
36
-ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
37
-ssl_session_cache shared:SSL:2m;
38
-
39
-ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
40
-
41
-ssl_prefer_server_ciphers on;
42
-
43
-upstream wiki { server 127.0.0.1:4567; }
44
-
45
-server {
46
- server_name internal.dn42 wiki.dn42;
47
-
48
- listen 172.23.0.80:80 default;
49
-
50
- add_header strict-transport-security "max-age=0; includeSubDomains";
51
-
52
- location / {
53
- location =/robots.txt { root <path>/wiki.dn42/; }
54
- location =/custom.css { root <path>/wiki.dn42/; }
55
- proxy_pass http://wiki;
56
- }
57
-}
58
-
59
-upstream wikirw { server 127.0.0.1:4568; }
60
-
61
-
62
-server {
63
- server_name internal.dn42 wiki.dn42;
64
-
65
- listen 172.23.0.80:443 ssl default;
66
-
67
- ssl on;
68
- ssl_certificate <path>/ssl.crt;
69
- ssl_certificate_key <path>/ssl.key;
70
-
71
- add_header strict-transport-security "max-age=0; includeSubDomains";
72
- add_header Public-Key-Pins 'pin-sha256="mJ1xUCzfru8Ckq2+M6VkNKGOGgSETImRAHBF24mjalw="; pin-sha256="/gOyi7syRMR+d2jZoB/MzcSD++8ciZkSl/hZAQgzWws="; max-age=0; includeSubDomains';
73
-
74
- location / {
75
- location =/robots.txt { root <path>/wiki.dn42/; }
76
- location =/custom.css { root <path>/wiki.dn42/; }
77
- proxy_pass http://wikirw;
78
- }
79
-}
80
-
81
-```
82
-
83
-### [ExaBGP](https://github.com/Exa-Networks/exabgp)
84
-
85
-##### exabgp.conf:
86
-
87
-```
88
-
89
-group gollum-watchdog {
90
- neighbor <peer1> {
91
- router-id x.x.x.x;
92
- local-address <source-address>;
93
- local-as <ownas>;
94
- peer-as <peeras>;
95
- }
96
-
97
- ## (example) peer with one of our iBGP speakers:
98
- neighbor <172.22.0.1> {
99
- router-id 172.23.0.80;
100
- local-address 172.22.0.2;
101
- local-as 123456;
102
- peer-as 123456;
103
- }
104
-
105
- ## ...
106
-
107
- process watch-gollum {
108
- run <path>/gollum-watchdog.sh;
109
- }
110
-}
111
-
112
-```
113
-
114
-Watchdog runs in an infinite loop, sending the appropriate commands to stdout. [ExaBGP](https://github.com/Exa-Networks/exabgp) attaches to the process' stdout and listens for instructions. Watchdog sends either a route announce or widthdraw.
115
-
116
-Run the script in a shell first to validate it's working.
117
-
118
-##### gollum-watchdog.sh:
119
-
120
-```
121
-#!/bin/bash
122
-
123
-CURL=curl
124
-
125
-## url's to check (all listed must be alive to send announce)
126
-URL=( "http://172.23.0.80" "https://172.23.0.80" )
127
-
128
-## the anycast route (/28 due to prefix size limits)
129
-ROUTE='172.23.0.80/28'
130
-
131
-## the next-hop we'll be advertising to neighbor(s)
132
-NEXTHOP='<source-address>'
133
-
134
-## regex match this keyword against HTTP response from curl
135
-VALIDATE_KEYWORD='gollum'
136
-
137
-INTERVAL=60
138
-
139
-###########################
140
-
141
-RUN_STATE=0
142
-
143
-check_urls() {
144
- for url in "${URL[@]}"; do
145
-
146
- ## workaround curl errno 23 when piping
147
- http_response=`${CURL} --insecure -L -o - "${url}"`
148
-
149
- echo "${http_response}" | egrep -q "${VALIDATE_KEYWORD}" || {
150
- return 1
151
- }
152
-
153
- ## add more checks
154
-
155
- done
156
- return 0
157
-}
158
-
159
-while [ 1 ]; do
160
- if [ ${RUN_STATE} -eq 0 ]; then
161
- check_urls && {
162
- RUN_STATE=1
163
- echo "announce route ${ROUTE} next-hop ${NEXTHOP}"
164
- }
165
- else
166
- check_urls || {
167
- RUN_STATE=0
168
- echo "withdraw route ${ROUTE} next-hop ${NEXTHOP}"
169
- }
170
- fi
171
-
172
- sleep ${INTERVAL}
173
-
174
-done
175
-
176
-exit 0
177
-
178
-
179
-```
180
-
181
- Normally SIGUSR1 to the exabgp process triggers a configuration update, but at occasion the process might need to be restarted - since its gracefull shutdown can be glitchy , this might be a bit difficult. Sending SIGKILL to the child(ren) and immediately after, the parent, does the job (quick-and-dirty).
182
-
183
-##### /etc/exabgp/run.sh:
184
-`USAGE: /etc/exabgp/run.sh [start|stop|restart]`
185
-
186
-```
187
-
188
-#!/bin/bash
189
-
190
-PID_FILE=/var/run/exaBGP/exabgp_PID
191
-
192
-######################################
193
-
194
-EXABGP=<path>/sbin/exabgp
195
-EXA_LOG=/var/log/exabgp.log
196
-CONF=/etc/exabgp/exabgp.conf
197
-
198
-
199
-start() {
200
- [ -f ${PID_FILE} ] && {
201
- echo "WARNING: `cat ${PID_FILE}`: exabgp already running"; return 1
202
- }
203
- ${EXABGP} ${CONF} &> ${EXA_LOG} &
204
- cpid=$!
205
- [ ${cpid} -eq 0 ] && {
206
- echo "ERROR: could not start process"; return 1
207
-
208
- }
209
- echo $! > ${PID_FILE}
210
-}
211
-
212
-stop(){
213
- [ -f ${PID_FILE} ] || return 1
214
- pkill -9 -P $(cat ${PID_FILE})
215
- kill -9 $(cat ${PID_FILE})
216
- rm -f ${PID_FILE}
217
-}
218
-
219
-case ${1} in
220
- start )
221
- start
222
- ;;
223
- stop )
224
- stop
225
- ;;
226
- restart )
227
- stop
228
- sleep 1
229
- start
230
- ;;
231
-esac
232
-
233
-exit 0
234
-
235
-```
236
-
237
-### Announcing
238
-
239
-The prefix AS-PATH should show the announcement is originating from your AS. After peering ExaBGP to the nearest speaker(s), check if the prefix is routing properly inside your network. Try not to blackhole the passing traffic (e.g. no static routes to `172.23.0.80/28`). Test the whole thing by shutting down nginx/gollum and watch what happens.
240
-
241
-
... ...
\ No newline at end of file
services/Anycast-Wiki.md
... ...
@@ -0,0 +1,241 @@
1
+## Distributed wiki sites
2
+
3
+The idea is to deploy the mirrors across dn42 using [anycast](https://en.wikipedia.org/wiki/Anycast) addressing (BGP), thus providing redundancy, load-balancing and improved access times for the site.
4
+The local webserver is monitored with a simple shell script (below) working in conjuction with [ExaBGP](https://github.com/Exa-Networks/exabgp), announcing/withdrawing the assigned route if the service is up/down.
5
+
6
+### Network
7
+
8
+ * Install wiki anycast address `172.23.0.80/32` on the system
9
+ * Setup tunnel(s) to the dn42 network (routing daemon not required)
10
+
11
+### Setup gollum
12
+
13
+ * Install [gollum](https://github.com/gollum/gollum)
14
+ * Clone the dn42 wiki repo:
15
+
16
+ `git clone ssh://[email protected]/dn42/wiki <path>`
17
+
18
+ * Setup cron for periodic pull/push jobs for the repo
19
+ * Generate a [CSR](/services/Certificate-Authority) and send to `[email protected]`. Wait for a reply containing internal.dn42/wiki.dn42 certificates.
20
+ * Start two gollum instances, read-only and editing on `127.0.0.1`:
21
+
22
+ Read/write (SSL access only):
23
+ ```
24
+gollum --css <path>/custom.css --gollum-path <path> --host 127.0.0.1 --port 4568
25
+ ```
26
+ Read-only:
27
+ ```
28
+gollum --css <path>/custom.css --gollum-path <path> --host 127.0.0.1 --port 4567 --no-edit
29
+ ```
30
+
31
+### Nginx proxy
32
+
33
+##### /etc/nginx/sites-enabled/wiki.dn42:
34
+
35
+```
36
+ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
37
+ssl_session_cache shared:SSL:2m;
38
+
39
+ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA;
40
+
41
+ssl_prefer_server_ciphers on;
42
+
43
+upstream wiki { server 127.0.0.1:4567; }
44
+
45
+server {
46
+ server_name internal.dn42 wiki.dn42;
47
+
48
+ listen 172.23.0.80:80 default;
49
+
50
+ add_header strict-transport-security "max-age=0; includeSubDomains";
51
+
52
+ location / {
53
+ location =/robots.txt { root <path>/wiki.dn42/; }
54
+ location =/custom.css { root <path>/wiki.dn42/; }
55
+ proxy_pass http://wiki;
56
+ }
57
+}
58
+
59
+upstream wikirw { server 127.0.0.1:4568; }
60
+
61
+
62
+server {
63
+ server_name internal.dn42 wiki.dn42;
64
+
65
+ listen 172.23.0.80:443 ssl default;
66
+
67
+ ssl on;
68
+ ssl_certificate <path>/ssl.crt;
69
+ ssl_certificate_key <path>/ssl.key;
70
+
71
+ add_header strict-transport-security "max-age=0; includeSubDomains";
72
+ add_header Public-Key-Pins 'pin-sha256="mJ1xUCzfru8Ckq2+M6VkNKGOGgSETImRAHBF24mjalw="; pin-sha256="/gOyi7syRMR+d2jZoB/MzcSD++8ciZkSl/hZAQgzWws="; max-age=0; includeSubDomains';
73
+
74
+ location / {
75
+ location =/robots.txt { root <path>/wiki.dn42/; }
76
+ location =/custom.css { root <path>/wiki.dn42/; }
77
+ proxy_pass http://wikirw;
78
+ }
79
+}
80
+
81
+```
82
+
83
+### [ExaBGP](https://github.com/Exa-Networks/exabgp)
84
+
85
+##### exabgp.conf:
86
+
87
+```
88
+
89
+group gollum-watchdog {
90
+ neighbor <peer1> {
91
+ router-id x.x.x.x;
92
+ local-address <source-address>;
93
+ local-as <ownas>;
94
+ peer-as <peeras>;
95
+ }
96
+
97
+ ## (example) peer with one of our iBGP speakers:
98
+ neighbor <172.22.0.1> {
99
+ router-id 172.23.0.80;
100
+ local-address 172.22.0.2;
101
+ local-as 123456;
102
+ peer-as 123456;
103
+ }
104
+
105
+ ## ...
106
+
107
+ process watch-gollum {
108
+ run <path>/gollum-watchdog.sh;
109
+ }
110
+}
111
+
112
+```
113
+
114
+Watchdog runs in an infinite loop, sending the appropriate commands to stdout. [ExaBGP](https://github.com/Exa-Networks/exabgp) attaches to the process' stdout and listens for instructions. Watchdog sends either a route announce or widthdraw.
115
+
116
+Run the script in a shell first to validate it's working.
117
+
118
+##### gollum-watchdog.sh:
119
+
120
+```
121
+#!/bin/bash
122
+
123
+CURL=curl
124
+
125
+## url's to check (all listed must be alive to send announce)
126
+URL=( "http://172.23.0.80" "https://172.23.0.80" )
127
+
128
+## the anycast route (/28 due to prefix size limits)
129
+ROUTE='172.23.0.80/28'
130
+
131
+## the next-hop we'll be advertising to neighbor(s)
132
+NEXTHOP='<source-address>'
133
+
134
+## regex match this keyword against HTTP response from curl
135
+VALIDATE_KEYWORD='gollum'
136
+
137
+INTERVAL=60
138
+
139
+###########################
140
+
141
+RUN_STATE=0
142
+
143
+check_urls() {
144
+ for url in "${URL[@]}"; do
145
+
146
+ ## workaround curl errno 23 when piping
147
+ http_response=`${CURL} --insecure -L -o - "${url}"`
148
+
149
+ echo "${http_response}" | egrep -q "${VALIDATE_KEYWORD}" || {
150
+ return 1
151
+ }
152
+
153
+ ## add more checks
154
+
155
+ done
156
+ return 0
157
+}
158
+
159
+while [ 1 ]; do
160
+ if [ ${RUN_STATE} -eq 0 ]; then
161
+ check_urls && {
162
+ RUN_STATE=1
163
+ echo "announce route ${ROUTE} next-hop ${NEXTHOP}"
164
+ }
165
+ else
166
+ check_urls || {
167
+ RUN_STATE=0
168
+ echo "withdraw route ${ROUTE} next-hop ${NEXTHOP}"
169
+ }
170
+ fi
171
+
172
+ sleep ${INTERVAL}
173
+
174
+done
175
+
176
+exit 0
177
+
178
+
179
+```
180
+
181
+ Normally SIGUSR1 to the exabgp process triggers a configuration update, but at occasion the process might need to be restarted - since its gracefull shutdown can be glitchy , this might be a bit difficult. Sending SIGKILL to the child(ren) and immediately after, the parent, does the job (quick-and-dirty).
182
+
183
+##### /etc/exabgp/run.sh:
184
+`USAGE: /etc/exabgp/run.sh [start|stop|restart]`
185
+
186
+```
187
+
188
+#!/bin/bash
189
+
190
+PID_FILE=/var/run/exaBGP/exabgp_PID
191
+
192
+######################################
193
+
194
+EXABGP=<path>/sbin/exabgp
195
+EXA_LOG=/var/log/exabgp.log
196
+CONF=/etc/exabgp/exabgp.conf
197
+
198
+
199
+start() {
200
+ [ -f ${PID_FILE} ] && {
201
+ echo "WARNING: `cat ${PID_FILE}`: exabgp already running"; return 1
202
+ }
203
+ ${EXABGP} ${CONF} &> ${EXA_LOG} &
204
+ cpid=$!
205
+ [ ${cpid} -eq 0 ] && {
206
+ echo "ERROR: could not start process"; return 1
207
+
208
+ }
209
+ echo $! > ${PID_FILE}
210
+}
211
+
212
+stop(){
213
+ [ -f ${PID_FILE} ] || return 1
214
+ pkill -9 -P $(cat ${PID_FILE})
215
+ kill -9 $(cat ${PID_FILE})
216
+ rm -f ${PID_FILE}
217
+}
218
+
219
+case ${1} in
220
+ start )
221
+ start
222
+ ;;
223
+ stop )
224
+ stop
225
+ ;;
226
+ restart )
227
+ stop
228
+ sleep 1
229
+ start
230
+ ;;
231
+esac
232
+
233
+exit 0
234
+
235
+```
236
+
237
+### Announcing
238
+
239
+The prefix AS-PATH should show the announcement is originating from your AS. After peering ExaBGP to the nearest speaker(s), check if the prefix is routing properly inside your network. Try not to blackhole the passing traffic (e.g. no static routes to `172.23.0.80/28`). Test the whole thing by shutting down nginx/gollum and watch what happens.
240
+
241
+
... ...
\ No newline at end of file