Skip to content

Commit 3f18bfc

Browse files
WIP try to get fips package available
1 parent 7ee581e commit 3f18bfc

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

dev-tools/mage/build.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func DefaultBuildArgs() BuildArgs {
5353
args.ExtraFlags = append(args.ExtraFlags, "-buildmode", "pie")
5454
}
5555

56+
if FIPSBuild {
57+
args.ExtraFlags = append(args.ExtraFlags, "-tags=fipsrequired")
58+
}
59+
5660
if DevBuild {
5761
// Disable optimizations (-N) and inlining (-l) for debugging.
5862
args.ExtraFlags = append(args.ExtraFlags, `-gcflags=all=-N -l`)
@@ -151,6 +155,12 @@ func Build(params BuildArgs) error {
151155
if params.CGO {
152156
cgoEnabled = "1"
153157
}
158+
159+
if FIPSBuild {
160+
cgoEnabled = "1"
161+
env["GOEXPERIMENT"] = "systemcrypto"
162+
}
163+
154164
env["CGO_ENABLED"] = cgoEnabled
155165

156166
// Spec

dev-tools/mage/crossbuild.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ func CrossBuildImage(platform string) (string, error) {
249249
return "", err
250250
}
251251

252+
if FIPSBuild {
253+
return FIPSBuildImage + ":" + goVersion + "-1-fips-bookworm", nil
254+
}
255+
252256
return BeatsCrossBuildImage + ":" + goVersion + "-" + tagSuffix, nil
253257
}
254258

@@ -332,6 +336,7 @@ func (b GolangCrossBuilder) Build() error {
332336
"--env", fmt.Sprintf("SNAPSHOT=%v", Snapshot),
333337
"--env", fmt.Sprintf("DEV=%v", DevBuild),
334338
"--env", fmt.Sprintf("EXTERNAL=%v", ExternalBuild),
339+
"--env", fmt.Sprintf("FIPS=%v", FIPSBuild),
335340
"-v", repoInfo.RootDir+":"+mountPoint,
336341
"-w", workDir,
337342
image,

dev-tools/mage/settings.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
beatsFPMImage = "docker.elastic.co/beats-dev/fpm"
3636
// BeatsCrossBuildImage is the image used for crossbuilding Beats.
3737
BeatsCrossBuildImage = "docker.elastic.co/beats-dev/golang-crossbuild"
38+
//FIPSBuildImage is the image used for building FIPS compliant artifacts
39+
FIPSBuildImage = "mcr.microsoft.com/oss/go/microsoft/golang"
3840

3941
elasticAgentImportPath = "github.com/elastic/elastic-agent"
4042

@@ -88,6 +90,7 @@ var (
8890
Snapshot bool
8991
DevBuild bool
9092
ExternalBuild bool
93+
FIPSBuild bool
9194

9295
versionQualified bool
9396
versionQualifier string
@@ -153,6 +156,11 @@ func initGlobals() {
153156
panic(fmt.Errorf("failed to parse EXTERNAL env value: %w", err))
154157
}
155158

159+
FIPSBuild, err = strconv.ParseBool(EnvOr("FIPS", "false"))
160+
if err != nil {
161+
panic(fmt.Errorf("failed to parse FIPS env value: %w", err))
162+
}
163+
156164
versionQualifier, versionQualified = os.LookupEnv("VERSION_QUALIFIER")
157165

158166
agentPackageVersion = EnvOr(agentPackageVersionEnvVar, "")
@@ -210,6 +218,7 @@ func varMap(args ...map[string]interface{}) map[string]interface{} {
210218
"Snapshot": Snapshot,
211219
"DEV": DevBuild,
212220
"EXTERNAL": ExternalBuild,
221+
"FIPS": FIPSBuild,
213222
"Qualifier": versionQualifier,
214223
"CI": CI,
215224
}

internal/pkg/release/version.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const (
2020
// snapshot is a flag marking build as a snapshot.
2121
var snapshot = ""
2222

23+
// fips is a flag for marking a FIPS compliant build.
24+
var fips = "false"
25+
2326
// complete is an environment variable marking the image as complete.
2427
var complete = "ELASTIC_AGENT_COMPLETE"
2528

@@ -77,12 +80,18 @@ func Complete() bool {
7780
return ok && isComplete == "true"
7881
}
7982

83+
func FIPS() bool {
84+
f, err := strconv.ParseBool(fips)
85+
return err == nil && f
86+
}
87+
8088
// VersionInfo is structure used by `version --yaml`.
8189
type VersionInfo struct {
8290
Version string `yaml:"version"`
8391
Commit string `yaml:"commit"`
8492
BuildTime time.Time `yaml:"build_time"`
8593
Snapshot bool `yaml:"snapshot"`
94+
FIPS bool `yaml:"fips"`
8695
}
8796

8897
// Info returns current version information.
@@ -92,6 +101,7 @@ func Info() VersionInfo {
92101
Commit: Commit(),
93102
BuildTime: BuildTime(),
94103
Snapshot: Snapshot(),
104+
FIPS: FIPS(),
95105
}
96106
}
97107

@@ -105,8 +115,12 @@ func (v VersionInfo) String() string {
105115
}
106116
sb.WriteString(" (build: ")
107117
sb.WriteString(v.Commit)
118+
if v.FIPS {
119+
sb.WriteString(" fips: true")
120+
}
108121
sb.WriteString(" at ")
109122
sb.WriteString(v.BuildTime.Format("2006-01-02 15:04:05 -0700 MST"))
110123
sb.WriteString(")")
124+
111125
return sb.String()
112126
}

magefile.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const (
8181
metaDir = "_meta"
8282
snapshotEnv = "SNAPSHOT"
8383
devEnv = "DEV"
84+
fipsEnv = "FIPS"
8485
externalArtifacts = "EXTERNAL"
8586
platformsEnv = "PLATFORMS"
8687
packagesEnv = "PACKAGES"
@@ -786,6 +787,9 @@ func (Cloud) Image(ctx context.Context) {
786787
variant := os.Getenv(dockerVariants)
787788
defer os.Setenv(dockerVariants, variant)
788789

790+
fips := os.Getenv(fipsEnv)
791+
defer os.Setenv(fipsEnv, fips)
792+
789793
os.Setenv(platformsEnv, "linux/amd64")
790794
os.Setenv(packagesEnv, "docker")
791795
os.Setenv(devEnv, "true")
@@ -800,6 +804,14 @@ func (Cloud) Image(ctx context.Context) {
800804
devtools.Snapshot = true
801805
}
802806

807+
if f, err := strconv.ParseBool(fips); err == nil && !f {
808+
os.Setenv(fipsEnv, "false")
809+
devtools.FIPSBuild = false
810+
} else {
811+
os.Setenv(fipsEnv, "true")
812+
devtools.FIPSBuild = true
813+
}
814+
803815
devtools.DevBuild = true
804816
devtools.Platforms = devtools.Platforms.Filter("linux/amd64")
805817
devtools.SelectedPackageTypes = []devtools.PackageType{devtools.Docker}
@@ -1756,6 +1768,12 @@ func buildVars() map[string]string {
17561768
isSnapshot, _ := os.LookupEnv(snapshotEnv)
17571769
vars["github.com/elastic/elastic-agent/internal/pkg/release.snapshot"] = isSnapshot
17581770

1771+
if fipsFlag, fipsFound := os.LookupEnv(fipsEnv); fipsFound {
1772+
if fips, err := strconv.ParseBool(fipsFlag); err == nil && fips {
1773+
vars["github.com/elastic/elastic-agent/internal/pkg/release.fips"] = "true"
1774+
}
1775+
}
1776+
17591777
if isDevFlag, devFound := os.LookupEnv(devEnv); devFound {
17601778
if isDev, err := strconv.ParseBool(isDevFlag); err == nil && isDev {
17611779
vars["github.com/elastic/elastic-agent/internal/pkg/release.allowEmptyPgp"] = "true"

0 commit comments

Comments
 (0)