Skip to content

Commit 1a42514

Browse files
added containerId if known
1 parent 45c1acf commit 1a42514

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

cmd/integration/make_backup/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ func TestInvalidDatabaseBackup(client pb.BackupServiceClient, opClient pb.Operat
5353
opID := types.GenerateObjectID()
5454
insertTBWRquery := fmt.Sprintf(
5555
`
56-
UPSERT INTO Operations
56+
UPSERT INTO Operations
5757
(id, type, container_id, database, endpoint, created_at, status, retries, retries_count)
58-
VALUES
58+
VALUES
5959
("%s", "TBWR", "%s", "%s", "%s", CurrentUTCTimestamp(), "RUNNING", 0, 3)
6060
`, opID, containerID, databaseName, invalidDatabaseEndpoint,
6161
)
@@ -342,7 +342,7 @@ func main() {
342342
Action: "ActionCreate",
343343
Component: "grpc_api",
344344
MethodName: pb.BackupService_MakeBackup_FullMethodName,
345-
ContainerID: "{none}",
345+
ContainerID: containerID,
346346
Subject: "anonymous@as",
347347
SanitizedToken: "",
348348
Status: "IN-PROCESS",

internal/audit/audit_event.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (e *Event) MarshalJSON() ([]byte, error) {
8282
Resource: e.Resource,
8383
Component: e.Component,
8484
MethodName: e.MethodName,
85-
ContainerID: e.ContainerID,
85+
ContainerID: formatContainerID(e.ContainerID),
8686
Subject: formatSubject(e.Subject),
8787
SanitizedToken: e.SanitizedToken,
8888
GRPCRequest: marshalProtoMessage(e.GRPCRequest),
@@ -129,6 +129,15 @@ func getStatus(inProgress bool, err error) (string, string) {
129129
return status, reason
130130
}
131131

132+
func formatContainerID(containerID string) string {
133+
switch containerID {
134+
case "", "{none}":
135+
return "{none}"
136+
default:
137+
return containerID
138+
}
139+
}
140+
132141
func formatSubject(subject string) string {
133142
switch subject {
134143
case "", "{none}":
@@ -168,10 +177,10 @@ func GRPCCallAuditEvent(
168177

169178
func ReportGRPCCallBegin(
170179
ctx context.Context, req proto.Message, methodName string,
171-
subject string, token string,
180+
subject string, token string, containerID string,
172181
) {
173182
event := GRPCCallAuditEvent(
174-
ctx, methodName, req, subject, token, "{none}", true, nil,
183+
ctx, methodName, req, subject, token, containerID, true, nil,
175184
)
176185
ReportAuditEvent(ctx, event)
177186
}

internal/audit/audit_interceptor.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ func NewAuditGRPCInterceptor(provider auth.AuthProvider) grpc.UnaryServerInterce
4040
ctx = grpcinfo.SetRequestID(ctx, requestID)
4141
subject, _ := authHelper.Authenticate(ctx, provider)
4242
token, _ := authHelper.GetMaskedToken(ctx, provider)
43+
containerID := ""
4344
pm, ok := req.(proto.Message)
4445
if !ok {
4546
xlog.Error(ctx, "got invalid proto.Message", zap.Any("GRPCRequest", req))
4647
} else {
47-
ReportGRPCCallBegin(
48-
ctx, pm, info.FullMethod, subject, token,
49-
)
48+
if getter, ok := req.(interface{ GetContainerId() string }); ok {
49+
containerID = getter.GetContainerId()
50+
}
51+
ReportGRPCCallBegin(ctx, pm, info.FullMethod, subject, token, containerID)
5052
}
5153
response, grpcErr := handler(ctx, req)
52-
containerID := GetContainerIDForRequest(requestID)
54+
containerID = GetContainerIDForRequest(requestID)
5355
defer ClearContainerIDForRequest(requestID)
5456
ReportGRPCCallEnd(ctx, info.FullMethod, subject, containerID, token, grpcErr)
5557
return response, grpcErr

0 commit comments

Comments
 (0)