Improved Security Logging

This commit is contained in:
ZizzyDizzyMC 2021-02-09 22:36:14 -05:00
parent b8fdab8822
commit de6b3bc23f
4 changed files with 10 additions and 4 deletions

View File

@ -25,6 +25,7 @@ type MetadataJSON struct {
Mimetype string `json:"mimetype"` Mimetype string `json:"mimetype"`
Size int64 `json:"size"` Size int64 `json:"size"`
Expiry int64 `json:"expiry"` Expiry int64 `json:"expiry"`
SrcIp string `json:"srcip,omitempty"`
ArchiveFiles []string `json:"archive_files,omitempty"` ArchiveFiles []string `json:"archive_files,omitempty"`
} }
@ -106,6 +107,8 @@ func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) er
Sha256sum: metadata.Sha256sum, Sha256sum: metadata.Sha256sum,
Expiry: metadata.Expiry.Unix(), Expiry: metadata.Expiry.Unix(),
Size: metadata.Size, Size: metadata.Size,
SrcIp: metadata.SrcIp,
} }
dst, err := os.Create(metaPath) dst, err := os.Create(metaPath)
@ -124,7 +127,7 @@ func (b LocalfsBackend) writeMetadata(key string, metadata backends.Metadata) er
return nil return nil
} }
func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (m backends.Metadata, err error) { func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (m backends.Metadata, err error) {
filePath := path.Join(b.filesPath, key) filePath := path.Join(b.filesPath, key)
dst, err := os.Create(filePath) dst, err := os.Create(filePath)
@ -153,6 +156,7 @@ func (b LocalfsBackend) Put(key string, r io.Reader, expiry time.Time, deleteKey
m.Expiry = expiry m.Expiry = expiry
m.DeleteKey = deleteKey m.DeleteKey = deleteKey
m.AccessKey = accessKey m.AccessKey = accessKey
m.SrcIp = srcIp
m.ArchiveFiles, _ = helpers.ListArchiveFiles(m.Mimetype, m.Size, dst) m.ArchiveFiles, _ = helpers.ListArchiveFiles(m.Mimetype, m.Size, dst)
err = b.writeMetadata(key, m) err = b.writeMetadata(key, m)

View File

@ -12,6 +12,7 @@ type Metadata struct {
Mimetype string Mimetype string
Size int64 Size int64
Expiry time.Time Expiry time.Time
SrcIp string
ArchiveFiles []string ArchiveFiles []string
} }

View File

@ -12,7 +12,7 @@ type StorageBackend interface {
Exists(key string) (bool, error) Exists(key string) (bool, error)
Head(key string) (Metadata, error) Head(key string) (Metadata, error)
Get(key string) (Metadata, io.ReadCloser, error) Get(key string) (Metadata, io.ReadCloser, error)
Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string) (Metadata, error) Put(key string, r io.Reader, expiry time.Time, deleteKey, accessKey string, srcIp string) (Metadata, error)
PutMetadata(key string, m Metadata) error PutMetadata(key string, m Metadata) error
ServeFile(key string, w http.ResponseWriter, r *http.Request) error ServeFile(key string, w http.ResponseWriter, r *http.Request) error
Size(key string) (int64, error) Size(key string) (int64, error)

View File

@ -42,6 +42,7 @@ type UploadRequest struct {
deleteKey string // Empty string if not defined deleteKey string // Empty string if not defined
randomBarename bool randomBarename bool
accessKey string // Empty string if not defined accessKey string // Empty string if not defined
srcIp string // Empty string if not defined
} }
// Metadata associated with a file as it would actually be stored // Metadata associated with a file as it would actually be stored
@ -333,8 +334,8 @@ func processUpload(upReq UploadRequest) (upload Upload, err error) {
if upReq.deleteKey == "" { if upReq.deleteKey == "" {
upReq.deleteKey = uniuri.NewLen(30) upReq.deleteKey = uniuri.NewLen(30)
} }
var srcIp = r.Header.get("X-Forwarded-For")
upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey) upload.Metadata, err = storageBackend.Put(upload.Filename, io.MultiReader(bytes.NewReader(header), upReq.src), fileExpiry, upReq.deleteKey, upReq.accessKey, srcIp)
if err != nil { if err != nil {
return upload, err return upload, err
} }