Dmitrii Stepanov
f729d1a8c8
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 1m35s
DCO action / DCO (pull_request) Successful in 1m47s
Vulncheck / Vulncheck (pull_request) Successful in 2m18s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m40s
Build / Build Components (pull_request) Successful in 2m47s
Tests and linters / gopls check (pull_request) Successful in 3m6s
Tests and linters / Staticcheck (pull_request) Successful in 3m10s
Tests and linters / Lint (pull_request) Successful in 3m53s
Tests and linters / Tests (pull_request) Successful in 4m46s
Tests and linters / Tests with -race (pull_request) Successful in 6m3s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package audit
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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(ctx context.Context, log *logger.Logger, operation string, req Request, target Target, status bool) {
|
|
var key []byte
|
|
if req != nil {
|
|
key = req.GetVerificationHeader().GetBodySignature().GetKey()
|
|
}
|
|
LogRequestWithKey(ctx, log, operation, key, target, status)
|
|
}
|
|
|
|
func LogRequestWithKey(ctx context.Context, 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(ctx, logs.AuditEventLogRecord,
|
|
zap.String("operation", operation),
|
|
zap.String("object", object),
|
|
zap.String("subject", subject),
|
|
zap.Bool("success", status))
|
|
}
|