-
Notifications
You must be signed in to change notification settings - Fork 8
feat: audit trail in stdout logs #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
8839bd1
feat: audit trail in stdout logs
fredmaggiowski 97bb1ed
optional auditing
fredmaggiowski ef76ca4
minor fixes + coverage
fredmaggiowski 074a75c
Update audit/agent_log_test.go
fredmaggiowski e221502
more tests
fredmaggiowski afe956a
fix
fredmaggiowski f9d4e2c
fix
fredmaggiowski 8f92bb4
refactor: renamed builtin, ensure context value and error in response…
fredmaggiowski 58c50bc
test: null logger
fredmaggiowski 6fe8c42
golang upgrade
fredmaggiowski 76bd7b8
dump tests
fredmaggiowski 498be87
Update service/opa_transport_test.go
fredmaggiowski f69eea8
chore: restore go mod
fredmaggiowski 25ff45d
test audit factory
fredmaggiowski 8e9c277
refactir: map[string]any
fredmaggiowski 17af74c
Apply suggestions from code review
fredmaggiowski 62d9a99
fix: copyright
fredmaggiowski 99a357b
refactor: move audit package to interanl
fredmaggiowski 6f85293
test: coverage for core custom builtins
fredmaggiowski 667ea71
refactor: append instead of for-loop
fredmaggiowski f63ab87
refactor: import
fredmaggiowski 9c1bdfd
test: unit agent log
fredmaggiowski 86e3dac
feat: trace policy failures as well
fredmaggiowski e2a143a
rem: enabled flag
fredmaggiowski 11d2717
rem: enabled flag
fredmaggiowski a75053e
fix: omitempty + refactor moved code
fredmaggiowski 031747e
add extra unit
fredmaggiowski 6d38186
more coverage
fredmaggiowski 5055223
fix: trace request verb and path
fredmaggiowski 96872ce
test case for requrst policy
fredmaggiowski 4a7f695
test case for requrst policy
fredmaggiowski 6f7d8e1
more test
fredmaggiowski 3bdbbef
more tests
fredmaggiowski 3e74554
refactor: constant fr audit tag
fredmaggiowski ceee236
fix: trace enabled for service
fredmaggiowski 93ecebb
Merge branch 'main' into feat/audit-trail-in-stdout-logs
fredmaggiowski 935cd76
target service name
fredmaggiowski eebc0e4
log service name + user agent
fredmaggiowski 5c92be6
refactor: use constant for user-agent
fredmaggiowski ef1c3bf
refactor: use constant for user-agent
fredmaggiowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2024 Mia srl | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package audit | ||
|
||
import "context" | ||
|
||
type Labels = map[string]any | ||
|
||
type Agent interface { | ||
Trace(context.Context, Audit) | ||
Cache() AuditCache | ||
SetGlobalLabels(labels Labels) | ||
} | ||
|
||
// noopAgent is a lazy agent that does nothing :( | ||
type noopAgent struct{} | ||
|
||
func NewNoopAgent() Agent { return &noopAgent{} } | ||
|
||
func (a *noopAgent) Trace(context.Context, Audit) {} | ||
func (a *noopAgent) Cache() AuditCache { return &SingleRecordCache{} } | ||
func (a *noopAgent) SetGlobalLabels(labels Labels) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2024 Mia srl | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package audit | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/rond-authz/rond/internal/utils" | ||
"github.com/rond-authz/rond/logging" | ||
) | ||
|
||
type logAgent struct { | ||
l logging.Logger | ||
cache AuditCache | ||
globals map[string]any | ||
} | ||
|
||
func NewLogAgent(l logging.Logger) Agent { | ||
return &logAgent{ | ||
l: l, | ||
cache: &SingleRecordCache{}, | ||
} | ||
} | ||
func (a *logAgent) SetGlobalLabels(labels Labels) { | ||
a.globals = labels | ||
} | ||
|
||
func (a *logAgent) Trace(_ context.Context, auditInput Audit) { | ||
data := a.cache.Load() | ||
|
||
auditData := auditInput.toPrint() | ||
if a.globals != nil { | ||
auditData.applyDataFromPolicy(a.globals) | ||
} | ||
|
||
if data != nil { | ||
auditData.applyDataFromPolicy(data) | ||
} | ||
|
||
a.l. | ||
WithField("trail", utils.ToMap(auditSerializerTagAnnotation, auditData)). | ||
Info("audit trail") | ||
} | ||
|
||
func (a *logAgent) Cache() AuditCache { | ||
return a.cache | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.