| index 5d2f0ab..55daa4b 100644 | ||
| --- a/README.md | ||
| +++ b/README.md | ||
| @@ -27,18 +27,31 @@ plugin_docker --meta | ||
| 27 | 27 | |
| 28 | 28 | ### Why it is safe |
| 29 | 29 | |
| 30 | -Container identifiers arrive from the browser, so they are the only real attack surface. | |
| 31 | -Before any identifier can reach a command line it must match: | |
| 30 | +Four independent layers, each covered by the test suite: | |
| 31 | + | |
| 32 | +**1. Node authentication.** The node API (`:8150`) is reachable from the LAN, so the plugin | |
| 33 | +refuses any request that does not carry the node password. Accepted forms match the rest of | |
| 34 | +the node API: `X-Bot-Password: <pwd>` (what `bot-web` proxies with), `Authorization: Bearer | |
| 35 | +<pwd>`, or `?pwd=<pwd>` (what the plugin iframe appends). If `BOT_PASSWORD` is unset the node | |
| 36 | +is in explicitly open mode and the check is a no-op, exactly like `terminal_tmux.c`. Without | |
| 37 | +this, anyone on the LAN could `POST ?action=control` and stop your containers. | |
| 38 | + | |
| 39 | +**2. Container identifier validation.** Identifiers are the only browser-supplied value that | |
| 40 | +reaches a shell, so they must match: | |
| 32 | 41 | |
| 33 | 42 | ``` |
| 34 | 43 | [A-Za-z0-9_.-]{1,128} and must not start with '-' or '.' |
| 35 | 44 | ``` |
| 36 | 45 | |
| 37 | 46 | That single rule blocks flag injection (`cid=--help`), command injection (`cid=a;id`), |
| 38 | -substitution (`cid=a$(id)`) and over-long inputs. A test asserts each of these. | |
| 47 | +substitution (`cid=a$(id)`) and over-long inputs. | |
| 48 | + | |
| 49 | +**3. POST-only, allowlisted control.** `action=control` refuses anything that is not | |
| 50 | +`REQUEST_METHOD: POST`, and `op` must be one of `start`, `stop`, `restart`. | |
| 39 | 51 | |
| 40 | -`action=control` additionally refuses to run unless `REQUEST_METHOD` is POST, and `op` must | |
| 41 | -be one of `start`, `stop`, `restart`. | |
| 52 | +**4. No shell metacharacters in the runtime path.** `DOCKER_BIN` is rejected if it contains a | |
| 53 | +quote, newline or carriage return, so the one other configurable string cannot break out of | |
| 54 | +its quotes either. | |
| 42 | 55 | |
| 43 | 56 | --- |
| 44 | 57 | |
| @@ -49,7 +62,7 @@ be one of `start`, `stop`, `restart`. | ||
| 49 | 62 | ```sh |
| 50 | 63 | # Linux x86_64 — the static musl binary works on Alpine, Debian, Ubuntu, Arch, Omarchy |
| 51 | 64 | mkdir -p ~/.scorpiox/plugins |
| 52 | -curl -fsSL https://dist.scorpiox.net/bot-plugins/docker/1.0.0/linux-x86_64-musl/plugin_docker \ | |
| 65 | +curl -fsSL https://dist.scorpiox.net/bot-plugins/docker/1.1.0/linux-x86_64-musl/plugin_docker \ | |
| 53 | 66 | -o ~/.scorpiox/plugins/plugin_docker |
| 54 | 67 | chmod +x ~/.scorpiox/plugins/plugin_docker |
| 55 | 68 | ~/.scorpiox/plugins/plugin_docker --meta |
| index a3f9efd..593f6fc 100755 | ||
| --- a/release-dist.sh | ||
| +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | |
| 29 | 29 | SLUG="docker" |
| 30 | 30 | ID="plugin_docker" |
| 31 | -VERSION="1.0.0" | |
| 31 | +VERSION="1.1.0" | |
| 32 | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | |
| 34 | 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| index f0c26fc..7436fba 100644 | ||
| --- a/src/plugin_docker.c | ||
| +++ b/src/plugin_docker.c | ||
| @@ -52,7 +52,7 @@ | ||
| 52 | 52 | |
| 53 | 53 | #define PLUGIN_SLUG "docker" |
| 54 | 54 | #define PLUGIN_ID "plugin_docker" |
| 55 | -#define PLUGIN_VER "1.0.0" | |
| 55 | +#define PLUGIN_VER "1.1.0" | |
| 56 | 56 | |
| 57 | 57 | #define MAX_CONTAINERS 256 |
| 58 | 58 | #define LOG_TAIL 100 |
| @@ -1030,6 +1030,62 @@ static int mode_html(int embed) | ||
| 1030 | 1030 | "</script></body></html>\n", stdout); |
| 1031 | 1031 | return 0; |
| 1032 | 1032 | } |
| 1033 | +/* ------------------------------------------------------------------ */ | |
| 1034 | +/* Node auth */ | |
| 1035 | +/* ------------------------------------------------------------------ */ | |
| 1036 | + | |
| 1037 | +/* | |
| 1038 | + * Every node plugin must refuse an unauthenticated caller before it touches | |
| 1039 | + * the container runtime. scorpiox-server runs plugins as CGI on the node API | |
| 1040 | + * (:8150), which is reachable from the LAN, so without this a POST | |
| 1041 | + * ?action=control would let anyone stop containers without knowing the node | |
| 1042 | + * password. Accepted forms, matching the rest of the node API: | |
| 1043 | + * | |
| 1044 | + * X-Bot-Password: <pwd> (what bot-web proxies with) | |
| 1045 | + * Authorization: Bearer <pwd> | |
| 1046 | + * ?pwd=<pwd> (what the plugin iframe appends) | |
| 1047 | + * | |
| 1048 | + * If BOT_PASSWORD is unset the node is running in explicitly open mode and the | |
| 1049 | + * check is a no-op, exactly like terminal_tmux.c and node_rdp.c. | |
| 1050 | + */ | |
| 1051 | +static void require_node_auth(void) | |
| 1052 | +{ | |
| 1053 | + const char *np = getenv("BOT_PASSWORD"); | |
| 1054 | + const char *xp; | |
| 1055 | + const char *auth; | |
| 1056 | + char qpwd[256]; | |
| 1057 | + const char *qs; | |
| 1058 | + | |
| 1059 | + if (!np || !*np) return; | |
| 1060 | + | |
| 1061 | + xp = getenv("HTTP_X_BOT_PASSWORD"); | |
| 1062 | + if (xp && strcmp(xp, np) == 0) return; | |
| 1063 | + | |
| 1064 | + auth = getenv("HTTP_AUTHORIZATION"); | |
| 1065 | + if (auth) { | |
| 1066 | + while (*auth == ' ') auth++; | |
| 1067 | + if (strncmp(auth, "Bearer ", 7) == 0) { | |
| 1068 | + auth += 7; | |
| 1069 | + while (*auth == ' ') auth++; | |
| 1070 | + if (strcmp(auth, np) == 0) return; | |
| 1071 | + } | |
| 1072 | + } | |
| 1073 | + | |
| 1074 | + qs = getenv("QUERY_STRING"); | |
| 1075 | + if (qs && get_query_val(qs, "pwd", qpwd, sizeof(qpwd)) && strcmp(qpwd, np) == 0) | |
| 1076 | + return; | |
| 1077 | + | |
| 1078 | + fputs("Status: 401 Unauthorized\r\n" | |
| 1079 | + "Content-Type: application/json; charset=utf-8\r\n" | |
| 1080 | + "Cache-Control: no-store\r\n" | |
| 1081 | + "X-Content-Type-Options: nosniff\r\n\r\n" | |
| 1082 | + "{\"ok\":false,\"error\":\"invalid node password\"}\n", stdout); | |
| 1083 | + exit(0); | |
| 1084 | +} | |
| 1085 | + | |
| 1086 | +/* ------------------------------------------------------------------ */ | |
| 1087 | +/* POST body */ | |
| 1088 | +/* ------------------------------------------------------------------ */ | |
| 1033 | 1089 | |
| 1034 | 1090 | /* ------------------------------------------------------------------ */ |
| 1035 | 1091 | /* POST body */ |
| @@ -1085,6 +1141,8 @@ int main(int argc, char **argv) | ||
| 1085 | 1141 | } |
| 1086 | 1142 | if (getenv("SX_PLUGIN_META")) return mode_meta(); |
| 1087 | 1143 | |
| 1144 | + require_node_auth(); | |
| 1145 | + | |
| 1088 | 1146 | qs = getenv("QUERY_STRING"); |
| 1089 | 1147 | if (!qs) qs = ""; |
| 1090 | 1148 |
| index fcc7031..1a02d6a 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -81,7 +81,7 @@ chmod +x "$MOCK" | ||
| 81 | 81 | # (no runtime helper: assignments are inlined at each call site) |
| 82 | 82 | |
| 83 | 83 | # ---------------------------------------------------------------- meta mode |
| 84 | -section "mode 1 --meta" | |
| 84 | +section "mode 1 --meta (must work without auth — discovery)" | |
| 85 | 85 | META=$("$BIN" --meta) |
| 86 | 86 | check "meta emits name docker" '"name":"docker"' "$META" |
| 87 | 87 | check "meta emits desc Containers" '"desc":"Containers"' "$META" |
| @@ -95,10 +95,31 @@ DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 95 | 95 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 96 | 96 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 97 | 97 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 98 | -check "--version prints version" '1.0.0' "$("$BIN" --version)" | |
| 98 | +check "--version prints version" '1.1.0' "$("$BIN" --version)" | |
| 99 | 99 | check "--help is available" 'usage:' "$("$BIN" --help)" |
| 100 | 100 | |
| 101 | 101 | # ---------------------------------------------------------------- list mode |
| 102 | +section "node auth" | |
| 103 | +AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=list' "$BIN") | |
| 104 | +check "no credentials -> 401" 'Status: 401' "$AUTHNONE" | |
| 105 | +check "401 body is json error" 'invalid node password' "$AUTHNONE" | |
| 106 | +check_not "401 leaks no container data" '"containers"' "$AUTHNONE" | |
| 107 | +AUTHBAD=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=wrong QUERY_STRING='action=list' "$BIN") | |
| 108 | +check "wrong header password -> 401" 'Status: 401' "$AUTHBAD" | |
| 109 | +AUTHHDR=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=list' "$BIN") | |
| 110 | +check "X-Bot-Password accepted" '"ok":true' "$(body "$AUTHHDR")" | |
| 111 | +AUTHBEAR=$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=list' "$BIN") | |
| 112 | +check "Authorization Bearer accepted" '"ok":true' "$(body "$AUTHBEAR")" | |
| 113 | +AUTHQ=$(BOT_PASSWORD=testpw QUERY_STRING='action=list&pwd=testpw' "$BIN") | |
| 114 | +check "?pwd= accepted" '"ok":true' "$(body "$AUTHQ")" | |
| 115 | +AUTHHTML=$(BOT_PASSWORD=testpw QUERY_STRING='' "$BIN") | |
| 116 | +check "html page requires auth too" 'Status: 401' "$AUTHHTML" | |
| 117 | +AUTHMETA=$(BOT_PASSWORD=testpw "$BIN" --meta) | |
| 118 | +check "--meta succeeds without auth" '"name":"docker"' "$AUTHMETA" | |
| 119 | +AUTHOPEN=$(QUERY_STRING='action=list' "$BIN") | |
| 120 | +check "unset BOT_PASSWORD = open node" 'Content-Type: application/json' "$AUTHOPEN" | |
| 121 | + | |
| 122 | +# All remaining checks run with BOT_PASSWORD unset (open mode) so they stay readable. | |
| 102 | 123 | section "mode 2 JSON list (mock runtime)" |
| 103 | 124 | export DOCKER_BIN="$MOCK" |
| 104 | 125 | LIST=$(QUERY_STRING='action=list' "$BIN") |
| @@ -108,7 +129,7 @@ check_not "list header has no Content-Length" 'Content-Length' "$LIST" | ||
| 108 | 129 | check "list ok:true" '"ok":true' "$LBODY" |
| 109 | 130 | check "list plugin id" '"plugin":"plugin_docker"' "$LBODY" |
| 110 | 131 | check "list slug docker" '"slug":"docker"' "$LBODY" |
| 111 | -check "list version" '"version":"1.0.0"' "$LBODY" | |
| 132 | +check "list version" '"version":"1.1.0"' "$LBODY" | |
| 112 | 133 | check "list runtime available" '"available":true' "$LBODY" |
| 113 | 134 | check "list daemon available" '"daemon_available":true' "$LBODY" |
| 114 | 135 | check "list count 3" '"count":3' "$LBODY" |
| 115 | 136 |
| index 5d2f0ab..55daa4b 100644 | index 5d2f0ab..55daa4b 100644 | ||
| --- a/README.md | --- a/README.md | ||
| +++ b/README.md | +++ b/README.md | ||
| @@ -27,18 +27,31 @@ plugin_docker --meta | @@ -27,18 +27,31 @@ plugin_docker --meta | ||
| 27 | 27 | ||
| 28 | ### Why it is safe | 28 | ### Why it is safe |
| 29 | 29 | ||
| 30 | -Container identifiers arrive from the browser, so they are the only real attack surface. | 30 | +Four independent layers, each covered by the test suite: |
| 31 | -Before any identifier can reach a command line it must match: | 31 | + |
| 32 | +**1. Node authentication.** The node API (`:8150`) is reachable from the LAN, so the plugin | ||
| 33 | +refuses any request that does not carry the node password. Accepted forms match the rest of | ||
| 34 | +the node API: `X-Bot-Password: <pwd>` (what `bot-web` proxies with), `Authorization: Bearer | ||
| 35 | +<pwd>`, or `?pwd=<pwd>` (what the plugin iframe appends). If `BOT_PASSWORD` is unset the node | ||
| 36 | +is in explicitly open mode and the check is a no-op, exactly like `terminal_tmux.c`. Without | ||
| 37 | +this, anyone on the LAN could `POST ?action=control` and stop your containers. | ||
| 38 | + | ||
| 39 | +**2. Container identifier validation.** Identifiers are the only browser-supplied value that | ||
| 40 | +reaches a shell, so they must match: | ||
| 32 | 41 | ||
| 33 | ``` | 42 | ``` |
| 34 | [A-Za-z0-9_.-]{1,128} and must not start with '-' or '.' | 43 | [A-Za-z0-9_.-]{1,128} and must not start with '-' or '.' |
| 35 | ``` | 44 | ``` |
| 36 | 45 | ||
| 37 | That single rule blocks flag injection (`cid=--help`), command injection (`cid=a;id`), | 46 | That single rule blocks flag injection (`cid=--help`), command injection (`cid=a;id`), |
| 38 | -substitution (`cid=a$(id)`) and over-long inputs. A test asserts each of these. | 47 | +substitution (`cid=a$(id)`) and over-long inputs. |
| 48 | + | ||
| 49 | +**3. POST-only, allowlisted control.** `action=control` refuses anything that is not | ||
| 50 | +`REQUEST_METHOD: POST`, and `op` must be one of `start`, `stop`, `restart`. | ||
| 39 | 51 | ||
| 40 | -`action=control` additionally refuses to run unless `REQUEST_METHOD` is POST, and `op` must | 52 | +**4. No shell metacharacters in the runtime path.** `DOCKER_BIN` is rejected if it contains a |
| 41 | -be one of `start`, `stop`, `restart`. | 53 | +quote, newline or carriage return, so the one other configurable string cannot break out of |
| 54 | +its quotes either. | ||
| 42 | 55 | ||
| 43 | --- | 56 | --- |
| 44 | 57 | ||
| @@ -49,7 +62,7 @@ be one of `start`, `stop`, `restart`. | @@ -49,7 +62,7 @@ be one of `start`, `stop`, `restart`. | ||
| 49 | ```sh | 62 | ```sh |
| 50 | # Linux x86_64 — the static musl binary works on Alpine, Debian, Ubuntu, Arch, Omarchy | 63 | # Linux x86_64 — the static musl binary works on Alpine, Debian, Ubuntu, Arch, Omarchy |
| 51 | mkdir -p ~/.scorpiox/plugins | 64 | mkdir -p ~/.scorpiox/plugins |
| 52 | -curl -fsSL https://dist.scorpiox.net/bot-plugins/docker/1.0.0/linux-x86_64-musl/plugin_docker \ | 65 | +curl -fsSL https://dist.scorpiox.net/bot-plugins/docker/1.1.0/linux-x86_64-musl/plugin_docker \ |
| 53 | -o ~/.scorpiox/plugins/plugin_docker | 66 | -o ~/.scorpiox/plugins/plugin_docker |
| 54 | chmod +x ~/.scorpiox/plugins/plugin_docker | 67 | chmod +x ~/.scorpiox/plugins/plugin_docker |
| 55 | ~/.scorpiox/plugins/plugin_docker --meta | 68 | ~/.scorpiox/plugins/plugin_docker --meta |
| index a3f9efd..593f6fc 100755 | index a3f9efd..593f6fc 100755 | ||
| --- a/release-dist.sh | --- a/release-dist.sh | ||
| +++ b/release-dist.sh | +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | ||
| 29 | SLUG="docker" | 29 | SLUG="docker" |
| 30 | ID="plugin_docker" | 30 | ID="plugin_docker" |
| 31 | -VERSION="1.0.0" | 31 | +VERSION="1.1.0" |
| 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | ||
| 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" | 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| index f0c26fc..7436fba 100644 | index f0c26fc..7436fba 100644 | ||
| --- a/src/plugin_docker.c | --- a/src/plugin_docker.c | ||
| +++ b/src/plugin_docker.c | +++ b/src/plugin_docker.c | ||
| @@ -52,7 +52,7 @@ | @@ -52,7 +52,7 @@ | ||
| 52 | 52 | ||
| 53 | #define PLUGIN_SLUG "docker" | 53 | #define PLUGIN_SLUG "docker" |
| 54 | #define PLUGIN_ID "plugin_docker" | 54 | #define PLUGIN_ID "plugin_docker" |
| 55 | -#define PLUGIN_VER "1.0.0" | 55 | +#define PLUGIN_VER "1.1.0" |
| 56 | 56 | ||
| 57 | #define MAX_CONTAINERS 256 | 57 | #define MAX_CONTAINERS 256 |
| 58 | #define LOG_TAIL 100 | 58 | #define LOG_TAIL 100 |
| @@ -1030,6 +1030,62 @@ static int mode_html(int embed) | @@ -1030,6 +1030,62 @@ static int mode_html(int embed) | ||
| 1030 | "</script></body></html>\n", stdout); | 1030 | "</script></body></html>\n", stdout); |
| 1031 | return 0; | 1031 | return 0; |
| 1032 | } | 1032 | } |
| 1033 | +/* ------------------------------------------------------------------ */ | ||
| 1034 | +/* Node auth */ | ||
| 1035 | +/* ------------------------------------------------------------------ */ | ||
| 1036 | + | ||
| 1037 | +/* | ||
| 1038 | + * Every node plugin must refuse an unauthenticated caller before it touches | ||
| 1039 | + * the container runtime. scorpiox-server runs plugins as CGI on the node API | ||
| 1040 | + * (:8150), which is reachable from the LAN, so without this a POST | ||
| 1041 | + * ?action=control would let anyone stop containers without knowing the node | ||
| 1042 | + * password. Accepted forms, matching the rest of the node API: | ||
| 1043 | + * | ||
| 1044 | + * X-Bot-Password: <pwd> (what bot-web proxies with) | ||
| 1045 | + * Authorization: Bearer <pwd> | ||
| 1046 | + * ?pwd=<pwd> (what the plugin iframe appends) | ||
| 1047 | + * | ||
| 1048 | + * If BOT_PASSWORD is unset the node is running in explicitly open mode and the | ||
| 1049 | + * check is a no-op, exactly like terminal_tmux.c and node_rdp.c. | ||
| 1050 | + */ | ||
| 1051 | +static void require_node_auth(void) | ||
| 1052 | +{ | ||
| 1053 | + const char *np = getenv("BOT_PASSWORD"); | ||
| 1054 | + const char *xp; | ||
| 1055 | + const char *auth; | ||
| 1056 | + char qpwd[256]; | ||
| 1057 | + const char *qs; | ||
| 1058 | + | ||
| 1059 | + if (!np || !*np) return; | ||
| 1060 | + | ||
| 1061 | + xp = getenv("HTTP_X_BOT_PASSWORD"); | ||
| 1062 | + if (xp && strcmp(xp, np) == 0) return; | ||
| 1063 | + | ||
| 1064 | + auth = getenv("HTTP_AUTHORIZATION"); | ||
| 1065 | + if (auth) { | ||
| 1066 | + while (*auth == ' ') auth++; | ||
| 1067 | + if (strncmp(auth, "Bearer ", 7) == 0) { | ||
| 1068 | + auth += 7; | ||
| 1069 | + while (*auth == ' ') auth++; | ||
| 1070 | + if (strcmp(auth, np) == 0) return; | ||
| 1071 | + } | ||
| 1072 | + } | ||
| 1073 | + | ||
| 1074 | + qs = getenv("QUERY_STRING"); | ||
| 1075 | + if (qs && get_query_val(qs, "pwd", qpwd, sizeof(qpwd)) && strcmp(qpwd, np) == 0) | ||
| 1076 | + return; | ||
| 1077 | + | ||
| 1078 | + fputs("Status: 401 Unauthorized\r\n" | ||
| 1079 | + "Content-Type: application/json; charset=utf-8\r\n" | ||
| 1080 | + "Cache-Control: no-store\r\n" | ||
| 1081 | + "X-Content-Type-Options: nosniff\r\n\r\n" | ||
| 1082 | + "{\"ok\":false,\"error\":\"invalid node password\"}\n", stdout); | ||
| 1083 | + exit(0); | ||
| 1084 | +} | ||
| 1085 | + | ||
| 1086 | +/* ------------------------------------------------------------------ */ | ||
| 1087 | +/* POST body */ | ||
| 1088 | +/* ------------------------------------------------------------------ */ | ||
| 1033 | 1089 | ||
| 1034 | /* ------------------------------------------------------------------ */ | 1090 | /* ------------------------------------------------------------------ */ |
| 1035 | /* POST body */ | 1091 | /* POST body */ |
| @@ -1085,6 +1141,8 @@ int main(int argc, char **argv) | @@ -1085,6 +1141,8 @@ int main(int argc, char **argv) | ||
| 1085 | } | 1141 | } |
| 1086 | if (getenv("SX_PLUGIN_META")) return mode_meta(); | 1142 | if (getenv("SX_PLUGIN_META")) return mode_meta(); |
| 1087 | 1143 | ||
| 1144 | + require_node_auth(); | ||
| 1145 | + | ||
| 1088 | qs = getenv("QUERY_STRING"); | 1146 | qs = getenv("QUERY_STRING"); |
| 1089 | if (!qs) qs = ""; | 1147 | if (!qs) qs = ""; |
| 1090 | 1148 |
| index fcc7031..1a02d6a 100755 | index fcc7031..1a02d6a 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -81,7 +81,7 @@ chmod +x "$MOCK" | @@ -81,7 +81,7 @@ chmod +x "$MOCK" | ||
| 81 | # (no runtime helper: assignments are inlined at each call site) | 81 | # (no runtime helper: assignments are inlined at each call site) |
| 82 | 82 | ||
| 83 | # ---------------------------------------------------------------- meta mode | 83 | # ---------------------------------------------------------------- meta mode |
| 84 | -section "mode 1 --meta" | 84 | +section "mode 1 --meta (must work without auth — discovery)" |
| 85 | META=$("$BIN" --meta) | 85 | META=$("$BIN" --meta) |
| 86 | check "meta emits name docker" '"name":"docker"' "$META" | 86 | check "meta emits name docker" '"name":"docker"' "$META" |
| 87 | check "meta emits desc Containers" '"desc":"Containers"' "$META" | 87 | check "meta emits desc Containers" '"desc":"Containers"' "$META" |
| @@ -95,10 +95,31 @@ DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') | @@ -95,10 +95,31 @@ DESC=$(printf '%s' "$META" | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 95 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" | 95 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 96 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') | 96 | NAME=$(printf '%s' "$META" | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 97 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" | 97 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 98 | -check "--version prints version" '1.0.0' "$("$BIN" --version)" | 98 | +check "--version prints version" '1.1.0' "$("$BIN" --version)" |
| 99 | check "--help is available" 'usage:' "$("$BIN" --help)" | 99 | check "--help is available" 'usage:' "$("$BIN" --help)" |
| 100 | 100 | ||
| 101 | # ---------------------------------------------------------------- list mode | 101 | # ---------------------------------------------------------------- list mode |
| 102 | +section "node auth" | ||
| 103 | +AUTHNONE=$(BOT_PASSWORD=testpw QUERY_STRING='action=list' "$BIN") | ||
| 104 | +check "no credentials -> 401" 'Status: 401' "$AUTHNONE" | ||
| 105 | +check "401 body is json error" 'invalid node password' "$AUTHNONE" | ||
| 106 | +check_not "401 leaks no container data" '"containers"' "$AUTHNONE" | ||
| 107 | +AUTHBAD=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=wrong QUERY_STRING='action=list' "$BIN") | ||
| 108 | +check "wrong header password -> 401" 'Status: 401' "$AUTHBAD" | ||
| 109 | +AUTHHDR=$(BOT_PASSWORD=testpw HTTP_X_BOT_PASSWORD=testpw QUERY_STRING='action=list' "$BIN") | ||
| 110 | +check "X-Bot-Password accepted" '"ok":true' "$(body "$AUTHHDR")" | ||
| 111 | +AUTHBEAR=$(BOT_PASSWORD=testpw HTTP_AUTHORIZATION='Bearer testpw' QUERY_STRING='action=list' "$BIN") | ||
| 112 | +check "Authorization Bearer accepted" '"ok":true' "$(body "$AUTHBEAR")" | ||
| 113 | +AUTHQ=$(BOT_PASSWORD=testpw QUERY_STRING='action=list&pwd=testpw' "$BIN") | ||
| 114 | +check "?pwd= accepted" '"ok":true' "$(body "$AUTHQ")" | ||
| 115 | +AUTHHTML=$(BOT_PASSWORD=testpw QUERY_STRING='' "$BIN") | ||
| 116 | +check "html page requires auth too" 'Status: 401' "$AUTHHTML" | ||
| 117 | +AUTHMETA=$(BOT_PASSWORD=testpw "$BIN" --meta) | ||
| 118 | +check "--meta succeeds without auth" '"name":"docker"' "$AUTHMETA" | ||
| 119 | +AUTHOPEN=$(QUERY_STRING='action=list' "$BIN") | ||
| 120 | +check "unset BOT_PASSWORD = open node" 'Content-Type: application/json' "$AUTHOPEN" | ||
| 121 | + | ||
| 122 | +# All remaining checks run with BOT_PASSWORD unset (open mode) so they stay readable. | ||
| 102 | section "mode 2 JSON list (mock runtime)" | 123 | section "mode 2 JSON list (mock runtime)" |
| 103 | export DOCKER_BIN="$MOCK" | 124 | export DOCKER_BIN="$MOCK" |
| 104 | LIST=$(QUERY_STRING='action=list' "$BIN") | 125 | LIST=$(QUERY_STRING='action=list' "$BIN") |
| @@ -108,7 +129,7 @@ check_not "list header has no Content-Length" 'Content-Length' "$LIST" | @@ -108,7 +129,7 @@ check_not "list header has no Content-Length" 'Content-Length' "$LIST" | ||
| 108 | check "list ok:true" '"ok":true' "$LBODY" | 129 | check "list ok:true" '"ok":true' "$LBODY" |
| 109 | check "list plugin id" '"plugin":"plugin_docker"' "$LBODY" | 130 | check "list plugin id" '"plugin":"plugin_docker"' "$LBODY" |
| 110 | check "list slug docker" '"slug":"docker"' "$LBODY" | 131 | check "list slug docker" '"slug":"docker"' "$LBODY" |
| 111 | -check "list version" '"version":"1.0.0"' "$LBODY" | 132 | +check "list version" '"version":"1.1.0"' "$LBODY" |
| 112 | check "list runtime available" '"available":true' "$LBODY" | 133 | check "list runtime available" '"available":true' "$LBODY" |
| 113 | check "list daemon available" '"daemon_available":true' "$LBODY" | 134 | check "list daemon available" '"daemon_available":true' "$LBODY" |
| 114 | check "list count 3" '"count":3' "$LBODY" | 135 | check "list count 3" '"count":3' "$LBODY" |
| 115 | 136 |