frostfs-node/internal/audit/request.go
Airat Arifullin e377a92d97
All checks were successful
DCO action / DCO (pull_request) Successful in 11m49s
Vulncheck / Vulncheck (pull_request) Successful in 12m48s
Build / Build Components (1.22) (pull_request) Successful in 14m58s
Build / Build Components (1.21) (pull_request) Successful in 15m34s
Tests and linters / gopls check (pull_request) Successful in 16m12s
Tests and linters / Lint (pull_request) Successful in 16m41s
Tests and linters / Staticcheck (pull_request) Successful in 16m35s
Tests and linters / Tests (1.21) (pull_request) Successful in 21m57s
Tests and linters / Tests (1.22) (pull_request) Successful in 21m55s
Tests and linters / Tests with -race (pull_request) Successful in 22m30s
Pre-commit hooks / Pre-commit (pull_request) Successful in 32m31s
[#1258] audit: Fix panic in LogRequest method
* Make `LogRequest` process `req=nil` to avoid panic.

Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
2024-07-19 11:27:33 +03:00

45 lines
1.2 KiB
Go

package audit
import (
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/session"
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"go.uber.org/zap"
)
type Request interface {
GetVerificationHeader() *session.RequestVerificationHeader
}
type Target interface {
String() string
}
func LogRequest(log *logger.Logger, operation string, req Request, target Target, status bool) {
var key []byte
if req != nil {
key = req.GetVerificationHeader().GetBodySignature().GetKey()
}
LogRequestWithKey(log, operation, key, target, status)
}
func LogRequestWithKey(log *logger.Logger, operation string, key []byte, target Target, status bool) {
object, subject := NotDefined, NotDefined
publicKey := crypto.UnmarshalPublicKey(key)
if publicKey != nil {
subject = ((*keys.PublicKey)(publicKey)).StringCompressed()
}
if target != nil {
object = target.String()
}
log.Info(logs.AuditEventLogRecord,
zap.String("operation", operation),
zap.String("object", object),
zap.String("subject", subject),
zap.Bool("success", status))
}