Skip to content

Commit

Permalink
Merge pull request #269 from gocardless/PDFR-19964/auth-rule-field
Browse files Browse the repository at this point in the history
Consoles: include authorisation rule name
  • Loading branch information
ttamimi authored Nov 22, 2022
2 parents 039113f + fd9cc7f commit dc945ad
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
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

0 comments on commit dc945ad

Please sign in to comment.