Skip to content

Commit 0d14694

Browse files
msorenssrenatus
andauthored
Add semgrep buildkite task for published rules (#4402)
Co-authored-by: Stephan Renatus <[email protected]>
1 parent eace032 commit 0d14694

File tree

11 files changed

+42
-16
lines changed

11 files changed

+42
-16
lines changed

.expeditor/verify.pipeline.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ steps:
6161
- HAB_STUDIO_SUP=false
6262
- HAB_NONINTERACTIVE=true
6363

64-
- label: ":semgrep: Semgrep"
64+
- label: ":semgrep: Custom"
6565
expeditor:
6666
executor:
6767
docker:
@@ -73,6 +73,24 @@ steps:
7373
"/go/src/github.com/chef/automate"
7474
]
7575

76+
- label: ":semgrep: Published"
77+
expeditor:
78+
executor:
79+
docker:
80+
image: returntocorp/semgrep:latest
81+
entrypoint: semgrep
82+
command: [
83+
"--error",
84+
"--exclude", "third_party",
85+
"--exclude", "*_test.go",
86+
"--exclude", "*.pb.go",
87+
"--exclude", "*.bindata.go",
88+
"--exclude", "*.spec.ts",
89+
"--timeout", "120",
90+
"--config", "https://semgrep.dev/p/r2c-ci",
91+
"/go/src/github.com/chef/automate"
92+
]
93+
7694
#
7795
# Static & Unit tests
7896
#

Makefile.common_go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ spell:
5050
# NB: "third_party" only exists for automate-gateway, but no harm having it for other dirs here.
5151
semgrep:
5252
# uncomment if custom rules beyond automate-ui ever get added
53-
# semgrep --config $(REPOROOT)/semgrep --exclude third_party
54-
semgrep --config https://semgrep.dev/p/r2c-ci --exclude third_party --autofix
53+
# semgrep --config $(REPOROOT)/semgrep --exclude third_party --exclude *_test.go --exclude *.pb.go --exclude *.bindata.go
54+
semgrep --config https://semgrep.dev/p/r2c-ci --exclude third_party --exclude *_test.go --exclude *.pb.go --exclude *.bindata.go
5555

5656
#: Security validation via semgrep; autofix where possible
5757
semgrep-and-fix:
5858
# uncomment if custom rules beyond automate-ui ever get added
59-
# semgrep --config $(REPOROOT)/semgrep --exclude third_party --autofix
60-
semgrep --config https://semgrep.dev/p/r2c-ci --exclude third_party --autofix
59+
# semgrep --config $(REPOROOT)/semgrep --exclude third_party --exclude *_test.go --exclude *.pb.go --exclude *.bindata.go --autofix
60+
semgrep --config https://semgrep.dev/p/r2c-ci --exclude third_party --exclude *_test.go --exclude *.pb.go --exclude *.bindata.go --autofix
6161

6262
.PHONY: lint fmt fmt-check golang_version_check semgrep semgrep-and-fix

