Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consoles: include authorisation rule name #269

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.0
3.10.0
3 changes: 3 additions & 0 deletions apis/workloads/v1alpha1/lifecycle_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ func (l *lifecycleEventRecorderImpl) makeConsoleCommonEvent(eventKind events.Eve

func (l *lifecycleEventRecorderImpl) ConsoleRequest(ctx context.Context, csl *Console, authRule *ConsoleAuthorisationRule) error {
authCount := 0
authRuleName := ""
if authRule != nil {
authCount = authRule.AuthorisationsRequired
authRuleName = authRule.Name
}

event := &events.ConsoleRequestEvent{
Expand All @@ -120,6 +122,7 @@ func (l *lifecycleEventRecorderImpl) ConsoleRequest(ctx context.Context, csl *Co
ConsoleTemplate: csl.Spec.ConsoleTemplateRef.Name,
Console: csl.Name,
RequiredAuthorisations: authCount,
AuthorisationRuleName: authRuleName,
Timestamp: csl.CreationTimestamp.Time,
Labels: csl.Labels,
},
Expand Down
7 changes: 4 additions & 3 deletions controllers/workloads/console/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ type consoleStatusContext struct {
}

func (r *ConsoleReconciler) generateStatusAndAuditEvents(ctx context.Context, logger logr.Logger, csl *workloadsv1alpha1.Console, statusCtx consoleStatusContext) (*workloadsv1alpha1.Console, error) {
logger = getAuditLogger(logger, csl, statusCtx)
logger = getAuditLogger(logger, r.ConsoleIdBuilder.BuildId(csl), csl, statusCtx)
newStatus := calculateStatus(csl, statusCtx)

if csl.Creating() && newStatus.Phase == workloadsv1alpha1.ConsolePendingAuthorisation {
Expand Down Expand Up @@ -1189,7 +1189,7 @@ func jobDiff(expectedObj runtime.Object, existingObj runtime.Object) recutil.Out
}

// getAuditLogger provides a decorated logger for audit purposes
func getAuditLogger(logger logr.Logger, c *workloadsv1alpha1.Console, statusCtx consoleStatusContext) logr.Logger {
func getAuditLogger(logger logr.Logger, consoleId string, c *workloadsv1alpha1.Console, statusCtx consoleStatusContext) logr.Logger {
loggerCtx := logging.WithNoRecord(logger)
// Append any label-based keys before doing anything else.
// This ensures that if there's duplicate keys (e.g. a `name` label on the
Expand All @@ -1205,7 +1205,8 @@ func getAuditLogger(logger logr.Logger, c *workloadsv1alpha1.Console, statusCtx
"kind", Console,
"console_name", c.Name,
"console_user", c.Spec.User,

"console_event_id", consoleId,
"request_time", c.CreationTimestamp.Time,
"console_requires_authorisation", requiresAuth,
// Note that a console that does not require authorisation is considered
// authorised by default.
Expand Down
1 change: 1 addition & 0 deletions controllers/workloads/console/integration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ var _ = BeforeSuite(func(done Done) {
LifecycleRecorder: lifecycleRecorder,
Log: ctrl.Log.WithName("controllers").WithName("console"),
Scheme: mgr.GetScheme(),
ConsoleIdBuilder: workloadsv1alpha1.NewConsoleIdBuilder("test"),
}).SetupWithManager(context.TODO(), mgr)
Expect(err).ToNot(HaveOccurred())

Expand Down
1 change: 1 addition & 0 deletions pkg/workloads/console/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ConsoleRequestSpec struct {
ConsoleTemplate string `json:"console_template"`
Console string `json:"console"`
RequiredAuthorisations int `json:"required_authorisations"`
AuthorisationRuleName string `json:"authorisation_rule_name"`
Timestamp time.Time `json:"timestamp"`
Labels map[string]string `json:"labels"`
}
Expand Down