2024-06-18 09:38:39 +00:00
|
|
|
package audit
|
|
|
|
|
|
|
|
import (
|
2024-10-21 07:22:54 +00:00
|
|
|
"context"
|
|
|
|
|
2024-06-18 09:38:39 +00:00
|
|
|
crypto "git.frostfs.info/TrueCloudLab/frostfs-crypto"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
|
2024-06-18 09:38:39 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Request interface {
|
|
|
|
GetVerificationHeader() *session.RequestVerificationHeader
|
|
|
|
}
|
|
|
|
|
|
|
|
type Target interface {
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func LogRequest(ctx context.Context, log *logger.Logger, operation string, req Request, target Target, status bool) {
|
2024-07-19 08:23:02 +00:00
|
|
|
var key []byte
|
|
|
|
if req != nil {
|
|
|
|
key = req.GetVerificationHeader().GetBodySignature().GetKey()
|
|
|
|
}
|
2024-10-21 13:27:28 +00:00
|
|
|
LogRequestWithKey(ctx, log, operation, key, target, status)
|
2024-06-18 09:38:39 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
func LogRequestWithKey(ctx context.Context, log *logger.Logger, operation string, key []byte, target Target, status bool) {
|
2024-06-18 09:38:39 +00:00
|
|
|
object, subject := NotDefined, NotDefined
|
|
|
|
|
|
|
|
publicKey := crypto.UnmarshalPublicKey(key)
|
|
|
|
if publicKey != nil {
|
|
|
|
subject = ((*keys.PublicKey)(publicKey)).StringCompressed()
|
|
|
|
}
|
|
|
|
|
|
|
|
if target != nil {
|
|
|
|
object = target.String()
|
|
|
|
}
|
|
|
|
|
2024-10-21 13:27:28 +00:00
|
|
|
log.Info(ctx, logs.AuditEventLogRecord,
|
2024-06-18 09:38:39 +00:00
|
|
|
zap.String("operation", operation),
|
|
|
|
zap.String("object", object),
|
|
|
|
zap.String("subject", subject),
|
|
|
|
zap.Bool("success", status))
|
|
|
|
}
|