Skip to content

Commit 22a85ec

Browse files
committed
sign: Don't delete source container before trying to inject signature
The new flow requires the source container, so we can't delete it before trying to inject the signature. Rework both paths to write to a temporary path, then `rename()` into place for consistency, and this is also closer to being an atomic operation.
1 parent e9bd01a commit 22a85ec

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/cmd-sign

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,15 @@ def robosign_ostree(args, s3, build, gpgkey):
179179
ostree_image = build['images']['ostree']
180180
exported_ostree_path = os.path.join(builddir, ostree_image['path'])
181181
exported_ostree_ref = f'oci-archive:{exported_ostree_path}:latest'
182-
# Files stored in the build directory are mode 0600 to prevent
183-
# accidental mutation. Remove the existing one because otherwise
184-
# we'll try to `open(O_TRUNC)` it and fail.
185-
os.unlink(exported_ostree_path)
186182
# Detect and use the replace-detached-metadata API only if available
187183
verb = "replace-detached-metadata"
188-
tmp_image = 'tmp.ociarchive'
184+
tmp_image = os.path.join(d, 'tmp.ociarchive')
185+
tmp_ref = f"oci-archive:{tmp_image}:latest"
189186
if subprocess.check_output(['ostree', 'container', 'image', '--help'], encoding='UTF-8').find(verb) >= 0:
190-
subprocess.check_call(['ostree', 'container', 'image', verb, f'--src={exported_ostree_ref}', f'--dest=oci-archive:{tmp_image}:latest', metapath])
191-
os.rename(tmp_image, exported_ostree_path)
187+
subprocess.check_call(['ostree', 'container', 'image', verb, f'--src={exported_ostree_ref}', f'--dest={tmp_ref}', metapath])
192188
else:
193-
subprocess.check_call(['ostree', 'container', 'export', '--repo=tmp/repo', checksum, exported_ostree_ref])
189+
subprocess.check_call(['ostree', 'container', 'export', '--repo=tmp/repo', checksum, tmp_ref])
190+
os.rename(tmp_image, exported_ostree_path)
194191
# Finalize the export by making it not writable.
195192
os.chmod(exported_ostree_path, 0o400)
196193
ostree_image['size'] = os.path.getsize(exported_ostree_path)

0 commit comments

Comments
 (0)