Skip to content

Commit 72887e7

Browse files
authored
feat: audit logging (#155)
* chore: audit logging poc * chore: move audit to pkg * chore(resource): add audit logs in resource service * chore: include app version in app details audit log * chore(audit): use context to pass audit actor information * chore(policy): add audit logs in policy service * chore(provider): add audit logs in provider service * chore(apepal): add audit logs in appeal service * chore(approval): add audit logs in approval service * chore: make audit log trace id header key configurable * chore: remove unused helpers * chore: change AuditKeys from variable to const * chore: enhance logging * chore: fix typo on WithTraceIDExtractor function * chore: fix warning * fix: use audit log trace id header key from config * chore: use domain.SystemActorName constant for system's audit events * refactor: pass db instance directly * refactor: rename ServiceOptions to ServiceDeps * refactor(audit): inject audit actor from grpc interceptor * refactor: use grpc panic handler from grpc_recovery * refactor: use const for approval action type * chore: add todo reminder for empty trace ID * chore: use new context for FetchResources go routine * chore: add todo for job handler timeout context * chore: add metadata field, and move trace_id into metadata * chore: replace pkg/audit with github.com/odpf/salt/audit * chore: use uuid to replace empty trace id * chore: update salt/audit and use custom actor and metadata extractor * chore: move logrus auth user logging to auth middleware * refactor: move repository interface from store to each core packages
1 parent 4d3af59 commit 72887e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1582
-777
lines changed

.goreleaser.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ builds:
1616
flags:
1717
- -a
1818
ldflags:
19-
- -X github.com/odpf/guardian/cli.Version={{.Tag}}
20-
- -X github.com/odpf/guardian/cli.BuildCommit={{.FullCommit}}
21-
- -X github.com/odpf/guardian/cli.BuildDate={{.Date}}
19+
- -X github.com/odpf/guardian/core.Version={{.Tag}}
20+
- -X github.com/odpf/guardian/core.BuildCommit={{.FullCommit}}
21+
- -X github.com/odpf/guardian/core.BuildDate={{.Date}}
2222
goos: [darwin, linux, windows]
2323
goarch: [amd64, 386, arm, arm64]
2424
env:

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ all: build
1010

1111
build: ## Build the guardian binary
1212
@echo " > building guardian version ${APP_VERSION}"
13-
go build -ldflags "-X ${NAME}/cmd.Version=${APP_VERSION} -X ${NAME}/cmd.BuildCommit=${LAST_COMMIT}" -o guardian .
13+
go build -ldflags "-X ${NAME}/core.Version=${APP_VERSION} -X ${NAME}/core.BuildCommit=${LAST_COMMIT}" -o guardian .
1414
@echo " - build complete"
1515

1616
buildr: install ## Build with goreleaser
@@ -20,14 +20,17 @@ test: ## Run the tests
2020
go test ./... -race -coverprofile=coverage.out
2121

2222
coverage: ## Print code coverage
23-
go test -race -coverprofile coverage.txt -covermode=atomic ./... & go tool cover -html=coverage.out
23+
go test -race -coverprofile coverage.out -covermode=atomic ./... && go tool cover -html=coverage.out
2424

2525
vet: ## Run the go vet tool
2626
go vet ./...
2727

2828
lint: ## Lint with golangci-lint
2929
golangci-lint run
3030

31+
generate: ## Generate mocks
32+
go generate ./...
33+
3134
proto: ## Generate the protobuf files
3235
@echo " > generating protobuf from odpf/proton"
3336
@echo " > [info] make sure correct version of dependencies are installed using 'make install'"

api/handler/v1beta1/grpc.go

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

cli/job.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"context"
45
"fmt"
56

67
"github.com/MakeNowJust/heredoc"
@@ -84,7 +85,7 @@ func runJobCmd() *cobra.Command {
8485
notifier,
8586
)
8687

87-
jobs := map[string]func() error{
88+
jobs := map[string]func(context.Context) error{
8889
"fetch_resources": handler.FetchResources,
8990
"appeal_expiration_reminder": handler.AppealExpirationReminder,
9091
"appeal_expiration_revocation": handler.RevokeExpiredAppeals,
@@ -95,7 +96,7 @@ func runJobCmd() *cobra.Command {
9596
if job == nil {
9697
return fmt.Errorf("invalid job name: %s", jobName)
9798
}
98-
if err := job(); err != nil {
99+
if err := job(context.Background()); err != nil {
99100
return fmt.Errorf(`failed to run job "%s": %w`, jobName, err)
100101
}
101102

cli/version.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,12 @@ package cli
33
import (
44
"fmt"
55

6+
"github.com/odpf/guardian/core"
67
"github.com/odpf/salt/term"
78
"github.com/odpf/salt/version"
89
"github.com/spf13/cobra"
910
)
1011

11-
var (
12-
// Version is the version of the binary
13-
Version string
14-
// BuildCommit is the commit hash of the binary
15-
BuildCommit string
16-
// BuildDate is the date of the build
17-
BuildDate string
18-
)
19-
2012
// VersionCmd prints the version of the binary
2113
func VersionCmd() *cobra.Command {
2214
return &cobra.Command{
@@ -26,13 +18,13 @@ func VersionCmd() *cobra.Command {
2618
RunE: func(cmd *cobra.Command, args []string) error {
2719
cs := term.NewColorScheme()
2820

29-
if Version == "" {
21+
if core.Version == "" {
3022
fmt.Println(cs.Yellow("guardian version (built from source)"))
3123
return nil
3224
}
3325

34-
fmt.Printf("guardian version %s (%s)\n\n", Version, BuildDate)
35-
fmt.Println(cs.Yellow(version.UpdateNotice(Version, "odpf/guardian")))
26+
fmt.Printf("guardian version %s (%s)\n\n", core.Version, core.BuildDate)
27+
fmt.Println(cs.Yellow(version.UpdateNotice(core.Version, "odpf/guardian")))
3628
return nil
3729
},
3830
}

core/appeal/mocks/approvalService.go

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/appeal/mocks/auditLogger.go

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/appeal/mocks/iamManager.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/appeal/mocks/notifier.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/appeal/mocks/policyService.go

Lines changed: 17 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)