Skip to content

Commit 31ce822

Browse files
fix(ci): suppress gosec false positives and handle cleanup errors in lock acquisition paths
1 parent 9c57f3c commit 31ce822

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

pkg/covenantsigner/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ func Initialize(
148148
// operations observe shutdown and terminate promptly.
149149
cancelService()
150150

151+
// #nosec G118 -- context.Background is required here because ctx is
152+
// already cancelled at this point; using it would make Shutdown return
153+
// immediately with context.Canceled before the drain completes.
151154
shutdownCtx, cancelShutdown := context.WithTimeout(
152155
context.Background(),
153156
5*time.Second,

pkg/covenantsigner/service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ func NewService(
103103
// Release the file lock if any subsequent initialization step fails.
104104
defer func() {
105105
if retErr != nil {
106-
service.store.Close()
106+
if closeErr := service.store.Close(); closeErr != nil {
107+
logger.Warnf("failed to close store after init failure: [%v]", closeErr)
108+
}
107109
}
108110
}()
109111

pkg/covenantsigner/store.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func NewStore(handle persistence.BasicHandle, dataDir string) (*Store, error) {
4848

4949
if err := store.load(); err != nil {
5050
// Release the lock if loading fails after successful acquisition.
51-
store.Close()
51+
if closeErr := store.Close(); closeErr != nil {
52+
logger.Warnf("failed to release store lock after load failure: [%v]", closeErr)
53+
}
5254
return nil, err
5355
}
5456

@@ -75,6 +77,8 @@ func acquireFileLock(dataDir string) (*os.File, error) {
7577
)
7678
}
7779

80+
// #nosec G304 -- lockPath is derived from operator-configured dataDir, not
81+
// from untrusted user input. The operator controls the data directory.
7882
lockFile, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0600)
7983
if err != nil {
8084
return nil, fmt.Errorf(
@@ -88,7 +92,9 @@ func acquireFileLock(dataDir string) (*os.File, error) {
8892
int(lockFile.Fd()),
8993
syscall.LOCK_EX|syscall.LOCK_NB,
9094
); err != nil {
91-
lockFile.Close()
95+
if closeErr := lockFile.Close(); closeErr != nil {
96+
logger.Warnf("failed to close lock file after failed flock: [%v]", closeErr)
97+
}
9298
return nil, fmt.Errorf(
9399
"cannot acquire exclusive lock on [%s]: "+
94100
"another process may already own the store: %w",

0 commit comments

Comments
 (0)