Skip to content

Commit 6a1ca4a

Browse files
committed
project documentation, helper scripts
1 parent 8092b81 commit 6a1ca4a

File tree

7 files changed

+107
-0
lines changed

7 files changed

+107
-0
lines changed

docs/build.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# How to build a fips compliant go binary that includes golang-fips patches
2+
3+
The easiest way to do is to simply clone this repo and run make. see a more comprehensive script at `scripts/build1.sh`
4+
5+
```
6+
git clone https://github.com/golang-fips/go.git golang-fips
7+
cd golang-fips
8+
./scripts/full-initialize-repo.sh go$GOLANG_VER
9+
cd go/src
10+
./make.bash --no-clean
11+
```
12+
13+
## Env variables
14+
15+
`GOEXPERIMENT=strictfipsruntime` helps ensure a fips compliant binary is build. Note that this is functionally equivalent of
16+
17+
```
18+
GO_BUILDTAGS+="goexperiment.strictfipsruntime"
19+
```
20+
21+
You can export more Go flags like `GO_GCFLAGS="-N -l"` to add symbols in the final binary.
22+
23+
# Other way to apply fips patches
24+
25+
Another way is to directly apply fips patches by downloading binaries for go and golang-fips. see full script at `scripts/build2.sh`
26+
27+
```
28+
wget https://github.com/golang/go/archive/refs/tags/go1.22.2.tar.gz
29+
wget https://github.com/golang-fips/go/archive/refs/tags/go1.22.2-1-openssl-fips.tar.gz
30+
tar -xf go1.22.2.tar.gz
31+
tar -xf go1.22.2-1-openssl-fips.tar.gz
32+
cd go-go1.22.2
33+
for patch in ../go-go1.22.2-1-openssl-fips/patches/*.patch; do
34+
patch -p1 < "${patch}"
35+
done
36+
cd src
37+
./make.bash --no-clean
38+
```

docs/deps.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Dependencies

docs/openssl.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# OpenSSL considerations

docs/overview.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Overview here

docs/test-conf.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test configuration

scripts/build1.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# this script builds a go binary after applying openssl fips patches.
3+
4+
set -x
5+
export GOLANG_VER=1.22.2
6+
TOP_DIR=/tmp/golang-fips/build1
7+
[[ -d $TOP_DIR ]] || mkdir -p $TOP_DIR
8+
cd $TOP_DIR
9+
[[ -d golang-fips ]] || git clone https://github.com/golang-fips/go.git golang-fips
10+
cd golang-fips
11+
./scripts/full-initialize-repo.sh go$GOLANG_VER
12+
cd go/src
13+
export GO_BUILDTAGS+="goexperiment.strictfipsruntime,!no_openssl"
14+
export CGO_ENABLED=1
15+
./make.bash --no-clean
16+
{ set +x ; } 2>/dev/null

scripts/build2.sh

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#! /usr/bin/env bash
2+
# this script builds a go binary after applying openssl fips patches one by one.
3+
#
4+
export GOLANG_VER=1.22.2
5+
export GOLANG_REL=1
6+
7+
# variables to store tar file names
8+
GO_TAR_NAME=go$GOLANG_VER
9+
PATCH_TAR_NAME=go$GOLANG_VER-$GOLANG_REL-openssl-fips
10+
GO_SRC_TAR=$GO_TAR_NAME.tar.gz
11+
PATCH_TAR=$PATCH_TAR_NAME.tar.gz
12+
13+
# after untar, the dir names are stored in PATCH_DIR and SRC_DIR
14+
SRC_DIR=go-$GO_TAR_NAME
15+
PATCH_DIR=go-$PATCH_TAR_NAME
16+
TOP_DIR=/tmp/golang-fips/build2
17+
# If the go src dir ends up in a weird state where in patches are failing to apply, you might want to remove the $TOP_DIR (rm -rf /tmp/golang-fips/build2) to start with a clean slate.
18+
PATCH_PATH=$TOP_DIR/$PATCH_DIR/patches
19+
20+
# this file stores state of last applied patch, that way patches are not reapplied
21+
PATCH_STATE=$TOP_DIR/state
22+
set -x
23+
[[ -d $TOP_DIR ]] || mkdir -p $TOP_DIR
24+
cd $TOP_DIR
25+
26+
[[ -f $GO_SRC_TAR ]] || wget -q --show-progress https://github.com/golang/go/archive/refs/tags/$GO_SRC_TAR
27+
[[ -f $PATCH_TAR ]] || wget -q --show-progress https://github.com/golang-fips/go/archive/refs/tags/$PATCH_TAR
28+
[[ -d $SRC_DIR ]] || tar -xf $GO_SRC_TAR
29+
[[ -d $PATCH_DIR ]] || tar -xf $PATCH_TAR
30+
31+
cd $SRC_DIR
32+
{ set +x; } 2>/dev/null
33+
if [[ -f $PATCH_STATE && "$(cat $PATCH_STATE)" == "complete" ]]; then
34+
echo "patches already applied. skipping"
35+
else
36+
for patch in $PATCH_PATH/*.patch; do
37+
patch -p1 < "${patch}"
38+
[[ $? -eq 0 ]] || { echo "incomplete" > $PATCH_STATE; break; exit 1; }
39+
done
40+
fi
41+
42+
echo "complete" > $PATCH_STATE
43+
# patches have been supplied successfully, simply build like above.
44+
set -x
45+
cd src
46+
export GO_BUILDTAGS+="goexperiment.strictfipsruntime,!no_openssl"
47+
export CGO_ENABLED=1
48+
./make.bash --no-clean
49+
{ set +x; } 2>/dev/null

0 commit comments

Comments
 (0)