Merge pull request #59 from vivekhiwarkar/add_audit_points

Adding audit points
This commit is contained in:
Abin Simon
2022-08-22 21:06:27 +05:30
committed by GitHub
3 changed files with 28 additions and 3 deletions
+4
View File
@@ -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
+22 -3
View File
@@ -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 {
+2
View File
@@ -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
}