Skip to content

Commit a39d95d

Browse files
committed
TUN-5551: Show whether the binary was built for FIPS compliance
This is shown in 3 ways: - the version output with `cloudflared version` and alike commands - the build_info prometheus metric - a logging message
1 parent 01ad278 commit a39d95d

File tree

8 files changed

+46
-29
lines changed

8 files changed

+46
-29
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ifeq ($(FIPS), true)
2525
LINK_FLAGS := -linkmode=external -extldflags=-static $(LINK_FLAGS)
2626
# Prevent linking with libc regardless of CGO enabled or not.
2727
GO_BUILD_TAGS := $(GO_BUILD_TAGS) osusergo netgo fips
28+
VERSION_FLAGS := $(VERSION_FLAGS) -X "main.BuildType=FIPS"
2829
endif
2930

3031
LDFLAGS := -ldflags='$(VERSION_FLAGS) $(LINK_FLAGS)'

cmd/cloudflared/buildinfo/build_info.go renamed to cmd/cloudflared/cliutil/build_info.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package buildinfo
1+
package cliutil
22

33
import (
44
"fmt"
@@ -11,23 +11,39 @@ type BuildInfo struct {
1111
GoOS string `json:"go_os"`
1212
GoVersion string `json:"go_version"`
1313
GoArch string `json:"go_arch"`
14+
BuildType string `json:"build_type"`
1415
CloudflaredVersion string `json:"cloudflared_version"`
1516
}
1617

17-
func GetBuildInfo(cloudflaredVersion string) *BuildInfo {
18+
func GetBuildInfo(buildType, version string) *BuildInfo {
1819
return &BuildInfo{
1920
GoOS: runtime.GOOS,
2021
GoVersion: runtime.Version(),
2122
GoArch: runtime.GOARCH,
22-
CloudflaredVersion: cloudflaredVersion,
23+
BuildType: buildType,
24+
CloudflaredVersion: version,
2325
}
2426
}
2527

2628
func (bi *BuildInfo) Log(log *zerolog.Logger) {
2729
log.Info().Msgf("Version %s", bi.CloudflaredVersion)
30+
if bi.BuildType != "" {
31+
log.Info().Msgf("Built%s", bi.GetBuildTypeMsg())
32+
}
2833
log.Info().Msgf("GOOS: %s, GOVersion: %s, GoArch: %s", bi.GoOS, bi.GoVersion, bi.GoArch)
2934
}
3035

3136
func (bi *BuildInfo) OSArch() string {
3237
return fmt.Sprintf("%s_%s", bi.GoOS, bi.GoArch)
3338
}
39+
40+
func (bi *BuildInfo) Version() string {
41+
return bi.CloudflaredVersion
42+
}
43+
44+
func (bi *BuildInfo) GetBuildTypeMsg() string {
45+
if bi.BuildType == "" {
46+
return ""
47+
}
48+
return fmt.Sprintf(" with %s", bi.BuildType)
49+
}

cmd/cloudflared/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
var (
3232
Version = "DEV"
3333
BuildTime = "unknown"
34+
BuildType = ""
3435
// Mostly network errors that we don't want reported back to Sentry, this is done by substring match.
3536
ignoredErrors = []string{
3637
"connection reset by peer",
@@ -46,9 +47,10 @@ var (
4647

4748
func main() {
4849
rand.Seed(time.Now().UnixNano())
49-
metrics.RegisterBuildInfo(BuildTime, Version)
50+
metrics.RegisterBuildInfo(BuildType, BuildTime, Version)
5051
raven.SetRelease(Version)
5152
maxprocs.Set()
53+
bInfo := cliutil.GetBuildInfo(BuildType, Version)
5254

5355
// Graceful shutdown channel used by the app. When closed, app must terminate gracefully.
5456
// Windows service manager closes this channel when it receives stop command.
@@ -71,7 +73,7 @@ func main() {
7173
Terms (https://www.cloudflare.com/terms/) and Privacy Policy (https://www.cloudflare.com/privacypolicy/).`,
7274
time.Now().Year(),
7375
)
74-
app.Version = fmt.Sprintf("%s (built %s)", Version, BuildTime)
76+
app.Version = fmt.Sprintf("%s (built %s%s)", Version, BuildTime, bInfo.GetBuildTypeMsg())
7577
app.Description = `cloudflared connects your machine or user identity to Cloudflare's global network.
7678
You can use it to authenticate a session to reach an API behind Access, route web traffic to this machine,
7779
and configure access control.
@@ -81,7 +83,7 @@ func main() {
8183
app.Action = action(graceShutdownC)
8284
app.Commands = commands(cli.ShowVersion)
8385

84-
tunnel.Init(Version, graceShutdownC) // we need this to support the tunnel sub command...
86+
tunnel.Init(bInfo, graceShutdownC) // we need this to support the tunnel sub command...
8587
access.Init(graceShutdownC)
8688
updater.Init(Version)
8789
runApp(app, graceShutdownC)

cmd/cloudflared/tunnel/cmd.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/urfave/cli/v2/altsrc"
2323

2424
"github.com/cloudflare/cloudflared/cfapi"
25-
"github.com/cloudflare/cloudflared/cmd/cloudflared/buildinfo"
2625
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
2726
"github.com/cloudflare/cloudflared/cmd/cloudflared/proxydns"
2827
"github.com/cloudflare/cloudflared/cmd/cloudflared/ui"
@@ -86,7 +85,7 @@ const (
8685

8786
var (
8887
graceShutdownC chan struct{}
89-
version string
88+
buildInfo *cliutil.BuildInfo
9089

9190
routeFailMsg = fmt.Sprintf("failed to provision routing, please create it manually via Cloudflare dashboard or UI; "+
9291
"most likely you already have a conflicting record there. You can also rerun this command with --%s to overwrite "+
@@ -175,8 +174,8 @@ func TunnelCommand(c *cli.Context) error {
175174
return runClassicTunnel(sc)
176175
}
177176

178-
func Init(ver string, gracefulShutdown chan struct{}) {
179-
version, graceShutdownC = ver, gracefulShutdown
177+
func Init(info *cliutil.BuildInfo, gracefulShutdown chan struct{}) {
178+
buildInfo, graceShutdownC = info, gracefulShutdown
180179
}
181180

182181
// runAdhocNamedTunnel create, route and run a named tunnel in one command
@@ -209,7 +208,7 @@ func runAdhocNamedTunnel(sc *subcommandContext, name, credentialsOutputPath stri
209208

210209
// runClassicTunnel creates a "classic" non-named tunnel
211210
func runClassicTunnel(sc *subcommandContext) error {
212-
return StartServer(sc.c, version, nil, sc.log, sc.isUIEnabled)
211+
return StartServer(sc.c, buildInfo, nil, sc.log, sc.isUIEnabled)
213212
}
214213

215214
func routeFromFlag(c *cli.Context) (route cfapi.HostnameRoute, ok bool) {
@@ -224,7 +223,7 @@ func routeFromFlag(c *cli.Context) (route cfapi.HostnameRoute, ok bool) {
224223

225224
func StartServer(
226225
c *cli.Context,
227-
version string,
226+
info *cliutil.BuildInfo,
228227
namedTunnel *connection.NamedTunnelConfig,
229228
log *zerolog.Logger,
230229
isUIEnabled bool,
@@ -271,8 +270,7 @@ func StartServer(
271270
defer trace.Stop()
272271
}
273272

274-
buildInfo := buildinfo.GetBuildInfo(version)
275-
buildInfo.Log(log)
273+
info.Log(log)
276274
logClientOptions(c, log)
277275

278276
// this context drives the server, when it's cancelled tunnel and all other components (origins, dns, etc...) should stop
@@ -336,7 +334,7 @@ func StartServer(
336334
observer.SendURL(quickTunnelURL)
337335
}
338336

339-
tunnelConfig, ingressRules, err := prepareTunnelConfig(c, buildInfo, version, log, logTransport, observer, namedTunnel)
337+
tunnelConfig, ingressRules, err := prepareTunnelConfig(c, info, log, logTransport, observer, namedTunnel)
340338
if err != nil {
341339
log.Err(err).Msg("Couldn't start tunnel")
342340
return err
@@ -377,7 +375,7 @@ func StartServer(
377375

378376
if isUIEnabled {
379377
tunnelUI := ui.NewUIModel(
380-
version,
378+
info.Version(),
381379
hostname,
382380
metricsListener.Addr().String(),
383381
&ingressRules,

cmd/cloudflared/tunnel/configuration.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
"github.com/urfave/cli/v2"
1717
"golang.org/x/crypto/ssh/terminal"
1818

19-
"github.com/cloudflare/cloudflared/cmd/cloudflared/buildinfo"
19+
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
20+
2021
"github.com/cloudflare/cloudflared/config"
2122
"github.com/cloudflare/cloudflared/connection"
2223
"github.com/cloudflare/cloudflared/edgediscovery"
@@ -148,8 +149,7 @@ func getOriginCert(originCertPath string, log *zerolog.Logger) ([]byte, error) {
148149

149150
func prepareTunnelConfig(
150151
c *cli.Context,
151-
buildInfo *buildinfo.BuildInfo,
152-
version string,
152+
info *cliutil.BuildInfo,
153153
log, logTransport *zerolog.Logger,
154154
observer *connection.Observer,
155155
namedTunnel *connection.NamedTunnelConfig,
@@ -193,8 +193,8 @@ func prepareTunnelConfig(
193193
namedTunnel.Client = tunnelpogs.ClientInfo{
194194
ClientID: clientUUID[:],
195195
Features: dedup(features),
196-
Version: version,
197-
Arch: buildInfo.OSArch(),
196+
Version: info.Version(),
197+
Arch: info.OSArch(),
198198
}
199199
ingressRules, err = ingress.ParseIngress(cfg)
200200
if err != nil && err != ingress.ErrNoIngressRules {
@@ -281,7 +281,7 @@ func prepareTunnelConfig(
281281

282282
return &origin.TunnelConfig{
283283
ConnectionConfig: connectionConfig,
284-
OSArch: buildInfo.OSArch(),
284+
OSArch: info.OSArch(),
285285
ClientID: clientID,
286286
EdgeAddrs: c.StringSlice("edge"),
287287
Region: c.String("region"),
@@ -293,7 +293,7 @@ func prepareTunnelConfig(
293293
Log: log,
294294
LogTransport: logTransport,
295295
Observer: observer,
296-
ReportedVersion: version,
296+
ReportedVersion: info.Version(),
297297
// Note TUN-3758 , we use Int because UInt is not supported with altsrc
298298
Retries: uint(c.Int("retries")),
299299
RunFromTerminal: isRunningFromTerminal(),

cmd/cloudflared/tunnel/quick_tunnel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func RunQuickTunnel(sc *subcommandContext) error {
7676

7777
return StartServer(
7878
sc.c,
79-
version,
79+
buildInfo,
8080
&connection.NamedTunnelConfig{Credentials: credentials, QuickTunnelUrl: data.Result.Hostname},
8181
sc.log,
8282
sc.isUIEnabled,

cmd/cloudflared/tunnel/subcommand_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (sc *subcommandContext) client() (cfapi.Client, error) {
7676
if err != nil {
7777
return nil, err
7878
}
79-
userAgent := fmt.Sprintf("cloudflared/%s", version)
79+
userAgent := fmt.Sprintf("cloudflared/%s", buildInfo.Version())
8080
client, err := cfapi.NewRESTClient(
8181
sc.c.String("api-url"),
8282
credential.cert.AccountID,
@@ -303,7 +303,7 @@ func (sc *subcommandContext) run(tunnelID uuid.UUID) error {
303303

304304
return StartServer(
305305
sc.c,
306-
version,
306+
buildInfo,
307307
&connection.NamedTunnelConfig{Credentials: credentials},
308308
sc.log,
309309
sc.isUIEnabled,

metrics/metrics.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ func ServeMetrics(
8383
return err
8484
}
8585

86-
func RegisterBuildInfo(buildTime string, version string) {
86+
func RegisterBuildInfo(buildType, buildTime, version string) {
8787
buildInfo := prometheus.NewGaugeVec(
8888
prometheus.GaugeOpts{
8989
// Don't namespace build_info, since we want it to be consistent across all Cloudflare services
9090
Name: "build_info",
9191
Help: "Build and version information",
9292
},
93-
[]string{"goversion", "revision", "version"},
93+
[]string{"goversion", "type", "revision", "version"},
9494
)
9595
prometheus.MustRegister(buildInfo)
96-
buildInfo.WithLabelValues(runtime.Version(), buildTime, version).Set(1)
96+
buildInfo.WithLabelValues(runtime.Version(), buildType, buildTime, version).Set(1)
9797
}

0 commit comments

Comments
 (0)