Skip to content

feat(coana): download the Coana CLI through SOCKET_COANA_MIRROR_URL - #1825

Merged
Oskar Haarklou Veileborg (BarrensZeppelin) merged 5 commits into
v1.xfrom
oskar/rea-1377-let-customers-download-coana-components
Dec 4, 2026
Merged

Oskar Haarklou Veileborg (BarrensZeppelin) merged 5 commits into
v1.xfrom
oskar/rea-1377-let-customers-download-coana-components

Conversation

@BarrensZeppelin

@BarrensZeppelin Oskar Haarklou Veileborg (BarrensZeppelin) commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

socket-cli's side of mirror support that Coana is also gaining for its own downloads.

Machines that can't reach storage.googleapis.com can mirror Coana's bucket, for example with an Artifactory generic remote repository with "Propagate Query Params" turned on, and set SOCKET_COANA_MIRROR_URL to it. socket-cli then downloads the cli component from the mirror:

  • The prefix https://storage.googleapis.com/socket-coana-cli/ of the signed URL is replaced with the mirror's URL, with a / appended when it lacks one. The query string, which holds the signature, is kept.
  • The value is checked, and the URL rewritten, only once a download is certain: after the resolved version missed the cache. A warm cache never trips on a stale value. The URL requested anew after a 4xx is rewritten too.
  • A signed URL outside the bucket is refused, including one that climbs out with .. or %2e%2e. The error leaves out the signature.
  • A mirror URL that isn't https, or that has a query or fragment, is refused with an InputError. The error leaves out the value, which may carry credentials.
  • Downloads get a 60 s inactivity timeout, so a stalled mirror can't hang the run, while a slow download that still progresses is not cut off.
  • A failed download names the host it went to, so the mirror's host when one is set, whether it answered with an error status or couldn't be reached.

Coana inherits the variable through the user's environment and applies the same rule to its own analyzers and facts downloads, once the pinned Coana supports the variable. Coana also accepts an http mirror; socket-cli refuses one, because apiFetch speaks only https.

Depends on a Coana version bump that supports the inherited SOCKET_COANA_MIRROR_URL.

Tests

New cases in src/utils/coana-release.test.mts mock the API and the download, and use an empty cache per test with the real cache script:

  • the rewrite keeps the signature;
  • the renewed URL after a 403 is rewritten;
  • the mirror's host is named in a download failure, for an error status and for a mirror that can't be reached, and the download has an idle timeout;
  • URLs outside the bucket are refused without showing their signature;
  • bad mirror values are refused before any download, without showing them;
  • a bad mirror value and a URL outside the bucket are ignored when a range resolves to a cached version.

All but the last fail against the previous implementation.

Expected reviewer effort: High-level design decisions

Machines that can't reach storage.googleapis.com can mirror Coana's bucket,
for example with an Artifactory remote repository, and set
SOCKET_COANA_MIRROR_URL to it. Each signed URL for the cli component then
has its https://storage.googleapis.com/socket-coana-cli/ prefix replaced
with the mirror's URL, keeping the signature, including the URL requested
anew after a 4xx. Coana, which inherits the variable, follows the same rule
for its own components.

A signed URL outside the bucket is refused rather than fetched from GCS. A
mirror URL that isn't https, or that has a query or fragment, is refused
before the API is asked, without echoing the value. socket-cli downloads
over https only, so unlike Coana it doesn't accept an http mirror.
@jdalton

Copy link
Copy Markdown
Contributor

Love it Oskar Haarklou Veileborg (@BarrensZeppelin) ❤️ !

Parse the signed URL once into a URL, and have the mirror rule throw its
errors so that the existing catch reports them as failures to get the
Coana CLI. installComponent takes the request function instead of the
org slug and mirror rule. The tests share one tarball fixture and API
response.
@cursor

cursor Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes how Coana binaries are fetched (URL rewriting and validation on a security-sensitive download path); behavior is opt-in via env var but wrong mirror config can break reachability installs in restricted networks.

Overview
Adds SOCKET_COANA_MIRROR_URL so Coana CLI downloads can go through an internal https mirror of storage.googleapis.com/socket-coana-cli/ when GCS is blocked (e.g. Artifactory remote repo).

In release.mts, signed artifact URLs from the Socket API are rewritten by swapping the GCS bucket prefix for the mirror base while keeping the query signature. The same rewrite applies when a 4xx forces a fresh signed URL. Invalid mirror values (non-https, query/fragment) and signed URLs outside the expected bucket (including .. escapes) are rejected early, with errors that omit secrets; failed downloads report the actual host used.

Docs (README, CHANGELOG) document the variable. coana-release.test.mts adds mirror rewrite, retry-after-403, failure messaging, and validation cases.

Reviewed by Cursor Bugbot for commit fbe7a91. Configure here.

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.

Works with the Coana 15.15.12 pin now on v1.x. A few comments, mostly small; the download timeout is the one I would most like to see handled.

Comment thread src/utils/coana/release.mts Resolved
Comment thread src/utils/coana/release.mts Resolved
Comment thread src/utils/coana/release.mts Resolved
Comment thread src/utils/coana/release.mts Resolved
Comment thread src/utils/coana/release.mts Resolved
Parse SOCKET_COANA_MIRROR_URL and rewrite the signed URL only after the
resolved version missed the cache, so a stale value or a URL outside the
bucket no longer breaks a run that needs no download. An invalid value
is an InputError.

Downloads get a 60 s inactivity timeout, so a stalled mirror can't hang
the run, and a failed download names the host it went to.

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.

Thanks, all addressed. Small thing: the "Depends on a Coana version bump" line in the description can go, since Coana 15.15.12 is on v1.x now.

@BarrensZeppelin
Oskar Haarklou Veileborg (BarrensZeppelin) merged commit 1413d21 into v1.x Dec 4, 2026
23 checks passed
@BarrensZeppelin
Oskar Haarklou Veileborg (BarrensZeppelin) deleted the oskar/rea-1377-let-customers-download-coana-components branch December 4, 2026 10:41
Oskar Haarklou Veileborg (BarrensZeppelin) added a commit to SocketDev/socket-python-cli that referenced this pull request Dec 4, 2026
* Download the Coana CLI through SOCKET_COANA_MIRROR_URL

When SOCKET_COANA_MIRROR_URL is set, the signed URL's prefix
https://storage.googleapis.com/socket-coana-cli/ is replaced with the
mirror's URL, keeping the query that holds the signature. The value is
read only after a cache miss. Signed URLs outside the bucket and invalid
values are refused without showing the signature or the value, and
download errors name the host without credentials.

Port of SocketDev/socket-cli#1825. Unlike the Node CLI, http mirrors are
accepted, as in Coana.

* Correct two comments on the mirror download

* Ride the unreleased 2.15.10 instead of bumping to 2.15.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants