Skip to content

Commit be5e151

Browse files
authored
Add the Private Endpoint Validation Logic Meet the Tenant Metadata (#25460)
Add the Private Endpoint Validation Logic Meet the Tenant Metadata. The privateLinkEnable is true, if there is the connection details in custom data.
1 parent 1a0af94 commit be5e151

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

server/routerlicious/packages/lambdas/src/nexus/networkHelper.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,37 @@ export async function checkNetworkInformation(
1919
): Promise<{ message: string; shouldConnect: boolean }> {
2020
const tenantId = socket?.handshake?.query?.tenantId as string | undefined;
2121
const tenantInfo = await tenantManager.getTenantfromRiddler(tenantId);
22-
const privateLinkEnable = tenantInfo?.customData?.privateEndpoints?.accountLinkId
23-
? true
24-
: false;
22+
const privateLinkEnable =
23+
tenantInfo?.customData?.privateEndpoints &&
24+
Array.isArray(tenantInfo.customData.privateEndpoints) &&
25+
tenantInfo.customData.privateEndpoints?.length > 0 &&
26+
tenantInfo.customData.privateEndpoints[0]?.privateEndpointConnectionProxy?.properties
27+
?.remotePrivateEndpoint?.connectionDetails &&
28+
Array.isArray(
29+
tenantInfo.customData.privateEndpoints[0]?.privateEndpointConnectionProxy?.properties
30+
?.remotePrivateEndpoint?.connectionDetails,
31+
) &&
32+
tenantInfo.customData.privateEndpoints[0]?.privateEndpointConnectionProxy?.properties
33+
?.remotePrivateEndpoint?.connectionDetails[0]
34+
? true
35+
: false;
2536
const xForwardedFor: string | undefined = socket.handshake.headers["x-forwarded-for"] as
2637
| string
2738
| undefined;
2839
const clientIPAddress = xForwardedFor?.split(",")[0];
2940
if (privateLinkEnable && !clientIPAddress) {
3041
return {
31-
message: "Client IP address is required for private link in x-forwarded-for",
42+
message: "Client ip address is required for private link in x-forwarded-for",
3243
shouldConnect: false,
3344
};
3445
}
3546
const networkInfo = getNetworkInformationFromIP(clientIPAddress);
3647
if (networkInfo.isPrivateLink) {
3748
if (privateLinkEnable) {
38-
const accountLinkId = tenantInfo?.customData?.privateEndpoints?.accountLinkId;
49+
const connectionDetail =
50+
tenantInfo.customData.privateEndpoints[0]?.privateEndpointConnectionProxy
51+
?.properties?.remotePrivateEndpoint?.connectionDetails[0];
52+
const accountLinkId = connectionDetail?.linkIdentifier;
3953
return networkInfo.privateLinkId === accountLinkId
4054
? { message: "This is a private link socket connection", shouldConnect: true }
4155
: {

server/routerlicious/packages/routerlicious-base/src/alfred/routes/api/restHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function getDocumentUrlsfromNetworkInfo(
137137
externalHistorianUrl: string,
138138
externalDeltaStreamUrl: string,
139139
enablePrivateLinkNetworkCheck: boolean = false,
140-
isPrivateLink?: boolean | false,
140+
isPrivateLink: boolean = false,
141141
privateServiceHost?: string | undefined,
142142
): {
143143
documentOrdererUrl: string;

server/routerlicious/packages/services-shared/src/http.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,27 @@ export function validatePrivateLink(
5656
next();
5757
}
5858
const tenantInfo: ITenantConfig = await tenantManager.getTenantfromRiddler(tenantId);
59-
const privateLinkEnable = tenantInfo?.customData?.privateEndpoints?.accountLinkId
60-
? true
61-
: false;
59+
const privateLinkEnable =
60+
tenantInfo?.customData?.privateEndpoints &&
61+
Array.isArray(tenantInfo.customData.privateEndpoints) &&
62+
tenantInfo.customData.privateEndpoints?.length > 0 &&
63+
tenantInfo.customData.privateEndpoints[0]?.privateEndpointConnectionProxy
64+
?.properties?.remotePrivateEndpoint?.connectionDetails &&
65+
Array.isArray(
66+
tenantInfo.customData.privateEndpoints[0]?.privateEndpointConnectionProxy
67+
?.properties?.remotePrivateEndpoint?.connectionDetails,
68+
) &&
69+
tenantInfo.customData.privateEndpoints[0]?.privateEndpointConnectionProxy
70+
?.properties?.remotePrivateEndpoint?.connectionDetails[0]
71+
? true
72+
: false;
6273
const clientIPAddress = req.ip ?? "";
6374
if (privateLinkEnable && (!clientIPAddress || clientIPAddress.trim() === "")) {
6475
return handleResponse(
6576
Promise.reject(
6677
new NetworkError(
6778
400,
68-
`Client IP address is required for private link in req.ip`,
79+
`Client ip address is required for private link in req.ip`,
6980
),
7081
),
7182
res,
@@ -74,18 +85,20 @@ export function validatePrivateLink(
7485
const networkInfo = getNetworkInformationFromIP(clientIPAddress);
7586
if (networkInfo.isPrivateLink) {
7687
if (privateLinkEnable) {
77-
const accountLinkId = tenantInfo?.customData?.privateEndpoints?.accountLinkId;
88+
const connectionDetail =
89+
tenantInfo?.customData?.privateEndpoints[0]?.privateEndpointConnectionProxy
90+
?.properties?.remotePrivateEndpoint?.connectionDetails[0];
91+
const accountLinkId = connectionDetail?.linkIdentifier;
7892
if (networkInfo.privateLinkId === accountLinkId) {
79-
Lumberjack.info("This is a private link request", {
93+
Lumberjack.info(`This is a private link request with matching link id.`, {
8094
tenantId,
81-
privateLinkId: networkInfo.privateLinkId,
8295
});
8396
} else {
8497
return handleResponse(
8598
Promise.reject(
8699
new NetworkError(
87100
400,
88-
`This private link should not be connected since the link id ${networkInfo.privateLinkId} does not match ${accountLinkId}`,
101+
`This private link should not be connected since the link id mismatch`,
89102
),
90103
),
91104
res,

0 commit comments

Comments
 (0)