forked from TrueCloudLab/frostfs-node
[#1184] node: Add audit package
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
7b8937ec35
commit
ac1f014747
5 changed files with 208 additions and 1 deletions
41
internal/audit/request.go
Normal file
41
internal/audit/request.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
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) {
|
||||
LogRequestWithKey(log, operation, req.GetVerificationHeader().GetBodySignature().GetKey(), 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))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue