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
- Variables
- func AcquireLock(path string) (release func(), err error)
- func ArchiveName(version, goos, goarch string) string
- func BundleName(version string) string
- func CheckSHA256(data []byte, want string) error
- func ChecksumsName(version string) string
- func DirWritable(dir string) bool
- func ExpectedSHA256(checksums []byte, name string) (string, error)
- func ExtractBinary(archive []byte, name string) ([]byte, error)
- func LockHeld(path string) bool
- func PublicGoodTrustedRoot() (root.TrustedMaterial, error)
- func RemoveOld(exe string)
- func ReplaceExecutable(exe string, data []byte, check func(candidate string) error) error
- func RunBinary(ctx context.Context, exe string, args ...string) ([]byte, error)
- func SmokeTest(ctx context.Context, run Runner, candidate, version string) error
- func StartDetached(exe string, args []string, logPath string) error
- func SyncSkills(ctx context.Context, run Runner, exe string) (string, error)
- func VerifyBundle(bundleJSON, artifact []byte, t Trust) error
- type Downloader
- type Identity
- type Runner
- type Trust
Constants ¶
const LockFile = "upgrade.lock"
LockFile is the file in the state directory that an upgrade holds.
const LogFile = "auto-upgrade.log"
LogFile is the file in the state directory where the background upgrade writes its output.
const OldSuffix = ".old"
OldSuffix names the previous binary that a Windows upgrade moves aside.
Variables ¶
var ErrLocked = errors.New("another ytrack upgrade is running")
ErrLocked is returned when another upgrade holds the lock.
var ErrRefused = errors.New("refusing to upgrade")
ErrRefused wraps every verification failure.
var Executable = os.Executable
Executable returns the running binary's path. A var so tests can name another binary.
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.
var Spawn = StartDetached
Spawn starts the background upgrade. A var so tests can watch it instead of starting a process.
Functions ¶
func AcquireLock ¶ added in v0.6.0
AcquireLock takes the lock at path, replacing one older than lockStale. It returns ErrLocked when another upgrade holds it.
func ArchiveName ¶
ArchiveName returns the release archive for version (no "v") on goos/goarch, as .goreleaser.yaml names it.
func BundleName ¶
BundleName returns the Sigstore bundle that signs the checksums file.
func CheckSHA256 ¶
CheckSHA256 reports an error unless data hashes to the hex digest want.
func ChecksumsName ¶
ChecksumsName returns the checksums file of a release.
func DirWritable ¶ added in v0.6.0
DirWritable reports whether a file can be created in dir, as ReplaceExecutable needs.
func ExpectedSHA256 ¶
ExpectedSHA256 returns the hex digest listed for name in a checksums file ("<hex> <name>" lines, as sha256sum writes them).
func ExtractBinary ¶
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 ¶
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. check, when not nil, runs on the written candidate before the rename; an error from it leaves exe untouched. 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 RunBinary ¶ added in v0.6.0
RunBinary is the real Runner. The binary runs with the release check and the background upgrade turned off, so it never starts one of its own.
func SmokeTest ¶ added in v0.6.0
SmokeTest runs the candidate binary's `version` and refuses it unless it exits 0 and names version.
func StartDetached ¶ added in v0.6.0
StartDetached starts exe with args in its own session (its own process group without a console on Windows), with no standard input and its output in logPath, and returns without waiting for it: the caller can exit at once, and a pipe the caller's caller reads never stays open for the child.
func SyncSkills ¶ added in v0.6.0
SyncSkills runs `ytrack skill sync` of the binary at exe, which refreshes the agent skill copies it installed, and returns its output. A binary without that command is not an error.
func VerifyBundle ¶
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.
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.
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. |