Skip to content

Commit

Permalink
Fixes security lint problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Mar 25, 2021
1 parent 9b6aa6f commit 2828b91
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 58 deletions.
50 changes: 5 additions & 45 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ run:
modules-download-mode: readonly

linters:
enable:
enable:
- "bodyclose"
# - "depguard" broken in golangci-lint 1.17.1
- "depguard"
- "dupl"
- "goconst"
- "gocritic"
Expand All @@ -46,17 +46,15 @@ linters:
- "golint"
- "gosec"
- "gosimple"
- "interfacer"
- "lll"
- "maligned"
- "misspell"
- "nakedret"
- "prealloc"
- "scopelint"
- "unconvert"
- "unparam"
disable:

disable:
- "gochecknoinits"
- "gochecknoglobals"

Expand Down Expand Up @@ -93,67 +91,30 @@ linters-settings:
unparam:
check-exported: false
gocritic:
enabled-checks:
- appendCombine
- appendAssign
- assignOp
- argOrder
- badCond
enabled-checks: # non-default checks we decided to also add
- boolExprSimplify
- builtinShadow
- captLocal
- caseOrder
- codegenComment
- commentedOutCode
- commentedOutImport
- defaultCaseOrder
- deprecatedComment
- docStub
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- elseif
- emptyFallthrough
- equalFold
- flagDeref
- flagName
- hexLiteral
- indexAlloc
- initClause
- methodExprCall
- nilValReturn
- octalLiteral
- offBy1
- rangeExprCopy
- regexpMust
- singleCaseSwitch
- sloppyLen
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- typeUnparen
- underef
- unlambda
- unnecessaryBlock
- unslice
- valSwap
- weakCond
- yodaStyleExpr
- commentFormatting
- emptyStringTest
- exitAfterDefer
- ifElseChain
- hugeParam
- importShadow
- nestingReduce
- paramTypeCombine
- ptrToRefParam
- rangeValCopy
- sloppyReassign
- unlabelStmt
- wrapperFunc

# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint` run to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
Expand All @@ -180,7 +141,6 @@ issues:
- errcheck
- dupl
- gosec
- maligned

# Exclude lll issues for long lines with go:generate
- linters:
Expand Down
2 changes: 1 addition & 1 deletion pkg/binary/envoy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (r *Runtime) SaveConfig(name, config string) (string, error) {
return "", fmt.Errorf("Unable to create directory %q: %v", configDir, err)
}
filename := name + ".yaml"
err := ioutil.WriteFile(filepath.Join(configDir, filename), []byte(config), 0644)
err := ioutil.WriteFile(filepath.Join(configDir, filename), []byte(config), 0600)
if err != nil {
return "", fmt.Errorf("Cannot save config file %s: %s", filepath.Join(configDir, filename), err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/binary/envoy/controlplane/istio.tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func writeIstioTemplate(path string) error {
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
return err
}
return ioutil.WriteFile(path, []byte(istioBootStrapTemplate), 0644)
return ioutil.WriteFile(path, []byte(istioBootStrapTemplate), 0600)
}

var istioBootStrapTemplate = `{
Expand Down
1 change: 1 addition & 0 deletions pkg/binary/envoy/debug/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func retrieveAdminAPIData(r binary.Runner) error {
multiErr = multierror.Append(multiErr, fmt.Errorf("received %v from /%v ", resp.StatusCode, path))
continue
}
// #nosec -> r.DebugStore() is allowed to be anywhere
f, err := os.OpenFile(filepath.Join(r.DebugStore(), file), os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
multiErr = multierror.Append(multiErr, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/binary/envoy/debug/log_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func captureStderr(r binary.Runner) error {
}

func createLogFile(path string) (*os.File, error) {
// #nosec -> logs can be written anywhere
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return nil, fmt.Errorf("unable to open file to write logs to %v: %v", path, err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/binary/envoy/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func fetchEnvoy(dst, src string) error {
}

func doDownload(dst, src string) (string, error) {
// #nosec -> src destination can be anywhere by design
// #nosec -> src can be anywhere by design
resp, err := transport.Get(src)
if err != nil {
return "", err
Expand All @@ -124,6 +124,7 @@ func doDownload(dst, src string) (string, error) {
}

tarball := filepath.Join(dst, "envoy.tar"+filepath.Ext(src))
// #nosec -> dst can be anywhere by design
f, err := os.OpenFile(tarball, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/extension/run/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ Run 'getenvoy extension run --help' for usage.

By("creating a non-executable file")
filePath := filepath.Join(tempDir, "envoy")
err = ioutil.WriteFile(filePath, []byte(`#!/bin/sh`), 0644)
err = ioutil.WriteFile(filePath, []byte(`#!/bin/sh`), 0600)
Expect(err).NotTo(HaveOccurred())

By("running command")
Expand Down Expand Up @@ -616,7 +616,7 @@ Run 'getenvoy extension run --help' for usage.
Expect(os.RemoveAll(tempDir)).To(Succeed())
}()
wasmFile := filepath.Join(tempDir, "extension.wasm")
err = ioutil.WriteFile(wasmFile, []byte{}, 0644)
err = ioutil.WriteFile(wasmFile, []byte{}, 0600)
Expect(err).NotTo(HaveOccurred())

