woodglue.apps.identity_providers¶
OpenID Connect and GitHub sign-in.
Signing in through Identity Providers: OpenID Connect, GitHub, and trusted reverse proxies.
woodglue is its own OAuth client (see docs/adr/0001). A sign-in is the
authorization code flow with PKCE:
/auth/start/<provider>records a pending sign-in (state, nonce, PKCE verifier, and where to return), binds it to the browser with a short-livedwgl_logincookie, and redirects to the provider./auth/callback/<provider>checks that the returnedstatematches the cookie, exchanges the code, and turns the provider's answer into anExternalIdentity. For OIDC that is the validated id_token (issuer, audience, expiry, nonce, signature against the provider's JWKS); for GitHub it is the user, verified primary email, orgs, and teams from the API.- The person is then checked against the provider's
admitrules, signed in as a local User (sign_in), and given a Session.
Admission and claim-to-Role mapping are re-evaluated at every sign-in. A User
the sign-in creates gets the status admit_status picks: pending under the
provider's admit_as: pending, unless the person is in auth.admins. A
pending User who is in auth.admins by the next sign-in becomes active.
A trusted proxy (JwtProxy, HeaderProxy) has no round trip: it asserts the
identity on every request, and woodglue.apps.authn turns the first valid
assertion into a Session.
Pending sign-ins live in memory for ten minutes, so a restart in the middle of one only means signing in again.
SignInError
¶
ExternalIdentity
dataclass
¶
What an Identity Provider asserts about a person.
Source code in src/woodglue/apps/identity_providers.py
PendingSignIns
¶
In-memory pending sign-ins keyed by OAuth state.
Source code in src/woodglue/apps/identity_providers.py
ProviderClient
¶
Bases: ABC
Talks to one Identity Provider. Subclasses implement one protocol.
Source code in src/woodglue/apps/identity_providers.py
GitHubClient
¶
Bases: ProviderClient
Source code in src/woodglue/apps/identity_providers.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
TrustedProxy
¶
Bases: ABC
Reads the identity a trusted reverse proxy asserts on each request.
Source code in src/woodglue/apps/identity_providers.py
JwksCache
¶
Signing keys from a JWKS URL, refreshed hourly and when a token names an unknown key id, but at most once a minute, so forged key ids cannot make woodglue hammer the URL.
https:// keys load in the background (load, which create_app starts),
so request handling never waits on the network: a token checked before
they arrive, or naming a key not seen yet, is refused while a refresh runs.
file:// keys, for providers whose keys are deployed as files, are read
in place.
Source code in src/woodglue/apps/identity_providers.py
load()
async
¶
Fetch the keys now. Failures are logged; a later check retries.
Source code in src/woodglue/apps/identity_providers.py
JwtProxy
¶
Bases: TrustedProxy
Verifies a JWT the proxy puts in a header, against keys from jwks_url.
Source code in src/woodglue/apps/identity_providers.py
HeaderProxy
¶
Bases: TrustedProxy
Trusts plain identity headers, but only from trusted_sources.
Source code in src/woodglue/apps/identity_providers.py
admits(rules, who)
¶
Whether rules admit who. Email rules only consider a verified email.
>>> ann = ExternalIdentity("okta", "1", "ann@x.com", True, "Ann", ("ops",))
>>> admits(AdmitRules(email_domains=["x.com"]), ann), admits(AdmitRules(groups=["ops"]), ann)
(True, True)
>>> eve = ExternalIdentity("okta", "2", "eve@x.com", False, "Eve")
>>> admits(AdmitRules(email_domains=["x.com"]), eve)
False
Source code in src/woodglue/apps/identity_providers.py
is_admin(who, admins)
¶
Whether who is one of the configured auth.admins, by verified email.
Source code in src/woodglue/apps/identity_providers.py
admit_status(provider, who, admins)
¶
The status of a User a sign-in creates: the provider's admit_as, except
that configured admins are always active, so a fresh deployment's first
admin is never left waiting for approval.
>>> p = ProviderConfig(id="gh", kind="github", client_id="c", client_secret="s",
... admit=AdmitRules(anyone=True), admit_as="pending")
>>> ann = ExternalIdentity("gh", "1", "ann@x.com", True, "Ann")
>>> str(admit_status(p, ann, [])), str(admit_status(p, ann, ["ann@x.com"]))
('pending', 'active')
Source code in src/woodglue/apps/identity_providers.py
role_sources(provider, who, admins)
¶
The Role assignments a sign-in sets, keyed by source: the provider's default
and group-mapped Roles, and admin for configured admins.
>>> p = ProviderConfig(id="okta", kind="oidc", issuer="https://i", client_id="c",
... client_secret="s", admit=AdmitRules(anyone=True), default_roles=["viewer"],
... group_roles={"ops": ["operator"]})
>>> ann = ExternalIdentity("okta", "1", "ann@x.com", True, "Ann", ("ops",))
>>> role_sources(p, ann, ["ANN@x.com"])
{'provider:okta': ['operator', 'viewer'], 'admins': ['admin']}
Source code in src/woodglue/apps/identity_providers.py
sign_in(store, provider, who, admins)
¶
Sign in who, already admitted by provider, as a local User: sync its
role_sources, create a new User with the status admit_status picks,
and make a pending User who is now in auth.admins active. Raises
UserDisabled for a disabled User, admin or not.
Source code in src/woodglue/apps/identity_providers.py
pkce_challenge(verifier)
¶
The S256 PKCE challenge for a verifier (RFC 7636).
make_clients(providers)
¶
Clients for the providers people sign in with through the login page.
Source code in src/woodglue/apps/identity_providers.py
make_trusted_proxies(providers)
¶
Verifiers for the trusted-proxy providers among providers.