Skip to content

Commit

Permalink
rbac: display the audit log details
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Dec 13, 2023
1 parent ef17c0b commit 34b1d79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/ctl/rbac/cleanupuserpermissions/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/AliyunContainerService/ack-ram-tool/pkg/ctl/rbac/scanuserpermissions"
"github.com/AliyunContainerService/ack-ram-tool/pkg/log"
"github.com/briandowns/spinner"
"github.com/fatih/color"
"k8s.io/apimachinery/pkg/api/errors"
"time"

Expand Down Expand Up @@ -161,7 +162,9 @@ func cleanupOneCluster(ctx context.Context, bindings []binding.Binding,
if err != nil {
logger.Errorf("check cluster audit log failed: %s", err)
} else if resp.Active {
logger.Warnf("this user is active, and the last activity time was: %s", resp.LastActivity)
warn := color.RedString("this user has been active in the past 7 days, and the last activity time was: %s", resp.LastLocalActivity())
logger.Warnf("%s. You will find the relevant audit log details below:\nsls project: %s\nsls logstore: %s\nlast activity: %s (auditID: %s)",
warn, resp.LogProjectName, resp.LogStoreName, resp.LastLocalActivity(), resp.LastAuditId)
} else if !resp.Active {
logger.Info("no activity has been found in the cluster audit log for this user in the past 7 days")
}
Expand Down
15 changes: 12 additions & 3 deletions pkg/openapi/cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"strings"
"time"

Expand Down Expand Up @@ -271,9 +272,17 @@ func (c *Client) CleanClusterUserPermissions(ctx context.Context, clusterId stri
}

type UserClusterActivityState struct {
Active bool `json:"active,omitempty"`
LastActivity string `json:"last_activity,omitempty"`
LastAuditId string `json:"last_audit_id,omitempty"`
LogProjectName string `json:"log_project_name,omitempty"`
LogStoreName string `json:"log_store_name,omitempty"`
LogQueryExp string `json:"log_query_exp,omitempty"`

Active bool `json:"active"`
LastActivity *metav1.Time `json:"last_activity,omitempty"`
LastAuditId string `json:"last_audit_id,omitempty"`
}

func (s UserClusterActivityState) LastLocalActivity() string {
return s.LastActivity.Local().Format(time.RFC3339)
}

type describeUserClusterActivityState struct {
Expand Down

0 comments on commit 34b1d79

Please sign in to comment.