api/config/cs_nginx/config_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ func (c *ConfigRequest) PrepareSystemConfig(creds *ac.TLSCredentials) (ac.Prepar
174174
// Digest::MD5.base64digest
175175
//
176176
func CalculateContentMD5(data []byte) string {
177-
md5sum := md5.Sum(data)
177+
md5sum := md5.Sum(data) // nosem
178178
return base64.StdEncoding.EncodeToString(md5sum[:])
179179
}

components/automate-deployment/pkg/airgap/bundle_creator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,14 @@ func (dl *netHabDownloader) DownloadHabBinary(version string, release string, w
100100
return errors.Errorf("Could not get hab binary. Got status %s", resp.Status)
101101
}
102102

103-
gzipReader, err := gzip.NewReader(resp.Body)
104-
103+
// NOTE: We're downloading this via HTTPS from a location that's trusted.
104+
gzipReader, err := gzip.NewReader(resp.Body) // nosem: go.lang.security.decompression_bomb.potential-dos-via-decompression-bomb
105105
if err != nil {
106106
return errors.Wrap(err, "Failed to download hab binary. Could not open gzip")
107107
}
108108

109-
tarReader := tar.NewReader(gzipReader)
109+
// NOTE: See above.
110+
tarReader := tar.NewReader(gzipReader) // nosem: go.lang.security.decompression_bomb.potential-dos-via-decompression-bomb
110111
for {
111112
hdr, err := tarReader.Next()
112113
if err == io.EOF {

components/automate-deployment/pkg/backup/artifact_repo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,8 @@ func (repo *ArtifactRepo) openGzipFile(ctx context.Context, name string) (*os.Fi
629629
return nil, "", err
630630
}
631631

632-
g, err := gzip.NewReader(reader)
632+
// NOTE: This reads a backup archive, provided by an admin. It's trusted input.
633+
g, err := gzip.NewReader(reader) // nosem: go.lang.security.decompression_bomb.potential-dos-via-decompression-bomb
633634
if err != nil {
634635
logClose(tmpFile, "failed to close temp file")
635636
return nil, "", err

components/automate-deployment/pkg/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ func (s *server) ConfigureDeployment(ctx context.Context,
744744
}
745745

746746
deploymentStatus := s.deployment.Status()
747-
configSHA1 := sha1.Sum([]byte(overrideConfig.String()))
747+
configSHA1 := sha1.Sum([]byte(overrideConfig.String())) // nosem
748748

749749
logrus.WithFields(logrus.Fields{
750750
"config_sha1": fmt.Sprintf("%x", configSHA1),

components/automate-gateway/pkg/nullbackend/backend.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import (
3434

3535
// NewServer returns a pointer to a new instance of the null backend server
3636
func NewServer() *grpc.Server {
37-
s := grpc.NewServer()
37+
// The nullbackend only listens on a unix socket. And it doesn't deal with interesting data,
38+
// but only "no implemented" responses.
39+
s := grpc.NewServer() // nosem: go.grpc.security.grpc-server-insecure-connection.grpc-server-insecure-connection
3840

3941
applications.RegisterApplicationsServiceServer(s, &applications.UnimplementedApplicationsServiceServer{})
4042
cds.RegisterCdsServer(s, &cds.UnimplementedCdsServer{})

components/cereal-service/cmd/cereal-service/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func serve(*cobra.Command, []string) error {
146146
}
147147

148148
if C.Service.DisableTLS {
149-
grpcServer = grpc.NewServer(grpcServerOpts...)
149+
grpcServer = grpc.NewServer(grpcServerOpts...) // nosem: go.grpc.security.grpc-server-insecure-connection.grpc-server-insecure-connection
150150
} else {
151151
serviceCerts, err := C.TLS.ReadCerts()
152152
if err != nil {

components/compliance-service/reporting/util/zip.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import (
1818

1919
// Zip2Path extracts a zip file on disk to a destination folder on disk.
2020
func Zip2Path(zipPath string, extractPath string) error {
21-
reader, err := zip.OpenReader(zipPath)
21+
// TODO(sr): This is not entirely ignorable, but worse things can happen
22+
// when a user uploads an inspec profile. So, let's keep it in mind but
23+
// move on.
24+
reader, err := zip.OpenReader(zipPath) // nosem: go.lang.security.decompression_bomb.potential-dos-via-decompression-bomb
2225
if err != nil {
2326
return err
2427
}

lib/grpc/secureconn/factory.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func (f *Factory) DialContext(
8585
// NewServer is a wrapper for grpc.NewServer that adds server options to verify clients using
8686
// the factory's root CA
8787
func (f *Factory) NewServer(opt ...grpc.ServerOption) *grpc.Server {
88-
s := grpc.NewServer(append(f.ServerOptions(), opt...)...)
88+
// f.ServerOptions() includes TLS settings, so this is not insecure (semgrep thinks so)
89+
s := grpc.NewServer(append(f.ServerOptions(), opt...)...) // nosem: go.grpc.security.grpc-server-insecure-connection.grpc-server-insecure-connection
8990

9091
if !f.DisableDebugServer {
9192
debug_api.RegisterDebugServer(s, debug.NewDebugServer(f.DebugServerOpts...))

tools/cereal-scaffold/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func runResetDB(_ *cobra.Command, args []string) error {
234234

235235
func getBackend() cereal.Driver {
236236
if opts.Endpoint != "" {
237-
conn, err := grpc.Dial(opts.Endpoint, grpc.WithInsecure(), grpc.WithMaxMsgSize(64*1024*1024))
237+
conn, err := grpc.Dial(opts.Endpoint, grpc.WithInsecure(), grpc.WithMaxMsgSize(64*1024*1024)) // nosem: go.grpc.security.grpc-client-insecure-connection.grpc-client-insecure-connection
238238
if err != nil {
239239
panic(err)
240240
}

0 commit comments

Comments
 (0)