diff --git a/CHANGELOG.md b/CHANGELOG.md index 56107af..31a835d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## Unreleased +## Added + +- Adding more audit points for better visibility from [vivekhiwarkar](https://github.com/vivekhiwarkar) + ## [0.1.2] - 2022-08-12 ## Fixed diff --git a/pkg/service/audit_utils.go b/pkg/service/audit_utils.go index 9db7faa..51556c8 100644 --- a/pkg/service/audit_utils.go +++ b/pkg/service/audit_utils.go @@ -16,9 +16,10 @@ import ( ) const ( - AuditActionCreate = "create" - AuditActionDelete = "delete" - AuditActionUpdate = "update" + AuditActionCreate = "create" + AuditActionDelete = "delete" + AuditActionUpdate = "update" + AuditActionDownload = "download" ) func CreateUserAuditEvent(ctx context.Context, al *zap.Logger, db bun.IDB, action string, name string, id uuid.UUID, rolesBefore, rolesAfter, groupsBefore, groupsAfter []uuid.UUID) { @@ -389,6 +390,24 @@ func CreateApiKeyAuditEvent(ctx context.Context, al *zap.Logger, action string, } } +func DownloadCliConfigAuditEvent(ctx context.Context, al *zap.Logger, action string, user string) { + sd, ok := GetSessionDataFromContext(ctx) + if !ok { + _log.Warn("unable to create audit event: could not fetch info from context") + return + } + + detail := &audit.EventDetail{ + Message: fmt.Sprintf("CLI config %sed for %s", action, user), + Meta: map[string]string{ + "username": user, + }, + } + if err := audit.CreateV1Event(al, sd, detail, fmt.Sprintf("cliconfig.%s.success", action), ""); err != nil { + _log.Warn("unable to create audit event", err) + } +} + func RevokeKubeconfigAuditEvent(ctx context.Context, al *zap.Logger, user string) { sd, ok := GetSessionDataFromContext(ctx) if !ok { diff --git a/pkg/service/user.go b/pkg/service/user.go index 5233222..0f653dc 100644 --- a/pkg/service/user.go +++ b/pkg/service/user.go @@ -941,6 +941,7 @@ func (s *userService) RetrieveCliConfig(ctx context.Context, req *userrpcv3.ApiK if err != nil { return nil, err } + CreateApiKeyAuditEvent(ctx, s.al, AuditActionCreate, req.Username) } cliConfig := &common.CliConfigDownloadData{ @@ -954,6 +955,7 @@ func (s *userService) RetrieveCliConfig(ctx context.Context, req *userrpcv3.ApiK Partner: part.Name, } + DownloadCliConfigAuditEvent(ctx, s.al, AuditActionDownload, req.Username) return cliConfig, nil }