Skip to content
Open
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
6 changes: 3 additions & 3 deletions cmd/integration/make_backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func TestInvalidDatabaseBackup(client pb.BackupServiceClient, opClient pb.Operat
opID := types.GenerateObjectID()
insertTBWRquery := fmt.Sprintf(
`
UPSERT INTO Operations
UPSERT INTO Operations
(id, type, container_id, database, endpoint, created_at, status, retries, retries_count)
VALUES
VALUES
("%s", "TBWR", "%s", "%s", "%s", CurrentUTCTimestamp(), "RUNNING", 0, 3)
`, opID, containerID, databaseName, invalidDatabaseEndpoint,
)
Expand Down Expand Up @@ -342,7 +342,7 @@ func main() {
Action: "ActionCreate",
Component: "grpc_api",
MethodName: pb.BackupService_MakeBackup_FullMethodName,
ContainerID: "{none}",
ContainerID: containerID,
Subject: "anonymous@as",
SanitizedToken: "",
Status: "IN-PROCESS",
Expand Down
15 changes: 12 additions & 3 deletions internal/audit/audit_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (e *Event) MarshalJSON() ([]byte, error) {
Resource: e.Resource,
Component: e.Component,
MethodName: e.MethodName,
ContainerID: e.ContainerID,
ContainerID: formatContainerID(e.ContainerID),
Subject: formatSubject(e.Subject),
SanitizedToken: e.SanitizedToken,
GRPCRequest: marshalProtoMessage(e.GRPCRequest),
Expand Down Expand Up @@ -129,6 +129,15 @@ func getStatus(inProgress bool, err error) (string, string) {
return status, reason
}

func formatContainerID(containerID string) string {
switch containerID {
case "", "{none}":
return "{none}"
default:
return containerID
}
}

func formatSubject(subject string) string {
switch subject {
case "", "{none}":
Expand Down Expand Up @@ -168,10 +177,10 @@ func GRPCCallAuditEvent(

func ReportGRPCCallBegin(
ctx context.Context, req proto.Message, methodName string,
subject string, token string,
subject string, token string, containerID string,
) {
event := GRPCCallAuditEvent(
ctx, methodName, req, subject, token, "{none}", true, nil,
ctx, methodName, req, subject, token, containerID, true, nil,
)
ReportAuditEvent(ctx, event)
}
Expand Down
12 changes: 8 additions & 4 deletions internal/audit/audit_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ func NewAuditGRPCInterceptor(provider auth.AuthProvider) grpc.UnaryServerInterce
ctx = grpcinfo.SetRequestID(ctx, requestID)
subject, _ := authHelper.Authenticate(ctx, provider)
token, _ := authHelper.GetMaskedToken(ctx, provider)
containerID := ""

pm, ok := req.(proto.Message)
if !ok {
xlog.Error(ctx, "got invalid proto.Message", zap.Any("GRPCRequest", req))
} else {
ReportGRPCCallBegin(
ctx, pm, info.FullMethod, subject, token,
)
if reqCast, ok := req.(interface{ GetContainerId() string }); ok {
containerID = reqCast.GetContainerId()
}
ReportGRPCCallBegin(ctx, pm, info.FullMethod, subject, token, containerID)
}

response, grpcErr := handler(ctx, req)
containerID := GetContainerIDForRequest(requestID)
containerID = GetContainerIDForRequest(requestID)
defer ClearContainerIDForRequest(requestID)
ReportGRPCCallEnd(ctx, info.FullMethod, subject, containerID, token, grpcErr)
return response, grpcErr
Expand Down
Loading