Skip to content

Commit 942f429

Browse files
committed
fix imports
1 parent 8fc3b14 commit 942f429

File tree

3 files changed

+41
-63
lines changed

3 files changed

+41
-63
lines changed

src/api/functions/authorization.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
QueryCommand,
55
} from "@aws-sdk/client-dynamodb";
66
import { unmarshall } from "@aws-sdk/util-dynamodb";
7-
import { genericConfig } from "common/config.js";
8-
import { DatabaseFetchError } from "common/errors/index.js";
9-
import { allAppRoles, AppRoles } from "common/roles.js";
7+
import { genericConfig } from "../../common/config.js";
8+
import { DatabaseFetchError } from "../../common/errors/index.js";
9+
import { allAppRoles, AppRoles } from "../../common/roles.js";
1010
import { FastifyInstance } from "fastify";
1111

1212
export const AUTH_DECISION_CACHE_SECONDS = 60;

src/api/plugins/auth.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
UnauthorizedError,
1515
} from "../../common/errors/index.js";
1616
import { genericConfig, SecretConfig } from "../../common/config.js";
17-
import { getGroupRoles, getUserRoles } from "api/functions/authorization.js";
17+
import { getGroupRoles, getUserRoles } from "../functions/authorization.js";
1818
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
1919

2020
function intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> {
@@ -165,10 +165,7 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
165165
request.tokenPayload = verifiedTokenData;
166166
request.username = verifiedTokenData.email || verifiedTokenData.sub;
167167
const expectedRoles = new Set(validRoles);
168-
if (
169-
verifiedTokenData.groups &&
170-
fastify.environmentConfig.GroupRoleMapping
171-
) {
168+
if (verifiedTokenData.groups) {
172169
const groupRoles = await Promise.allSettled(
173170
verifiedTokenData.groups.map((x) =>
174171
getGroupRoles(dynamoClient, fastify, x),
@@ -201,23 +198,20 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
201198
}
202199

203200
// add user-specific role overrides
204-
if (request.username && fastify.environmentConfig.UserRoleMapping) {
205-
if (fastify.environmentConfig["UserRoleMapping"][request.username]) {
206-
try {
207-
const userAuth = await getUserRoles(
208-
dynamoClient,
209-
fastify,
210-
request.username,
211-
);
212-
for (const role of userAuth) {
213-
userRoles.add(role);
214-
}
215-
} catch (e) {
216-
request.log.warn(
217-
`Failed to get user role mapping for ${request.username}`,
218-
e,
219-
);
201+
if (request.username) {
202+
try {
203+
const userAuth = await getUserRoles(
204+
dynamoClient,
205+
fastify,
206+
request.username,
207+
);
208+
for (const role of userAuth) {
209+
userRoles.add(role);
220210
}
211+
} catch (e) {
212+
request.log.warn(
213+
`Failed to get user role mapping for ${request.username}: ${e}`,
214+
);
221215
}
222216
}
223217
if (
@@ -238,13 +232,13 @@ const authPlugin: FastifyPluginAsync = async (fastify, _options) => {
238232
});
239233
}
240234
if (err instanceof Error) {
241-
request.log.error(`Failed to verify JWT: ${err.toString()}`);
235+
request.log.error(`Failed to verify JWT: ${err.toString()} `);
242236
}
243237
throw new UnauthenticatedError({
244238
message: "Invalid token.",
245239
});
246240
}
247-
request.log.info(`authenticated request from ${request.username}`);
241+
request.log.info(`authenticated request from ${request.username} `);
248242
return userRoles;
249243
},
250244
);

src/common/config.ts

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ type ArrayOfValueOrArray<T> = Array<ValueOrArray<T>>;
66
type OriginType = string | boolean | RegExp;
77
type ValueOrArray<T> = T | ArrayOfValueOrArray<T>;
88

9-
type GroupRoleMapping = Record<string, readonly AppRoles[]>;
109
type AzureRoleMapping = Record<string, readonly AppRoles[]>;
11-
type UserRoleMapping = Record<string, readonly AppRoles[]>;
1210

1311
export type ConfigType = {
14-
GroupRoleMapping: GroupRoleMapping;
1512
AzureRoleMapping: AzureRoleMapping;
16-
UserRoleMapping: UserRoleMapping;
1713
ValidCorsOrigins: ValueOrArray<OriginType> | OriginFunction;
1814
AadValidClientId: string;
1915
};
@@ -60,18 +56,6 @@ const genericConfig: GenericConfigType = {
6056

6157
const environmentConfig: EnvironmentConfigType = {
6258
dev: {
63-
GroupRoleMapping: {
64-
[infraChairsGroupId]: allAppRoles, // Infra Chairs
65-
"940e4f9e-6891-4e28-9e29-148798495cdb": allAppRoles, // ACM Infra Team
66-
"f8dfc4cf-456b-4da3-9053-f7fdeda5d5d6": allAppRoles, // Infra Leads
67-
"0": allAppRoles, // Dummy Group for development only
68-
"1": [], // Dummy Group for development only
69-
"scanner-only": [AppRoles.TICKETS_SCANNER],
70-
},
71-
UserRoleMapping: {
72-
"[email protected]": [AppRoles.TICKETS_SCANNER],
73-
"kLkvWTYwNnJfBkIK7mBi4niXXHYNR7ygbV8utlvFxjw": allAppRoles
74-
},
7559
AzureRoleMapping: { AutonomousWriters: [AppRoles.EVENTS_MANAGER] },
7660
ValidCorsOrigins: [
7761
"http://localhost:3000",
@@ -84,27 +68,27 @@ const environmentConfig: EnvironmentConfigType = {
8468
AadValidClientId: "39c28870-94e4-47ee-b4fb-affe0bf96c9f",
8569
},
8670
prod: {
87-
GroupRoleMapping: {
88-
[infraChairsGroupId]: allAppRoles, // Infra Chairs
89-
[officersGroupId]: allAppRoles, // Officers
90-
[execCouncilGroupId]: [AppRoles.EVENTS_MANAGER, AppRoles.IAM_INVITE_ONLY], // Exec
91-
},
92-
UserRoleMapping: {
93-
"[email protected]": allAppRoles,
94-
"[email protected]": [AppRoles.TICKETS_SCANNER],
95-
"[email protected]": [AppRoles.TICKETS_SCANNER],
96-
"[email protected]": [AppRoles.TICKETS_SCANNER],
97-
"[email protected]": [AppRoles.TICKETS_SCANNER],
98-
99-
AppRoles.TICKETS_SCANNER,
100-
AppRoles.TICKETS_MANAGER,
101-
],
102-
103-
AppRoles.TICKETS_SCANNER,
104-
AppRoles.TICKETS_MANAGER,
105-
],
106-
"[email protected]": [AppRoles.TICKETS_MANAGER, AppRoles.TICKETS_SCANNER]
107-
},
71+
// GroupRoleMapping: {
72+
// [infraChairsGroupId]: allAppRoles, // Infra Chairs
73+
// [officersGroupId]: allAppRoles, // Officers
74+
// [execCouncilGroupId]: [AppRoles.EVENTS_MANAGER, AppRoles.IAM_INVITE_ONLY], // Exec
75+
// },
76+
// UserRoleMapping: {
77+
// "[email protected]": allAppRoles,
78+
// "[email protected]": [AppRoles.TICKETS_SCANNER],
79+
// "[email protected]": [AppRoles.TICKETS_SCANNER],
80+
// "[email protected]": [AppRoles.TICKETS_SCANNER],
81+
// "[email protected]": [AppRoles.TICKETS_SCANNER],
82+
83+
// AppRoles.TICKETS_SCANNER,
84+
// AppRoles.TICKETS_MANAGER,
85+
// ],
86+
87+
// AppRoles.TICKETS_SCANNER,
88+
// AppRoles.TICKETS_MANAGER,
89+
// ],
90+
// "[email protected]": [AppRoles.TICKETS_MANAGER, AppRoles.TICKETS_SCANNER]
91+
// },
10892
AzureRoleMapping: { AutonomousWriters: [AppRoles.EVENTS_MANAGER] },
10993
ValidCorsOrigins: [
11094
"https://acm.illinois.edu",

0 commit comments

Comments
 (0)