mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-03 19:21:11 +02:00
Handle backward compatability
This commit is contained in:
@@ -79,7 +79,10 @@ import logger from "@server/logger";
|
|||||||
import { decrypt } from "@server/lib/crypto";
|
import { decrypt } from "@server/lib/crypto";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import { exchangeSession } from "@server/routers/badger";
|
import { exchangeSession } from "@server/routers/badger";
|
||||||
import { validateResourceSessionToken } from "@server/auth/sessions/resource";
|
import {
|
||||||
|
ResourceSessionValidationResult,
|
||||||
|
validateResourceSessionToken
|
||||||
|
} from "@server/auth/sessions/resource";
|
||||||
import { checkExitNodeOrg, resolveExitNodes } from "#private/lib/exitNodes";
|
import { checkExitNodeOrg, resolveExitNodes } from "#private/lib/exitNodes";
|
||||||
import { maxmindLookup } from "@server/db/maxmind";
|
import { maxmindLookup } from "@server/db/maxmind";
|
||||||
import { verifyResourceAccessToken } from "@server/auth/verifyResourceAccessToken";
|
import { verifyResourceAccessToken } from "@server/auth/verifyResourceAccessToken";
|
||||||
@@ -1754,11 +1757,34 @@ hybridRouter.post(
|
|||||||
resourceId
|
resourceId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// this is for backward compatibility with nodes that did not have the policy id checking
|
||||||
|
const modifiedResult: ResourceSessionValidationResult = {
|
||||||
|
...result,
|
||||||
|
resourceSession: result.resourceSession
|
||||||
|
? {
|
||||||
|
...result.resourceSession,
|
||||||
|
// Prefer policy IDs, but keep legacy IDs populated for older nodes.
|
||||||
|
pincodeId:
|
||||||
|
result.resourceSession.policyPincodeId ??
|
||||||
|
result.resourceSession.pincodeId ??
|
||||||
|
null,
|
||||||
|
passwordId:
|
||||||
|
result.resourceSession.policyPasswordId ??
|
||||||
|
result.resourceSession.passwordId ??
|
||||||
|
null,
|
||||||
|
whitelistId:
|
||||||
|
result.resourceSession.policyWhitelistId ??
|
||||||
|
result.resourceSession.whitelistId ??
|
||||||
|
null
|
||||||
|
}
|
||||||
|
: null
|
||||||
|
};
|
||||||
|
|
||||||
return response(res, {
|
return response(res, {
|
||||||
data: result,
|
data: modifiedResult,
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
message: result.resourceSession
|
message: modifiedResult.resourceSession
|
||||||
? "Resource session token is valid"
|
? "Resource session token is valid"
|
||||||
: "Resource session token is invalid or expired",
|
: "Resource session token is invalid or expired",
|
||||||
status: HttpCode.OK
|
status: HttpCode.OK
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ import {
|
|||||||
ResourcePolicyPincode,
|
ResourcePolicyPincode,
|
||||||
ResourcePolicyPassword,
|
ResourcePolicyPassword,
|
||||||
ResourcePolicyHeaderAuth,
|
ResourcePolicyHeaderAuth,
|
||||||
ResourceRule
|
ResourceRule,
|
||||||
|
ResourceSession
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import { isIpInCidr, stripPortFromHost } from "@server/lib/ip";
|
import { isIpInCidr, stripPortFromHost } from "@server/lib/ip";
|
||||||
@@ -536,7 +537,8 @@ export async function verifyResourceSession(
|
|||||||
|
|
||||||
if (resourceSessionToken) {
|
if (resourceSessionToken) {
|
||||||
const sessionCacheKey = `session:${resourceSessionToken}`;
|
const sessionCacheKey = `session:${resourceSessionToken}`;
|
||||||
let resourceSession: any = localCache.get(sessionCacheKey);
|
let resourceSession: ResourceSession | null | undefined =
|
||||||
|
localCache.get(sessionCacheKey);
|
||||||
|
|
||||||
if (!resourceSession) {
|
if (!resourceSession) {
|
||||||
const result = await validateResourceSessionToken(
|
const result = await validateResourceSessionToken(
|
||||||
@@ -671,7 +673,7 @@ export async function verifyResourceSession(
|
|||||||
orgId: resource.orgId,
|
orgId: resource.orgId,
|
||||||
location: ipCC,
|
location: ipCC,
|
||||||
apiKey: {
|
apiKey: {
|
||||||
name: resourceSession.accessTokenTitle,
|
name: null,
|
||||||
apiKeyId: resourceSession.accessTokenId
|
apiKeyId: resourceSession.accessTokenId
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -717,7 +719,7 @@ export async function verifyResourceSession(
|
|||||||
location: ipCC,
|
location: ipCC,
|
||||||
user: {
|
user: {
|
||||||
username: allowedUserData.username,
|
username: allowedUserData.username,
|
||||||
userId: resourceSession.userId
|
userId: allowedUserData.userId
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parsedBody.data
|
parsedBody.data
|
||||||
|
|||||||
@@ -108,10 +108,7 @@ export default async function ClientResourcesPage(
|
|||||||
siteNiceId: siteResource.siteNiceIds[idx],
|
siteNiceId: siteResource.siteNiceIds[idx],
|
||||||
online: siteResource.siteOnlines[idx]
|
online: siteResource.siteOnlines[idx]
|
||||||
})),
|
})),
|
||||||
mode:
|
mode: siteResource.mode,
|
||||||
siteResource.pamMode && siteResource.mode === "host"
|
|
||||||
? "ssh"
|
|
||||||
: siteResource.mode,
|
|
||||||
scheme: siteResource.scheme,
|
scheme: siteResource.scheme,
|
||||||
ssl: siteResource.ssl,
|
ssl: siteResource.ssl,
|
||||||
siteNames: siteResource.siteNames,
|
siteNames: siteResource.siteNames,
|
||||||
|
|||||||
Reference in New Issue
Block a user