mirror of
https://github.com/fosrl/pangolin.git
synced 2026-09-11 21:41:41 +02:00
Add cert_mode to know when to gen or pull certs
This commit is contained in:
@@ -358,7 +358,7 @@ export class TraefikConfigManager {
|
|||||||
this.lastActiveDomains = new Set(domains);
|
this.lastActiveDomains = new Set(domains);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.USE_PANGOLIN_DNS === "true" && build != "oss") {
|
if (process.env.CERT_MODE === "pangolin" && build != "oss") {
|
||||||
// Scan current local certificate state
|
// Scan current local certificate state
|
||||||
this.lastLocalCertificateState =
|
this.lastLocalCertificateState =
|
||||||
await this.scanLocalCertificateState();
|
await this.scanLocalCertificateState();
|
||||||
|
|||||||
@@ -17,14 +17,8 @@ import { privateConfig } from "#private/lib/config";
|
|||||||
let dnsServer: AuthoritativeDNSServer | undefined;
|
let dnsServer: AuthoritativeDNSServer | undefined;
|
||||||
|
|
||||||
export async function startDnsServer() {
|
export async function startDnsServer() {
|
||||||
const use_pangolin_dns =
|
|
||||||
privateConfig.getRawPrivateConfig().flags.use_pangolin_dns;
|
|
||||||
if (!use_pangolin_dns) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dnsConfig = privateConfig.getRawPrivateConfig().dns;
|
const dnsConfig = privateConfig.getRawPrivateConfig().dns;
|
||||||
if (!dnsConfig) {
|
if (!dnsConfig || !dnsConfig.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,10 @@ export class PrivateConfig {
|
|||||||
process.env.USE_PANGOLIN_DNS =
|
process.env.USE_PANGOLIN_DNS =
|
||||||
this.rawPrivateConfig.flags.use_pangolin_dns.toString();
|
this.rawPrivateConfig.flags.use_pangolin_dns.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.rawPrivateConfig.acme?.cert_mode) {
|
||||||
|
process.env.CERT_MODE = this.rawPrivateConfig.acme.cert_mode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getRawPrivateConfig() {
|
public getRawPrivateConfig() {
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ export const privateConfigSchema = z
|
|||||||
.optional(),
|
.optional(),
|
||||||
dns: z
|
dns: z
|
||||||
.object({
|
.object({
|
||||||
|
enabled: z.boolean().optional().default(false),
|
||||||
listen_port: z.number(),
|
listen_port: z.number(),
|
||||||
nameserver_name: z.string(),
|
nameserver_name: z.string(),
|
||||||
cname_extension: z.string(),
|
cname_extension: z.string(),
|
||||||
@@ -188,14 +189,26 @@ export const privateConfigSchema = z
|
|||||||
})
|
})
|
||||||
.optional()
|
.optional()
|
||||||
.prefault({}),
|
.prefault({}),
|
||||||
// @deprecated Moved to the public config file as `acme`
|
|
||||||
// (server/lib/readConfigFile.ts). Kept here only so existing private
|
|
||||||
// config files keep parsing; any value set here is migrated into the
|
|
||||||
// public config at startup by PrivateConfig (server/private/lib/config.ts).
|
|
||||||
acme: z
|
acme: z
|
||||||
.object({
|
.object({
|
||||||
|
cert_mode: z
|
||||||
|
.enum(["traefik", "pangolin"])
|
||||||
|
.optional()
|
||||||
|
.default("traefik"),
|
||||||
|
// @deprecated Moved to the public config file
|
||||||
|
// (server/lib/readConfigFile.ts). Kept here only so existing private
|
||||||
|
// config files keep parsing; any value set here is migrated into the
|
||||||
|
// public config at startup by PrivateConfig (server/private/lib/config.ts).
|
||||||
acme_json_path: z.string().optional(),
|
acme_json_path: z.string().optional(),
|
||||||
|
// @deprecated Moved to the public config file
|
||||||
|
// (server/lib/readConfigFile.ts). Kept here only so existing private
|
||||||
|
// config files keep parsing; any value set here is migrated into the
|
||||||
|
// public config at startup by PrivateConfig (server/private/lib/config.ts).
|
||||||
acme_http_endpoint: z.string().optional(),
|
acme_http_endpoint: z.string().optional(),
|
||||||
|
// @deprecated Moved to the public config file
|
||||||
|
// (server/lib/readConfigFile.ts). Kept here only so existing private
|
||||||
|
// config files keep parsing; any value set here is migrated into the
|
||||||
|
// public config at startup by PrivateConfig (server/private/lib/config.ts).
|
||||||
sync_interval_ms: z.number().optional()
|
sync_interval_ms: z.number().optional()
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ export async function getTraefikConfig(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let validCerts: CertificateResult[] = [];
|
let validCerts: CertificateResult[] = [];
|
||||||
if (privateConfig.getRawPrivateConfig().flags.use_pangolin_dns) {
|
if (privateConfig.getRawPrivateConfig().acme?.cert_mode == "pangolin") {
|
||||||
// create a list of all domains to get certs for
|
// create a list of all domains to get certs for
|
||||||
const domains = new Set<string>();
|
const domains = new Set<string>();
|
||||||
for (const resource of resourcesMap.values()) {
|
for (const resource of resourcesMap.values()) {
|
||||||
@@ -522,7 +522,10 @@ export async function getTraefikConfig(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let tls = {};
|
let tls = {};
|
||||||
if (!privateConfig.getRawPrivateConfig().flags.use_pangolin_dns) {
|
if (
|
||||||
|
privateConfig.getRawPrivateConfig().acme?.cert_mode !=
|
||||||
|
"pangolin"
|
||||||
|
) {
|
||||||
tls = buildWildcardTls({
|
tls = buildWildcardTls({
|
||||||
fullDomain,
|
fullDomain,
|
||||||
hasSubdomain: !!resource.subdomain,
|
hasSubdomain: !!resource.subdomain,
|
||||||
@@ -789,7 +792,8 @@ export async function getTraefikConfig(
|
|||||||
preferWildcardCert
|
preferWildcardCert
|
||||||
}) => {
|
}) => {
|
||||||
if (
|
if (
|
||||||
!privateConfig.getRawPrivateConfig().flags.use_pangolin_dns
|
privateConfig.getRawPrivateConfig().acme?.cert_mode !=
|
||||||
|
"pangolin"
|
||||||
) {
|
) {
|
||||||
return buildWildcardTls({
|
return buildWildcardTls({
|
||||||
fullDomain,
|
fullDomain,
|
||||||
@@ -832,7 +836,8 @@ export async function getTraefikConfig(
|
|||||||
redirectHttpsMiddlewareName,
|
redirectHttpsMiddlewareName,
|
||||||
resolveTls: (fullDomain) => {
|
resolveTls: (fullDomain) => {
|
||||||
if (
|
if (
|
||||||
!privateConfig.getRawPrivateConfig().flags.use_pangolin_dns
|
privateConfig.getRawPrivateConfig().acme?.cert_mode !=
|
||||||
|
"pangolin"
|
||||||
) {
|
) {
|
||||||
// siteResource aliases don't have a per-domain cert
|
// siteResource aliases don't have a per-domain cert
|
||||||
// resolver stored, so always fall back to the global
|
// resolver stored, so always fall back to the global
|
||||||
@@ -924,7 +929,10 @@ export async function getTraefikConfig(
|
|||||||
const rule = buildHostRule(fullDomain, ir.wildcard);
|
const rule = buildHostRule(fullDomain, ir.wildcard);
|
||||||
|
|
||||||
let tls: any = {};
|
let tls: any = {};
|
||||||
if (!privateConfig.getRawPrivateConfig().flags.use_pangolin_dns) {
|
if (
|
||||||
|
privateConfig.getRawPrivateConfig().acme?.cert_mode !=
|
||||||
|
"pangolin"
|
||||||
|
) {
|
||||||
tls = buildWildcardTls({
|
tls = buildWildcardTls({
|
||||||
fullDomain,
|
fullDomain,
|
||||||
hasSubdomain: !!ir.subdomain,
|
hasSubdomain: !!ir.subdomain,
|
||||||
@@ -1005,7 +1013,8 @@ export async function getTraefikConfig(
|
|||||||
|
|
||||||
let tls: any = {};
|
let tls: any = {};
|
||||||
if (
|
if (
|
||||||
!privateConfig.getRawPrivateConfig().flags.use_pangolin_dns
|
privateConfig.getRawPrivateConfig().acme?.cert_mode !=
|
||||||
|
"pangolin"
|
||||||
) {
|
) {
|
||||||
// siteResource aliases don't have a per-domain cert
|
// siteResource aliases don't have a per-domain cert
|
||||||
// resolver stored, so always fall back to the global
|
// resolver stored, so always fall back to the global
|
||||||
@@ -1080,7 +1089,7 @@ export async function getTraefikConfig(
|
|||||||
.where(eq(exitNodes.exitNodeId, exitNodeId));
|
.where(eq(exitNodes.exitNodeId, exitNodeId));
|
||||||
|
|
||||||
let validCertsLoginPages: CertificateResult[] = [];
|
let validCertsLoginPages: CertificateResult[] = [];
|
||||||
if (privateConfig.getRawPrivateConfig().flags.use_pangolin_dns) {
|
if (privateConfig.getRawPrivateConfig().acme?.cert_mode == "pangolin") {
|
||||||
// create a list of all domains to get certs for
|
// create a list of all domains to get certs for
|
||||||
const domains = new Set<string>();
|
const domains = new Set<string>();
|
||||||
for (const lp of exitNodeLoginPages) {
|
for (const lp of exitNodeLoginPages) {
|
||||||
@@ -1126,7 +1135,8 @@ export async function getTraefikConfig(
|
|||||||
|
|
||||||
const tls = {};
|
const tls = {};
|
||||||
if (
|
if (
|
||||||
!privateConfig.getRawPrivateConfig().flags.use_pangolin_dns
|
privateConfig.getRawPrivateConfig().acme?.cert_mode !=
|
||||||
|
"pangolin"
|
||||||
) {
|
) {
|
||||||
// TODO: we need to add the wildcard logic here too
|
// TODO: we need to add the wildcard logic here too
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-3
@@ -1,3 +1,4 @@
|
|||||||
|
import { build } from "@server/build";
|
||||||
import { Env } from "./types/env";
|
import { Env } from "./types/env";
|
||||||
|
|
||||||
export function pullEnv(): Env {
|
export function pullEnv(): Env {
|
||||||
@@ -34,9 +35,7 @@ export function pullEnv(): Env {
|
|||||||
: false
|
: false
|
||||||
},
|
},
|
||||||
identityProviderMode: process.env.IDENTITY_PROVIDER_MODE as
|
identityProviderMode: process.env.IDENTITY_PROVIDER_MODE as
|
||||||
| "org"
|
"org" | "global" | undefined
|
||||||
| "global"
|
|
||||||
| undefined
|
|
||||||
},
|
},
|
||||||
email: {
|
email: {
|
||||||
emailEnabled: process.env.EMAIL_ENABLED === "true" ? true : false
|
emailEnabled: process.env.EMAIL_ENABLED === "true" ? true : false
|
||||||
|
|||||||
Reference in New Issue
Block a user