Skip to content

Commit ad2bb02

Browse files
committed
add some audit logging statements parseable in cloudwatch
1 parent 50bdf06 commit ad2bb02

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async function init() {
7272
req.startTime = now();
7373
const hostname = req.hostname;
7474
const url = req.raw.url;
75-
req.log.info({ hostname, url }, "received request");
75+
req.log.info({ hostname, url, method: req.method }, "received request");
7676
done();
7777
});
7878

src/api/plugins/auth.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
222222
message: "Invalid token.",
223223
});
224224
}
225+
request.log.info(
226+
{ type: "audit", actor: request.username },
227+
"authenticated request",
228+
);
225229
return userRoles;
226230
},
227231
);

src/api/routes/events.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
134134
Item: marshall(entry),
135135
}),
136136
);
137-
137+
let verb = "created";
138+
if (userProvidedId && userProvidedId === entryUUID) {
139+
verb = "modified";
140+
}
138141
try {
139142
if (request.body.featured && !request.body.repeats) {
140143
await updateDiscord(entry, false, request.log);
@@ -157,18 +160,21 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
157160
}
158161

159162
if (e instanceof Error) {
160-
request.log.error(`Failed to publish event to Discord: ${e}`);
163+
request.log.error(`Failed to publish event to Discord: ${e} `);
161164
}
162165
if (e instanceof BaseError) {
163166
throw e;
164167
}
165168
throw new DiscordEventError({});
166169
}
167-
168170
reply.send({
169171
id: entryUUID,
170172
resource: `/api/v1/events/${entryUUID}`,
171173
});
174+
request.log.info(
175+
{ type: "audit", actor: request.username, target: entryUUID },
176+
`${verb} event "${entryUUID}"`,
177+
);
172178
} catch (e: unknown) {
173179
if (e instanceof Error) {
174180
request.log.error("Failed to insert to DynamoDB: " + e.toString());
@@ -254,6 +260,10 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
254260
message: "Failed to delete event from Dynamo table.",
255261
});
256262
}
263+
request.log.info(
264+
{ type: "audit", actor: request.username, target: id },
265+
`deleted event "${id}"`,
266+
);
257267
},
258268
);
259269
type EventsGetRequest = {
@@ -306,7 +316,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
306316
);
307317
} catch (e: unknown) {
308318
request.log.warn(
309-
`Could not compute upcoming event status for event ${item.title}: ${e instanceof Error ? e.toString() : e}`,
319+
`Could not compute upcoming event status for event ${item.title}: ${e instanceof Error ? e.toString() : e} `,
310320
);
311321
return false;
312322
}
@@ -322,7 +332,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
322332
if (e instanceof Error) {
323333
request.log.error("Failed to get from DynamoDB: " + e.toString());
324334
} else {
325-
request.log.error(`Failed to get from DynamoDB. ${e}`);
335+
request.log.error(`Failed to get from DynamoDB.${e} `);
326336
}
327337
throw new DatabaseFetchError({
328338
message: "Failed to get events from Dynamo table.",

src/api/routes/iam.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@ import {
1515
EntraInvitationError,
1616
InternalServerError,
1717
NotFoundError,
18-
ValidationError,
1918
} from "../../common/errors/index.js";
2019
import {
2120
DynamoDBClient,
2221
GetItemCommand,
2322
PutItemCommand,
2423
} from "@aws-sdk/client-dynamodb";
25-
import {
26-
execCouncilGroupId,
27-
execCouncilTestingGroupId,
28-
genericConfig,
29-
} from "../../common/config.js";
24+
import { genericConfig } from "../../common/config.js";
3025
import { marshall, unmarshall } from "@aws-sdk/util-dynamodb";
3126
import {
3227
InviteUserPostRequest,
@@ -143,6 +138,10 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
143138
});
144139
}
145140
reply.send({ message: "OK" });
141+
request.log.info(
142+
{ type: "audit", actor: request.username, target: groupId },
143+
`set group ID roles to ${request.body.roles.toString()}`,
144+
);
146145
},
147146
);
148147
fastify.post<{ Body: InviteUserPostRequest }>(
@@ -178,13 +177,26 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
178177
for (let i = 0; i < results.length; i++) {
179178
const result = results[i];
180179
if (result.status === "fulfilled") {
180+
request.log.info(
181+
{ type: "audit", actor: request.username, target: emails[i] },
182+
"invited user to Entra ID tenant.",
183+
);
181184
response.success.push({ email: emails[i] });
182185
} else {
186+
request.log.info(
187+
{ type: "audit", actor: request.username, target: emails[i] },
188+
"failed to invite user to Entra ID tenant.",
189+
);
183190
if (result.reason instanceof EntraInvitationError) {
184191
response.failure.push({
185192
email: emails[i],
186193
message: result.reason.message,
187194
});
195+
} else {
196+
response.failure.push({
197+
email: emails[i],
198+
message: "An unknown error occurred.",
199+
});
188200
}
189201
}
190202
}
@@ -254,7 +266,23 @@ const iamRoutes: FastifyPluginAsync = async (fastify, _options) => {
254266
const result = addResults[i];
255267
if (result.status === "fulfilled") {
256268
response.success.push({ email: request.body.add[i] });
269+
request.log.info(
270+
{
271+
type: "audit",
272+
actor: request.username,
273+
target: request.body.add[i],
274+
},
275+
`added target to group ID ${groupId}`,
276+
);
257277
} else {
278+
request.log.info(
279+
{
280+
type: "audit",
281+
actor: request.username,
282+
target: request.body.add[i],
283+
},
284+
`failed to add added target to group ID ${groupId}`,
285+
);
258286
if (result.reason instanceof EntraGroupError) {
259287
response.failure.push({
260288
email: request.body.add[i],

src/api/routes/tickets.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ const ticketsPlugin: FastifyPluginAsync = async (fastify, _options) => {
438438
}
439439
await dynamoClient.send(command);
440440
reply.send(response);
441+
request.log.info(
442+
{ type: "audit", actor: request.username, target: ticketId },
443+
`checked in ticket of type "${request.body.type}" ${request.body.type === "merch" ? `purchased by email ${request.body.email}.` : "."}`,
444+
);
441445
},
442446
);
443447
};

0 commit comments

Comments
 (0)