Skip to content

fix(downloads): Add Custom User Agent for download origin - #450

Open
Antonio Salinas (Tonisal-byte) wants to merge 3 commits into
mainfrom
tonisal-byte-animated-chainsaw
Open

Antonio Salinas (Tonisal-byte) wants to merge 3 commits into
mainfrom
tonisal-byte-animated-chainsaw

Conversation

@Tonisal-byte

@Tonisal-byte Antonio Salinas (Tonisal-byte) commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

OW2 returned an HTML challenge with HTTP 200 instead of the pinned objectweb-asm archive, causing prepare-sources to fail checksum validation.

Add an optional origin.user-agent to TOML download origins. It applies only to the configured origin, not to lookaside requests. When omitted, downloads retain Go's default User-Agent. There is no built-in curl identity or subprocess, and checksum validation is unchanged.

Related to microsoft/azurelinux#20268

Validation

  • mage build unit and mage check default passed. Regression tests cover TOML validation and ensure the configured header reaches the origin but not lookaside.
  • In a temporary checkout of microsoft/AzureLinux at objectweb-asm-9.11.1-cves, added the documented User-Agent to the archive entry and ran azldev component prepare-sources -p objectweb-asm --without-git --network-retries 1. The OW2 origin download succeeded and matched the pinned SHA-512.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the optional per-source origin User-Agent setting.

No open issues 🎉

1 file not reviewed
  • internal/utils/downloader/downloader_test/downloader_mocks.go: Generated file
What changed in this PR

Adds an optional per-source origin.user-agent setting so downloads can work with origins that reject Go’s default User-Agent. Lookaside requests, default download behavior, and checksum validation remain unchanged.

Changes:

  • Adds the configuration field, validation, and schema support without affecting component fingerprints.
  • Passes the configured User-Agent through download options only for origin requests.
  • Updates mocks, regression tests, and configuration documentation.
File Description
schemas/​azldev.schema.json Exposes the optional user-agent setting.
internal/​utils/​downloader/​downloader.go Adds download options and conditional User-Agent headers.
internal/​utils/​downloader/​downloader_test/​downloader_mocks.go Updates generated mocks for download options.
internal/​providers/​sourceproviders/​sourcemanager.go Applies the override to configured origin downloads.
internal/​providers/​sourceproviders/​sourcemanager_internal_test.go Tests origin-only header behavior and updates mock callbacks.
internal/​providers/​sourceproviders/​fedorasource/​fedorasource_test.go Adapts mock callbacks to the updated downloader interface.
internal/​projectconfig/​fingerprint_test.go Registers User-Agent as excluded download metadata.
internal/​projectconfig/​configfile.go Rejects unsupported origin types and control characters.
internal/​projectconfig/​configfile_test.go Tests parsing and validation of the new setting.
internal/​projectconfig/​component.go Defines the optional origin User-Agent field.
docs/​user/​reference/​config/​components.md Documents the setting with an OW2 archive example.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Changing only origin.user-agent incorrectly reports a build-input change because normalization retains UserAgent; it needs to be cleared and covered by the excluded-fields regression test.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Exclude origin user-agent from component change comparisons

internal/​projectconfig/​component.go:75

Adding or changing only origin.user-agent makes component changed --without-lockfile report a build-input change even when the pinned source hash is unchanged. The fingerprint:"-" tag does not affect this path: normalizeComponentForComparison clears Origin.Type and Origin.Uri, but retains UserAgent in the JSON comparison. Clear Origin.UserAgent in internal/app/azldev/cmds/component/changed_upstreamcommit.go:327–331 too, and extend TestClassifyHistoricalComponent_ExcludedFieldsUnchanged to cover it.

1 file not reviewed
  • internal/utils/downloader/downloader_test/downloader_mocks.go: Generated file

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 00:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the optional per-origin User-Agent change.

No open issues 🎉

1 file not reviewed
  • internal/utils/downloader/downloader_test/downloader_mocks.go: Generated file

Review effort: Balanced

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.

3 participants