Skip to content

Commit e06ae42

Browse files
committed
fix(build): Namespace snapshot object keys by org and project
Previously, snapshot images were stored using only their SHA256 hash as the object key. This could cause collisions or incorrect sharing of objects across organizations and projects with identical file contents. Now keys are scoped as `{org_id}/{project_id}/{hash}` to ensure proper isolation in the object store.
1 parent c84fd84 commit e06ae42

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/commands/build/snapshots.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ fn upload_images(
216216
}
217217
let session = scope.session(&client)?;
218218

219+
let org_id = options
220+
.objectstore
221+
.scopes
222+
.iter()
223+
.find(|(k, _)| k == "org")
224+
.map(|(_, v)| v.as_str())
225+
.context("Missing 'org' scope in upload options")?;
226+
let project_id = options
227+
.objectstore
228+
.scopes
229+
.iter()
230+
.find(|(k, _)| k == "project")
231+
.map(|(_, v)| v.as_str())
232+
.context("Missing 'project' scope in upload options")?;
233+
219234
let runtime = tokio::runtime::Builder::new_current_thread()
220235
.enable_all()
221236
.build()
@@ -231,13 +246,14 @@ fn upload_images(
231246
let contents = fs::read(&image.path)
232247
.with_context(|| format!("Failed to read image: {}", image.path.display()))?;
233248
let hash = compute_sha256_hash(&contents);
249+
let object_key = format!("{org_id}/{project_id}/{hash}");
234250

235-
info!("Queueing {} as {hash}", image.relative_path.display());
251+
info!("Queueing {} as {object_key}", image.relative_path.display());
236252

237253
many_builder = many_builder.push(
238254
session
239255
.put(contents)
240-
.key(&hash)
256+
.key(&object_key)
241257
.expiration_policy(expiration),
242258
);
243259

0 commit comments

Comments
 (0)