Skip to content

Download advisories via an authenticated GitLab client - #122

Merged
tommartensen merged 1 commit into
mainfrom
gitlab-advisory-download
Dec 4, 2026
Merged

tommartensen merged 1 commit into
mainfrom
gitlab-advisory-download

Conversation

@tommartensen

@tommartensen tommartensen commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The advisory download in GetAdvisoryFromRelease did a plain http.Get on the release's advisory web URL, which fails with 404: the raw web API on gitlab.cee.redhat.com is private, and the release status only exposes the GitLab web URL, not the API URL.

This adds a GitLab client (pkg/client/gitlab) that:

  • reads GITLAB_TOKEN lazily on first use, following the sub-client pattern from Scope credentials to the commands that need them #119 — only commands that download advisory content require the token, and the error surfaces at that point
  • converts the web URL (/releng/advisories/-/raw/main/data/...) to the repository files API URL with URL-encoded project and file path (slashes → %2F)
  • authenticates with Authorization: Bearer <token> (preferred over GitLab's PRIVATE-TOKEN)
  • distinguishes an invalid/expired token (401) from a missing or inaccessible file (404) in its errors

GITLAB_TOKEN is a personal access token with the read_api scope, created at https://gitlab.cee.redhat.com/-/user_settings/personal_access_tokens; it is now documented in the README.

Testing

  • New tests/gitlab suite: success path (verifies the web→API conversion, URL encoding via an escaped-path matcher, and the Bearer header), 401/404 errors, missing token, invalid URLs — all green; full go test ./..., go vet, golangci-lint pass.
  • Verified against the real cluster: without GITLAB_TOKEN the command now fails with a clear GITLAB_TOKEN environment variable is required instead of a downstream parse error; with a token, the raw advisory downloads (endpoint validated via curl).

🤖 Generated with Claude Code

Triggered by https://redhat-internal.slack.com/archives/C0BV9SM5PJ4/p1796308868260249

@tommartensen tommartensen self-assigned this Dec 3, 2026
The advisory download did a plain http.Get on the release's advisory
web URL, which fails with 404 because the GitLab API requires
authentication and a URL-encoded API URL.

Add a GitLab client that reads GITLAB_TOKEN lazily on first use (like
the other sub-clients), converts the web URL to the repository files
API URL with URL-encoded project and file path, and authenticates with
an Authorization: Bearer header. Errors distinguish an invalid or
expired token (401) from a missing or inaccessible file (404).

Co-Authored-By: Claude Code <noreply@anthropic.com>
@tommartensen
tommartensen force-pushed the gitlab-advisory-download branch from f14c513 to e0a4722 Compare December 3, 2026 15:51
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Advisory content can now be retrieved from GitLab using a personal access token.
  • Documentation
    • Added setup guidance for GITLAB_TOKEN, including the required read_api scope and an export example.
  • Bug Fixes
    • GitLab advisory downloads now report clear errors for missing tokens, invalid URLs, unauthorized access, and unavailable content.

The change adds an authenticated GitLab client for raw-file downloads and routes Konflux advisory retrieval through that client. It also adds GitLab client accessors, tests for retrieval and error cases, and GITLAB_TOKEN configuration documentation.

Changes: GitLab advisory retrieval

Layer / File(s) Summary
GitLab client and configuration
pkg/client/gitlab/client.go, pkg/client/client.go, README.md
Adds an authenticated GitLab raw-file client, initializes it in the standard and test client constructors, and documents the required GITLAB_TOKEN scope and setup.
Konflux advisory integration
pkg/client/konflux/advisories.go, pkg/konflux/release.go, tests/helpers/gitlab_mocks.go, tests/gitlab/advisories_test.go
Konflux passes the GitLab client to advisory retrieval, which downloads advisory bytes through GetRawFile. Tests cover successful retrieval, HTTP errors, missing tokens, and invalid URLs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Release as GetOperatorBundleImageForRelease
  participant Advisory as GetAdvisoryFromRelease
  participant GitLab as gitlab.Client
  participant API as GitLab files API
  Release->>Advisory: pass GitLab client and release
  Advisory->>GitLab: GetRawFile with advisory URL
  GitLab->>API: authenticated GET for raw file
  API-->>GitLab: response body
  GitLab-->>Advisory: advisory bytes
  Advisory-->>Release: parsed advisory
Loading

Suggested reviewers: kurlov

Merge Risk: Minimal · up to e0a47

This change adds an authenticated GitLab client for downloading advisories, and the token is only needed when advisory content is fetched. No concrete merge-blocking defect was established. Whether the token could be sent to an unexpected host depends on who can write release status, which the repository does not show.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Download advisories via an authenticated GitLab client" matches the main change. The PR adds a GitLab client with Bearer-token authentication and changes GetAdvisoryFromRelease to fetch adv…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states the problem (plain http.Get on the advisory web URL returns 404 because the raw web API is private) and describes the new GitLab client, the GITLAB_TOKEN lazy loading, URL conve…
Full details: Title check

Explanation

The title "Download advisories via an authenticated GitLab client" matches the main change. The PR adds a GitLab client with Bearer-token authentication and changes GetAdvisoryFromRelease to fetch advisory content through it. The title is short, specific, and free of filler.

Full details: Description check

Explanation

The description states the problem (plain http.Get on the advisory web URL returns 404 because the raw web API is private) and describes the new GitLab client, the GITLAB_TOKEN lazy loading, URL conversion, Bearer auth, 401/404 error distinction, README documentation, and the tests run. It is clearly related to the changeset.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 65d2d439-fa1e-4d2b-bdf4-326ff0e9806e
Commits

Reviewing files that changed from the base of the PR and between 4180c90 and e0a4722.

Files selected for processing: 7

  • README.md
  • pkg/client/client.go
  • pkg/client/gitlab/client.go
  • pkg/client/konflux/advisories.go
  • pkg/konflux/release.go
  • tests/gitlab/advisories_test.go
  • tests/helpers/gitlab_mocks.go

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@tommartensen
tommartensen requested a review from kurlov December 3, 2026 15:57
@tommartensen
tommartensen marked this pull request as ready for review December 3, 2026 15:57
@tommartensen
tommartensen requested a review from a team as a code owner December 3, 2026 15:57
@tommartensen
tommartensen merged commit a328484 into main Dec 4, 2026
6 checks passed
@tommartensen
tommartensen deleted the gitlab-advisory-download branch December 4, 2026 07:57
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.

2 participants