Commit cba96af
fix(outlook): skip mailbox-less accounts and stop SSL misconfig from aborting sync (#4085)
## Relates to elastic/sdh-search#1898
Fixes two independent failure modes in the Outlook Server connector that
caused an entire sync job to abort when a single account or the SSL
configuration was misconfigured. The guiding principle of this branch:
**per-account problems skip that account and continue; connection-wide
problems fail the sync loudly** (so they cannot silently empty the
index).
**Issue A — `ErrorNonExistentMailbox` kills the whole sync**
When iterating over AD user accounts, `get_mails()` accesses
`account.inbox`, which lazily resolves `account.root` via an EWS
`GetFolder` call. For AD users whose SMTP address has no associated
Exchange mailbox (a valid LDAP entry but no mailbox provisioned),
`exchangelib` raises `ErrorNonExistentMailbox`. With no exception
handling around the per-account block, this propagated up and terminated
the sync, losing all remaining accounts. This is the still-open part of
#2931.
**Fix:** the per-account block in `get_docs()` is wrapped in `try/except
ErrorNonExistentMailbox`. A missing mailbox is specific to a single
account, so the account is skipped with a warning and the sync continues
with the remaining accounts.
**Issue B — `NO_CERTIFICATE_OR_CRL_FOUND` SSL crash**
When `ssl_enabled=True` but no certificate is provided, `ssl_ca` is set
to `""`. The old code wrote that empty string to the cert file and still
selected `RootCAAdapter`. When urllib3 later called
`context.load_verify_locations()` on the empty file it raised
`NO_CERTIFICATE_OR_CRL_FOUND`, aborting the sync. The error occurs
inside the HTTP layer (not inside `cert_verify()`), so `RootCAAdapter`'s
own `try/except` never caught it.
**Fix:** in `ExchangeUsers.get_user_accounts()`, the cert file is
written and `RootCAAdapter` is selected only when `ssl_ca` is actually
populated. When SSL is enabled but no certificate is supplied, the
connector falls back to `NoVerifyHTTPAdapter` and logs a clear warning
instead of crashing.
### Why connection-wide SSL errors are NOT skipped per account
An earlier iteration of this branch also caught a custom `SSLFailed`
exception inside the per-account loop to "skip" accounts on SSL
problems. That approach was removed because it was both ineffective and
dangerous:
- **Ineffective:** `SSLFailed` is only raised inside
`RootCAAdapter.cert_verify`, and `requests`' `cert_verify` does not
actually load the certificate — it only records the CA path. A genuinely
bad/expired cert fails later, during the TLS handshake, where
`exchangelib` catches the underlying `requests.exceptions.SSLError` and
re-raises it as `exchangelib.errors.TransportError` (and explicitly does
**not** retry it). So `SSLFailed` was never raised in practice and the
`except SSLFailed` clause was dead code.
- **Dangerous:** an SSL/connection failure affects *every* account, not
one. Silently skipping all accounts would produce an empty but
"successful" sync, which the framework interprets as "all documents
deleted" — wiping previously indexed data.
Therefore only `ErrorNonExistentMailbox` (genuinely per-account) is
skipped. Connection-wide failures — TLS errors surfaced as
`TransportError`, and any other unexpected error — propagate and abort
the sync loudly, so the misconfiguration is surfaced to the operator and
existing indexed data is preserved.
## Checklists
#### Pre-Review Checklist
- [ ] this PR does NOT contain credentials of any kind, such as API keys
or username/passwords (double check `config.yml.example`)
- [x] this PR has a meaningful title
- [x] this PR links to all relevant github issues that it fixes or
partially addresses
- [ ] if there is no GH issue, please create it. Each PR should have a
link to an issue
- [x] this PR has a thorough description
- [x] Covered the changes with automated tests
- [x] Tested the changes locally
- [x] Added a label for each target release version (example: `v7.13.2`,
`v7.14.0`, `v8.0.0`)
- [ ] For bugfixes: backport safely to all minor branches still
receiving patch releases
- [ ] Considered corresponding documentation changes
- [ ] Contributed any configuration settings changes to the
configuration reference
- [ ] if you added or changed Rich Configurable Fields for a Native
Connector, you made a corresponding PR in
[Kibana](https://github.com/elastic/kibana/blob/main/packages/kbn-search-connectors/types/native_connectors.ts)
#### Changes Requiring Extra Attention
- [x] Security-related changes (encryption, TLS, SSRF, etc) — the SSL
cert fallback behaviour changes: `ssl_enabled=True` with no cert now
falls back to `NoVerifyHTTPAdapter` (unverified connections) instead of
crashing. A genuinely invalid/expired certificate now fails the sync
loudly rather than being silently skipped. Reviewers should confirm the
no-cert fallback posture is desired.
## Related Pull Requests
* Partially addresses #2931
## Release Note
**Outlook Server connector**: sync jobs no longer abort when an Active
Directory user has a valid SMTP address but no associated Exchange
mailbox (`ErrorNonExistentMailbox`). The affected account is now skipped
with a warning and the sync continues. Additionally, configuring SSL
without providing a certificate no longer crashes with
`NO_CERTIFICATE_OR_CRL_FOUND`; the connector falls back to unverified
connections and logs a clear warning. Genuine certificate/connection
errors still fail the sync loudly rather than silently emptying the
index.
Made with [Cursor](https://cursor.com)
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent e038128 commit cba96af
4 files changed
Lines changed: 251 additions & 28 deletions
File tree
- app/connectors_service
- connectors
- sources/outlook
- tests
- sources
Lines changed: 65 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
294 | 296 | | |
295 | 297 | | |
296 | 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 | + | |
297 | 334 | | |
298 | 335 | | |
299 | 336 | | |
| |||
562 | 599 | | |
563 | 600 | | |
564 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
565 | 605 | | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
573 | 610 | | |
574 | | - | |
575 | | - | |
| 611 | + | |
| 612 | + | |
576 | 613 | | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
581 | 618 | | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
558 | 558 | | |
559 | 559 | | |
560 | 560 | | |
561 | | - | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
562 | 569 | | |
563 | 570 | | |
564 | | - | |
565 | | - | |
| 571 | + | |
| 572 | + | |
566 | 573 | | |
567 | 574 | | |
568 | 575 | | |
| |||
574 | 581 | | |
575 | 582 | | |
576 | 583 | | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
577 | 591 | | |
578 | 592 | | |
579 | 593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
770 | 774 | | |
771 | 775 | | |
772 | 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 | + | |
| 840 | + | |
773 | 841 | | |
774 | 842 | | |
775 | 843 | | |
| |||
780 | 848 | | |
781 | 849 | | |
782 | 850 | | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
783 | 906 | | |
784 | 907 | | |
785 | 908 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
847 | 847 | | |
848 | 848 | | |
849 | 849 | | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
850 | 856 | | |
851 | 857 | | |
852 | 858 | | |
| |||
860 | 866 | | |
861 | 867 | | |
862 | 868 | | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | 869 | | |
868 | 870 | | |
869 | | - | |
870 | | - | |
| 871 | + | |
871 | 872 | | |
872 | 873 | | |
873 | 874 | | |
| |||
884 | 885 | | |
885 | 886 | | |
886 | 887 | | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
887 | 926 | | |
888 | 927 | | |
889 | 928 | | |
| |||
0 commit comments