Skip to content

feat: add boringcrypto builds for linux #9528

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

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
strip debug symbols, add BoringCryto to buildinfo
Signed-off-by: Spike Curtis <spike@coder.com>
  • Loading branch information
spikecurtis committed Sep 5, 2023
commit dbb504f36f8f1000e3cf696e6e85ad0b5759013d
16 changes: 0 additions & 16 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,6 @@ jobs:
AC_APIKEY_ID: ${{ secrets.AC_APIKEY_ID }}
AC_APIKEY_FILE: /tmp/apple_apikey.p8

- name: Check Boring Crypto
run: |
set -euo pipefail

version="$(./scripts/version.sh)"
go tool nm build/coder_"$version"_linux_amd64 | grep "_Cfunc__goboringcrypto_" &>/dev/null
if [[ "$?" == "1" ]]; then
echo "build/coder_${version}_linux_amd64 is not built with Boring Crypto"
exit 1
fi
go tool nm build/coder-slim_"$version"_linux_amd64 | grep "_Cfunc__goboringcrypto_" &>/dev/null
if [[ "$?" == "1" ]]; then
echo "build/coder-slim_${version}_linux_amd64 is not built with Boring Crypto"
exit 1
fi

- name: Delete Apple Developer certificate and API key
run: rm -f /tmp/{apple_cert.p12,apple_cert_password.txt,apple_apikey.p8}

Expand Down
14 changes: 3 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,8 @@ CODER_ARCH_IMAGE_PREREQUISITES := \
endif

# used to decide if we can build with boringcrypto
ifeq ($(OS),Windows_NT)
local_os:=Windows
local_arch:="" #ignored, no boringcrypto support for Windows
else
local_os:=$(shell uname -s)
local_arch:=$(shell uname -m)
endif
ifeq ($(local_arch),x86_64)
local_arch:=amd64
endif
local_os:=$(shell go env GOHOSTOS)
local_arch:=$(shell go env GOHOSTARCH)

clean:
rm -rf build site/out
Expand Down Expand Up @@ -235,7 +227,7 @@ $(CODER_ALL_BINARIES): go.mod go.sum \

# boringcrypto is only supported on Linux
# boringcrypto uses CGO, which isn't supported when cross compiling architectures
if [[ "$$os" == "linux" ]] && [[ "${local_os}" == "Linux" ]] && [[ "$$arch" == "${local_arch}" ]]; then
if [[ "$$os" == "linux" ]] && [[ "${local_os}" == "linux" ]] && [[ "$$arch" == "${local_arch}" ]]; then
build_args+=(--boringcrypto)
fi

Expand Down
7 changes: 7 additions & 0 deletions buildinfo/boring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build boringcrypto

package buildinfo

import "crypto/boring"

var boringcrypto = boring.Enabled()
4 changes: 4 additions & 0 deletions buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ func IsAGPL() bool {
return strings.Contains(agpl, "t")
}

func IsBoringCrypto() bool {
return boringcrypto
}

// ExternalURL returns a URL referencing the current Coder version.
// For production builds, this will link directly to a release.
// For development builds, this will link to a commit.
Expand Down
5 changes: 5 additions & 0 deletions buildinfo/notboring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build !boringcrypto

package buildinfo

var boringcrypto = false
25 changes: 15 additions & 10 deletions cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import (
// versionInfo wraps the stuff we get from buildinfo so that it's
// easier to emit in different formats.
type versionInfo struct {
Version string `json:"version"`
BuildTime time.Time `json:"build_time"`
ExternalURL string `json:"external_url"`
Slim bool `json:"slim"`
AGPL bool `json:"agpl"`
Version string `json:"version"`
BuildTime time.Time `json:"build_time"`
ExternalURL string `json:"external_url"`
Slim bool `json:"slim"`
AGPL bool `json:"agpl"`
BoringCrypto bool `json:"boring_crypto"`
}

// String() implements Stringer
Expand All @@ -28,6 +29,9 @@ func (vi versionInfo) String() string {
_, _ = str.WriteString("(AGPL) ")
}
_, _ = str.WriteString(vi.Version)
if vi.BoringCrypto {
_, _ = str.WriteString(" BoringCrypto")
}

if !vi.BuildTime.IsZero() {
_, _ = str.WriteString(" " + vi.BuildTime.Format(time.UnixDate))
Expand All @@ -45,11 +49,12 @@ func (vi versionInfo) String() string {
func defaultVersionInfo() *versionInfo {
buildTime, _ := buildinfo.Time()
return &versionInfo{
Version: buildinfo.Version(),
BuildTime: buildTime,
ExternalURL: buildinfo.ExternalURL(),
Slim: buildinfo.IsSlim(),
AGPL: buildinfo.IsAGPL(),
Version: buildinfo.Version(),
BuildTime: buildTime,
ExternalURL: buildinfo.ExternalURL(),
Slim: buildinfo.IsSlim(),
AGPL: buildinfo.IsAGPL(),
BoringCrypto: buildinfo.IsBoringCrypto(),
}
}

Expand Down
7 changes: 1 addition & 6 deletions scripts/build_go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,11 @@ if [[ "$sign_darwin" == 1 ]]; then
fi

ldflags=(
-s
-w
-X "'github.com/coder/coder/v2/buildinfo.tag=$version'"
)

# For boringcrypto we want to leave the symbols so we can verify it was build correctly for
# FIPS compliance. This adds a few MiB to the binary.
if [[ "$boringcrypto" == 0 ]]; then
ldflags+=(-s)
fi

# We use ts_omit_aws here because on Linux it prevents Tailscale from importing
# github.com/aws/aws-sdk-go-v2/aws, which adds 7 MB to the binary.
TS_EXTRA_SMALL="ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube"
Expand Down