Skip to content

Commit 8dad4d8

Browse files
committed
feat: Allow compilation without sandbox
Build without sandbox must be explicit.
1 parent 4ab17f2 commit 8dad4d8

File tree

6 files changed

+43
-4
lines changed

6 files changed

+43
-4
lines changed

.github/workflows/publish.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ jobs:
4343
matrix:
4444
include:
4545
- bin_name: opinions-openbsd_amd64-hardened
46+
- bin_name: opinions-linux_amd64
47+
- bin_name: opinions-linux_arm
48+
- bin_name: opinions-linux_arm64
49+
- bin_name: opinions-freebsd_amd64
50+
- bin_name: opinions-windows_amd64.exe
4651

4752
steps:
4853
- name: Extract build artifacts

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,28 @@ build: check test
3333
PSEUDOVERSION="$${PREV_VER_TAG:-0.0.0}-$$CURRENT_COMMIT_TAG"; \
3434
VERSION="$${CURRENT_VER_TAG:-$$PSEUDOVERSION}"; \
3535
# hardened \
36-
GOOS=openbsd GOARCH=amd64 go build -C cmd/ -v -ldflags="-s -w -X main.AppVersion=$$VERSION" -o "../dist/opinions-openbsd_amd64-hardened"; \
36+
GOOS=openbsd GOARCH=amd64 go build -C cmd/ -ldflags="-s -w -X main.AppVersion=$$VERSION" -o '../dist/opinions-openbsd_amd64-hardened'; \
3737
# without sandbox \
38+
GOOS=linux GOARCH=amd64 go build -C cmd/ -tags unsafe -ldflags="-s -w -X main.AppVersion=$$VERSION" -o '../dist/opinions-linux_amd64'; \
39+
GOOS=linux GOARCH=arm go build -C cmd/ -tags unsafe -ldflags="-s -w -X main.AppVersion=$$VERSION" -o '../dist/opinions-linux_arm'; \
40+
GOOS=linux GOARCH=arm64 go build -C cmd/ -tags unsafe -ldflags="-s -w -X main.AppVersion=$$VERSION" -o '../dist/opinions-linux_arm64'; \
41+
GOOS=freebsd GOARCH=amd64 go build -C cmd/ -tags unsafe -ldflags="-s -w -X main.AppVersion=$$VERSION" -o '../dist/opinions-freebsd_amd64'; \
42+
GOOS=windows GOARCH=amd64 go build -C cmd/ -tags unsafe -ldflags="-s -w -X main.AppVersion=$$VERSION" -o '../dist/opinions-windows_amd64.exe'; \
3843

3944
@echo '# Create binaries checksum' >&2
4045
@sha256sum ./dist/* >./dist/sha256sum.txt
4146

47+
unsafe: check test
48+
@echo '# Create release binary without sandbox in ./dist/opinions-unsafe' >&2
49+
@CURRENT_VER_TAG="$$(git tag --points-at HEAD | sed 's/^v//' | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1)"; \
50+
PREV_VER_TAG="$$(git tag | sed 's/^v//' | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1)"; \
51+
CURRENT_COMMIT_TAG="$$(TZ=UTC git --no-pager show --quiet --abbrev=12 --date='format-local:%Y%m%d%H%M%S' --format='%cd-%h')"; \
52+
PSEUDOVERSION="$${PREV_VER_TAG:-0.0.0}-$$CURRENT_COMMIT_TAG"; \
53+
VERSION="$${CURRENT_VER_TAG:-$$PSEUDOVERSION}"; \
54+
go build -C cmd/ -tags unsafe -ldflags="-s -w -X main.AppVersion=$$VERSION" -o '../dist/opinions-unsafe'
55+
@echo '# Create checksum' >&2
56+
@sha256sum ./dist/opinions-unsafe >./dist/opinions-unsafe.sha256sum.txt
57+
4258
release: prepare-release build
4359

4460
install-dependencies:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Use `make` (GNU or BSD):
3535
- `make test` - runs test
3636
- `make check` - static code analysis
3737
- `make build` - compile binaries from latest commit for supported OSes (with [proper version number](https://go.dev/doc/modules/version-numbers))
38+
- `make unsafe` - compile binaries from latest commit without security sandbox
3839
- `make release` - mark latest commit with choosen version tag and compile binaries for supported OSes
3940
- `make clean` - removes compilation artifacts
4041
- `make info` - print system info (useful for debugging).

security/sandbox.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// Package security contains OS specific mitigation mechanisms.
22

3-
//go:build !openbsd
3+
//go:build !openbsd && !unsafe
44

55
package security
66

7+
import (
8+
"fmt"
9+
"runtime"
10+
)
11+
712
// IsHardened reports whether security sandbox is enabled.
813
const IsHardened = false
914

1015
// Sandbox restrict access to system resources.
1116
func Sandbox() error {
12-
return nil
17+
return fmt.Errorf("security sandbox is unavailable on %s/%s. To use app on this platform, compile it without sandbox (with 'unsafe' flag)", runtime.GOOS, runtime.GOARCH)
1318
}

security/sandbox_openbsd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build openbsd
1+
//go:build openbsd && !unsafe
22

33
package security
44

security/sandbox_unsafe.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build unsafe
2+
3+
package security
4+
5+
// IsHardened reports whether security sandbox is enabled.
6+
const IsHardened = false
7+
8+
// Sandbox restrict access to system resources. In unsafe builds sandbox is
9+
// disabled.
10+
func Sandbox() error {
11+
return nil
12+
}

0 commit comments

Comments
 (0)