mudauth 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,98 @@
1
+ # mudauth configuration (copy to .env and fill in).
2
+ #
3
+ # Only providers with BOTH a client id and secret set will appear in the
4
+ # login menu; Steam is the exception and needs only STEAM_API_KEY. Register
5
+ # each app's redirect URI as the value of AUTH_CALLBACK_URL (or the
6
+ # per-provider *_CALLBACK_URL override).
7
+
8
+ # Public base the player opens in a browser (behind your reverse proxy). This is
9
+ # the host root; the service serves its /auth/* routes beneath it (the game
10
+ # appends /auth/login/... and the callback is this + /auth/callback). Use the
11
+ # canonical host so provider redirects land with no extra 301 hop.
12
+ AUTH_PUBLIC_BASE=https://mud.example
13
+
14
+ # Loopback listener the MUD talks to. Never expose this to the internet.
15
+ AUTH_BIND=127.0.0.1:7700
16
+
17
+ # How many reverse proxies append to X-Forwarded-For between the browser and
18
+ # this service. The default of 1 matches the shipped nginx and Apache configs.
19
+ # Count only the proxies that APPEND, and count them exactly: the service reads
20
+ # the Nth element from the right, so
21
+ # * too LOW reads a hop one of your own proxies wrote -- not forgeable, but
22
+ # every login then binds to that proxy's address instead of the player's,
23
+ # and the binding stops distinguishing players from each other;
24
+ # * too HIGH reads an element the CLIENT wrote, whenever a client pads the
25
+ # header far enough to reach that far back -- which is exactly the caller
26
+ # naming its own origin that this setting exists to prevent. When the
27
+ # client does not pad, the chain is shorter than the count and the request
28
+ # is refused and logged rather than guessed at.
29
+ # Raise it only if you really do run a second appending proxy (a CDN in front of
30
+ # nginx, say). A value below 1, or one that is not a whole number, stops the
31
+ # service at startup instead of being silently clamped.
32
+ # AUTH_TRUSTED_PROXY_HOPS=1
33
+
34
+ # Shared secret that identifies your game to this service as trusted-loopback, sent
35
+ # as X-Auth-Service-Token on every request. Without it, the game is told apart from a
36
+ # browser only by the ABSENCE of X-Forwarded-For/X-Real-IP -- which a proxy
37
+ # misconfiguration (ProxyAddHeaders Off, a hand-rolled vhost) can erase for every
38
+ # internet caller at once, silently skipping the origin check entirely. Set the SAME
39
+ # value here and in your game's environment (AUTH_SERVICE_TOKEN). Unset is a
40
+ # supported, backward-compatible default (the service warns at startup and falls back
41
+ # to the header-absence rule) -- but see docs/deploy.md for the order to turn this on
42
+ # without taking logins down: the game must be sending the token before this service
43
+ # starts requiring it. Must be A-Z a-z 0-9 _ - only -- the client refuses to send
44
+ # anything outside that charset, and this service refuses to start on a token it
45
+ # would never receive (whitespace is stripped, so a stray trailing space is
46
+ # harmless).
47
+ # secrets.token_urlsafe already stays within the charset, so generate one with:
48
+ # python3 -c "import secrets; print(secrets.token_urlsafe(32))"
49
+ # AUTH_SERVICE_TOKEN=
50
+
51
+ # Default OAuth callback (must be registered with each provider).
52
+ AUTH_CALLBACK_URL=https://mud.example/auth/callback
53
+
54
+ # Shown on the browser page after sign-in, and sent as the User-Agent to providers.
55
+ AUTH_BRAND_NAME=My MUD
56
+ AUTH_USER_AGENT=MyMUD-Auth/1.0 (+https://mud.example)
57
+
58
+ # ── Providers ────────────────────────────────────────────────────────────
59
+ DISCORD_CLIENT_ID=
60
+ DISCORD_CLIENT_SECRET=
61
+ # DISCORD_CALLBACK_URL=
62
+
63
+ GITHUB_CLIENT_ID=
64
+ GITHUB_CLIENT_SECRET=
65
+ # GITHUB_CALLBACK_URL=
66
+
67
+ MICROSOFT_CLIENT_ID=
68
+ MICROSOFT_CLIENT_SECRET=
69
+ # MICROSOFT_CALLBACK_URL=
70
+
71
+ GOOGLE_CLIENT_ID=
72
+ GOOGLE_CLIENT_SECRET=
73
+ # GOOGLE_CALLBACK_URL=
74
+
75
+ # Twitch (dev.twitch.tv/console/apps; the account needs 2FA to register apps)
76
+ TWITCH_CLIENT_ID=
77
+ TWITCH_CLIENT_SECRET=
78
+ # TWITCH_CALLBACK_URL=
79
+
80
+ # Facebook (developers.facebook.com; App ID / App Secret from Settings→Basic.
81
+ # The app must be Live, which requires a privacy policy URL and a data
82
+ # deletion instructions URL in the app settings.)
83
+ FACEBOOK_CLIENT_ID=
84
+ FACEBOOK_CLIENT_SECRET=
85
+ # FACEBOOK_CALLBACK_URL=
86
+
87
+ # Apple (developer.apple.com; requires the paid Developer Program).
88
+ # APPLE_CLIENT_ID is the Services ID; APPLE_CLIENT_SECRET is an ES256 JWT you
89
+ # generate with `mudauth apple-secret` -- it expires within 6 months, so
90
+ # rotate it. Apple only accepts https return URLs (no local-dev callback).
91
+ APPLE_CLIENT_ID=
92
+ APPLE_CLIENT_SECRET=
93
+ # APPLE_CALLBACK_URL=
94
+
95
+ # Steam (steamcommunity.com/dev/apikey; OpenID 2.0, so no client id/secret --
96
+ # just the Web API key, used only for the persona-name lookup)
97
+ STEAM_API_KEY=
98
+ # STEAM_CALLBACK_URL=
mudauth-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 StickMUD Entertainment, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ # The wheel carries only the package. The sdist additionally carries the
2
+ # files an operator or a distro packager needs: the environment template the
3
+ # README and deploy guide tell people to copy, the reverse-proxy and systemd
4
+ # snippets, the documentation, and the test suite so the package can be
5
+ # verified from source.
6
+ include .env.example
7
+ recursive-include deploy *
8
+ recursive-include docs *.md
9
+ recursive-include tests *.py
mudauth-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: mudauth
3
+ Version: 0.1.0
4
+ Summary: Stateless OAuth/OIDC sign-in broker for MUDs implementing the GMCP Authentication standard
5
+ Author-email: "StickMUD Entertainment, LLC" <support@stickmud.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/StickMUD/mudauth
8
+ Project-URL: Documentation, https://github.com/StickMUD/mudauth/tree/main/docs
9
+ Project-URL: Issues, https://github.com/StickMUD/mudauth/issues
10
+ Project-URL: Standard, https://wiki.mudlet.org/w/Standards:GMCP_Authentication
11
+ Keywords: mud,gmcp,oauth,oidc,mudlet,ldmud,telnet
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: No Input/Output (Daemon)
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Games/Entertainment :: Multi-User Dungeons (MUD)
20
+ Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Provides-Extra: apple
25
+ Requires-Dist: PyJWT[crypto]>=2; extra == "apple"
26
+ Provides-Extra: ldmud
27
+ Provides-Extra: dev
28
+ Requires-Dist: ruff>=0.6; extra == "dev"
29
+ Requires-Dist: build; extra == "dev"
30
+ Requires-Dist: twine; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # mudauth
34
+
35
+ Sign in to your MUD with Discord, GitHub, Google, Microsoft, Apple, Twitch, Facebook, or Steam.
36
+ `mudauth` is a small, **stateless** OAuth/OIDC broker for games that implement the
37
+ [GMCP Authentication standard](https://wiki.mudlet.org/w/Standards:GMCP_Authentication) — supported today by Mudlet 5 and LociTerm.
38
+
39
+ - **No database.** It verifies a provider identity and hands `{provider, provider_id, username}` to your game once. Your game stays the source of truth for accounts and characters.
40
+ - **No dependencies.** Python 3.11+ standard library only. One process, one env file.
41
+ - **No inbound port on the game.** The game polls `mudauth` over loopback; only `mudauth` sits behind your TLS proxy.
42
+ - **Eight providers**, each enabled by environment variables — a client id and secret for the seven OAuth/OIDC providers, a single Web API key for Steam.
43
+
44
+ ## Install
45
+
46
+ pipx install mudauth # or: pip install mudauth
47
+ brew install stickmud/tap/mudauth
48
+
49
+ ## Run
50
+
51
+ mudauth serve --env-file .env # listens on 127.0.0.1:7700
52
+ mudauth check --env-file .env # validates config and reaches the running service
53
+
54
+ `.env` is yours to write: `AUTH_PUBLIC_BASE` and one provider's id and secret are
55
+ enough to start. `pip`/`pipx` install only the Python code and the `mudauth`
56
+ command, so the annotated template lives in the source rather than on your PATH —
57
+ take it from a checkout, from the sdist, or straight from the repository:
58
+
59
+ curl -fsSLO https://raw.githubusercontent.com/StickMUD/mudauth/main/.env.example
60
+ cp .env.example .env
61
+
62
+ Put a TLS reverse proxy in front of `AUTH_PUBLIC_BASE` and forward `/auth/` to the
63
+ loopback listener. See [docs/deploy.md](docs/deploy.md) for systemd, nginx, and Apache.
64
+
65
+ ## Integrate your game
66
+
67
+ Your game starts a login with `GET /auth/login/<provider>/<nonce>`, hands the player
68
+ the returned URL over `Char.Login.URL`, and polls `GET /auth/token-poll?nonce=` until
69
+ the identity arrives. Full contract: [docs/protocol.md](docs/protocol.md).
70
+ Driver-specific notes (LDMud efun, Evennia, Node): [docs/integrating.md](docs/integrating.md).
71
+
72
+ LDMud games get a ready-made efun: `pip install "mudauth[ldmud]"` registers
73
+ `auth_service_request(method, path, body)`.
74
+
75
+ ## Endpoints
76
+
77
+ | Method | Path | Purpose |
78
+ |--------|------|---------|
79
+ | GET | `/auth/providers` | List configured providers and the public base |
80
+ | GET | `/auth/login/<provider>/<nonce>` | Begin a login (302 to the provider) |
81
+ | GET | `/auth/callback?code=&state=` | OAuth redirect target |
82
+ | GET | `/auth/token-poll?nonce=` | Poll for the verified identity (returned once) |
83
+ | POST | `/auth/login-cancel` `{nonce}` | Drop a pending login |
84
+ | GET | `/auth/healthz` | Liveness check |
85
+
86
+ ## Configuration
87
+
88
+ All settings are environment variables; `--env-file` loads a `KEY=VALUE` file.
89
+
90
+ | Variable | Default | Meaning |
91
+ |----------|---------|---------|
92
+ | `AUTH_BIND` | `127.0.0.1:7700` | Loopback listener. Never expose it. |
93
+ | `AUTH_PUBLIC_BASE` | `http://localhost:7700` | Browser-facing prefix *before* `/auth/*` |
94
+ | `AUTH_CALLBACK_URL` | `$AUTH_PUBLIC_BASE/auth/callback` | Redirect URI registered with each provider |
95
+ | `AUTH_BRAND_NAME` | `mudauth` | Name on the "you may close this tab" page |
96
+ | `AUTH_TRUSTED_PROXY_HOPS` | `1` | Proxies that append to `X-Forwarded-For` between the browser and the service |
97
+ | `AUTH_SERVICE_TOKEN` | unset | Shared secret identifying the game to the loopback exemption; set the *same* value in the game's environment. Recommended — see [docs/deploy.md](docs/deploy.md) for the migration order. |
98
+ | `AUTH_USER_AGENT` | `mudauth/<version>` | Outbound User-Agent; set it to name your game |
99
+ | `<PROVIDER>_CLIENT_ID` / `_CLIENT_SECRET` | — | Enables that provider |
100
+ | `<PROVIDER>_CALLBACK_URL` | `$AUTH_CALLBACK_URL` | Per-provider override |
101
+ | `STEAM_API_KEY` | — | Steam uses OpenID 2.0; the key is only for the persona lookup |
102
+
103
+ One more variable belongs to the *game* side, not the service: `AUTH_SERVICE_URL`
104
+ (default `http://127.0.0.1:7700`) names the loopback listener the game talks to.
105
+
106
+ Provider registration walkthroughs: [docs/providers.md](docs/providers.md).
107
+
108
+ ## Security model
109
+
110
+ Random per-flow `state` (CSRF); client-generated `nonce` with a 10-minute TTL; the
111
+ identity is returned exactly once and forgotten; non-loopback pollers must come from
112
+ the IP that started the flow; provider secrets never leave the service. Loopback
113
+ callers are trusted — the listener must stay on loopback. `X-Forwarded-For` and
114
+ `X-Real-IP` are believed only from a loopback peer (your reverse proxy), and only
115
+ the rightmost `X-Forwarded-For` element — the hop your proxy appended — is read, so
116
+ a caller cannot name its own origin. If two proxies append to the header, set
117
+ `AUTH_TRUSTED_PROXY_HOPS=2`.
118
+
119
+ Count the appending proxies exactly. Reading too few hops back binds every login to one
120
+ of your own proxies' addresses instead of the player's; reading too many reads an
121
+ element the client wrote whenever a client pads the header. The value is validated at
122
+ startup — a non-integer or anything below 1 stops the service with a message rather
123
+ than being clamped — and the effective count is printed in the startup banner. When a
124
+ request's forwarding header is not the shape that count promises, or carries something
125
+ that is not an IP address, the service logs an `[auth][security]` line and refuses the
126
+ request; it never falls back to the loopback peer, which would make every origin match.
127
+
128
+ That "loopback caller" test is itself worth strengthening: by default it rests on the
129
+ *absence* of `X-Forwarded-For`/`X-Real-IP`, which a proxy that stops adding them (a
130
+ misconfiguration, not an attack) can erase for every internet caller at once. Set
131
+ `AUTH_SERVICE_TOKEN` to the same value in the service's environment and the game's, and
132
+ the exemption instead requires a loopback peer, a matching `X-Auth-Service-Token`
133
+ header, **and** that same header absence — the token tightens the legacy rule, it does
134
+ not replace it, so a caller who learns the token still cannot claim the exemption
135
+ through the proxy. Unset is a supported, backward-compatible default — the service warns
136
+ at startup — but see [docs/deploy.md](docs/deploy.md) for the order to turn it on without
137
+ taking logins down.
138
+
139
+ Both shipped proxy configs turn access logging off for `/auth/`, because the request
140
+ line carries the nonce and the authorization code. Report vulnerabilities per
141
+ [SECURITY.md](SECURITY.md).
142
+
143
+ ## Test
144
+
145
+ python -m unittest discover -s tests -v
146
+
147
+ ## Credits and license
148
+
149
+ Originally built as the auth service for [StickMUD](https://stickmud.com), following
150
+ the pattern proven by [MUDdown](https://github.com/MUDdown/MUDdown). MIT licensed —
151
+ see [LICENSE](LICENSE).
@@ -0,0 +1,119 @@
1
+ # mudauth
2
+
3
+ Sign in to your MUD with Discord, GitHub, Google, Microsoft, Apple, Twitch, Facebook, or Steam.
4
+ `mudauth` is a small, **stateless** OAuth/OIDC broker for games that implement the
5
+ [GMCP Authentication standard](https://wiki.mudlet.org/w/Standards:GMCP_Authentication) — supported today by Mudlet 5 and LociTerm.
6
+
7
+ - **No database.** It verifies a provider identity and hands `{provider, provider_id, username}` to your game once. Your game stays the source of truth for accounts and characters.
8
+ - **No dependencies.** Python 3.11+ standard library only. One process, one env file.
9
+ - **No inbound port on the game.** The game polls `mudauth` over loopback; only `mudauth` sits behind your TLS proxy.
10
+ - **Eight providers**, each enabled by environment variables — a client id and secret for the seven OAuth/OIDC providers, a single Web API key for Steam.
11
+
12
+ ## Install
13
+
14
+ pipx install mudauth # or: pip install mudauth
15
+ brew install stickmud/tap/mudauth
16
+
17
+ ## Run
18
+
19
+ mudauth serve --env-file .env # listens on 127.0.0.1:7700
20
+ mudauth check --env-file .env # validates config and reaches the running service
21
+
22
+ `.env` is yours to write: `AUTH_PUBLIC_BASE` and one provider's id and secret are
23
+ enough to start. `pip`/`pipx` install only the Python code and the `mudauth`
24
+ command, so the annotated template lives in the source rather than on your PATH —
25
+ take it from a checkout, from the sdist, or straight from the repository:
26
+
27
+ curl -fsSLO https://raw.githubusercontent.com/StickMUD/mudauth/main/.env.example
28
+ cp .env.example .env
29
+
30
+ Put a TLS reverse proxy in front of `AUTH_PUBLIC_BASE` and forward `/auth/` to the
31
+ loopback listener. See [docs/deploy.md](docs/deploy.md) for systemd, nginx, and Apache.
32
+
33
+ ## Integrate your game
34
+
35
+ Your game starts a login with `GET /auth/login/<provider>/<nonce>`, hands the player
36
+ the returned URL over `Char.Login.URL`, and polls `GET /auth/token-poll?nonce=` until
37
+ the identity arrives. Full contract: [docs/protocol.md](docs/protocol.md).
38
+ Driver-specific notes (LDMud efun, Evennia, Node): [docs/integrating.md](docs/integrating.md).
39
+
40
+ LDMud games get a ready-made efun: `pip install "mudauth[ldmud]"` registers
41
+ `auth_service_request(method, path, body)`.
42
+
43
+ ## Endpoints
44
+
45
+ | Method | Path | Purpose |
46
+ |--------|------|---------|
47
+ | GET | `/auth/providers` | List configured providers and the public base |
48
+ | GET | `/auth/login/<provider>/<nonce>` | Begin a login (302 to the provider) |
49
+ | GET | `/auth/callback?code=&state=` | OAuth redirect target |
50
+ | GET | `/auth/token-poll?nonce=` | Poll for the verified identity (returned once) |
51
+ | POST | `/auth/login-cancel` `{nonce}` | Drop a pending login |
52
+ | GET | `/auth/healthz` | Liveness check |
53
+
54
+ ## Configuration
55
+
56
+ All settings are environment variables; `--env-file` loads a `KEY=VALUE` file.
57
+
58
+ | Variable | Default | Meaning |
59
+ |----------|---------|---------|
60
+ | `AUTH_BIND` | `127.0.0.1:7700` | Loopback listener. Never expose it. |
61
+ | `AUTH_PUBLIC_BASE` | `http://localhost:7700` | Browser-facing prefix *before* `/auth/*` |
62
+ | `AUTH_CALLBACK_URL` | `$AUTH_PUBLIC_BASE/auth/callback` | Redirect URI registered with each provider |
63
+ | `AUTH_BRAND_NAME` | `mudauth` | Name on the "you may close this tab" page |
64
+ | `AUTH_TRUSTED_PROXY_HOPS` | `1` | Proxies that append to `X-Forwarded-For` between the browser and the service |
65
+ | `AUTH_SERVICE_TOKEN` | unset | Shared secret identifying the game to the loopback exemption; set the *same* value in the game's environment. Recommended — see [docs/deploy.md](docs/deploy.md) for the migration order. |
66
+ | `AUTH_USER_AGENT` | `mudauth/<version>` | Outbound User-Agent; set it to name your game |
67
+ | `<PROVIDER>_CLIENT_ID` / `_CLIENT_SECRET` | — | Enables that provider |
68
+ | `<PROVIDER>_CALLBACK_URL` | `$AUTH_CALLBACK_URL` | Per-provider override |
69
+ | `STEAM_API_KEY` | — | Steam uses OpenID 2.0; the key is only for the persona lookup |
70
+
71
+ One more variable belongs to the *game* side, not the service: `AUTH_SERVICE_URL`
72
+ (default `http://127.0.0.1:7700`) names the loopback listener the game talks to.
73
+
74
+ Provider registration walkthroughs: [docs/providers.md](docs/providers.md).
75
+
76
+ ## Security model
77
+
78
+ Random per-flow `state` (CSRF); client-generated `nonce` with a 10-minute TTL; the
79
+ identity is returned exactly once and forgotten; non-loopback pollers must come from
80
+ the IP that started the flow; provider secrets never leave the service. Loopback
81
+ callers are trusted — the listener must stay on loopback. `X-Forwarded-For` and
82
+ `X-Real-IP` are believed only from a loopback peer (your reverse proxy), and only
83
+ the rightmost `X-Forwarded-For` element — the hop your proxy appended — is read, so
84
+ a caller cannot name its own origin. If two proxies append to the header, set
85
+ `AUTH_TRUSTED_PROXY_HOPS=2`.
86
+
87
+ Count the appending proxies exactly. Reading too few hops back binds every login to one
88
+ of your own proxies' addresses instead of the player's; reading too many reads an
89
+ element the client wrote whenever a client pads the header. The value is validated at
90
+ startup — a non-integer or anything below 1 stops the service with a message rather
91
+ than being clamped — and the effective count is printed in the startup banner. When a
92
+ request's forwarding header is not the shape that count promises, or carries something
93
+ that is not an IP address, the service logs an `[auth][security]` line and refuses the
94
+ request; it never falls back to the loopback peer, which would make every origin match.
95
+
96
+ That "loopback caller" test is itself worth strengthening: by default it rests on the
97
+ *absence* of `X-Forwarded-For`/`X-Real-IP`, which a proxy that stops adding them (a
98
+ misconfiguration, not an attack) can erase for every internet caller at once. Set
99
+ `AUTH_SERVICE_TOKEN` to the same value in the service's environment and the game's, and
100
+ the exemption instead requires a loopback peer, a matching `X-Auth-Service-Token`
101
+ header, **and** that same header absence — the token tightens the legacy rule, it does
102
+ not replace it, so a caller who learns the token still cannot claim the exemption
103
+ through the proxy. Unset is a supported, backward-compatible default — the service warns
104
+ at startup — but see [docs/deploy.md](docs/deploy.md) for the order to turn it on without
105
+ taking logins down.
106
+
107
+ Both shipped proxy configs turn access logging off for `/auth/`, because the request
108
+ line carries the nonce and the authorization code. Report vulnerabilities per
109
+ [SECURITY.md](SECURITY.md).
110
+
111
+ ## Test
112
+
113
+ python -m unittest discover -s tests -v
114
+
115
+ ## Credits and license
116
+
117
+ Originally built as the auth service for [StickMUD](https://stickmud.com), following
118
+ the pattern proven by [MUDdown](https://github.com/MUDdown/MUDdown). MIT licensed —
119
+ see [LICENSE](LICENSE).
@@ -0,0 +1,86 @@
1
+ # mudauth -- Apache 2.4 reverse proxy for the public /auth/ path.
2
+ #
3
+ # Apache equivalent of deploy/nginx/mudauth.conf, for servers that use Apache
4
+ # (certbot --apache) instead of nginx. Apache terminates TLS and proxies the
5
+ # browser-facing OAuth endpoints to the loopback mudauth listener. The MUD
6
+ # itself never accepts inbound HTTP; only Apache -> 127.0.0.1:7700 does.
7
+ #
8
+ # These directives go INSIDE the HTTPS <VirtualHost *:443> that serves your MUD
9
+ # domain -- the block certbot manages, e.g.
10
+ # /etc/apache2/sites-available/<domain>-le-ssl.conf
11
+ # Find it with: sudo apache2ctl -S
12
+ # This file is a reference snippet; do NOT `Include` it as its own vhost.
13
+ #
14
+ # Enable the proxy modules once:
15
+ # sudo a2enmod proxy proxy_http headers
16
+ # sudo systemctl reload apache2
17
+ #
18
+ # After editing the vhost, validate and reload:
19
+ # sudo apache2ctl configtest && sudo systemctl reload apache2
20
+
21
+ # Forward the original Host and mark the scheme as HTTPS for the backend.
22
+ ProxyPreserveHost On
23
+ RequestHeader set X-Forwarded-Proto "https"
24
+
25
+ # Origin binding depends on the backend seeing the browser's real address, so
26
+ # pin it here rather than relying on what mod_proxy adds by default. Setting it
27
+ # explicitly also overwrites any X-Real-IP the client sent, which is the point.
28
+ RequestHeader set X-Real-IP "%{REMOTE_ADDR}s"
29
+
30
+ # ProxyAddHeaders MUST remain On (its default) -- that is what appends the
31
+ # client to X-Forwarded-For. Turning it Off, a common privacy hardening, would
32
+ # strip the forwarding headers mod_proxy adds; every internet request would then
33
+ # reach the service from 127.0.0.1 with nothing to distinguish it from the
34
+ # game's own loopback calls, and origin binding would be skipped entirely. The
35
+ # explicit X-Real-IP above is a second line of defense, not a replacement.
36
+ ProxyAddHeaders On
37
+
38
+ # Strip whatever a client sent in this header before proxying: the loopback
39
+ # exemption's token check requires no forwarding header on the request, but
40
+ # the service still trusts THIS header at face value from a loopback peer.
41
+ # Passing a client-supplied value through would let anyone who has learned
42
+ # AUTH_SERVICE_TOKEN present it via this proxy and inherit the game's
43
+ # exemption remotely.
44
+ RequestHeader unset X-Auth-Service-Token
45
+
46
+ # https://<host>/auth/* -> 127.0.0.1:7700/auth/* (prefix preserved).
47
+ # The game builds <AUTH_PUBLIC_BASE>/auth/login/... so the host-root public base
48
+ # (AUTH_PUBLIC_BASE = "https://mud.example") lands on the service's own /auth/*
49
+ # routes here.
50
+ ProxyPass /auth/ http://127.0.0.1:7700/auth/
51
+ ProxyPassReverse /auth/ http://127.0.0.1:7700/auth/
52
+
53
+ # --- Notes ------------------------------------------------------------------
54
+ #
55
+ # Canonical host: if the vhost redirects bare <domain> -> www.<domain> (or the
56
+ # reverse), register the OAuth callback on the CANONICAL host and use that same
57
+ # host in AUTH_PUBLIC_BASE / AUTH_CALLBACK_URL and in each provider's redirect
58
+ # URI, so the provider redirect lands with no extra 301 hop and the redirect_uri
59
+ # matches exactly.
60
+ #
61
+ # Access logging: the request line carries live credentials for their 10-minute
62
+ # lifetime -- the login_nonce in /auth/login/<provider>/<nonce>, ?code= and
63
+ # ?nonce=, and Steam's signed assertion. The service redacts them from its own
64
+ # log; this vhost's CustomLog records them in full. The nginx config turns
65
+ # logging off for the /auth/ location; Apache's equivalent is a condition on the
66
+ # CustomLog line in this vhost:
67
+ # SetEnvIf Request_URI "^/auth/" auth_request
68
+ # CustomLog /var/log/apache2/<domain>-access.log combined env=!auth_request
69
+ # Adjust the existing CustomLog rather than adding a second one, or the requests
70
+ # will simply be logged by the line you left alone.
71
+ #
72
+ # Rate limiting: the nginx config uses `limit_req`; Apache has no built-in
73
+ # equivalent. Add mod_evasive or mod_qos if you want one. It is optional -- the
74
+ # service already enforces per-flow CSRF `state`, single-use nonces with a
75
+ # 10-minute TTL, and origin-IP binding, so this is defense in depth.
76
+ #
77
+ # Firewall: nothing new here. Callbacks ride :443 (this vhost); mudauth listens
78
+ # on loopback only (127.0.0.1:7700) and is never exposed. Only the game's
79
+ # telnet/TLS ports need firewall rules.
80
+ #
81
+ # A second instance: if you run a staging service on another port, add a second
82
+ # pair of ProxyPass directives for it and set that instance's AUTH_PUBLIC_BASE
83
+ # to the prefix you proxy it at. Mind the prefix arithmetic -- mudauth always
84
+ # serves its routes under /auth/, so a public base of "https://<host>/staging"
85
+ # must reach the service at /staging/auth/*, which means mapping /staging/ to
86
+ # the service ROOT, not to its /auth/.
@@ -0,0 +1,36 @@
1
+ [Unit]
2
+ Description=mudauth OAuth/OIDC sign-in broker
3
+ Documentation=https://github.com/StickMUD/mudauth
4
+ After=network.target
5
+ StartLimitIntervalSec=60s
6
+ StartLimitBurst=5
7
+
8
+ [Service]
9
+ Type=simple
10
+ User=mudauth
11
+ Group=mudauth
12
+ # PYTHONUNBUFFERED: stdout is block-buffered when not a TTY (always true
13
+ # here), so without this a diagnostic can sit unflushed in the journal for a
14
+ # long time. server.py now flushes every print() itself; this is belt and
15
+ # braces for anyone launching it a different way.
16
+ Environment=PYTHONUNBUFFERED=1
17
+ EnvironmentFile=/etc/mudauth/.env
18
+ ExecStart=/home/mudauth/.local/bin/mudauth serve
19
+ Restart=on-failure
20
+ RestartSec=5
21
+ NoNewPrivileges=yes
22
+ ProtectSystem=strict
23
+ ProtectHome=read-only
24
+ PrivateTmp=yes
25
+ PrivateDevices=yes
26
+ ProtectKernelTunables=yes
27
+ ProtectKernelModules=yes
28
+ ProtectControlGroups=yes
29
+ RestrictAddressFamilies=AF_INET AF_INET6
30
+ LimitNOFILE=8192
31
+ StandardOutput=journal
32
+ StandardError=journal
33
+ SyslogIdentifier=mudauth
34
+
35
+ [Install]
36
+ WantedBy=multi-user.target
@@ -0,0 +1,48 @@
1
+ # mudauth -- nginx reverse proxy for the public /auth/ path.
2
+ #
3
+ # nginx terminates TLS (certbot) and proxies the browser-facing OAuth endpoints
4
+ # to the loopback mudauth listener. The MUD itself never accepts inbound HTTP;
5
+ # only nginx -> 127.0.0.1:7700 does.
6
+ #
7
+ # Add this location block inside the HTTPS `server { }` block that serves
8
+ # mud.example (the same block certbot manages). It makes
9
+ # https://mud.example/auth/* reach mudauth, which is exactly the value of
10
+ # AUTH_PUBLIC_BASE in the service's .env.
11
+ #
12
+ # A matching rate-limit zone (defined once at http{} scope):
13
+ # limit_req_zone $binary_remote_addr zone=auth:10m rate=10r/s;
14
+
15
+ location /auth/ {
16
+ limit_req zone=auth burst=20 nodelay;
17
+
18
+ # The request line carries live credentials for their 10-minute lifetime:
19
+ # the login_nonce in /auth/login/<provider>/<nonce>, ?code= and ?nonce=,
20
+ # and Steam's signed assertion. The service redacts them from its own log;
21
+ # nginx's access_log would record them in full, so it is off here.
22
+ access_log off;
23
+
24
+ # No trailing slash on proxy_pass: the /auth/ prefix is preserved, so
25
+ # /auth/login and /auth/callback map straight through to the service.
26
+ proxy_pass http://127.0.0.1:7700;
27
+ proxy_http_version 1.1;
28
+
29
+ proxy_set_header Host $host;
30
+ proxy_set_header X-Real-IP $remote_addr;
31
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
32
+ proxy_set_header X-Forwarded-Proto $scheme;
33
+
34
+ # Strip whatever a client sent in this header before proxying: the
35
+ # loopback exemption's token check requires no forwarding header on the
36
+ # request, but the service still trusts THIS header at face value from a
37
+ # loopback peer. Passing a client-supplied value through would let anyone
38
+ # who has learned AUTH_SERVICE_TOKEN present it via this proxy and
39
+ # inherit the game's exemption remotely. Blank clears it; nginx does not
40
+ # merge repeated proxy_set_header lines for the same name, so this line
41
+ # alone is the whole value the service receives, even if the client sent
42
+ # one.
43
+ proxy_set_header X-Auth-Service-Token "";
44
+
45
+ proxy_connect_timeout 10s;
46
+ proxy_read_timeout 30s;
47
+ proxy_send_timeout 30s;
48
+ }