Skip to content

Commit 77a8d7d

Browse files
committed
Added audit logs for all file operations
1 parent 84e8f94 commit 77a8d7d

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

bucketio.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ type S3ObjectStat struct {
438438
}
439439

440440
func (sos *S3ObjectStat) ListAt(result []os.FileInfo, o int64) (int, error) {
441-
F(sos.Debug, "S3ObjectStat.: len(result)=%d offset=%d", len(result), o)
441+
F(sos.Debug, "S3ObjectStat.ListAt: len(result)=%d offset=%d", len(result), o)
442442
_o, err := castInt64ToInt(o)
443443
if err != nil {
444444
return 0, err
@@ -578,6 +578,7 @@ func (s3io *S3BucketIO) Fileread(req *sftp.Request) (io.ReaderAt, error) {
578578

579579
keyStr := key.String()
580580
ctx := combineContext(s3io.Ctx, req.Context())
581+
F(s3io.Log.Info, "Audit: User %s downloaded file \"%s\"", s3io.UserInfo.String(), keyStr)
581582
F(s3io.Log.Debug, "GetObject(Bucket=%s, Key=%s)", s3io.Bucket.Bucket, keyStr)
582583
sse := s3io.ServerSideEncryption
583584
goo, err := s3.GetObjectWithContext(
@@ -620,7 +621,7 @@ func (s3io *S3BucketIO) Filewrite(req *sftp.Request) (io.WriterAt, error) {
620621
Size: 0,
621622
LastModified: s3io.Now(),
622623
}
623-
F(s3io.Log.Info, "Upload file %s by user %s", key, s3io.UserInfo.User)
624+
F(s3io.Log.Info, "Audit: User %s uploaded file \"%s\"", s3io.UserInfo.String(), key)
624625
F(s3io.Log.Debug, "S3PutObjectWriter.New(key=%s)", key)
625626
oow := &S3PutObjectWriter{
626627
Ctx: combineContext(s3io.Ctx, req.Context()),
@@ -658,6 +659,7 @@ func (s3io *S3BucketIO) Filecmd(req *sftp.Request) error {
658659
destStr := dest.String()
659660
copySource := s3io.Bucket.Bucket + "/" + srcStr
660661
sse := s3io.ServerSideEncryption
662+
F(s3io.Log.Info, "Audit: User %s renamed \"%s\" to \"%s\"", s3io.UserInfo.String(), srcStr, destStr)
661663
F(s3io.Log.Debug, "CopyObject(Bucket=%s, Key=%s, CopySource=%s, Sse=%v)", s3io.Bucket.Bucket, destStr, copySource, sse.Type)
662664
_, err = s3io.Bucket.S3(sess).CopyObjectWithContext(
663665
combineContext(s3io.Ctx, req.Context()),
@@ -702,6 +704,7 @@ func (s3io *S3BucketIO) Filecmd(req *sftp.Request) error {
702704
return err
703705
}
704706
keyStr := key.String()
707+
F(s3io.Log.Info, "Audit: User %s deleted file \"%s\"", s3io.UserInfo.String(), key)
705708
F(s3io.Log.Debug, "DeleteObject(Bucket=%s, Key=%s)", s3io.Bucket.Bucket, key)
706709
_, err = s3io.Bucket.S3(sess).DeleteObjectWithContext(
707710
combineContext(s3io.Ctx, req.Context()),
@@ -728,6 +731,7 @@ func (s3io *S3BucketIO) Filelist(req *sftp.Request) (sftp.ListerAt, error) {
728731
if !s3io.Perms.Readable && !s3io.Perms.Listable {
729732
return nil, fmt.Errorf("stat operation not allowed as per configuration")
730733
}
734+
F(s3io.Log.Info, "Audit: User %s read path stats \"%s\"", s3io.UserInfo.String(), req.Filepath)
731735
key := buildKey(s3io.Bucket, req.Filepath)
732736
return &S3ObjectStat{
733737
DebugLogger: s3io.Log,
@@ -742,6 +746,7 @@ func (s3io *S3BucketIO) Filelist(req *sftp.Request) (sftp.ListerAt, error) {
742746
if !s3io.Perms.Listable {
743747
return nil, fmt.Errorf("listing operation not allowed as per configuration")
744748
}
749+
F(s3io.Log.Info, "Audit: User %s listed path \"%s\"", s3io.UserInfo.String(), req.Filepath)
745750
return &S3ObjectLister{
746751
DebugLogger: s3io.Log,
747752
Ctx: combineContext(s3io.Ctx, req.Context()),

user_info.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package main
22

3-
import "net"
3+
import (
4+
"fmt"
5+
"net"
6+
)
47

58
type UserInfo struct {
6-
Addr net.Addr
9+
Addr net.Addr
710
User string
811
}
12+
13+
func (uInfo UserInfo) String() string {
14+
return fmt.Sprintf("%s from %s", uInfo.User, uInfo.Addr.String())
15+
}

0 commit comments

Comments
 (0)