-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if metadata files at revision match those downloaded by TUF updater #389
Changes from 4 commits
b6e59fc
645f043
69c9f90
83ec4cd
75af901
86d548f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import functools | ||
from logging import DEBUG, INFO | ||
from pathlib import Path | ||
import re | ||
import shutil | ||
import tempfile | ||
from typing import Any, Dict, List, Optional | ||
|
@@ -94,7 +95,8 @@ def wrapper(self, *args, **kwargs): | |
return result | ||
finally: | ||
if ( | ||
self.state.event == Event.FAILED | ||
not self.only_validate | ||
and self.state.event == Event.FAILED | ||
and not self.state.existing_repo | ||
and self.state.users_auth_repo is not None | ||
): | ||
|
@@ -1205,6 +1207,45 @@ def _update_tuf_current_revision(): | |
target_filepath, | ||
current_commit, | ||
) | ||
|
||
# TUF updater does not always check the validity of all metadata files | ||
# if timestamp is not updated, the updater will determine that a new version | ||
# of the snapshot file does not need to be downloaded and it will not be validated | ||
# during the update process, the metadata files that TUF updater downloads is stored | ||
# in a separate folder within the temp directory | ||
# For each commit, check if the metadata files inside that directory are the same | ||
# as the ones in the auth repository's metadata folder at that revision | ||
pattern = r"\d+\.[^\.\s]+\.\w+" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to add explanation as to what this pattern is searching for |
||
for metadata_file_name in git_updater.get_current_metadata(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're reading all metadata files from disk for each commit, it's worth timing the updater to see how long this new validation takes, compared to the implementation we have on master. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ran SMC clone a couoek of times. The first was was slightly slower than on master, the second faster than on master, so I don't think that this impacts the performance. Other operations are much slower There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome |
||
# version (consistent snapshot files) are downloaded to remote | ||
# by the TUF updater, but saved to the main metadata file | ||
# so, 2.root.json is downloaded and saved to root.json | ||
if re.search(pattern, metadata_file_name): | ||
continue | ||
|
||
current_tuf_metadata_file = Path( | ||
git_updater.metadata_dir, metadata_file_name | ||
) | ||
if not current_tuf_metadata_file.is_file(): | ||
# this validation causes an issue with one of the first | ||
# commits of our production repositories and it should | ||
# not be enabled until we specify a later commit of those | ||
# repositories as the initial valid ones | ||
# this error happens when a metadata file is added, but | ||
# snapshot is not updated | ||
# raise UpdateFailedError( | ||
# f"Invalid metadata file {metadata_file_name}" | ||
# ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we turn this into an issue? |
||
continue | ||
metadata_content = git_updater.get_current_metadata_data( | ||
metadata_file_name | ||
) | ||
tuf_metadata_content = current_tuf_metadata_file.read_text() | ||
if metadata_content != tuf_metadata_content: | ||
raise UpdateFailedError( | ||
f"Invalid metadata file {metadata_file_name}" | ||
) | ||
|
||
return current_commit | ||
except Exception as e: | ||
metadata_expired = EXPIRED_METADATA_ERROR in type( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This explanation looks like a good candidate to be a docstring. Could we move the code to a function?