woodglue.auth_store¶
Users, Role assignments, and credentials in auth.db.
Users, Role assignments, and credentials in auth.db.
AuthStore is the only reader and writer of auth.db. Credentials are opaque
random secrets looked up on every request (see docs/adr/0002), so revoking a
token, disabling or deleting a User, or changing a Role assignment takes effect
immediately, including on a running server.
A User's status (UserStatus) is pending, active, or disabled. A person
whose Identity Provider sets admit_as: pending starts pending: signed in, with
its synced Role assignments, but no Grants and no way to create credentials
until approve_user makes it active. Only person Users are ever pending.
Disabling a User keeps its record, so the person stays refused; it is also how a
pending User is denied. Enabling makes a disabled User active, never pending.
Deleting erases a User, with its Role assignments, Linked Identities, and
credentials; if the person signs in again they become a new User. Run history
outside auth.db keeps the deleted User's id.
Each Role assignment has a source: manual for one an admin made, or the
sign-in source that set it (provider:<id>, admins), which the next sign-in
through it replaces. unassign_role removes a Role from every source, so a
synced Role comes back at that User's next sign-in.
Role definitions are not stored here: they come from woodglue.yaml (see
woodglue.access). A Role assignment naming a Role that is no longer defined
grants nothing.
A Session is the credential behind a browser's cookie. It ends after
session_idle without use or session_max after creation, whichever is first;
woodglue does not re-check with the Identity Provider in between.
A Delegated Token lets a Process-backed UI call the API as the User viewing
it. It belongs to one Session and one UI, carries the Session's Grants narrowed
to the UI's own grants, and ends with the Session. Its use does not keep the
Session alive: only the person's own requests, including those through the UI,
do.
The built-in admin Service User owns the tokens that wgl token prints. Tokens
from the pre-Users tokens table are migrated to it on first open, so existing
scripts keep working. It cannot be disabled, deleted, or lose the admin Role,
so wgl token always yields full access.
MANUAL = 'manual'
module-attribute
¶
Source of Role assignments made by an admin, as opposed to synced at sign-in.
UserStatus
¶
Bases: StrEnum
pending Users are signed in but hold no Grants until approved; only
person Users can be pending. disabled Users are refused everywhere.
Source code in src/woodglue/auth_store.py
RoleAssignment
¶
Bases: BaseModel
One Role given to a User by one source: manual for an admin, otherwise a
sign-in source such as provider:<id> or admins, which the next sign-in
through it sets again.
Source code in src/woodglue/auth_store.py
User
¶
Bases: BaseModel
Source code in src/woodglue/auth_store.py
roles = []
class-attribute
instance-attribute
¶
Distinct Roles from all of role_assignments.
providers = []
class-attribute
instance-attribute
¶
Identity Providers of the User's Linked Identities.
builtin = False
class-attribute
instance-attribute
¶
The built-in admin Service User, which cannot be disabled, deleted, or lose admin.
TokenInfo
¶
Bases: BaseModel
A Personal Access Token as listed; never includes the secret.
Source code in src/woodglue/auth_store.py
IssuedToken
¶
AuthStore
¶
Access to auth.db. roles maps Role names to their Grants, as returned
by woodglue.access.resolve_roles.
Source code in src/woodglue/auth_store.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | |
find_user(ref)
¶
Look up a User by id, email, or name. A name matching several Users is
ambiguous and raises UnknownUser.
Source code in src/woodglue/auth_store.py
unassign_role(user_id, role)
¶
Remove a Role from every source; a provider re-adds its own at the next sign-in.
Source code in src/woodglue/auth_store.py
approve_user(user_id, roles=())
¶
Make a pending User active, assigning roles manually. Raises
ValueError if the User is not pending, so that approving from a stale
view fails visibly rather than doing nothing.
Source code in src/woodglue/auth_store.py
set_disabled(user_id, disabled)
¶
Disable or re-enable a User. Disabling deletes all of its credentials
and is also how a pending User is denied. Enabling makes the User
active; a pending User must be approved instead.
Source code in src/woodglue/auth_store.py
delete_user(user_id)
¶
Erase a User. ON DELETE CASCADE removes its Role assignments, Linked
Identities, and credentials, including Delegated Tokens.
Source code in src/woodglue/auth_store.py
linked_user(provider, subject)
¶
The id of the User linked to an Identity Provider's subject, if any.
Source code in src/woodglue/auth_store.py
sign_in_person(provider, subject, *, email, email_verified, name, role_sources, admit_as=UserStatus.active, activate_pending=False)
¶
Find or create the User for an Identity Provider's assertion, after the caller has decided the person is admitted.
The User is found by its Linked Identity, else by a verified email
matching an existing User (linking the identity to it), else created.
An unverified email is not stored, so it can never take over an account.
Each entry of role_sources replaces that source's Role assignments,
leaving assignments from other sources (and manual ones) alone.
admit_as is the status of a User this creates, active or pending;
an existing User keeps its status, except that activate_pending
(set for configured admins) makes a pending User active.
Raises UserDisabled if the User is disabled.
Source code in src/woodglue/auth_store.py
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
create_token(user_id, name, *, expires_at=None, grants=None)
¶
Issue a Personal Access Token. grants, if given, narrows the token to
a subset of its User's Grants; they are validated but not checked
against the User, since the effective set is computed per request.
Raises UserPending or UserDisabled unless the User is active. The
check is here, not only at each route, because a request approved
earlier (such as a CLI code) can be redeemed after the status changed.
Source code in src/woodglue/auth_store.py
ensure_admin_token()
¶
Create a token for the built-in admin User if it has none.
admin_tokens()
¶
rotate_admin_token()
¶
Replace all admin tokens with one new one, in one transaction, so a
concurrent resolve never sees the admin without a token.
Source code in src/woodglue/auth_store.py
live_session(user_id, name)
¶
The secret of a live Session of user_id started under name, if any.
Source code in src/woodglue/auth_store.py
create_session(user_id, name='browser')
¶
Start a Session for a User and return its secret, for the browser
cookie. name records how it was started.
Source code in src/woodglue/auth_store.py
delegate(session_secret, ui_name, grants=None)
¶
The Delegated Token for a UI acting on behalf of a Session, created on
first use. grants, the UI's configured Grants, narrows it like a
narrowed Personal Access Token, and is updated on each call so a config
change applies at once. Raises ValueError unless session_secret is
a live Session.
Source code in src/woodglue/auth_store.py
session_is_live(secret)
¶
Whether a Session is still valid, without counting this check as use.
Source code in src/woodglue/auth_store.py
resolve(secret)
¶
Return the Caller for a credential secret, or None if it is not valid
now. Resolving a Session counts as using it; resolving one of its
Delegated Tokens does not.