Use versioned wheelsmith prefix for downloader v2 targets#23937
Use versioned wheelsmith prefix for downloader v2 targets#23937dkirov-dd wants to merge 9 commits into
Conversation
…n pointer validation The v2 TUF pointer downloader already routes every target lookup through `Updater.get_targetinfo(target_path)`, so python-tuf walks delegations on its own based on the `paths` or `path_hash_prefixes` declared in the parent Targets metadata. There is no need for the downloader to know any delegated-role name. Make that contract explicit and lock it in with tests so it can't regress when the production repository's delegation layout evolves. Implementation: - Document the delegation-agnostic design at the module level. - Tighten `_validate_pointer` to reject obvious wheel_path attacks (`//` scheme bypass, `..` segments, non-canonical paths) and enforce the expected types and shapes for `digest` (64-char lowercase hex) and `length` (non-negative int, not bool). Tests: - Add `TestUpdaterContract` asserting `get_targetinfo` is called with the target path alone (no role kwarg, no role-prefixed path). - Add `TestDelegationTraversal` that stands up a real signed v2-style TUF repository with one delegated targets role (over a local HTTP server) and verifies `get_pointer` resolves through both `paths` and `path_hash_prefixes` delegations without the downloader naming the role. Also verifies unmatched paths surface as `TargetNotFoundError`. - Extend `TestMalformedPointer` with path-traversal/scheme-bypass cases, digest/length type and shape checks, a zero-length-wheel happy path, and a forward-compatibility test for unknown pointer keys.
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 367d822 | Docs | Datadog PR Page | Give us feedback! |
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6df9147cff
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| SPEC_VERSION = '1.0.31' | ||
| EXPIRY = datetime(2099, 1, 1, tzinfo=timezone.utc) | ||
| TOP_LEVEL_ROLES = ('root', 'targets', 'snapshot', 'timestamp') | ||
|
|
There was a problem hiding this comment.
Add type hints to new helper signatures
The repository instructions in /workspace/integrations-core/AGENTS.md require newly generated Python code to add type hints to methods/functions. This new helper is unannotated, and the same applies to other new helpers such as serve_directory, so the new test support code violates the documented standard; please annotate the parameters and return types before merging.
Useful? React with 👍 / 👎.
Validation ReportAll 21 validations passed. Show details
|
What does this PR do?
Hardens the v2 TUF pointer downloader (
datadog_checks_downloader.download_v2) and aligns its target lookups with the TUF-on-CI storage-path contract:<package>/<version>.jsontowheelsmith/v1/<package>/<version>.json(andwheelsmith/v1/<package>/latest.json). Thewheelsmith/prefix is the client/publisher storage namespace required by the delegated target layout, andv1/versions the pointer-file contract._validate_pointerto reject obviouswheel_pathattacks (//-scheme bypass,..segments, non-canonical paths) and to enforce the expected types/shapes fordigest(64-char lowercase hex) andlength(non-negative int, not bool).TestUpdaterContractassertingUpdater.get_targetinfois called with the stablewheelsmith/v1/<package>/<version>.jsonpath alone — no role kwarg is passed to the TUF client.TestDelegationTraversal, an end-to-end test that stands up a real signed v2-style TUF repository with awheelsmithdelegated targets role over a local HTTP server and verifiesget_pointerresolves through bothpathsandpath_hash_prefixesdelegations.TestMalformedPointerwith path-traversal / scheme-bypass cases, digest/length type and shape checks, a zero-length-wheel happy path, and a forward-compatibility test for unknown pointer keys.Motivation
TUF-on-CI expects the first top-level directory under
targets/to correspond to the delegated target namespace. For the downloader and publisher pipeline, that means the stable v2 pointer target path is now:That path has two explicit layers:
wheelsmith/: the TUF-on-CI storage/delegation namespace.v1/: the pointer-file contract version.As long as this path remains stable, the repository can later replace the planned single delegation with hash-bin delegations, nested delegations, or another compatible topology without changing the downloader:
tuf.ngclient.Updater.get_targetinfo(path)walks the TUF delegation metadata for that path.By contrast, changes to the target path or pointer JSON schema are downloader-facing contract changes and require either a downloader update or compatibility aliases/fields. This PR makes that boundary explicit and adds tests that lock in the expected behavior.
Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required. (qa/skip-qa: behavior is covered by unit/integration-style local TUF tests and affects repository path/validation logic, not a manually QA-able integration behavior.)backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged