mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-24 17:52:33 +00:00
Compare commits
7 Commits
888f5f8bb6
...
fb19e10cdc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fb19e10cdc | ||
|
|
2f1756ccf2 | ||
|
|
ce632a25cf | ||
|
|
79ba804c88 | ||
|
|
f4496bb23a | ||
|
|
c93766bb48 | ||
|
|
1065004fa3 |
@@ -1308,6 +1308,7 @@
|
|||||||
"setupErrorCreateAdmin": "An error occurred while creating the server admin account.",
|
"setupErrorCreateAdmin": "An error occurred while creating the server admin account.",
|
||||||
"certificateStatus": "Certificate Status",
|
"certificateStatus": "Certificate Status",
|
||||||
"loading": "Loading",
|
"loading": "Loading",
|
||||||
|
"loadingAnalytics": "Loading Analytics",
|
||||||
"restart": "Restart",
|
"restart": "Restart",
|
||||||
"domains": "Domains",
|
"domains": "Domains",
|
||||||
"domainsDescription": "Create and manage domains available in the organization",
|
"domainsDescription": "Create and manage domains available in the organization",
|
||||||
|
|||||||
@@ -307,7 +307,6 @@ async function cleanupOrphanedClients(
|
|||||||
await sendTerminateClient(
|
await sendTerminateClient(
|
||||||
deletedClient.clientId,
|
deletedClient.clientId,
|
||||||
OlmErrorCodes.TERMINATED_DELETED,
|
OlmErrorCodes.TERMINATED_DELETED,
|
||||||
"Deleted",
|
|
||||||
deletedClient.olmId
|
deletedClient.olmId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import { OpenAPITags, registry } from "@server/openApi";
|
|||||||
import { hashPassword } from "@server/auth/password";
|
import { hashPassword } from "@server/auth/password";
|
||||||
import { disconnectClient, sendToClient } from "#private/routers/ws";
|
import { disconnectClient, sendToClient } from "#private/routers/ws";
|
||||||
import { OlmErrorCodes, sendOlmError } from "@server/routers/olm/error";
|
import { OlmErrorCodes, sendOlmError } from "@server/routers/olm/error";
|
||||||
|
import { sendTerminateClient } from "@server/routers/client/terminate";
|
||||||
|
|
||||||
const reGenerateSecretParamsSchema = z.strictObject({
|
const reGenerateSecretParamsSchema = z.strictObject({
|
||||||
clientId: z.string().transform(Number).pipe(z.int().positive())
|
clientId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
@@ -118,15 +119,12 @@ export async function reGenerateClientSecret(
|
|||||||
|
|
||||||
// Only disconnect if explicitly requested
|
// Only disconnect if explicitly requested
|
||||||
if (disconnect) {
|
if (disconnect) {
|
||||||
const payload = {
|
|
||||||
type: `olm/terminate`,
|
|
||||||
data: {
|
|
||||||
code: OlmErrorCodes.TERMINATED_REKEYED,
|
|
||||||
message: "Client secret has been regenerated"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Don't await this to prevent blocking the response
|
// Don't await this to prevent blocking the response
|
||||||
sendToClient(existingOlms[0].olmId, payload).catch((error) => {
|
sendTerminateClient(
|
||||||
|
clientId,
|
||||||
|
OlmErrorCodes.TERMINATED_REKEYED,
|
||||||
|
existingOlms[0].olmId
|
||||||
|
).catch((error) => {
|
||||||
logger.error(
|
logger.error(
|
||||||
"Failed to send termination message to olm:",
|
"Failed to send termination message to olm:",
|
||||||
error
|
error
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export async function blockClient(
|
|||||||
|
|
||||||
// Send terminate signal if there's an associated OLM and it's connected
|
// Send terminate signal if there's an associated OLM and it's connected
|
||||||
if (client.olmId && client.online) {
|
if (client.olmId && client.online) {
|
||||||
await sendTerminateClient(client.clientId, OlmErrorCodes.TERMINATED_BLOCKED, "Blocked", client.olmId);
|
await sendTerminateClient(client.clientId, OlmErrorCodes.TERMINATED_BLOCKED, client.olmId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export async function deleteClient(
|
|||||||
await rebuildClientAssociationsFromClient(deletedClient, trx);
|
await rebuildClientAssociationsFromClient(deletedClient, trx);
|
||||||
|
|
||||||
if (olm) {
|
if (olm) {
|
||||||
await sendTerminateClient(deletedClient.clientId, OlmErrorCodes.TERMINATED_DELETED, "Deleted", olm.olmId); // the olmId needs to be provided because it cant look it up after deletion
|
await sendTerminateClient(deletedClient.clientId, OlmErrorCodes.TERMINATED_DELETED, olm.olmId); // the olmId needs to be provided because it cant look it up after deletion
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import { OlmErrorCodes } from "../olm/error";
|
|||||||
|
|
||||||
export async function sendTerminateClient(
|
export async function sendTerminateClient(
|
||||||
clientId: number,
|
clientId: number,
|
||||||
code: (typeof OlmErrorCodes)[keyof typeof OlmErrorCodes],
|
error: (typeof OlmErrorCodes)[keyof typeof OlmErrorCodes],
|
||||||
message: string,
|
|
||||||
olmId?: string | null
|
olmId?: string | null
|
||||||
) {
|
) {
|
||||||
if (!olmId) {
|
if (!olmId) {
|
||||||
@@ -24,8 +23,8 @@ export async function sendTerminateClient(
|
|||||||
await sendToClient(olmId, {
|
await sendToClient(olmId, {
|
||||||
type: `olm/terminate`,
|
type: `olm/terminate`,
|
||||||
data: {
|
data: {
|
||||||
code,
|
code: error.code,
|
||||||
message
|
message: error.message
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export async function archiveUserOlm(
|
|||||||
.where(eq(clients.clientId, client.clientId));
|
.where(eq(clients.clientId, client.clientId));
|
||||||
|
|
||||||
await rebuildClientAssociationsFromClient(client, trx);
|
await rebuildClientAssociationsFromClient(client, trx);
|
||||||
await sendTerminateClient(client.clientId, OlmErrorCodes.TERMINATED_ARCHIVED, "Archived", olmId);
|
await sendTerminateClient(client.clientId, OlmErrorCodes.TERMINATED_ARCHIVED, olmId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Archive the OLM (set archived to true)
|
// Archive the OLM (set archived to true)
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ export async function deleteUserOlm(
|
|||||||
await sendTerminateClient(
|
await sendTerminateClient(
|
||||||
deletedClient.clientId,
|
deletedClient.clientId,
|
||||||
OlmErrorCodes.TERMINATED_DELETED,
|
OlmErrorCodes.TERMINATED_DELETED,
|
||||||
"Deleted",
|
|
||||||
olm.olmId
|
olm.olmId
|
||||||
); // the olmId needs to be provided because it cant look it up after deletion
|
); // the olmId needs to be provided because it cant look it up after deletion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,104 @@
|
|||||||
import { sendToClient } from "#dynamic/routers/ws";
|
import { sendToClient } from "#dynamic/routers/ws";
|
||||||
// Error codes for registration failures
|
// Error codes for registration failures
|
||||||
export const OlmErrorCodes = {
|
export const OlmErrorCodes = {
|
||||||
OLM_NOT_FOUND: "OLM_NOT_FOUND",
|
OLM_NOT_FOUND: {
|
||||||
CLIENT_ID_NOT_FOUND: "CLIENT_ID_NOT_FOUND",
|
code: "OLM_NOT_FOUND",
|
||||||
CLIENT_NOT_FOUND: "CLIENT_NOT_FOUND",
|
message: "The specified device could not be found."
|
||||||
CLIENT_BLOCKED: "CLIENT_BLOCKED",
|
},
|
||||||
CLIENT_PENDING: "CLIENT_PENDING",
|
CLIENT_ID_NOT_FOUND: {
|
||||||
ORG_NOT_FOUND: "ORG_NOT_FOUND",
|
code: "CLIENT_ID_NOT_FOUND",
|
||||||
USER_ID_NOT_FOUND: "USER_ID_NOT_FOUND",
|
message: "No client ID was provided in the request."
|
||||||
INVALID_USER_SESSION: "INVALID_USER_SESSION",
|
},
|
||||||
USER_ID_MISMATCH: "USER_ID_MISMATCH",
|
CLIENT_NOT_FOUND: {
|
||||||
ACCESS_POLICY_DENIED: "ACCESS_POLICY_DENIED",
|
code: "CLIENT_NOT_FOUND",
|
||||||
TERMINATED_REKEYED: "TERMINATED_REKEYED",
|
message: "The specified client does not exist."
|
||||||
TERMINATED_ORG_DELETED: "TERMINATED_ORG_DELETED",
|
},
|
||||||
TERMINATED_INACTIVITY: "TERMINATED_INACTIVITY",
|
CLIENT_BLOCKED: {
|
||||||
TERMINATED_DELETED: "TERMINATED_DELETED",
|
code: "CLIENT_BLOCKED",
|
||||||
TERMINATED_ARCHIVED: "TERMINATED_ARCHIVED",
|
message:
|
||||||
TERMINATED_BLOCKED: "TERMINATED_BLOCKED"
|
"This client has been blocked in this organization and cannot connect. Please contact your administrator."
|
||||||
|
},
|
||||||
|
CLIENT_PENDING: {
|
||||||
|
code: "CLIENT_PENDING",
|
||||||
|
message:
|
||||||
|
"This client is pending approval and cannot connect yet. Please contact your administrator."
|
||||||
|
},
|
||||||
|
ORG_NOT_FOUND: {
|
||||||
|
code: "ORG_NOT_FOUND",
|
||||||
|
message:
|
||||||
|
"The organization could not be found. Please select a valid organization."
|
||||||
|
},
|
||||||
|
USER_ID_NOT_FOUND: {
|
||||||
|
code: "USER_ID_NOT_FOUND",
|
||||||
|
message: "No user ID was provided in the request."
|
||||||
|
},
|
||||||
|
INVALID_USER_SESSION: {
|
||||||
|
code: "INVALID_USER_SESSION",
|
||||||
|
message:
|
||||||
|
"Your user session is invalid or has expired. Please log in again."
|
||||||
|
},
|
||||||
|
USER_ID_MISMATCH: {
|
||||||
|
code: "USER_ID_MISMATCH",
|
||||||
|
message: "The provided user ID does not match the session."
|
||||||
|
},
|
||||||
|
ORG_ACCESS_POLICY_DENIED: {
|
||||||
|
code: "ORG_ACCESS_POLICY_DENIED",
|
||||||
|
message:
|
||||||
|
"Access to this organization has been denied by policy. Please contact your administrator."
|
||||||
|
},
|
||||||
|
ORG_ACCESS_POLICY_PASSWORD_EXPIRED: {
|
||||||
|
code: "ORG_ACCESS_POLICY_PASSWORD_EXPIRED",
|
||||||
|
message:
|
||||||
|
"Access to this organization has been denied because your password has expired. Please visit this organization's dashboard to update your password."
|
||||||
|
},
|
||||||
|
ORG_ACCESS_POLICY_SESSION_EXPIRED: {
|
||||||
|
code: "ORG_ACCESS_POLICY_SESSION_EXPIRED",
|
||||||
|
message:
|
||||||
|
"Access to this organization has been denied because your session has expired. Please log in again to refresh the session."
|
||||||
|
},
|
||||||
|
ORG_ACCESS_POLICY_2FA_REQUIRED: {
|
||||||
|
code: "ORG_ACCESS_POLICY_2FA_REQUIRED",
|
||||||
|
message:
|
||||||
|
"Access to this organization requires two-factor authentication. Please visit this organization's dashboard to enable two-factor authentication."
|
||||||
|
},
|
||||||
|
TERMINATED_REKEYED: {
|
||||||
|
code: "TERMINATED_REKEYED",
|
||||||
|
message:
|
||||||
|
"This session was terminated because encryption keys were regenerated."
|
||||||
|
},
|
||||||
|
TERMINATED_ORG_DELETED: {
|
||||||
|
code: "TERMINATED_ORG_DELETED",
|
||||||
|
message:
|
||||||
|
"This session was terminated because the organization was deleted."
|
||||||
|
},
|
||||||
|
TERMINATED_INACTIVITY: {
|
||||||
|
code: "TERMINATED_INACTIVITY",
|
||||||
|
message: "This session was terminated due to inactivity."
|
||||||
|
},
|
||||||
|
TERMINATED_DELETED: {
|
||||||
|
code: "TERMINATED_DELETED",
|
||||||
|
message: "This session was terminated because it was deleted."
|
||||||
|
},
|
||||||
|
TERMINATED_ARCHIVED: {
|
||||||
|
code: "TERMINATED_ARCHIVED",
|
||||||
|
message: "This session was terminated because it was archived."
|
||||||
|
},
|
||||||
|
TERMINATED_BLOCKED: {
|
||||||
|
code: "TERMINATED_BLOCKED",
|
||||||
|
message: "This session was terminated because access was blocked."
|
||||||
|
}
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
// Helper function to send registration error
|
// Helper function to send registration error
|
||||||
export async function sendOlmError(
|
export async function sendOlmError(
|
||||||
code: string,
|
error: (typeof OlmErrorCodes)[keyof typeof OlmErrorCodes],
|
||||||
errorMessage: string,
|
|
||||||
olmId: string
|
olmId: string
|
||||||
) {
|
) {
|
||||||
sendToClient(olmId, {
|
sendToClient(olmId, {
|
||||||
type: "olm/error",
|
type: "olm/error",
|
||||||
data: {
|
data: {
|
||||||
code,
|
code: error.code,
|
||||||
message: errorMessage
|
message: error.message
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ export const startOlmOfflineChecker = (): void => {
|
|||||||
await sendTerminateClient(
|
await sendTerminateClient(
|
||||||
offlineClient.clientId,
|
offlineClient.clientId,
|
||||||
OlmErrorCodes.TERMINATED_INACTIVITY,
|
OlmErrorCodes.TERMINATED_INACTIVITY,
|
||||||
"Client terminated due to inactivity",
|
|
||||||
offlineClient.olmId
|
offlineClient.olmId
|
||||||
); // terminate first
|
); // terminate first
|
||||||
// wait a moment to ensure the message is sent
|
// wait a moment to ensure the message is sent
|
||||||
|
|||||||
@@ -1,29 +1,16 @@
|
|||||||
import {
|
import { clientPostureSnapshots, db, fingerprints, orgs } from "@server/db";
|
||||||
Client,
|
|
||||||
clientPostureSnapshots,
|
|
||||||
clientSiteResourcesAssociationsCache,
|
|
||||||
db,
|
|
||||||
fingerprints,
|
|
||||||
orgs,
|
|
||||||
siteResources
|
|
||||||
} from "@server/db";
|
|
||||||
import { MessageHandler } from "@server/routers/ws";
|
import { MessageHandler } from "@server/routers/ws";
|
||||||
import {
|
import {
|
||||||
clients,
|
clients,
|
||||||
clientSitesAssociationsCache,
|
clientSitesAssociationsCache,
|
||||||
exitNodes,
|
|
||||||
Olm,
|
Olm,
|
||||||
olms,
|
olms,
|
||||||
sites
|
sites
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import { and, count, eq, inArray, isNull } from "drizzle-orm";
|
import { count, eq } from "drizzle-orm";
|
||||||
import { addPeer, deletePeer } from "../newt/peers";
|
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { generateAliasConfig } from "@server/lib/ip";
|
|
||||||
import { generateRemoteSubnets } from "@server/lib/ip";
|
|
||||||
import { checkOrgAccessPolicy } from "#dynamic/lib/checkOrgAccessPolicy";
|
import { checkOrgAccessPolicy } from "#dynamic/lib/checkOrgAccessPolicy";
|
||||||
import { validateSessionToken } from "@server/auth/sessions/app";
|
import { validateSessionToken } from "@server/auth/sessions/app";
|
||||||
import config from "@server/lib/config";
|
|
||||||
import { encodeHexLowerCase } from "@oslojs/encoding";
|
import { encodeHexLowerCase } from "@oslojs/encoding";
|
||||||
import { sha256 } from "@oslojs/crypto/sha2";
|
import { sha256 } from "@oslojs/crypto/sha2";
|
||||||
import { buildSiteConfigurationForOlmClient } from "./buildConfiguration";
|
import { buildSiteConfigurationForOlmClient } from "./buildConfiguration";
|
||||||
@@ -54,11 +41,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
|
|
||||||
if (!olm.clientId) {
|
if (!olm.clientId) {
|
||||||
logger.warn("Olm client ID not found");
|
logger.warn("Olm client ID not found");
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.CLIENT_ID_NOT_FOUND, olm.olmId);
|
||||||
OlmErrorCodes.CLIENT_ID_NOT_FOUND,
|
|
||||||
"Olm client ID not found",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,11 +53,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
logger.warn("Client ID not found");
|
logger.warn("Client ID not found");
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.CLIENT_NOT_FOUND, olm.olmId);
|
||||||
OlmErrorCodes.CLIENT_NOT_FOUND,
|
|
||||||
"Client not found in organization",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,11 +61,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
`Client ${client.clientId} is blocked. Ignoring register.`
|
`Client ${client.clientId} is blocked. Ignoring register.`
|
||||||
);
|
);
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.CLIENT_BLOCKED, olm.olmId);
|
||||||
OlmErrorCodes.CLIENT_BLOCKED,
|
|
||||||
"Client is blocked",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,11 +69,7 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
`Client ${client.clientId} approval is pending. Ignoring register.`
|
`Client ${client.clientId} approval is pending. Ignoring register.`
|
||||||
);
|
);
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.CLIENT_PENDING, olm.olmId);
|
||||||
OlmErrorCodes.CLIENT_PENDING,
|
|
||||||
"Client approval is pending",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,22 +81,14 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
|
|
||||||
if (!org) {
|
if (!org) {
|
||||||
logger.warn("Org not found");
|
logger.warn("Org not found");
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.ORG_NOT_FOUND, olm.olmId);
|
||||||
OlmErrorCodes.ORG_NOT_FOUND,
|
|
||||||
"Organization not found",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (orgId) {
|
if (orgId) {
|
||||||
if (!olm.userId) {
|
if (!olm.userId) {
|
||||||
logger.warn("Olm has no user ID");
|
logger.warn("Olm has no user ID");
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.USER_ID_NOT_FOUND, olm.olmId);
|
||||||
OlmErrorCodes.USER_ID_NOT_FOUND,
|
|
||||||
"User ID not found for this client",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,20 +96,12 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
await validateSessionToken(userToken);
|
await validateSessionToken(userToken);
|
||||||
if (!userSession || !user) {
|
if (!userSession || !user) {
|
||||||
logger.warn("Invalid user session for olm register");
|
logger.warn("Invalid user session for olm register");
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.INVALID_USER_SESSION, olm.olmId);
|
||||||
OlmErrorCodes.INVALID_USER_SESSION,
|
|
||||||
"Invalid or expired user session token",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (user.userId !== olm.userId) {
|
if (user.userId !== olm.userId) {
|
||||||
logger.warn("User ID mismatch for olm register");
|
logger.warn("User ID mismatch for olm register");
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.USER_ID_MISMATCH, olm.olmId);
|
||||||
OlmErrorCodes.USER_ID_MISMATCH,
|
|
||||||
"User ID does not match the authenticated session",
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,15 +115,46 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
sessionId // this is the user token passed in the message
|
sessionId // this is the user token passed in the message
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!policyCheck.allowed) {
|
if (policyCheck?.error) {
|
||||||
|
logger.error(
|
||||||
|
`Error checking access policies for olm user ${olm.userId} in org ${orgId}: ${policyCheck?.error}`
|
||||||
|
);
|
||||||
|
sendOlmError(OlmErrorCodes.ORG_ACCESS_POLICY_DENIED, olm.olmId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (policyCheck?.policies?.passwordAge?.compliant) {
|
||||||
|
logger.warn(
|
||||||
|
`Olm user ${olm.userId} has non-compliant password age for org ${orgId}`
|
||||||
|
);
|
||||||
|
sendOlmError(
|
||||||
|
OlmErrorCodes.ORG_ACCESS_POLICY_PASSWORD_EXPIRED,
|
||||||
|
olm.olmId
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else if (policyCheck?.policies?.maxSessionLength?.compliant) {
|
||||||
|
logger.warn(
|
||||||
|
`Olm user ${olm.userId} has non-compliant session length for org ${orgId}`
|
||||||
|
);
|
||||||
|
sendOlmError(
|
||||||
|
OlmErrorCodes.ORG_ACCESS_POLICY_SESSION_EXPIRED,
|
||||||
|
olm.olmId
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else if (policyCheck?.policies?.requiredTwoFactor) {
|
||||||
|
logger.warn(
|
||||||
|
`Olm user ${olm.userId} does not have 2FA enabled for org ${orgId}`
|
||||||
|
);
|
||||||
|
sendOlmError(
|
||||||
|
OlmErrorCodes.ORG_ACCESS_POLICY_2FA_REQUIRED,
|
||||||
|
olm.olmId
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
} else if (!policyCheck.allowed) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
`Olm user ${olm.userId} does not pass access policies for org ${orgId}: ${policyCheck.error}`
|
`Olm user ${olm.userId} does not pass access policies for org ${orgId}: ${policyCheck.error}`
|
||||||
);
|
);
|
||||||
sendOlmError(
|
sendOlmError(OlmErrorCodes.ORG_ACCESS_POLICY_DENIED, olm.olmId);
|
||||||
OlmErrorCodes.ACCESS_POLICY_DENIED,
|
|
||||||
`Access policy denied: ${policyCheck.error}`,
|
|
||||||
olm.olmId
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { sendToClient } from "#dynamic/routers/ws";
|
|||||||
import { deletePeer } from "../gerbil/peers";
|
import { deletePeer } from "../gerbil/peers";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
import { OlmErrorCodes } from "../olm/error";
|
import { OlmErrorCodes } from "../olm/error";
|
||||||
|
import { sendTerminateClient } from "../client/terminate";
|
||||||
|
|
||||||
const deleteOrgSchema = z.strictObject({
|
const deleteOrgSchema = z.strictObject({
|
||||||
orgId: z.string()
|
orgId: z.string()
|
||||||
@@ -207,13 +208,11 @@ export async function deleteOrg(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const olmId of olmsToTerminate) {
|
for (const olmId of olmsToTerminate) {
|
||||||
sendToClient(olmId, {
|
sendTerminateClient(
|
||||||
type: "olm/terminate",
|
0, // clientId not needed since we're passing olmId
|
||||||
data: {
|
OlmErrorCodes.TERMINATED_REKEYED,
|
||||||
code: OlmErrorCodes.TERMINATED_REKEYED,
|
olmId
|
||||||
message: "Organization has been deleted"
|
).catch((error) => {
|
||||||
}
|
|
||||||
}).catch((error) => {
|
|
||||||
logger.error(
|
logger.error(
|
||||||
"Failed to send termination message to olm:",
|
"Failed to send termination message to olm:",
|
||||||
error
|
error
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import {
|
|||||||
TooltipTrigger
|
TooltipTrigger
|
||||||
} from "./ui/tooltip";
|
} from "./ui/tooltip";
|
||||||
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
||||||
|
import type { QueryRequestAnalyticsResponse } from "@server/routers/auditLogs";
|
||||||
|
|
||||||
export type AnalyticsContentProps = {
|
export type AnalyticsContentProps = {
|
||||||
orgId: string;
|
orgId: string;
|
||||||
@@ -276,13 +277,32 @@ export function LogAnalyticsData(props: AnalyticsContentProps) {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card className="w-full h-full flex flex-col gap-8">
|
<Card className="w-full h-full flex flex-col gap-8 relative">
|
||||||
|
{isLoadingAnalytics && (
|
||||||
|
<div className="absolute z-20 left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 border border-border rounded-md bg-muted">
|
||||||
|
<div className="flex items-center gap-2 p-6">
|
||||||
|
<LoaderIcon className="size-4 animate-spin" />
|
||||||
|
{t("loadingAnalytics")}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<h3 className="font-semibold">{t("requestsByDay")}</h3>
|
<h3 className="font-semibold">{t("requestsByDay")}</h3>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent className="relative">
|
||||||
|
{isLoadingAnalytics && (
|
||||||
|
<div className="backdrop-blur-[2px] z-10 absolute inset-0"></div>
|
||||||
|
)}
|
||||||
<RequestChart
|
<RequestChart
|
||||||
data={stats?.requestsPerDay ?? []}
|
className={cn(
|
||||||
|
isLoadingAnalytics &&
|
||||||
|
"opacity-50 pointer-events-none"
|
||||||
|
)}
|
||||||
|
data={
|
||||||
|
stats?.requestsPerDay ??
|
||||||
|
generateSampleDailyRequests()
|
||||||
|
}
|
||||||
isLoading={isLoadingAnalytics}
|
isLoading={isLoadingAnalytics}
|
||||||
/>
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
@@ -323,6 +343,28 @@ export function LogAnalyticsData(props: AnalyticsContentProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function generateSampleDailyRequests(): QueryRequestAnalyticsResponse["requestsPerDay"] {
|
||||||
|
const today = new Date();
|
||||||
|
|
||||||
|
// generate sample data for the last 7 days
|
||||||
|
const requestsPerDay = Array.from({ length: 7 }, (_, i) => {
|
||||||
|
const date = new Date(today);
|
||||||
|
date.setDate(date.getDate() - (6 - i));
|
||||||
|
// generate a random number of requests between 1 and 100
|
||||||
|
const totalCount = Math.floor(Math.random() * 100) + 1;
|
||||||
|
// generate a random number of requests between 1 and totalCount
|
||||||
|
const blockedCount = Math.floor(Math.random() * (totalCount + 1));
|
||||||
|
return {
|
||||||
|
day: date.toISOString().split("T")[0],
|
||||||
|
allowedCount: totalCount - blockedCount,
|
||||||
|
blockedCount,
|
||||||
|
totalCount
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return requestsPerDay;
|
||||||
|
}
|
||||||
|
|
||||||
type RequestChartProps = {
|
type RequestChartProps = {
|
||||||
data: {
|
data: {
|
||||||
day: string;
|
day: string;
|
||||||
@@ -331,6 +373,7 @@ type RequestChartProps = {
|
|||||||
totalCount: number;
|
totalCount: number;
|
||||||
}[];
|
}[];
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function RequestChart(props: RequestChartProps) {
|
function RequestChart(props: RequestChartProps) {
|
||||||
@@ -359,7 +402,7 @@ function RequestChart(props: RequestChartProps) {
|
|||||||
return (
|
return (
|
||||||
<ChartContainer
|
<ChartContainer
|
||||||
config={chartConfig}
|
config={chartConfig}
|
||||||
className="min-h-[200px] w-full h-80"
|
className={cn("min-h-50 w-full h-80", props.className)}
|
||||||
>
|
>
|
||||||
<LineChart accessibilityLayer data={props.data}>
|
<LineChart accessibilityLayer data={props.data}>
|
||||||
<ChartLegend content={<ChartLegendContent />} />
|
<ChartLegend content={<ChartLegendContent />} />
|
||||||
@@ -467,7 +510,7 @@ function TopCountriesList(props: TopCountriesListProps) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{/* `aspect-475/335` is the same aspect ratio as the world map component */}
|
{/* `aspect-475/335` is the same aspect ratio as the world map component */}
|
||||||
<ol className="w-full overflow-auto grid gap-1 aspect-475/335">
|
<ol className="w-full overflow-auto gap-1 aspect-475/335 flex flex-col">
|
||||||
{props.countries.length === 0 && (
|
{props.countries.length === 0 && (
|
||||||
<div className="flex items-center justify-center size-full text-muted-foreground gap-1">
|
<div className="flex items-center justify-center size-full text-muted-foreground gap-1">
|
||||||
{props.isLoading ? (
|
{props.isLoading ? (
|
||||||
@@ -485,7 +528,7 @@ function TopCountriesList(props: TopCountriesListProps) {
|
|||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
key={country.code}
|
key={country.code}
|
||||||
className="grid grid-cols-7 rounded-xs hover:bg-muted relative items-center text-sm"
|
className="w-full grid grid-cols-7 rounded-xs hover:bg-muted relative items-center text-sm"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|||||||
Reference in New Issue
Block a user