-
Notifications
You must be signed in to change notification settings - Fork 697
chore: bump toolkit to go 1.25 to fix CVEs #18645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Muhammad Falak R Wani (mfrw)
wants to merge
12
commits into
3.0-dev
Choose a base branch
from
mfrw/toolkit-update-go-1.25
base: 3.0-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4693e7f
chore: bump toolkit to go 1.25 to fix CVEs
mfrw 4978fe3
chore: install upstream go 1.25 on Ubuntu releases without a distro p…
mfrw e591701
fix: prefer the distro golang package on Ubuntu releases that have it
mfrw ccc21b5
fix: do not overwrite an existing Go toolchain in /usr/local/go
mfrw 2406138
fix: warn when another go on PATH shadows the installed toolchain
mfrw 3c0455a
docs: drop the stale msft-golang note from the Azure Linux prerequisites
mfrw c47ff8f
docs: record how and when to advance the pinned Go version
mfrw 3927cf3
fix: explain a checksum mismatch instead of printing sha256sum's FAILED
mfrw 4e955f6
fix: do not accept a prerelease of the minimum Go series
mfrw b6a4529
docs: correct the release terminology and the shadowed-Go advice
mfrw b037c5e
refactor: let the Go helpers resolve the toolchain themselves
mfrw cfcd6dc
ci: install the toolkit's prerequisites before building tools
mfrw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,123 @@ | |
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| set -e | ||
| set -eo pipefail | ||
|
|
||
| # Go is installed separately from the other packages because its source depends on the release. | ||
| # Ubuntu 26.04 packages Go 1.25 as golang-1.25-go; 22.04 and 24.04 do not package it at all, so | ||
| # those fall back to the upstream toolchain. The distro package is preferred so that hosts which | ||
| # can reach an apt mirror but not go.dev keep working without external egress. | ||
| # | ||
| # Go supports only the two most recent release series, so this pin has to keep moving. See | ||
| # "Updating the pinned Go version" in prerequisites-ubuntu.md before changing any of it: the | ||
| # minimum version is spelled out in four other places that must move at the same time. | ||
| # Checksums are from https://go.dev/dl and must be updated together with GO_VERSION. | ||
| GO_APT_PACKAGE=golang-1.25-go | ||
| GO_APT_ROOT=/usr/lib/go-1.25 | ||
| GO_VERSION=1.25.14 | ||
| GO_SHA256_AMD64=a21ae5633a269bcd7e90cf767e48225633795e99d831742cbf3397064fee7712 | ||
| GO_SHA256_ARM64=9bf234ea70ffec9347fdf6b22ce4add51717d3386a38a441e8c8743fceb5eaee | ||
|
|
||
| # Returns zero when the given go binary meets the toolkit's minimum. Prereleases of the minimum | ||
| # series must not qualify -- go1.25rc1 predates go1.25.0 and the toolkit would reject it -- while | ||
| # prereleases of later series (go1.26rc1) are new enough. | ||
| go_version_ok() { | ||
| "$1" version 2>/dev/null | grep -qE 'go1\.(25\.[0-9]|2[6-9]|[3-9][0-9])' | ||
| } | ||
|
|
||
| # Echoes the root of an installed Go toolchain, preferring the distro package over the upstream | ||
| # tarball, and a toolchain that meets the minimum over one that does not -- so a stale apt root | ||
| # does not get linked over a good upstream one. Returns non-zero when neither root has a Go. | ||
| go_root() { | ||
| go_root_fallback="" | ||
| for root in "$GO_APT_ROOT" /usr/local/go; do | ||
| if [ -x "$root/bin/go" ]; then | ||
| go_version_ok "$root/bin/go" && { echo "$root"; return 0; } | ||
| [ -z "$go_root_fallback" ] && go_root_fallback="$root" | ||
| fi | ||
| done | ||
|
|
||
| [ -n "$go_root_fallback" ] && { echo "$go_root_fallback"; return 0; } | ||
| return 1 | ||
| } | ||
|
|
||
| # Returns zero when a Go new enough for the toolkit is already available, whether it is first on | ||
| # PATH or sitting unlinked in one of the roots this script manages. | ||
| go_is_supported() { | ||
| go_version_ok go && return 0 | ||
|
|
||
| go_installed_root="$(go_root)" || return 1 | ||
| go_version_ok "$go_installed_root/bin/go" | ||
| } | ||
|
|
||
| # Installs Go from the distro when it is packaged, otherwise from the pinned upstream tarball. | ||
| install_go() { | ||
| echo "Checking apt for '$GO_APT_PACKAGE' (not packaged before Ubuntu 26.04)..." | ||
| if apt install -y "$GO_APT_PACKAGE" && [ -x "$GO_APT_ROOT/bin/go" ]; then | ||
| echo "Installed $GO_APT_PACKAGE from apt." | ||
| return | ||
| fi | ||
|
|
||
| echo "'$GO_APT_PACKAGE' is unavailable on this release, using the upstream toolchain..." | ||
| go_arch="$(dpkg --print-architecture)" | ||
| case "$go_arch" in | ||
| amd64) go_sha256="$GO_SHA256_AMD64"; go_sha256_var=GO_SHA256_AMD64 ;; | ||
| arm64) go_sha256="$GO_SHA256_ARM64"; go_sha256_var=GO_SHA256_ARM64 ;; | ||
| *) | ||
| echo "ERROR: no upstream Go build is pinned for architecture '$go_arch'." >&2 | ||
| echo "Install Go $GO_VERSION or newer manually, then re-run with --no-install-prereqs." >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
|
|
||
| echo "Installing Go $GO_VERSION ($go_arch) from https://go.dev/dl..." | ||
| # Deliberately not 'local': the EXIT trap below runs after this function has returned, when a | ||
| # function-scoped variable would already be out of scope and the temp dir would leak. | ||
| go_tmp_dir="$(mktemp -d)" | ||
| trap 'rm -rf "$go_tmp_dir"' EXIT | ||
| curl -fsSL -o "$go_tmp_dir/go.tar.gz" \ | ||
| "https://go.dev/dl/go${GO_VERSION}.linux-${go_arch}.tar.gz" | ||
| if echo "$go_sha256 $go_tmp_dir/go.tar.gz" | sha256sum --status -c -; then | ||
| echo "Checksum OK." | ||
| else | ||
| echo "ERROR: go${GO_VERSION}.linux-${go_arch}.tar.gz does not match its pinned checksum." >&2 | ||
| echo " expected: $go_sha256" >&2 | ||
| echo " actual: $(sha256sum < "$go_tmp_dir/go.tar.gz" | cut -d ' ' -f 1)" >&2 | ||
| echo "Either the download was corrupted or tampered with, or GO_VERSION was changed in" >&2 | ||
| echo "$0 without refreshing $go_sha256_var. The expected value for a given release is" >&2 | ||
| echo "published at https://go.dev/dl. Nothing has been installed." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -e /usr/local/go ]; then | ||
| echo "WARNING: replacing the Go installation in /usr/local/go, it is older than $GO_VERSION." >&2 | ||
| fi | ||
| rm -rf /usr/local/go | ||
| tar -C /usr/local -xzf "$go_tmp_dir/go.tar.gz" | ||
| } | ||
|
|
||
| # Points /usr/bin/go and /usr/bin/gofmt at the installed Go root, then checks the links actually win. | ||
| link_go() { | ||
| if ! go_link_root="$(go_root)"; then | ||
| echo "No Go installation in $GO_APT_ROOT or /usr/local/go, skipping Go symlinks..." | ||
| return | ||
| fi | ||
|
|
||
| echo "Creating Go symlinks from $go_link_root..." | ||
| ln -vsf "$go_link_root/bin/go" /usr/bin/go | ||
| ln -vsf "$go_link_root/bin/gofmt" /usr/bin/gofmt | ||
|
|
||
| # Ubuntu's default PATH, and sudo's secure_path, list /usr/local/bin ahead of /usr/bin, so a | ||
| # stray go left there keeps winning. Without this warning the toolkit's own version gate fails | ||
| # much later, from a different script, with nothing pointing back to the real cause. | ||
| hash -r | ||
| go_on_path="$(command -v go 2>/dev/null || true)" | ||
| if [ -n "$go_on_path" ] && ! [ "$go_on_path" -ef /usr/bin/go ]; then | ||
| echo "WARNING: '$go_on_path' precedes /usr/bin/go on PATH and will be used instead:" >&2 | ||
| echo "WARNING: $("$go_on_path" version 2>&1 | head -n 1)" >&2 | ||
| echo "WARNING: remove it if the build later reports an unsupported Go version." >&2 | ||
| fi | ||
| } | ||
|
|
||
| # Define usage function | ||
| usage() { | ||
|
|
@@ -46,9 +162,6 @@ while [ $# -gt 0 ]; do | |
| done | ||
|
|
||
| # Install prerequisites if not disabled | ||
| # golang version pinned for stability to avoid breaking changes. As of 11-Jun-2025 we are using golang-1.23.1 on Ubuntu 22.04 since it is the most recent release available. | ||
| # When making a breaking change to the toolkit which requires a newer golang version, update this version if needed. | ||
| # If no newer version is available, suggest moving to a newer Ubuntu LTS version | ||
| if [ "$INSTALL_PREREQS" = true ]; then | ||
| echo "Installing required packages..." | ||
| apt update | ||
|
|
@@ -59,7 +172,6 @@ if [ "$INSTALL_PREREQS" = true ]; then | |
| gawk \ | ||
| genisoimage \ | ||
| git \ | ||
| golang-1.24-go \ | ||
| jq \ | ||
| make \ | ||
| openssl \ | ||
|
|
@@ -72,15 +184,24 @@ if [ "$INSTALL_PREREQS" = true ]; then | |
| wget \ | ||
| xfsprogs \ | ||
| zstd | ||
|
|
||
| # Install Go separately from the packages above: which source it comes from depends on the | ||
| # Ubuntu release, and a toolchain that is already good enough is reused rather than replaced. | ||
| if go_is_supported; then | ||
| echo "Found a Go toolchain that meets the minimum, skipping Go installation..." | ||
| else | ||
| install_go | ||
| fi | ||
| else | ||
| echo "Skipping installation of prerequisite packages..." | ||
| fi | ||
|
|
||
| # Fix go 1.24 links if requested | ||
| if [ "$FIX_GO_LINKS" = true ]; then | ||
| echo "Creating Go symlinks..." | ||
| ln -vsf /usr/lib/go-1.24/bin/go /usr/bin/go | ||
| ln -vsf /usr/lib/go-1.24/bin/gofmt /usr/bin/gofmt | ||
| # Neither Go root is on PATH -- that is the whole reason --fix-go-links exists -- so installing | ||
| # prerequisites has to refresh the links as well, or the toolkit this just prepared still cannot | ||
| # find go. --fix-go-links then means "only do the links", to repair them or to pair with | ||
| # --no-install-prereqs. | ||
| if [ "$INSTALL_PREREQS" = true ] || [ "$FIX_GO_LINKS" = true ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this check. If |
||
| link_go | ||
| fi | ||
|
|
||
| # Install and configure Docker if requested | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rephrase this comment? I'm having a hard time understanding what you mean with "Neither Go root is on PATH" or "or the toolkit this just prepared still cannot find go".