mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-13 16:00:02 +02:00
Allow remote header overrides and fix display issues with log
This commit is contained in:
@@ -111,6 +111,20 @@ export const configSchema = z
|
||||
})
|
||||
.optional()
|
||||
.prefault({}),
|
||||
remote_headers: z
|
||||
.object({
|
||||
user_id: z.string().optional().default("Remote-User-Id"),
|
||||
virtual_api_key_id: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("Remote-Virtual-Api-Key-Id"),
|
||||
user: z.string().optional().default("Remote-User"),
|
||||
email: z.string().optional().default("Remote-Email"),
|
||||
name: z.string().optional().default("Remote-Name"),
|
||||
role: z.string().optional().default("Remote-Role")
|
||||
})
|
||||
.optional()
|
||||
.prefault({}),
|
||||
resource_session_request_param: z
|
||||
.string()
|
||||
.optional()
|
||||
@@ -154,6 +168,14 @@ export const configSchema = z
|
||||
id: "P-Access-Token-Id",
|
||||
token: "P-Access-Token"
|
||||
},
|
||||
remote_headers: {
|
||||
user_id: "Remote-User-Id",
|
||||
virtual_api_key_id: "Remote-Virtual-Api-Key-Id",
|
||||
user: "Remote-User",
|
||||
email: "Remote-Email",
|
||||
name: "Remote-Name",
|
||||
role: "Remote-Role"
|
||||
},
|
||||
resource_session_request_param:
|
||||
"resource_session_request_param",
|
||||
dashboard_session_length_hours: 720,
|
||||
|
||||
@@ -605,7 +605,31 @@ export class TraefikConfigManager {
|
||||
|
||||
resourceSessionRequestParam:
|
||||
config.getRawConfig().server
|
||||
.resource_session_request_param
|
||||
.resource_session_request_param,
|
||||
|
||||
remoteUserIdHeader:
|
||||
config.getRawConfig().server.remote_headers
|
||||
.user_id,
|
||||
|
||||
remoteVirtualApiKeyIdHeader:
|
||||
config.getRawConfig().server.remote_headers
|
||||
.virtual_api_key_id,
|
||||
|
||||
remoteUserHeader:
|
||||
config.getRawConfig().server.remote_headers
|
||||
.user,
|
||||
|
||||
remoteEmailHeader:
|
||||
config.getRawConfig().server.remote_headers
|
||||
.email,
|
||||
|
||||
remoteNameHeader:
|
||||
config.getRawConfig().server.remote_headers
|
||||
.name,
|
||||
|
||||
remoteRoleHeader:
|
||||
config.getRawConfig().server.remote_headers
|
||||
.role
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
import {
|
||||
db,
|
||||
resources,
|
||||
User,
|
||||
virtualApiKeyResources,
|
||||
virtualApiKeys,
|
||||
type Transaction,
|
||||
@@ -148,12 +149,12 @@ async function selectUserVirtualApiKey(
|
||||
|
||||
export async function getOrCreateUserVirtualApiKey(params: {
|
||||
orgId: string;
|
||||
userId: string;
|
||||
user: User;
|
||||
createdByUserId?: string | null;
|
||||
}): Promise<{ key: VirtualApiKey; secret: string }> {
|
||||
const { orgId, userId, createdByUserId } = params;
|
||||
const { orgId, user, createdByUserId } = params;
|
||||
|
||||
const existing = await selectUserVirtualApiKey(orgId, userId);
|
||||
const existing = await selectUserVirtualApiKey(orgId, user.userId);
|
||||
if (existing) {
|
||||
return {
|
||||
key: existing,
|
||||
@@ -171,8 +172,8 @@ export async function getOrCreateUserVirtualApiKey(params: {
|
||||
virtualApiKeyId: minted.virtualApiKeyId,
|
||||
orgId,
|
||||
kind: "user",
|
||||
userId,
|
||||
name: null,
|
||||
userId: user.userId,
|
||||
name: `${user.name ?? user.username}'s API Key`,
|
||||
description: null,
|
||||
token: encryptVirtualApiKeyToken(minted.secret),
|
||||
lastChars: minted.lastChars,
|
||||
@@ -186,7 +187,7 @@ export async function getOrCreateUserVirtualApiKey(params: {
|
||||
|
||||
return { key: created, secret: minted.secret };
|
||||
} catch {
|
||||
const raced = await selectUserVirtualApiKey(orgId, userId);
|
||||
const raced = await selectUserVirtualApiKey(orgId, user.userId);
|
||||
if (raced) {
|
||||
return {
|
||||
key: raced,
|
||||
@@ -199,11 +200,11 @@ export async function getOrCreateUserVirtualApiKey(params: {
|
||||
|
||||
export async function rotateUserVirtualApiKey(params: {
|
||||
orgId: string;
|
||||
userId: string;
|
||||
user: User;
|
||||
createdByUserId?: string | null;
|
||||
}): Promise<{ key: VirtualApiKey; secret: string }> {
|
||||
const { orgId, userId, createdByUserId } = params;
|
||||
const existing = await selectUserVirtualApiKey(orgId, userId);
|
||||
const { orgId, user, createdByUserId } = params;
|
||||
const existing = await selectUserVirtualApiKey(orgId, user.userId);
|
||||
|
||||
if (!existing) {
|
||||
return getOrCreateUserVirtualApiKey(params);
|
||||
|
||||
Reference in New Issue
Block a user