Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows: Fix gosec errors & enable code annotations #19

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches: [ main ]
pull_request: { }

permissions:
contents: read
checks: write

jobs:
go:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ func jitter(n int64) int64 {
return 0
}

return n/2 + rand.Int63n(n/2)
return n/2 + rand.Int63n(n/2) // #nosec G404 -- Use of weak random number generator - we don't need crypto/rand here though.
}
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func FromYAMLFile(name string, v Validator) error {
return errors.Wrapf(ErrInvalidArgument, "non-nil pointer expected, got %T", v)
}

// #nosec G304 -- Potential file inclusion via variable - Its purpose is to load any file name that is passed to it, so doesn't need to validate anything.
f, err := os.Open(name)
if err != nil {
return errors.Wrap(err, "can't open YAML file "+name)
Expand Down
2 changes: 1 addition & 1 deletion config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (t *TLS) MakeConfig(serverName string) (*tls.Config, error) {
return nil, nil
}

tlsConfig := &tls.Config{}
tlsConfig := &tls.Config{MinVersion: tls.VersionTLS12}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if t.Cert == "" {
if t.Key != "" {
return nil, errors.New("private key given, but client certificate missing")
Expand Down
4 changes: 3 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package utils

import (
"context"
"crypto/sha1"
"crypto/sha1" // #nosec G505 -- Blocklisted import crypto/sha1
"fmt"
"github.com/go-sql-driver/mysql"
"github.com/lib/pq"
Expand Down Expand Up @@ -64,8 +64,10 @@ func Checksum(data interface{}) []byte {

switch data := data.(type) {
case string:
// #nosec G401 -- Use of weak cryptographic primitive - we don't intend to change this anytime soon.
chksm = sha1.Sum([]byte(data))
case []byte:
// #nosec G401 -- Use of weak cryptographic primitive - we don't intend to change this anytime soon.
chksm = sha1.Sum(data)
default:
panic(fmt.Sprintf("Unable to create checksum for type %T", data))
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (o *osRelease) DisplayVersion() string {
// readOsRelease reads and parses the os-release file.
func readOsRelease() (*osRelease, error) {
for _, path := range []string{"/etc/os-release", "/usr/lib/os-release"} {
f, err := os.Open(path)
f, err := os.Open(path) // #nosec G304 -- Potential file inclusion via variable - Hard-coded files, so not affected by this issue.
if err != nil {
if os.IsNotExist(err) {
continue // Try next path.
Expand Down