Skip to content

fix(persistence): give the S3 export scratch a private directory - #2951

Open
angela-helios wants to merge 1 commit into
mainfrom
fix/s3-export-scratch
Open

angela-helios wants to merge 1 commit into
mainfrom
fix/s3-export-scratch

Conversation

@angela-helios

Copy link
Copy Markdown
Contributor

Stacked on #2901. This branch starts from #2901's branch so that Test FHIRPath passes against the current fhir-test-cases master; its commit leaves this diff once #2901 merges.

Closes #2950

Summary

S3OutputStore kept in-flight export parts, patient data included, under the fixed {temp_dir}/hfs-export-scratch. Another local user could create that directory first and read the parts, or plant links among them: create_dir_all accepts an existing directory whoever owns it.

S3OutputStore::new now creates its default scratch directory with tempfile::Builder::new().prefix("hfs-export-scratch-").tempdir():

  • the name is random;
  • the directory is owner-only (0700) on Unix;
  • the TempDir is held in the store, so the directory is removed when the store is dropped.

with_scratch_dir still sets an operator-chosen directory and releases the private one. If the temp directory is not writable, the store logs a warning and falls back to a random-named path; writing a part then fails as it would have before.

Trade-off

A fixed path let a restarted process find the scratch an earlier run had left. A private directory belongs to one process, so after a crash its scratch stays in the temp directory instead of being reused. A graceful shutdown removes it.

Not changed

The bulk-export job database falls back to {temp_dir}/hfs-bulk-export-{pid}.db when there is no output or data dir (main.rs:2871). It is mentioned in #2950 and left for a separate change.

Tests

output_store::tests::the_default_scratch_directory_is_private_to_the_store checks:

  • the default directory is not {temp}/hfs-export-scratch, and two stores get different directories;
  • it exists and, on Unix, has no group or other permission bits;
  • a part writes and finalizes through it;
  • the directory is gone once the store is dropped.

With the old fixed path restored, the test fails at the first assertion (left: "...\Temp\hfs-export-scratch").

cargo test -p helios-persistence --features s3 --lib backends::s3::output_store: 6 passed. Clippy on helios-persistence --features s3 --lib --tests is clean.

S3OutputStore kept in-flight export parts under the fixed
{temp_dir}/hfs-export-scratch, which another local user could create first
and read from. The default is now a tempfile directory: random name,
owner-only on Unix, removed with the store.

Closes #2950

This branch has not been deployed

No deployments
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.

S3 export scratch files go to a fixed directory in the shared temp dir

1 participant