upgrade

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package upgrade downloads a ytrack release, verifies it and replaces the running binary with it.

Trust chain: the release's checksums file must carry a Sigstore keyless signature by this repository's release workflow (ReleaseIdentity); the archive must match its SHA-256 in that file. Only then is the binary extracted and swapped in. Any failed check refuses the upgrade and leaves the installed binary untouched.

Index

Constants

View Source
const OldSuffix = ".old"

OldSuffix names the previous binary that a Windows upgrade moves aside.

Variables

View Source
var ErrRefused = errors.New("refusing to upgrade")

ErrRefused wraps every verification failure.

View Source
var ReleaseIdentity = Identity{
	Issuer: "https://token.actions.githubusercontent.com",
	SubjectRegexp: `^https://github\.com/BrainerVirus/youtrack-cli/\.github/workflows/release\.yml@refs/` +
		`tags/v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$`,
}

ReleaseIdentity is the release workflow of this repository on GitHub Actions, run for a release tag: a tag push signs with refs/tags/vX.Y.Z, and a manual rerun must be dispatched from that tag (never from a branch), so it signs with the same ref.

Functions

func ArchiveName

func ArchiveName(version, goos, goarch string) string

ArchiveName returns the release archive for version (no "v") on goos/goarch, as .goreleaser.yaml names it.

func BundleName

func BundleName(version string) string

BundleName returns the Sigstore bundle that signs the checksums file.

func CheckSHA256

func CheckSHA256(data []byte, want string) error

CheckSHA256 reports an error unless data hashes to the hex digest want.

func ChecksumsName

func ChecksumsName(version string) string

ChecksumsName returns the checksums file of a release.

func ExpectedSHA256

func ExpectedSHA256(checksums []byte, name string) (string, error)

ExpectedSHA256 returns the hex digest listed for name in a checksums file ("<hex> <name>" lines, as sha256sum writes them).

func ExtractBinary

func ExtractBinary(archive []byte, name string) ([]byte, error)

ExtractBinary returns the ytrack executable from a release archive (tar.gz, or zip for Windows).

func PublicGoodTrustedRoot

func PublicGoodTrustedRoot() (root.TrustedMaterial, error)

PublicGoodTrustedRoot returns Sigstore's public-good trusted root (Fulcio CAs, Rekor v1 and v2 logs, CT logs, timestamp authorities), fetched and verified through Sigstore's TUF repository, starting from the TUF root that sigstore-go embeds. The TUF metadata is cached under ytrack's user cache directory, so key rotations reach ytrack without a new release.

func RemoveOld

func RemoveOld(exe string)

RemoveOld deletes the binary a previous Windows upgrade moved aside.

func ReplaceExecutable

func ReplaceExecutable(exe string, data []byte) error

ReplaceExecutable atomically replaces the file at exe with data, keeping its permissions. The new file is written next to exe and renamed over it, so exe is either the old or the new binary, never a partial one. Windows cannot overwrite a running executable but can rename it, so there the old binary is first moved to exe+OldSuffix (removed by the next upgrade).

func VerifyBundle

func VerifyBundle(bundleJSON, artifact []byte, t Trust) error

VerifyBundle checks with sigstore-go that bundleJSON (a Sigstore bundle, as `cosign sign-blob --bundle` writes it) is a keyless signature of artifact by t.Identity: the certificate chains to a trusted Fulcio CA at a time attested by a transparency log entry (Rekor v1 or v2) or a signed timestamp, carries a valid SCT, names the identity, and its key signed the artifact's SHA-256. Any failed check is an error.

Types

type Downloader

type Downloader struct {
	HTTP      *http.Client
	Trust     Trust
	GOOS      string
	GOARCH    string
	UserAgent string
	// APIURL is the GitHub REST API root used for the fallback;
	// update.DefaultAPIURL when empty.
	APIURL string
	// Sleep waits between retries; nil waits on a timer, honouring ctx.
	Sleep func(ctx context.Context, d time.Duration) error
	// Notice, when set, is told each time a file came through the API
	// fallback.
	Notice func(msg string)
	// contains filtered or unexported fields
}

Downloader fetches and verifies release binaries.

Each file is fetched from its release download URL; a transient failure (transport error, HTTP 5xx or 429) is retried with backoff. If that URL still fails, or answers another HTTP error, the file is fetched once more through the GitHub REST API (the asset's API URL with Accept: application/octet-stream), with the same retries. GitHub's download CDN can serve an edge-cached error for one asset while the API serves it fine. Both paths keep the same guards (https only, no redirect off https, size limit, User-Agent), and the signature and checksum checks run on the bytes either way.

func (*Downloader) Binary

func (d *Downloader) Binary(ctx context.Context, rel *update.Release) ([]byte, error)

Binary downloads the release archive for d.GOOS/d.GOARCH and returns the ytrack executable inside it, after checking the signature of the checksums file and the archive's checksum.

type Identity

type Identity struct {
	Issuer        string // OIDC issuer, matched exactly
	SubjectRegexp string // certificate SAN (for GitHub Actions, the workflow URI)
}

Identity is the signer a bundle's Fulcio certificate must name.

type Trust

type Trust struct {
	Material root.TrustedMaterial
	Identity Identity
	// NoSCT skips the certificate transparency (SCT) check. Only for test
	// Sigstores, whose certificates carry no SCT; never set in production.
	NoSCT bool
}

Trust is what a release signature must verify against.

Directories

Path Synopsis
Package upgradetest provides Sigstore bundles signed by sigstore-go's virtual Sigstore and a fake GitHub release server for tests.
Package upgradetest provides Sigstore bundles signed by sigstore-go's virtual Sigstore and a fake GitHub release server for tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL