Commit 0f940ca
feat(telegram): add allow_all_users/allowed_users to [telegram] config (#1297)
* feat(telegram): add allow_all_users/allowed_users to [telegram] config
Discord and Slack have had allowed_users in their first-class config
sections for a while, but [telegram] never did - the only way to
restrict who can message a Telegram bot was the shared GATEWAY_*
env vars (GATEWAY_ALLOW_ALL_USERS/GATEWAY_ALLOWED_USERS), which
default to deny-all (per the identity-trust-none ADR) and aren't
Telegram-specific.
Add allow_all_users/allowed_users to TelegramConfig, matching the same
resolution convention already used for every other [telegram] field
and for Discord's allowed_users: config value wins, falls back to a
TELEGRAM_* env var (TELEGRAM_ALLOW_ALL_USERS / TELEGRAM_ALLOWED_USERS,
comma-separated), then auto-detects allow_all_users from whether the
resolved list is empty (same convention as [discord]/[slack]).
Wire the resolved values into main.rs's PlatformTrustConfigs registry
as a Telegram-specific override, mirroring exactly how Discord's own
block already overrides the shared GATEWAY_* L3 defaults - added
right after the existing Discord override.
Now a bot operator can write:
[telegram]
bot_token = "${TELEGRAM_BOT_TOKEN}"
allowed_users = ["176096071"]
instead of routing a plain user ID through spec.secrets/Secrets
Manager (oabctl's manifest has no plain env var field) or opening the
bot to allow_all_users=true just to admit one person.
Testing: cargo build/clippy -D warnings/test clean on macmini for the
whole workspace (openab-core: 48 tests incl. 5 new allowed_users
scenarios in telegram_resolve_all_scenarios; openab binary: 15 tests).
No regressions. Fixed one now-incomplete TelegramConfig struct literal
in an existing test (missing the two new fields).
* docs(telegram): document allowed_users/allow_all_users config
Add the new [telegram] user access control fields to:
- Unified mode env vars table
- Full example config block
- Field precedence table
- Gateway Environment Variables table
- New 'User Access Control' section with auto-detect logic explanation
* feat(telegram): default allow_all_users to false (deny-all)
Align [telegram] user gating with the identity-trust-none ADR:
- Empty allowed_users + no explicit flag → deny all (was: allow all)
- Users must now explicitly set allow_all_users = true or list
specific IDs in allowed_users to admit senders
- Matches the shared GATEWAY_ALLOW_ALL_USERS default (false)
This is not a breaking change for existing deployments because:
- [telegram] config section is brand new (introduced in this PR)
- Existing env-only deployments use GATEWAY_ALLOW_ALL_USERS which
already defaults to deny-all
Added Scenario 12 test: explicit allow_all_users = true opt-in.
* fix(review): env-only bypass + Option<Vec> for config-authoritative override
- F1: Resolve Telegram trust override even when [telegram] section is
absent but TELEGRAM_ALLOWED_USERS / TELEGRAM_ALLOW_ALL_USERS env vars
are set. Previously, env-only deployments (no config.toml section)
silently ignored these env vars and fell back to GATEWAY_* defaults.
- F2: Change TelegramConfig.allowed_users from Vec<String> (with
#[serde(default)]) to Option<Vec<String>>. This lets serde distinguish
omitted (None → fall back to env) from explicitly empty (Some([]) →
deny all, config-authoritative). Fixes the case where allowed_users=[]
in config.toml could not override a non-empty TELEGRAM_ALLOWED_USERS
env var.
- Add Scenario 13 test: explicit empty list overrides env var.
Addresses review findings from 法師團隊 on PR #1297.
* fix(review): empty-string env fail-open, doc clarity, gateway scope
- TELEGRAM_ALLOW_ALL_USERS="" now resolves to false (deny-all) instead
of true. Adds .filter(|v| !v.is_empty()) before parsing to prevent
accidental fail-open from empty env var.
- Added doc comment clarifying that allow_all_users=true bypasses the
allowed_users list entirely.
- Marked TELEGRAM_ALLOWED_USERS/TELEGRAM_ALLOW_ALL_USERS as "Unified
binary only" in the Gateway env vars table — standalone gateway uses
[gateway].allowed_users instead.
- Added Scenario 14 test: empty-string env var must resolve to false.
---------
Co-authored-by: chaodu-agent <chaodu-agent@users.noreply.github.com>
Co-authored-by: chaodu-agent <chaodu-agent@openab.dev>1 parent e804673 commit 0f940ca
3 files changed
Lines changed: 169 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
605 | 605 | | |
606 | 606 | | |
607 | 607 | | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
608 | 621 | | |
609 | 622 | | |
610 | 623 | | |
| |||
618 | 631 | | |
619 | 632 | | |
620 | 633 | | |
| 634 | + | |
| 635 | + | |
621 | 636 | | |
622 | 637 | | |
623 | 638 | | |
| |||
627 | 642 | | |
628 | 643 | | |
629 | 644 | | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
630 | 654 | | |
631 | 655 | | |
632 | 656 | | |
| |||
658 | 682 | | |
659 | 683 | | |
660 | 684 | | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
661 | 693 | | |
662 | 694 | | |
663 | 695 | | |
| |||
1521 | 1553 | | |
1522 | 1554 | | |
1523 | 1555 | | |
| 1556 | + | |
| 1557 | + | |
1524 | 1558 | | |
1525 | 1559 | | |
1526 | 1560 | | |
| |||
1534 | 1568 | | |
1535 | 1569 | | |
1536 | 1570 | | |
| 1571 | + | |
| 1572 | + | |
1537 | 1573 | | |
1538 | 1574 | | |
1539 | 1575 | | |
| |||
1608 | 1644 | | |
1609 | 1645 | | |
1610 | 1646 | | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
1611 | 1718 | | |
1612 | 1719 | | |
1613 | 1720 | | |
| |||
1616 | 1723 | | |
1617 | 1724 | | |
1618 | 1725 | | |
| 1726 | + | |
| 1727 | + | |
1619 | 1728 | | |
1620 | 1729 | | |
1621 | 1730 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | 109 | | |
104 | 110 | | |
| |||
117 | 123 | | |
118 | 124 | | |
119 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
120 | 145 | | |
121 | 146 | | |
122 | 147 | | |
| |||
350 | 375 | | |
351 | 376 | | |
352 | 377 | | |
| 378 | + | |
| 379 | + | |
353 | 380 | | |
354 | 381 | | |
355 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 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 | + | |
319 | 352 | | |
320 | 353 | | |
321 | 354 | | |
| |||
0 commit comments