By("running command")
Expand Down Expand Up @@ -648,7 +648,7 @@ Run 'getenvoy extension run --help' for usage.
Expect(os.RemoveAll(tempDir)).To(Succeed())
}()
configFile := filepath.Join(tempDir, "config.json")
err = ioutil.WriteFile(configFile, []byte(`{"key2":"value2"}`), 0644)
err = ioutil.WriteFile(configFile, []byte(`{"key2":"value2"}`), 0600)
Expect(err).NotTo(HaveOccurred())

By("running command")
Expand Down
6 changes: 3 additions & 3 deletions pkg/extension/wasmimage/puller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func NewPuller(insecure, useHTTP bool) (*Puller, error) {

client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
// nolint:gosec this option is only enabled when the user specify the insecure flag.
InsecureSkipVerify: insecure,
// this option is only enabled when the user specify the insecure flag.
InsecureSkipVerify: insecure, // nolint:gosec
},
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func (p *Puller) Pull(imageRef, imagePath string) (ocispec.Descriptor, error) {
}
manifest, image, _ := store.Get(layers[0])

if err := ioutil.WriteFile(imagePath, image, 0755); err != nil {
if err := ioutil.WriteFile(imagePath, image, 0600); err != nil {
return manifest, fmt.Errorf("failed to write image: %w", err)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/extension/wasmimage/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func NewPusher(insecure, useHTTP bool) (*Pusher, error) {
if insecure {
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
// nolint:gosec this option is only enabled when the user specify the insecure flag.
InsecureSkipVerify: true,
// this option is only enabled when the user specify the insecure flag.
InsecureSkipVerify: true, // nolint:gosec
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (d *configDir) writeFile(fileName string, data []byte) error {
if err := osutil.EnsureDirExists(filepath.Dir(outputFile)); err != nil {
return err
}
if err := ioutil.WriteFile(outputFile, data, 0644); err != nil {
if err := ioutil.WriteFile(outputFile, data, 0600); err != nil {
return errors.Wrapf(err, "failed to write config file to %q", outputFile)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/extension/workspace/fs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (d workspaceDir) WriteFile(path string, data []byte) error {
if err := osutil.EnsureDirExists(filepath.Dir(path)); err != nil {
return err
}
return ioutil.WriteFile(path, data, 0644)
return ioutil.WriteFile(path, data, 0600)
}

func (d workspaceDir) HasDir(path string) (bool, error) {
Expand Down

0 comments on commit 2828b91

Please sign in to comment.