Skip to content

Commit

Permalink
fix: audit timestamp generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fredmaggiowski committed Jan 30, 2025
1 parent 02d87e5 commit 955c451
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
14 changes: 6 additions & 8 deletions internal/audit/agent_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestLogAgent(t *testing.T) {
ID: "some user",
Groups: []string{"g1", "g2"},
},
Request: RequestInfo{Body: []byte("some body")},
Request: RequestInfo{Body: []byte("some body")},
Timestamp: 123123123,
})

entries := hook.AllEntries()
Expand All @@ -59,9 +60,6 @@ func TestLogAgent(t *testing.T) {
require.NotEmpty(t, trailDataMap["id"])
delete(trailDataMap, "id")

require.NotNil(t, trailData.(map[string]interface{})["timestamp"])
delete(trailData.(map[string]interface{}), "timestamp")

require.Equal(t, map[string]any{
"aggregationId": "the-aggregation-id",
"authorization": map[string]any{
Expand All @@ -81,6 +79,7 @@ func TestLogAgent(t *testing.T) {
"groups": []string{"g1", "g2"},
"id": "some user",
},
"timestamp": int64(123123123),
}, trailData)
}

Expand Down Expand Up @@ -108,7 +107,8 @@ func TestLogAgentWithGlobalLabels(t *testing.T) {
ID: "some user",
Groups: []string{"g1", "g2"},
},
Request: RequestInfo{Body: []byte("some body")},
Request: RequestInfo{Body: []byte("some body")},
Timestamp: 543543543,
})

entries := hook.AllEntries()
Expand All @@ -123,9 +123,6 @@ func TestLogAgentWithGlobalLabels(t *testing.T) {
require.NotEmpty(t, trailDataMap["id"])
delete(trailDataMap, "id")

require.NotNil(t, trailData.(map[string]interface{})["timestamp"])
delete(trailData.(map[string]interface{}), "timestamp")

require.Equal(t, map[string]any{
"aggregationId": "the-aggregation-id",
"authorization": map[string]any{
Expand All @@ -147,5 +144,6 @@ func TestLogAgentWithGlobalLabels(t *testing.T) {
"groups": []string{"g1", "g2"},
"id": "some user",
},
"timestamp": int64(543543543),
}, trailData)
}
4 changes: 2 additions & 2 deletions internal/audit/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package audit

import (
"slices"
"time"

"github.com/google/uuid"
"github.com/rond-authz/rond/internal/utils"
Expand Down Expand Up @@ -46,6 +45,7 @@ type Audit struct {
Subject SubjectInfo
Request RequestInfo
Labels Labels
Timestamp int64
}

type AuthzInfo struct {
Expand Down Expand Up @@ -100,7 +100,7 @@ func (a *Audit) toPrint(data map[string]any) auditToPrint {
Subject: a.Subject,
Request: a.Request,
Labels: a.Labels,
Timestamp: time.Now().Unix(),
Timestamp: a.Timestamp,
}
if data != nil {
print.applyDataFromPolicy(data)
Expand Down
5 changes: 5 additions & 0 deletions sdk/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"errors"
"time"

"github.com/rond-authz/rond/core"
"github.com/rond-authz/rond/internal/audit"
Expand Down Expand Up @@ -124,6 +125,7 @@ func (e evaluator) EvaluateRequestPolicy(ctx context.Context, rondInput core.Inp
Path: rondInput.Request.Path,
UserAgent: rondInput.Request.Headers.Get(userAgentHeaderKey),
},
Timestamp: time.Now().Unix(),
}); err != nil {
logger.WithField("error", map[string]any{
"aggregationId": options.Audit.AggregationID,
Expand Down Expand Up @@ -160,6 +162,7 @@ func (e evaluator) EvaluateRequestPolicy(ctx context.Context, rondInput core.Inp
Path: rondInput.Request.Path,
UserAgent: rondInput.Request.Headers.Get(userAgentHeaderKey),
},
Timestamp: time.Now().Unix(),
}); err != nil {
logger.WithField("error", map[string]any{
"aggregationId": options.Audit.AggregationID,
Expand Down Expand Up @@ -213,6 +216,7 @@ func (e evaluator) EvaluateResponsePolicy(ctx context.Context, rondInput core.In
Path: rondInput.Request.Path,
UserAgent: rondInput.Request.Headers.Get(userAgentHeaderKey),
},
Timestamp: time.Now().Unix(),
}); err != nil {
logger.WithField("error", map[string]any{
"aggregationId": options.Audit.AggregationID,
Expand All @@ -237,6 +241,7 @@ func (e evaluator) EvaluateResponsePolicy(ctx context.Context, rondInput core.In
Path: rondInput.Request.Path,
UserAgent: rondInput.Request.Headers.Get(userAgentHeaderKey),
},
Timestamp: time.Now().Unix(),
}); err != nil {
logger.WithField("error", map[string]any{
"aggregationId": options.Audit.AggregationID,
Expand Down

0 comments on commit 955c451

Please sign in to comment.