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

Go sec fix #42

Merged
merged 1 commit into from
Feb 20, 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
20 changes: 16 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,24 @@
func Run(
ctx context.Context,
appName, appDescription, appUsage string,
sp retriever.PluginProvider) {

Check failure on line 54 in main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

// Check for the debug value.
if v, ok := csictx.LookupEnv(ctx, gocsi.EnvVarDebug); ok {
/* #nosec G104 */
if ok, _ := strconv.ParseBool(v); ok {
csictx.Setenv(ctx, gocsi.EnvVarLogLevel, "debug")
csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true")
csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true")
err := csictx.Setenv(ctx, gocsi.EnvVarLogLevel, "debug")
if err != nil {
log.Warnf("failed to set EnvVarLogLevel")
}
err = csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true")
if err != nil {
log.Warnf("failed to set EnvVarReqLogging")
}
err = csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true")
if err != nil {
log.Warnf("failed to set EnvVarRepLogging")
}
}
}

Expand Down Expand Up @@ -130,7 +139,10 @@
/* #nosec G104 */
if l.Addr().Network() == netUnix {
sockFile := l.Addr().String()
os.RemoveAll(sockFile)
err := os.RemoveAll(sockFile)
if err != nil {
log.Warnf("failed to remove sock file: %s", err)
}
log.WithField("path", sockFile).Info("removed sock file")
}
})
Expand Down
10 changes: 8 additions & 2 deletions retriever/go-metadata-retreiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// PluginProvider is able to serve a gRPC endpoint that provides
// the CSI services: Retriever
type PluginProvider interface {

Check failure on line 42 in retriever/go-metadata-retreiver.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
// Serve accepts incoming connections on the listener lis, creating
// a new ServerTransport and service goroutine for each. The service
// goroutine read gRPC requests and then call the registered handlers
Expand Down Expand Up @@ -173,7 +173,7 @@
// It cancels all active RPCs on the server side and the corresponding
// pending RPCs on the client side will get notified by connection
// errors.
func (sp *Plugin) Stop(ctx context.Context) {

Check warning on line 176 in retriever/go-metadata-retreiver.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
sp.stopOnce.Do(func() {
if sp.server != nil {
sp.server.Stop()
Expand All @@ -185,7 +185,7 @@
// GracefulStop stops the gRPC server gracefully. It stops the server
// from accepting new connections and RPCs and blocks until all the
// pending RPCs are finished.
func (sp *Plugin) GracefulStop(ctx context.Context) {

Check warning on line 188 in retriever/go-metadata-retreiver.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
sp.stopOnce.Do(func() {
if sp.server != nil {
sp.server.GracefulStop()
Expand All @@ -197,7 +197,7 @@
const netUnix = "unix"

func (sp *Plugin) initEndpointPerms(
ctx context.Context, lis net.Listener) error {

Check failure on line 200 in retriever/go-metadata-retreiver.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

if lis.Addr().Network() != netUnix {
return nil
Expand All @@ -220,7 +220,7 @@
"mode": m,
}).Info("chmod csi endpoint")

if err := os.Chmod(p, m); err != nil {

Check warning on line 223 in retriever/go-metadata-retreiver.go

View workflow job for this annotation

GitHub Actions / golangci-lint

if-return: redundant if ...; err != nil check, just return error instead. (revive)
return err
}

Expand All @@ -228,7 +228,7 @@
}

func (sp *Plugin) initEndpointOwner(
ctx context.Context, lis net.Listener) error {

Check failure on line 231 in retriever/go-metadata-retreiver.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

if lis.Addr().Network() != netUnix {
return nil
Expand Down Expand Up @@ -324,7 +324,7 @@
}

func (sp *Plugin) initEnvVars(ctx context.Context) {

Check failure on line 327 in retriever/go-metadata-retreiver.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
// Copy the environment variables from the public EnvVar
// string slice to the private envVars map for quick lookup.
sp.envVars = map[string]string{}
Expand Down Expand Up @@ -359,8 +359,14 @@
if v, ok := csictx.LookupEnv(ctx, gocsi.EnvVarDebug); ok {
/* #nosec G104 */
if ok, _ := strconv.ParseBool(v); ok {
csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true")
csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true")
err := csictx.Setenv(ctx, gocsi.EnvVarReqLogging, "true")
if err != nil {
log.Warnf("failed to set EnvVarReqLogging")
}
err = csictx.Setenv(ctx, gocsi.EnvVarRepLogging, "true")
if err != nil {
log.Warnf("failed to set EnvVarRepLogging")
}
}
}

Expand Down
Loading