Repository navigation
[#343] Tamper-evident CSV audit: start the rotation checks once a resumed file is verified - #352
Closed
vharseko wants to merge 1 commit into
Conversation
…on checks once a resumed file is verified SecureCsvWriter built its RotatableWriter, which scheduled the rotation and retention checks, before it read the keys and verified the file it resumes. When the construction outlasted the check interval, a rotation renamed the file and its keystore and wrote new keys while the constructor still read or verified them, and the topic failed to start. RotatableWriter gets a constructor that leaves the checks to startRotationAndRetentionChecks(), which SecureCsvWriter calls once its constructor has succeeded. The file is still opened first, so a file that cannot be opened still fails only its topic.
Member
Author
|
Closing in favour of #355, which fixes #343 too. Both PRs make the first rotation check run only once the resumed file is verified. #355 does it in #355 is preferred because:
The other window this PR closed, a check that could run before |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #343.
Cause
SecureCsvWriterbuilt itsRotatableWriterbefore it read the keys and verified the file it resumes, andRotatableWriterschedules the rotation and retention checks in its constructor. A resumed file due for a rotation (rotationInterval, a rotation time, a loweredmaxFileSize) was rotated at the first check when the construction outlasted the check interval. The file and its.keystorewere renamed, andpostRotationActionwrote new keys while the constructor still read or verified them, so the topic failed to start:master. There,postRotationActionalso fails with aNullPointerExceptionand leaves the time of the last rotation as it was, so the rotator renames the new live file again at each check.Fix
RotatableWritergets a public constructor with astartChecksflag, andstartRotationAndRetentionChecks(). The existing constructors start the checks as before. The check interval is still validated in the constructor, so an invalid interval fails as before.SecureCsvWriterconstructs it without the checks, and starts them once its constructor has succeeded: after the keys are read and the file is verified. The file is still opened first, so a file that cannot be opened still fails only its topic with anIOException.This also closes two smaller windows. The checks used to start before
registerRotationHooks(), so a check could run with the no-op hooks. A writer that fails to construct no longer leaves a running rotator thread behind; the file it leaves open is #340.I tried a simpler fix first and dropped it: opening the file only after the verification. Then the keystore of a new file is stored before the file is opened. A log directory that cannot be created then fails the whole startup with a
RuntimeException, instead of failing only the topic with anIOExceptionas atmaster.CsvAuditEventHandlerTest.canConfigureCsvHandlerFromJsonAndRegisterWithAuditServicefails on it.Tests
SecureCsvWriterTest.shouldRotateResumedFileOnlyOnceItIsVerified: a written file, last modified 2 hours ago, is resumed with a 1 hourrotationIntervaland a 10 ms check interval. Each read of the handler keystore takes 100 ms, so the construction outlasts many check intervals. The construction succeeds, then the file is rotated, and the archive passes verification with its own keystore. The test fails with theSecureCsvWriterofmaster, and when the writer starts the checks inRotatableWriter's constructor.RotatableWriterTest.testEvaluatesPoliciesPeriodicallyOnlyOnceTheChecksAreStarted: a file due for a rotation is not rotated during 50 check intervals beforestartRotationAndRetentionChecks(), and is rotated after it. The test fails when the flag is ignored.audit/core,audit/jsonandaudit/handler-csvpass locally. Both new tests passed 3 more runs.Other open PRs
audit/handler-csvpasses on each merge.