mirror of
https://github.com/paralus/paralus.git
synced 2026-08-24 15:47:19 +00:00
Adding audit points
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
commonv3 "github.com/paralus/paralus/proto/types/commonpb/v3"
|
||||
sentry "github.com/paralus/paralus/proto/types/sentry"
|
||||
|
||||
//"go.uber.org/zap"
|
||||
clientcmdapiv1 "k8s.io/client-go/tools/clientcmd/api/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
@@ -342,6 +343,7 @@ func GetConfigForUser(ctx context.Context, bs service.BootstrapService, aps serv
|
||||
message, groups)
|
||||
*/
|
||||
|
||||
//service.DownloadKubeconfigAuditEvent(ctx, zap.L(), username)
|
||||
return yaml.JSONToYAML(jb)
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ func (s *apiKeyService) Get(ctx context.Context, req *rpcv3.ApiKeyRequest) (*mod
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
GenerateApiKeyAuditEvent(ctx, s.al, AuditActionGenerate, req.Username)
|
||||
return &apikey, err
|
||||
}
|
||||
|
||||
@@ -114,5 +115,6 @@ func (s *apiKeyService) GetByKey(ctx context.Context, req *rpcv3.ApiKeyRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
GenerateApiKeyAuditEvent(ctx, s.al, AuditActionGenerate, req.Username)
|
||||
return &apikey, err
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
AuditActionCreate = "create"
|
||||
AuditActionDelete = "delete"
|
||||
AuditActionUpdate = "update"
|
||||
AuditActionCreate = "create"
|
||||
AuditActionDelete = "delete"
|
||||
AuditActionUpdate = "update"
|
||||
AuditActionGenerate = "generate"
|
||||
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 +391,57 @@ func CreateApiKeyAuditEvent(ctx context.Context, al *zap.Logger, action string,
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateApiKeyAuditEvent(ctx context.Context, al *zap.Logger, action string, id 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("ApiKey %sd for user %s", action, id),
|
||||
Meta: map[string]string{
|
||||
"apikey": id,
|
||||
},
|
||||
}
|
||||
if err := audit.CreateV1Event(al, sd, detail, fmt.Sprintf("apikey.%s.success", action), ""); err != nil {
|
||||
_log.Warn("unable to create audit event", err)
|
||||
}
|
||||
}
|
||||
|
||||
func DownloadKubeconfigAuditEvent(ctx context.Context, al *zap.Logger, 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("Kubeconfig Downloaded for user %s", user),
|
||||
}
|
||||
_log.Infow(fmt.Sprintf("Kubeconfig Downloaded for user %s", user))
|
||||
if err := audit.CreateV1Event(al, sd, detail, fmt.Sprintf("Kubeconfig Download success %s", user), ""); err != nil {
|
||||
_log.Warn("unable to create audit event", err)
|
||||
}
|
||||
_log.Infow("Audit event created")
|
||||
}
|
||||
|
||||
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 Downloaded for %s", user),
|
||||
}
|
||||
_log.Infow(fmt.Sprintf("CLI config Downloaded for %s", user))
|
||||
if err := audit.CreateV1Event(al, sd, detail, fmt.Sprintf("CLI Config.%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 {
|
||||
|
||||
@@ -954,6 +954,7 @@ func (s *userService) RetrieveCliConfig(ctx context.Context, req *userrpcv3.ApiK
|
||||
Partner: part.Name,
|
||||
}
|
||||
|
||||
DownloadCliConfigAuditEvent(ctx, s.al, AuditActionCreate, req.Username)
|
||||
return cliConfig, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user