Skip to content

Commit 895b4f5

Browse files
Add mage target and buildkite step to flag crypto imports for FIPS builds (#5534) (#5558)
* Add mage target and buildkite step to flag crypto imports for FIPS builds * Rename file (cherry picked from commit f44372c) Co-authored-by: Michel Laterman <[email protected]>
1 parent 6ec290f commit 895b4f5

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

.buildkite/pipeline.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ steps:
4242
agents:
4343
provider: "gcp"
4444

45+
- label: "Detect FIPS crypto imports"
46+
command: ".buildkite/scripts/check_detect_fips_crypto.sh"
47+
4548
- label: "Package x86_64"
4649
key: "package-x86-64-pr"
4750
env:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
source .buildkite/scripts/common.sh
6+
7+
add_bin_path
8+
9+
with_go
10+
11+
with_mage
12+
13+
mage check:detectFIPSCryptoImports

magefile.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,31 @@ func (Check) Notice() {
483483
mg.SerialDeps(mg.F(genNotice, false), mg.F(genNotice, true))
484484
}
485485

486+
// DetectFIPSCryptoImports will do a best effort attempt to ensure that the imports list for FIPS compatible artifacts does not contain any external crypto libraries.
487+
// Specifically it will fail if the modules list contains an entry with: "crypto", "gokrb5", or "pbkdf2"
488+
func (Check) DetectFIPSCryptoImports() error {
489+
tags := []string{"requirefips", "ms_tls13kdf"}
490+
mods, err := getModules(tags...)
491+
if err != nil {
492+
return err
493+
}
494+
495+
args := append([]string{"list", "-m"}, mods...)
496+
output, err := sh.Output("go", args...)
497+
if err != nil {
498+
return err
499+
}
500+
for _, line := range strings.Split(output, "\n") {
501+
// keywords are crypto for x/crypto imports, gokrb5 for kerberos, and pbkdf2 for pbkdf2 generation
502+
for _, keyword := range []string{"crypto", "gokrb5", "pbkdf2"} {
503+
if strings.Contains(line, keyword) {
504+
err = errors.Join(err, fmt.Errorf("Detected import %s may implement crypto functionality", line))
505+
}
506+
}
507+
}
508+
return err
509+
}
510+
486511
// genNotice generates the NOTICE.txt or the NOTICE-fips.txt file.
487512
func genNotice(fips bool) error {
488513
tags := []string{}

0 commit comments

Comments
 (0)