|
4 | 4 | "cell_type": "markdown",
|
5 | 5 | "metadata": {},
|
6 | 6 | "source": [
|
7 |
| - "# 1 start pods on Azure AKS" |
| 7 | + "# 1 start business logic pods on Azure AKS" |
8 | 8 | ]
|
9 | 9 | },
|
10 | 10 | {
|
|
89 | 89 | "source ${PJ_ROOT}/docs/environments/azure_aks/env"
|
90 | 90 | ]
|
91 | 91 | },
|
| 92 | + { |
| 93 | + "cell_type": "markdown", |
| 94 | + "metadata": {}, |
| 95 | + "source": [ |
| 96 | + "## add auth tokens for the web app of example-turtlebot3" |
| 97 | + ] |
| 98 | + }, |
| 99 | + { |
| 100 | + "cell_type": "markdown", |
| 101 | + "metadata": {}, |
| 102 | + "source": [ |
| 103 | + "### create new `secrets/auth-tokens.json`" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "markdown", |
| 108 | + "metadata": {}, |
| 109 | + "source": [ |
| 110 | + "example)\n", |
| 111 | + "```json\n", |
| 112 | + "[\n", |
| 113 | + " {\n", |
| 114 | + " \"host\": \"api\\\\..+$\",\n", |
| 115 | + " \"settings\": {\n", |
| 116 | + " \"bearer_tokens\": [\n", |
| 117 | + " {\n", |
| 118 | + " \"token\": \"nrWtb8sS0MmwlkhHXv0DC6orPMpFFbni\",\n", |
| 119 | + " \"allowed_paths\": [\"^/orion/.*$\", \"^/idas/.*$\"]\n", |
| 120 | + " }\n", |
| 121 | + " ],\n", |
| 122 | + " \"basic_auths\": [],\n", |
| 123 | + " \"no_auths\": {}\n", |
| 124 | + " }\n", |
| 125 | + " },\n", |
| 126 | + " {\n", |
| 127 | + " \"host\": \"kibana\\\\..+$\",\n", |
| 128 | + " \"settings\": {\n", |
| 129 | + " \"bearer_tokens\": [],\n", |
| 130 | + " \"basic_auths\": [\n", |
| 131 | + " {\n", |
| 132 | + " \"username\": \"yW7FvSGD\",\n", |
| 133 | + " \"password\": \"6BoTFE5xfUlX3ssV\",\n", |
| 134 | + " \"allowed_paths\": [\"^.*$\"]\n", |
| 135 | + " }\n", |
| 136 | + " ],\n", |
| 137 | + " \"no_auths\": {\n", |
| 138 | + " \"allowed_paths\": []\n", |
| 139 | + " }\n", |
| 140 | + " }\n", |
| 141 | + " },\n", |
| 142 | + " {\n", |
| 143 | + " \"host\": \"grafana\\\\..+$\",\n", |
| 144 | + " \"settings\": {\n", |
| 145 | + " \"bearer_tokens\": [],\n", |
| 146 | + " \"basic_auths\": [],\n", |
| 147 | + " \"no_auths\": {\n", |
| 148 | + " \"allowed_paths\": [\"^.*$\"]\n", |
| 149 | + " }\n", |
| 150 | + " }\n", |
| 151 | + " },\n", |
| 152 | + " {\n", |
| 153 | + " \"host\": \"web\\\\..+$\",\n", |
| 154 | + " \"settings\": {\n", |
| 155 | + " \"bearer_tokens\": [\n", |
| 156 | + " {\n", |
| 157 | + " \"token\": \"Udgzdg6xMD5ymtQlInFHsM5UVD9OA2Wi\",\n", |
| 158 | + " \"allowed_paths\": [\n", |
| 159 | + " \"^/visualizer/positions/$\"\n", |
| 160 | + " ]\n", |
| 161 | + " }\n", |
| 162 | + " ],\n", |
| 163 | + " \"basic_auths\": [\n", |
| 164 | + " {\n", |
| 165 | + " \"username\": \"1JMF6D46\",\n", |
| 166 | + " \"password\": \"6u5M0bUhfjj7wMdM\",\n", |
| 167 | + " \"allowed_paths\": [\n", |
| 168 | + " \"/controller/web/\",\n", |
| 169 | + " \"/visualizer/locus/\"\n", |
| 170 | + " ]\n", |
| 171 | + " }\n", |
| 172 | + " ],\n", |
| 173 | + " \"no_auths\": {\n", |
| 174 | + " \"allowed_paths\": [\n", |
| 175 | + " \"^.*/static/.*$\"\n", |
| 176 | + " ]\n", |
| 177 | + " }\n", |
| 178 | + " }\n", |
| 179 | + " }\n", |
| 180 | + "]\n", |
| 181 | + "```" |
| 182 | + ] |
| 183 | + }, |
| 184 | + { |
| 185 | + "cell_type": "markdown", |
| 186 | + "metadata": {}, |
| 187 | + "source": [ |
| 188 | + "#### for macOS" |
| 189 | + ] |
| 190 | + }, |
| 191 | + { |
| 192 | + "cell_type": "code", |
| 193 | + "execution_count": null, |
| 194 | + "metadata": {}, |
| 195 | + "outputs": [], |
| 196 | + "source": [ |
| 197 | + "cat ${CORE_ROOT}/secrets/auth-tokens.json | jq '.|=.+[{\n", |
| 198 | + " \"host\": \"web\\\\..+$\",\n", |
| 199 | + " \"settings\": {\n", |
| 200 | + " \"bearer_tokens\": [\n", |
| 201 | + " {\n", |
| 202 | + " \"token\": \"'$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | head -c 32)'\",\n", |
| 203 | + " \"allowed_paths\": [\"^/visualizer/positions/$\"]\n", |
| 204 | + " }\n", |
| 205 | + " ],\n", |
| 206 | + " \"basic_auths\": [\n", |
| 207 | + " {\n", |
| 208 | + " \"username\": \"'$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | head -c 8)'\",\n", |
| 209 | + " \"password\": \"'$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | head -c 16)'\",\n", |
| 210 | + " \"allowed_paths\": [\"/controller/web/\", \"/visualizer/locus/\"]\n", |
| 211 | + " }\n", |
| 212 | + " ],\n", |
| 213 | + " \"no_auths\": {\n", |
| 214 | + " \"allowed_paths\": [\"^.*/static/.*$\"]\n", |
| 215 | + " }\n", |
| 216 | + " }\n", |
| 217 | + "}]' | tee /tmp/auth-tokens.json\n", |
| 218 | + "mv ${CORE_ROOT}/secrets/auth-tokens.json ${CORE_ROOT}/secrets/auth-tokens.json.back\n", |
| 219 | + "mv /tmp/auth-tokens.json ${CORE_ROOT}/secrets/auth-tokens.json" |
| 220 | + ] |
| 221 | + }, |
| 222 | + { |
| 223 | + "cell_type": "markdown", |
| 224 | + "metadata": {}, |
| 225 | + "source": [ |
| 226 | + "#### for Ubuntu" |
| 227 | + ] |
| 228 | + }, |
| 229 | + { |
| 230 | + "cell_type": "code", |
| 231 | + "execution_count": null, |
| 232 | + "metadata": {}, |
| 233 | + "outputs": [], |
| 234 | + "source": [ |
| 235 | + "cat ${CORE_ROOT}/secrets/auth-tokens.json | jq '.|=.+[{\n", |
| 236 | + " \"host\": \"web\\\\..+$\",\n", |
| 237 | + " \"settings\": {\n", |
| 238 | + " \"bearer_tokens\": [\n", |
| 239 | + " {\n", |
| 240 | + " \"token\": \"'$(cat /dev/urandom 2>/dev/null | head -n 40 | tr -cd 'a-zA-Z0-9' | head -c 32)'\",\n", |
| 241 | + " \"allowed_paths\": [\"^/visualizer/positions/$\"]\n", |
| 242 | + " }\n", |
| 243 | + " ],\n", |
| 244 | + " \"basic_auths\": [\n", |
| 245 | + " {\n", |
| 246 | + " \"username\": \"'$(cat /dev/urandom 2>/dev/null | head -n 40 | tr -cd 'a-zA-Z0-9' | head -c 8)'\",\n", |
| 247 | + " \"password\": \"'$(cat /dev/urandom 2>/dev/null | head -n 40 | tr -cd 'a-zA-Z0-9' | head -c 16)'\",\n", |
| 248 | + " \"allowed_paths\": [\"/controller/web/\", \"/visualizer/locus/\"]\n", |
| 249 | + " }\n", |
| 250 | + " ],\n", |
| 251 | + " \"no_auths\": {\n", |
| 252 | + " \"allowed_paths\": [\"^.*/static/.*$\"]\n", |
| 253 | + " }\n", |
| 254 | + " }\n", |
| 255 | + "}]' | tee /tmp/auth-tokens.json\n", |
| 256 | + "mv ${CORE_ROOT}/secrets/auth-tokens.json ${CORE_ROOT}/secrets/auth-tokens.json.back\n", |
| 257 | + "mv /tmp/auth-tokens.json ${CORE_ROOT}/secrets/auth-tokens.json" |
| 258 | + ] |
| 259 | + }, |
| 260 | + { |
| 261 | + "cell_type": "markdown", |
| 262 | + "metadata": {}, |
| 263 | + "source": [ |
| 264 | + "## change the auth-tokens to kubernetes secrets" |
| 265 | + ] |
| 266 | + }, |
| 267 | + { |
| 268 | + "cell_type": "markdown", |
| 269 | + "metadata": {}, |
| 270 | + "source": [ |
| 271 | + "### watch `auth` log" |
| 272 | + ] |
| 273 | + }, |
| 274 | + { |
| 275 | + "cell_type": "markdown", |
| 276 | + "metadata": {}, |
| 277 | + "source": [ |
| 278 | + "_Outside of this notebook_\n", |
| 279 | + "1. open a ternminal.\n", |
| 280 | + "1. run a command displayed below." |
| 281 | + ] |
| 282 | + }, |
| 283 | + { |
| 284 | + "cell_type": "code", |
| 285 | + "execution_count": null, |
| 286 | + "metadata": {}, |
| 287 | + "outputs": [], |
| 288 | + "source": [ |
| 289 | + "echo \"kubectl logs -f -lapp=auth --all-containers=true\"" |
| 290 | + ] |
| 291 | + }, |
| 292 | + { |
| 293 | + "cell_type": "markdown", |
| 294 | + "metadata": {}, |
| 295 | + "source": [ |
| 296 | + "### delete and re-register auth-tokens to kubernetes secrets" |
| 297 | + ] |
| 298 | + }, |
| 299 | + { |
| 300 | + "cell_type": "code", |
| 301 | + "execution_count": null, |
| 302 | + "metadata": {}, |
| 303 | + "outputs": [], |
| 304 | + "source": [ |
| 305 | + "kubectl delete secret auth-tokens" |
| 306 | + ] |
| 307 | + }, |
| 308 | + { |
| 309 | + "cell_type": "code", |
| 310 | + "execution_count": null, |
| 311 | + "metadata": {}, |
| 312 | + "outputs": [], |
| 313 | + "source": [ |
| 314 | + "kubectl create secret generic auth-tokens --from-file=${CORE_ROOT}/secrets/auth-tokens.json" |
| 315 | + ] |
| 316 | + }, |
| 317 | + { |
| 318 | + "cell_type": "markdown", |
| 319 | + "metadata": {}, |
| 320 | + "source": [ |
| 321 | + "### confirm the token will be reloaded" |
| 322 | + ] |
| 323 | + }, |
| 324 | + { |
| 325 | + "cell_type": "markdown", |
| 326 | + "metadata": {}, |
| 327 | + "source": [ |
| 328 | + "**wait a few minutes until the change of secret is detected by Kubernetes.** \n", |
| 329 | + "When the new secret is detected, the tokens of auth will be reloaded automatically." |
| 330 | + ] |
| 331 | + }, |
| 332 | + { |
| 333 | + "cell_type": "markdown", |
| 334 | + "metadata": {}, |
| 335 | + "source": [ |
| 336 | + "log messages like below will be shown after tokens is reloaded.\n", |
| 337 | + "\n", |
| 338 | + "```\n", |
| 339 | + "...\n", |
| 340 | + "--------\n", |
| 341 | + "2019/05/21 01:51:07 hosts: [api\\..+$ kibana\\..+$ grafana\\..+$ web\\..+$]\n", |
| 342 | + "--------\n", |
| 343 | + "2019/05/21 01:51:07 bearerTokenAllowedPaths: map[api\\..+$:map[XbZX1LpVv7DG9fu1X3WUq5kiqZyF34zI:[^/orion/.*$ ^/idas/.*$]] web\\..+$:map[Udgzdg6xMD5ymtQlInFHsM5UVD9OA2Wi:[^/visualizer/positions/$]]]\n", |
| 344 | + "--------\n", |
| 345 | + "2019/05/21 01:51:07 basicAuthPaths, map[kibana\\..+$:map[^.*$:map[1IGQBVF5:zRa2mxZVdBOyO6Zd]] web\\..+$:map[/controller/web/:map[1JMF6D46:6u5M0bUhfjj7wMdM] /visualizer/locus/:map[1JMF6D46:6u5M0bUhfjj7wMdM]]]\n", |
| 346 | + "--------\n", |
| 347 | + "2019/05/21 01:51:07 noAuthPaths, map[grafana\\..+$:[^.*$] web\\..+$:[^.*/static/.*$] api\\..+$:[] kibana\\..+$:[]]\n", |
| 348 | + "--------\n", |
| 349 | + "```" |
| 350 | + ] |
| 351 | + }, |
92 | 352 | {
|
93 | 353 | "cell_type": "markdown",
|
94 | 354 | "metadata": {},
|
|
180 | 440 | "source": [
|
181 | 441 | "export MONGODB_DATABASE=\"sth_${FIWARE_SERVICE}\"\n",
|
182 | 442 | "export MONGODB_COLLECTION=\"sth_${ROBOT_SERVICEPATH}_${ROBOT_ID}_${ROBOT_TYPE}\"\n",
|
183 |
| - "env BEARER_AUTH=$(cat ${CORE_ROOT}/secrets/auth-tokens.json | jq '.[0].settings.bearer_tokens | map(select(.allowed_paths[] | contains (\"^/visualizer/positions/$\"))) | .[0].token' -r) envsubst < controller/robot-visualization-deployment.yaml | kubectl apply -f -" |
| 443 | + "env BEARER_AUTH=$(cat ${CORE_ROOT}/secrets/auth-tokens.json | jq '.[]|select(.host == \"web\\\\..+$\")|.settings.bearer_tokens | map(select(.allowed_paths[] | contains(\"^/visualizer/positions/$\"))) | .[0].token' -r) envsubst < controller/robot-visualization-deployment.yaml | kubectl apply -f -" |
184 | 444 | ]
|
185 | 445 | },
|
186 | 446 | {
|
|
224 | 484 | "robot-visualization ClusterIP 10.0.112.72 <none> 8888/TCP 13m\n",
|
225 | 485 | "```"
|
226 | 486 | ]
|
| 487 | + }, |
| 488 | + { |
| 489 | + "cell_type": "markdown", |
| 490 | + "metadata": {}, |
| 491 | + "source": [ |
| 492 | + "### register DNS A Record for business logic" |
| 493 | + ] |
| 494 | + }, |
| 495 | + { |
| 496 | + "cell_type": "code", |
| 497 | + "execution_count": null, |
| 498 | + "metadata": {}, |
| 499 | + "outputs": [], |
| 500 | + "source": [ |
| 501 | + "HTTPS_IPADDR=$(kubectl get services -l app=ambassador -o json | jq '.items[0].status.loadBalancer.ingress[0].ip' -r)\n", |
| 502 | + "az network dns record-set a add-record --resource-group ${DNS_ZONE_RG} --zone-name \"${DOMAIN}\" --record-set-name \"web\" --ipv4-address \"${HTTPS_IPADDR}\"" |
| 503 | + ] |
227 | 504 | }
|
228 | 505 | ],
|
229 | 506 | "metadata": {
|
|
0 commit comments