Skip to content

Audit build outcomes/kira pilot #5143

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

Merged
merged 10 commits into from
Nov 22, 2022
Merged

Conversation

Kira-Pilot
Copy link
Member

resolves #4724
Previously, all workspace_build audit logs showed 201 status codes - regardless of success or failure. This was because we were logging the initiation of the request - but not the outcome.

We are now logging the outcome (and have stopped logging the initiation for now). If a build fails, the audit log will reflect that failure (status code 500). If it is successful, the audit log will reflect that success (status code 200). The tradeoff is that there may be a delay in log generation as we have to wait for the build to finish. There are no diffs for workspace_build audit logs. I will add links to build logs in a fast follow to this PR so users can investigate failures.

Kapture 2022-11-21 at 12 07 42

@Kira-Pilot Kira-Pilot requested a review from a team as a code owner November 21, 2022 17:15
@Kira-Pilot Kira-Pilot requested review from presleyp and coadler and removed request for a team November 21, 2022 17:15
coderd/audit.go Outdated
Comment on lines 193 to 197
var agent string

if dblog.UserAgent.Valid {
agent = dblog.UserAgent.String
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be necessary. You can access dblog.UserAgent.String safely without checking if it's valid, it'll just be an empty string, so both outcomes are essentially the same.

@@ -967,6 +1035,19 @@ func convertWorkspaceTransition(transition database.WorkspaceTransition) (sdkpro
}
}

func determineAuditAction(transition database.WorkspaceTransition) database.AuditAction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think auditActionFromTransition would make this more clearer.

JobID: job.ID,
Action: auditAction,
New: workspaceBuild,
Status: 200,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Status: 200,
Status: http.StatusOK,


wriBytes, err := json.Marshal(workspaceResourceInfo)
if err != nil {
server.Logger.Error(ctx, "could not marshal workspace name", slog.Error(err))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
server.Logger.Error(ctx, "could not marshal workspace name", slog.Error(err))
server.Logger.Error(ctx, "marshal resource info", slog.Error(err))

@@ -596,11 +635,12 @@ func (server *Server) CompleteJob(ctx context.Context, completed *proto.Complete
return nil, xerrors.Errorf("get workspace build: %w", err)
}

workspace, getWorkspaceError := server.Database.GetWorkspaceByID(ctx, workspaceBuild.WorkspaceID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this GetWorkspaceByID needs to stay in the transaction, otherwise it's unsafe to update it. You could make it assign to a variable outside of the function to access the info!

Copy link
Contributor

@presleyp presleyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frontend ✅

@Kira-Pilot Kira-Pilot merged commit 6786ca2 into main Nov 22, 2022
@Kira-Pilot Kira-Pilot deleted the audit-build-outcomes/kira-pilot branch November 22, 2022 18:22
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

audit: resource creation failure should result in an audit log entry
3 participants