Skip to content

fix(backend-2fa): remove process-terminating expect from AWS provider initialization - #1273

Merged
llinsss merged 2 commits into
DogStark:mainfrom
rudeus112266:fix/1222-aws-provider-expect
Aug 31, 2026
Merged

fix(backend-2fa): remove process-terminating expect from AWS provider initialization#1273
llinsss merged 2 commits into
DogStark:mainfrom
rudeus112266:fix/1222-aws-provider-expect

Conversation

@rudeus112266

Copy link
Copy Markdown
Contributor

Summary

select_secret_provider() called .expect("failed to initialise AwsSecretsManagerProvider") on AwsSecretsManagerProvider::new(). Any AWS provider construction failure (e.g. the internal Tokio runtime failing to start) panicked the whole process instead of surfacing an actionable startup error. This propagates the error via Result instead.

Before / After

  • Before: select_secret_provider() -> Box<dyn SecretProvider>, panics on AWS init failure.
  • After: select_secret_provider() -> Result<Box<dyn SecretProvider>, String>, returns Err on AWS init failure.
  • AwsSecretsManagerProvider::new() itself already returned Result and was not the source of the panic — the panic was solely at this call site.

Testing

Added focused tests, run with cargo test -p petchain-2fa --lib db:::

  • missing AWS_REGION/AWS_DEFAULT_REGION: construction must not panic (confirmed — aws-config's loader is lazy and doesn't eagerly validate region).
  • missing AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY: construction succeeds, but get_secret returns Err, never panics.
  • missing/empty secret name: get_secret("") returns Err, never panics.

Note: upstream/main (HEAD 2a8656b) currently has 8 pre-existing cargo check -p petchain-2fa --lib errors unrelated to this change (missing enroll_lock field on TwoFactorHandlers, TenantScopedStore not implementing TwoFactorStore), and 14 pre-existing errors in the test-cfg build. Verified this diff adds zero additional errors to either baseline.

Threat model

A panic on AWS misconfiguration is an availability/DoS risk (crashes the whole process instead of degrading to a clear config error), not a confidentiality or authorization concern — no secret values are included in any new error message.

Closes #1222

… init

select_secret_provider() panicked via .expect() if AWS provider construction
failed. It now returns Result and propagates a typed error instead, so
misconfiguration is reported, not fatal.
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@rudeus112266 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@llinsss
llinsss merged commit 64832ea into DogStark:main Aug 31, 2026
0 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[backend-2fa] Remove process-terminating expect from AWS provider initialization

2 participants