allthingssecurity opened a new pull request, #30814:
URL: https://github.com/apache/camel/pull/30814

   # Description
   
   [CAMEL-27488](https://issues.apache.org/jira/browse/CAMEL-27488)
   
   The AWS Secrets Manager and HashiCorp Vault secret refresh tasks marked an 
update as seen before they reloaded the CamelContext:
   - `CloudTrailReloadTriggerTask` in CloudTrail mode moved `lastTime` and 
added the event ids to `seenEventIds`; in SQS mode it deleted the notification 
from the queue;
   - `HashicorpVaultReloadTriggerTask` stored the new version in `versionsMap`.
   
   Then they called `reload.onReload(this)`. 
`DefaultContextReloadStrategy.onReload` catches every exception: it counts a 
failed reload, logs a WARN and emits an event, and the task never learned that 
the reload failed. The next check found nothing new, so nothing reloaded again.
   
   A reload removes all the routes first and then starts them again from their 
definitions. So with the default route controller, when one route failed to 
start during the reload (its broker briefly unreachable, a placeholder lookup 
that failed), that route stayed stopped and the routes after it were not added 
back to the context, until the next update of a secret, a manual reload or a 
restart. (With the supervising route controller a route that fails to start 
does not fail the reload: the controller starts it again by itself, and the 
reload counts as succeeded, so the task marks the update as seen, as it 
should.) The "Will try again on next run" in the task's logs only ever applied 
to a failed call to the secret store.
   
   Change: the tasks mark an update as seen only once the reload succeeded.
   - CloudTrail mode: the event ids of the check and the new `lastTime` are 
committed after the reload. A failed reload leaves them as they were, so the 
next check looks up the same range, sees the same event as new and reloads 
again.
   - SQS mode: a message that is not an update of a tracked secret, or that is 
not valid JSON, is still deleted at once, so the queue is still drained 
(CAMEL-24193). The notification of an update is deleted after the reload 
succeeded. After a failed reload the queue delivers it again once its 
visibility timeout is over, and that check reloads again (a redrive policy on 
the queue can move it to its dead-letter queue first, and then there is no 
retry). A delete that fails is now logged as a WARN and does not stop the check 
(before, it ended the check).
   - HashiCorp Vault: the new versions are stored in `versionsMap` after the 
reload.
   
   The task tells a failed reload from the reload strategy's failed counter 
(`ReloadStrategy.getFailedCounter()`, read before and after `onReload`, as 
`ReloadDevConsole` already does), so no public API changes and 
`DefaultContextReloadStrategy` is not touched. An exception thrown by another 
`ContextReloadStrategy` also counts as a failed reload. A reload from another 
source (JMX, for example) that fails between the two reads is also seen as 
failed by the task; that costs one more reload at the next check, nothing else.
   
   The retry is bounded: one reload per check, with a WARN each time it fails, 
and at most 10 in a row (`MAX_RELOAD_ATTEMPTS`). Then the update is marked as 
seen with a WARN, as the code did before, and the task waits for the next 
update. With the default refresh periods that is about 5 minutes (AWS, 30 s) or 
10 minutes (HashiCorp, 60 s). A reload that keeps failing therefore stops and 
starts the routes up to 10 times; before it did so once.
   
   Docs: both component pages say what happens after a failed reload (catalog 
copies regenerated), and the 4.24 upgrade guide has a new section 
`camel-hashicorp-vault, camel-aws-secrets-manager - a failed reload after a 
secret update is tried again`, because users can see the extra reloads and the 
later delete of the SQS notification.
   
   Not changed here:
   - `lastCheckTime` and `lastReloadTime` are still set before the check and 
before the reload, so the secrets dev consoles show a check that failed, or a 
reload that failed, as done (low; I will file a follow-up ticket);
   - an event that CloudTrail makes visible more than 10 minutes after a newer 
one is still missed (the documented look-back of CAMEL-25980);
   - the GCP, Azure, IBM, Kubernetes and Spring Cloud Config refresh tasks also 
ignore whether the reload succeeded; I did not look at whether each can retry, 
and will file a follow-up ticket;
   - two reloads at the same time (this task and JMX, for example) can leave a 
copy of every route: that is CAMEL-27489, in #30806;
   - a CloudTrail or SQS call has no timeout, so a slow store holds the thread 
of every periodic task: a separate ticket, with its own PR.
   
   Tests (package-private, no sleep):
   - `CloudTrailReloadTriggerTaskReloadRetryTest` (mocked `CloudTrailClient` 
and `SqsClient`, a real CamelContext with a `DefaultContextReloadStrategy` and 
a route whose consumer fails to start once, and a properties function that 
stands for the secret store):
     - `failedReloadIsTriedAgainByTheNextRun`: after a `PutSecretValue` event 
and a failed reload the route is Stopped; the next check reloads, the route is 
Started with the new value, and a further check does not reload again;
     - `failedReloadIsTriedAtMostMaxAttemptsTimes`: a reload that keeps failing 
is tried 10 times over 13 checks, then no more; the next update reloads again;
     - `notificationIsDeletedOnlyOnceTheReloadSucceeded`: SQS mode, the 
notification is not deleted after the failed reload, and deleted once the 
reload of the redelivered notification succeeded;
   - `HashicorpVaultReloadTriggerTaskReloadRetryTest` (a fake Vault KV v2 over 
HTTP, as in `HashicorpVaultReloadTriggerTaskTest`): the same first two cases 
with versions 1, 2 and 3 of the secret.
   
   The five tests fail with the current tasks (the next check does not reload: 
0 reloads instead of 1, 1 failed reload instead of 10, the notification deleted 
after the failed reload). With the change, the unit tests of 
camel-aws-secrets-manager (35 run, 0 failures) and camel-hashicorp-vault (86 
run, 0 failures) pass, and each new test class passes 20 of 20 runs. On a merge 
with the two sibling branches below, the same suites pass (38 and 86 run, 0 
failures). The ITs of both modules were not run locally (CI runs them).
   
   A TLA+ model of the refresh tasks, the shared periodic task thread and the 
context reload found this: its property "every update observed is eventually 
applied by a successful reload" fails on the current code, and holds when the 
update is marked as seen only after a successful reload (checked with 1 and 2 
tasks, 1 to 2 updates, one failure of each kind).
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it): 
[CAMEL-27488](https://issues.apache.org/jira/browse/CAMEL-27488).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built camel-aws-secrets-manager, camel-hashicorp-vault and the core 
modules with the formatter and import-sort plugins and ran their unit tests. I 
did not run the full root build. The catalog copies of the two component pages 
are included.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to