mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add workspace agent connect and app open audit types (#16493)
This commit adds new audit resource types for workspace agents and workspace apps, as well as connect/disconnect and open/close actions. The idea is that we will log new audit events for connecting to the agent via SSH/editor. Likewise, we will log openings of `coder_app`s. This change also introduces support for filtering by `request_id`. Updates #15139
This commit is contained in:
@@ -19,6 +19,20 @@ import (
|
||||
|
||||
// AuditLogs requires the database to fetch an organization by name
|
||||
// to convert to organization uuid.
|
||||
//
|
||||
// Supported query parameters:
|
||||
//
|
||||
// - request_id: UUID (can be used to search for associated audits e.g. connect/disconnect or open/close)
|
||||
// - resource_id: UUID
|
||||
// - resource_target: string
|
||||
// - username: string
|
||||
// - email: string
|
||||
// - date_from: string (date in format "2006-01-02")
|
||||
// - date_to: string (date in format "2006-01-02")
|
||||
// - organization: string (organization UUID or name)
|
||||
// - resource_type: string (enum)
|
||||
// - action: string (enum)
|
||||
// - build_reason: string (enum)
|
||||
func AuditLogs(ctx context.Context, db database.Store, query string) (database.GetAuditLogsOffsetParams, []codersdk.ValidationError) {
|
||||
// Always lowercase for all searches.
|
||||
query = strings.ToLower(query)
|
||||
@@ -33,6 +47,7 @@ func AuditLogs(ctx context.Context, db database.Store, query string) (database.G
|
||||
const dateLayout = "2006-01-02"
|
||||
parser := httpapi.NewQueryParamParser()
|
||||
filter := database.GetAuditLogsOffsetParams{
|
||||
RequestID: parser.UUID(values, uuid.Nil, "request_id"),
|
||||
ResourceID: parser.UUID(values, uuid.Nil, "resource_id"),
|
||||
ResourceTarget: parser.String(values, "", "resource_target"),
|
||||
Username: parser.String(values, "", "username"),
|
||||
|
||||
@@ -344,6 +344,11 @@ func TestSearchAudit(t *testing.T) {
|
||||
ResourceTarget: "foo",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "RequestID",
|
||||
Query: "request_id:foo",
|
||||
ExpectedErrorContains: "valid uuid",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range testCases {
|
||||
|
||||
Reference in New Issue
Block a user