Compare commits

..

17 Commits

Author SHA1 Message Date
43f15c7957 feat: GoCache | deploy go package cache 2025-12-01 23:00:32 +05:00
8dc22ff13b fix: RateLimit | increase rate limits for public usage 2025-12-01 18:44:29 +05:00
69bdd52df6 feat: Netbird | set up netbird vpn 2025-11-29 13:20:50 +05:00
2c57f8005d feat: MediaServices | add ingress for arr services 2025-11-29 13:20:31 +05:00
33a8dcdaf2 fix: Traefik | abstract TLSOptions class 2025-11-29 13:20:10 +05:00
ca8d140baf fix: Postgres | enable WAL archiver 2025-11-29 13:19:43 +05:00
874f5e2dc2 fix: Gitea | fix internal tls cert 2025-11-29 13:19:33 +05:00
ff2174205a feat: Traefik | add custom TLSOptions 2025-11-29 13:19:14 +05:00
ad3478c48c sec: Traefik | disable ingressClass 2025-11-29 13:19:01 +05:00
3f6f4550d1 chore: TFG | update to 0.11.8 2025-11-29 13:18:48 +05:00
3c947c05ad feat: CertManager | update to latest version
Also improve pki
2025-11-29 13:18:34 +05:00
a753fc0e1e fix: Utils | update public and internal cert algorithms 2025-11-24 22:08:49 +05:00
d6c534378a chore: Minecraft | clean up old servers 2025-11-24 20:21:38 +05:00
10ed028c4b feat: Jellyfin | enable server discovery 2025-11-24 20:20:25 +05:00
b4e57b4f0c feat: MediaServices | deploy through cdktf 2025-11-24 12:14:27 +05:00
d003c3f280 chore: Authentik | remove unused ingress values 2025-11-24 11:29:52 +05:00
d75671f5dd fix: Ingress | simplify https infrastructure 2025-11-24 11:29:27 +05:00
42 changed files with 1496 additions and 889 deletions

View File

@@ -0,0 +1,41 @@
import * as fs from "fs";
import * as path from "path";
import { Release } from "@cdktf/provider-helm/lib/release";
import { Construct } from "constructs";
import { PublicIngressRoute } from "../../utils";
import { Providers } from "../../types";
type GoCacheOptions = {
providers: Providers;
namespace: string;
name: string;
host: string;
};
export class GoCache extends Construct {
constructor(scope: Construct, id: string, opts: GoCacheOptions) {
super(scope, id);
const { namespace, name, host } = opts;
const { helm, kubernetes } = opts.providers;
new Release(this, "helm-release", {
provider: helm,
name,
namespace,
repository: "https://gomods.github.io/athens-charts",
chart: "athens-proxy",
values: [fs.readFileSync(path.join(__dirname, "values.yaml"), "utf8")],
});
new PublicIngressRoute(this, "ingress", {
provider: kubernetes,
namespace,
name,
host,
serviceName: `${name}-athens-proxy`,
servicePort: 80,
});
}
}

View File

@@ -0,0 +1,20 @@
replicaCount: 3
image:
runAsNonRoot: true
nodeSelector:
nodepool: worker
strategy:
type: Recreate
storage:
disk:
persistence:
enabled: true
accessMode: ReadWriteMany
size: 64Gi
storageClass: longhorn
configEnvVars:
- name: ATHENS_DOWNLOAD_MODE
value: "sync"
upstreamProxy:
enabled: true
url: "https://proxy.golang.org"

View File

@@ -5,15 +5,23 @@ import { NamespaceV1 } from "@cdktf/provider-kubernetes/lib/namespace-v1";
import { NixCache } from "./nix"; import { NixCache } from "./nix";
import { NpmCache } from "./npm"; import { NpmCache } from "./npm";
import { PipCache } from "./pip"; import { PipCache } from "./pip";
import { GoCache } from "./go";
import { HelmProvider } from "@cdktf/provider-helm/lib/provider";
export class CacheInfrastructure extends TerraformStack { export class CacheInfrastructure extends TerraformStack {
constructor(scope: Construct, id: string) { constructor(scope: Construct, id: string) {
super(scope, id); super(scope, id);
const provider = new KubernetesProvider(this, "kubernetes", { const kubernetes = new KubernetesProvider(this, "kubernetes", {
configPath: "~/.kube/config", configPath: "~/.kube/config",
}); });
const helm = new HelmProvider(this, "helm", {
kubernetes: {
configPath: "~/.kube/config",
},
});
const namespace = "package-cache"; const namespace = "package-cache";
new NamespaceV1(this, "package-cache-namespace", { new NamespaceV1(this, "package-cache-namespace", {
@@ -24,24 +32,34 @@ export class CacheInfrastructure extends TerraformStack {
// Add cache-related infrastructure components here // Add cache-related infrastructure components here
new NixCache(this, "nix-cache", { new NixCache(this, "nix-cache", {
provider, provider: kubernetes,
namespace, namespace,
name: "nix-cache", name: "nix-cache",
host: "nix.dogar.dev", host: "nix.dogar.dev",
}); });
new NpmCache(this, "npm-cache", { new NpmCache(this, "npm-cache", {
provider, provider: kubernetes,
namespace, namespace,
name: "npm-cache", name: "npm-cache",
host: "npm.dogar.dev", host: "npm.dogar.dev",
}); });
new PipCache(this, "pip-cache", { new PipCache(this, "pip-cache", {
provider, provider: kubernetes,
namespace, namespace,
name: "pip-cache", name: "pip-cache",
host: "pip.dogar.dev", host: "pip.dogar.dev",
}); });
new GoCache(this, "go-cache", {
providers: {
kubernetes,
helm,
},
namespace,
name: "go-cache",
host: "go.dogar.dev",
});
} }
} }

View File

@@ -6,7 +6,6 @@ import { Construct } from "constructs";
type CertManagerOptions = { type CertManagerOptions = {
provider: HelmProvider; provider: HelmProvider;
version: string;
name: string; name: string;
namespace: string; namespace: string;
}; };
@@ -15,13 +14,12 @@ export class CertManager extends Construct {
constructor(scope: Construct, id: string, options: CertManagerOptions) { constructor(scope: Construct, id: string, options: CertManagerOptions) {
super(scope, id); super(scope, id);
const { namespace, name, version, provider } = options; const { namespace, name, provider } = options;
new Release(this, id, { new Release(this, id, {
provider, provider,
name, name,
namespace, namespace,
version,
repository: "https://charts.jetstack.io", repository: "https://charts.jetstack.io",
chart: "cert-manager", chart: "cert-manager",
createNamespace: true, createNamespace: true,

View File

@@ -1,6 +1,8 @@
crds: crds:
enabled: true enabled: true
keep: true
prometheus: prometheus:
enabled: true enabled: true
webhook: webhook:
timeoutSeconds: 4 timeoutSeconds: 4
enableCertificateOwnerRef: true

View File

@@ -59,7 +59,6 @@ export class CoreServices extends TerraformStack {
provider: helm, provider: helm,
name: "cert-manager", name: "cert-manager",
namespace, namespace,
version: "1.18.2",
}); });
} }
} }

View File

@@ -3,7 +3,7 @@ providers:
allowCrossNamespace: true allowCrossNamespace: true
ingress: ingress:
ingressClass: ingressClass:
enabled: true enabled: false
isDefaultClass: true isDefaultClass: true
name: traefik name: traefik
deployment: deployment:

View File

@@ -46,7 +46,7 @@ export class TerraFirmaGreg extends Construct {
}, },
{ {
name: "CF_FILENAME_MATCHER", name: "CF_FILENAME_MATCHER",
value: "0.10.17", value: "0.11.8",
}, },
{ {
name: "VERSION", name: "VERSION",

10
main.ts
View File

@@ -7,7 +7,9 @@ import { K8SOperators } from "./k8s-operators";
import { CoreServices } from "./core-services"; import { CoreServices } from "./core-services";
import { NetworkSecurity } from "./network-security"; import { NetworkSecurity } from "./network-security";
import { GamingServices } from "./gaming-services/minecraft"; import { GamingServices } from "./gaming-services/minecraft";
import { MediaServices } from "./media-services";
import { PKI } from "./pki"; import { PKI } from "./pki";
import { Netbird } from "./netbird";
dotenv.config(); dotenv.config();
@@ -39,9 +41,15 @@ utilityServices.node.addDependency(networkSecurity);
const gamingServices = new GamingServices(app, "gaming-services"); const gamingServices = new GamingServices(app, "gaming-services");
gamingServices.node.addDependency(networkSecurity); gamingServices.node.addDependency(networkSecurity);
const mediaServices = new MediaServices(app, "media-services");
mediaServices.node.addDependency(networkSecurity);
const caches = new CacheInfrastructure(app, "cache-infrastructure"); const caches = new CacheInfrastructure(app, "cache-infrastructure");
caches.node.addDependency(utilityServices); caches.node.addDependency(utilityServices);
const netbird = new Netbird(app, "netbird");
netbird.node.addDependency(utilityServices);
const deploy: (stack: TerraformStack, key: string) => S3Backend = ( const deploy: (stack: TerraformStack, key: string) => S3Backend = (
stack, stack,
key, key,
@@ -70,5 +78,7 @@ deploy(networkSecurity, "network-security");
deploy(utilityServices, "utility-services"); deploy(utilityServices, "utility-services");
deploy(caches, "cache-infrastructure"); deploy(caches, "cache-infrastructure");
deploy(gamingServices, "gaming-services"); deploy(gamingServices, "gaming-services");
deploy(mediaServices, "media-services");
deploy(netbird, "netbird");
app.synth(); app.synth();

82
media-services/index.ts Normal file
View File

@@ -0,0 +1,82 @@
import { Construct } from "constructs";
import { TerraformStack } from "cdktf";
import { KubernetesProvider } from "@cdktf/provider-kubernetes/lib/provider";
import { NamespaceV1 } from "@cdktf/provider-kubernetes/lib/namespace-v1";
import { LonghornPvc } from "../utils";
import { JellyfinServer } from "./jellyfin";
import { SonarrServer } from "./sonarr";
import { RadarrServer } from "./radarr";
import { QBittorrentServer } from "./qbittorrent";
import { ProwlarrServer } from "./prowlarr";
export class MediaServices extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id);
const provider = new KubernetesProvider(this, "kubernetes", {
configPath: "~/.kube/config",
});
const namespace = "media";
// Create namespace
new NamespaceV1(this, "namespace", {
metadata: {
name: namespace,
},
});
// Shared PVCs
const mediaPvc = new LonghornPvc(this, "media-pvc", {
provider,
name: "media",
namespace,
size: "1Ti",
});
const downloadsPvc = new LonghornPvc(this, "downloads-pvc", {
provider,
name: "downloads",
namespace,
size: "450Gi",
});
// Deploy media services
new JellyfinServer(this, "jellyfin", {
provider,
namespace,
mediaPvcName: mediaPvc.name,
host: "media.dogar.dev",
});
new SonarrServer(this, "sonarr", {
provider,
namespace,
mediaPvcName: mediaPvc.name,
downloadsPvcName: downloadsPvc.name,
host: "sonarr.dogar.dev",
});
new RadarrServer(this, "radarr", {
provider,
namespace,
mediaPvcName: mediaPvc.name,
downloadsPvcName: downloadsPvc.name,
host: "radarr.dogar.dev",
});
new QBittorrentServer(this, "qbittorrent", {
provider,
namespace,
downloadsPvcName: downloadsPvc.name,
host: "torrent.dogar.dev",
});
new ProwlarrServer(this, "prowlarr", {
provider,
namespace,
host: "prowlarr.dogar.dev",
});
}
}

View File

@@ -0,0 +1,163 @@
import { Construct } from "constructs";
import { DeploymentV1 } from "@cdktf/provider-kubernetes/lib/deployment-v1";
import { ServiceV1 } from "@cdktf/provider-kubernetes/lib/service-v1";
import {
CloudflareCertificate,
InternalIngressRoute,
LonghornPvc,
} from "../../utils";
import { BaseMediaServiceOptions, getAamil3NodeSelector } from "../types";
type JellyfinServerOptions = BaseMediaServiceOptions & {
/** Name of the shared media PVC */
mediaPvcName: string;
/** Hostname for the ingress */
host: string;
};
export class JellyfinServer extends Construct {
constructor(scope: Construct, id: string, options: JellyfinServerOptions) {
super(scope, id);
const { provider, namespace, mediaPvcName, host } = options;
const name = "server";
// Config PVC with backup
const configPvc = new LonghornPvc(this, "config", {
provider,
name: "jellyfin-config",
namespace,
size: "5Gi",
backup: true,
});
// Service
new ServiceV1(this, "service", {
provider,
metadata: {
name,
namespace,
},
spec: {
selector: {
app: name,
},
port: [
{
name: "http",
port: 80,
targetPort: "http",
},
{
name: "discovery",
port: 7359,
targetPort: "discovery",
},
],
type: "LoadBalancer",
},
});
// Deployment
new DeploymentV1(this, "deployment", {
provider,
metadata: {
name,
namespace,
},
spec: {
replicas: "1",
selector: {
matchLabels: {
app: name,
},
},
template: {
metadata: {
labels: {
app: name,
},
},
spec: {
nodeSelector: getAamil3NodeSelector(),
container: [
{
name,
image: "jellyfin/jellyfin:latest",
imagePullPolicy: "IfNotPresent",
port: [
{
containerPort: 8096,
name: "http",
},
{
containerPort: 7359,
name: "discovery",
},
],
env: [
{
name: "TZ",
value: "Asia/Karachi",
},
],
volumeMount: [
{
name: "config",
mountPath: "/config",
},
{
name: "cache",
mountPath: "/cache",
},
{
name: "media",
mountPath: "/media",
},
],
},
],
volume: [
{
name: "config",
persistentVolumeClaim: {
claimName: configPvc.name,
},
},
{
name: "cache",
emptyDir: {},
},
{
name: "media",
persistentVolumeClaim: {
claimName: mediaPvcName,
},
},
],
},
},
},
});
new CloudflareCertificate(this, "certificate", {
provider,
namespace,
name,
secretName: "jellyfin-tls",
dnsNames: [host],
});
// Ingress - using internal ingress for secure access
new InternalIngressRoute(this, "ingress", {
provider,
namespace,
name,
host,
serviceName: name,
servicePort: 80,
tlsSecretName: "jellyfin-tls",
});
}
}

View File

@@ -0,0 +1,134 @@
import { Construct } from "constructs";
import { DeploymentV1 } from "@cdktf/provider-kubernetes/lib/deployment-v1";
import { ServiceV1 } from "@cdktf/provider-kubernetes/lib/service-v1";
import {
InternalIngressRoute,
LonghornPvc,
PrivateCertificate,
} from "../../utils";
import {
BaseMediaServiceOptions,
getWorkerNodeSelector,
getCommonEnv,
} from "../types";
type ProwlarrOptions = BaseMediaServiceOptions & {
/** Hostname for the ingress */
host: string;
};
export class ProwlarrServer extends Construct {
constructor(scope: Construct, id: string, options: ProwlarrOptions) {
super(scope, id);
const { provider, namespace, host } = options;
const name = "prowlarr";
// Config PVC with backup
const configPvc = new LonghornPvc(this, "config", {
provider,
name: "prowlarr-config",
namespace,
size: "512Mi",
backup: true,
});
// Service
new ServiceV1(this, "service", {
provider,
metadata: {
name,
namespace,
},
spec: {
selector: {
app: name,
},
port: [
{
name: "http",
port: 80,
targetPort: "9696",
},
],
type: "ClusterIP",
},
});
// Deployment
new DeploymentV1(this, "deployment", {
provider,
metadata: {
name,
namespace,
},
spec: {
replicas: "1",
selector: {
matchLabels: {
app: name,
},
},
template: {
metadata: {
labels: {
app: name,
},
},
spec: {
nodeSelector: getWorkerNodeSelector(),
container: [
{
name,
image: "lscr.io/linuxserver/prowlarr:latest",
imagePullPolicy: "IfNotPresent",
port: [
{
containerPort: 9696,
name: "http",
},
],
env: getCommonEnv(),
volumeMount: [
{
name: "config",
mountPath: "/config",
},
],
},
],
volume: [
{
name: "config",
persistentVolumeClaim: {
claimName: configPvc.name,
},
},
],
},
},
},
});
new PrivateCertificate(this, "certificate", {
provider,
namespace,
name,
commonName: host,
dnsNames: [host],
secretName: `${name}-tls`,
});
// Ingress
new InternalIngressRoute(this, "ingress", {
provider,
namespace,
name,
host,
serviceName: name,
servicePort: 80,
tlsSecretName: `${name}-tls`,
});
}
}

View File

@@ -0,0 +1,160 @@
import { Construct } from "constructs";
import { DeploymentV1 } from "@cdktf/provider-kubernetes/lib/deployment-v1";
import { ServiceV1 } from "@cdktf/provider-kubernetes/lib/service-v1";
import {
InternalIngressRoute,
LonghornPvc,
PrivateCertificate,
} from "../../utils";
import {
BaseMediaServiceOptions,
getAamil3NodeSelector,
getCommonEnv,
} from "../types";
type QBittorrentServerOptions = BaseMediaServiceOptions & {
/** Name of the shared downloads PVC */
downloadsPvcName: string;
/** Hostname for the ingress */
host: string;
};
export class QBittorrentServer extends Construct {
constructor(scope: Construct, id: string, options: QBittorrentServerOptions) {
super(scope, id);
const { provider, namespace, downloadsPvcName, host } = options;
const name = "qbittorrent";
// Config PVC with backup
const configPvc = new LonghornPvc(this, "config", {
provider,
name: "qbittorrent-config",
namespace,
size: "512Mi",
backup: true,
});
// Service
new ServiceV1(this, "service", {
provider,
metadata: {
name,
namespace,
},
spec: {
selector: {
app: name,
},
port: [
{
name: "http",
port: 80,
targetPort: "8080",
},
],
type: "ClusterIP",
},
});
// Deployment
new DeploymentV1(this, "deployment", {
provider,
metadata: {
name,
namespace,
},
spec: {
replicas: "1",
selector: {
matchLabels: {
app: name,
},
},
template: {
metadata: {
labels: {
app: name,
},
},
spec: {
nodeSelector: getAamil3NodeSelector(),
container: [
{
name,
image: "lscr.io/linuxserver/qbittorrent:latest",
port: [
{
containerPort: 8080,
name: "http",
},
{
containerPort: 6881,
name: "bt",
},
{
containerPort: 6881,
protocol: "UDP",
name: "bt-udp",
},
],
env: [
...getCommonEnv(),
{
name: "WEBUI_PORT",
value: "8080",
},
],
volumeMount: [
{
name: "config",
mountPath: "/config",
},
{
name: "downloads",
mountPath: "/downloads",
},
],
},
],
volume: [
{
name: "config",
persistentVolumeClaim: {
claimName: configPvc.name,
},
},
{
name: "downloads",
persistentVolumeClaim: {
claimName: downloadsPvcName,
},
},
],
},
},
},
});
new PrivateCertificate(this, "certificate", {
provider,
namespace,
name,
commonName: host,
dnsNames: [host],
secretName: `${name}-tls`,
});
// Ingress
new InternalIngressRoute(this, "ingress", {
provider,
namespace,
name,
host,
serviceName: name,
servicePort: 80,
tlsSecretName: `${name}-tls`,
});
}
}

View File

@@ -0,0 +1,159 @@
import { Construct } from "constructs";
import { DeploymentV1 } from "@cdktf/provider-kubernetes/lib/deployment-v1";
import { ServiceV1 } from "@cdktf/provider-kubernetes/lib/service-v1";
import {
InternalIngressRoute,
LonghornPvc,
PrivateCertificate,
} from "../../utils";
import {
BaseMediaServiceOptions,
getAamil3NodeSelector,
getCommonEnv,
} from "../types";
type RadarrServerOptions = BaseMediaServiceOptions & {
/** Name of the shared media PVC */
mediaPvcName: string;
/** Name of the shared downloads PVC */
downloadsPvcName: string;
/** Hostname for the ingress */
host: string;
};
export class RadarrServer extends Construct {
constructor(scope: Construct, id: string, options: RadarrServerOptions) {
super(scope, id);
const { provider, namespace, mediaPvcName, downloadsPvcName, host } =
options;
const name = "radarr";
// Config PVC with backup
const configPvc = new LonghornPvc(this, "config", {
provider,
name: "radarr-config",
namespace,
size: "512Mi",
backup: true,
});
// Service
new ServiceV1(this, "service", {
provider,
metadata: {
name,
namespace,
},
spec: {
selector: {
app: name,
},
port: [
{
name: "http",
port: 80,
targetPort: "7878",
},
],
type: "ClusterIP",
},
});
// Deployment
new DeploymentV1(this, "deployment", {
provider,
metadata: {
name,
namespace,
},
spec: {
replicas: "1",
selector: {
matchLabels: {
app: name,
},
},
template: {
metadata: {
labels: {
app: name,
},
},
spec: {
nodeSelector: getAamil3NodeSelector(),
container: [
{
name,
image: "lscr.io/linuxserver/radarr:latest",
imagePullPolicy: "IfNotPresent",
port: [
{
containerPort: 7878,
name: "http",
},
],
env: getCommonEnv(),
volumeMount: [
{
name: "config",
mountPath: "/config",
},
{
name: "media",
mountPath: "/media",
},
{
name: "downloads",
mountPath: "/downloads",
},
],
},
],
volume: [
{
name: "config",
persistentVolumeClaim: {
claimName: configPvc.name,
},
},
{
name: "media",
persistentVolumeClaim: {
claimName: mediaPvcName,
},
},
{
name: "downloads",
persistentVolumeClaim: {
claimName: downloadsPvcName,
},
},
],
},
},
},
});
new PrivateCertificate(this, "certificate", {
provider,
namespace,
name,
commonName: host,
dnsNames: [host],
secretName: `${name}-tls`,
});
// Ingress
new InternalIngressRoute(this, "ingress", {
provider,
namespace,
name,
host,
serviceName: name,
servicePort: 80,
tlsSecretName: `${name}-tls`,
});
}
}

View File

@@ -0,0 +1,159 @@
import { Construct } from "constructs";
import { DeploymentV1 } from "@cdktf/provider-kubernetes/lib/deployment-v1";
import { ServiceV1 } from "@cdktf/provider-kubernetes/lib/service-v1";
import {
InternalIngressRoute,
LonghornPvc,
PrivateCertificate,
} from "../../utils";
import {
BaseMediaServiceOptions,
getAamil3NodeSelector,
getCommonEnv,
} from "../types";
type SonarrServerOptions = BaseMediaServiceOptions & {
/** Name of the shared media PVC */
mediaPvcName: string;
/** Name of the shared downloads PVC */
downloadsPvcName: string;
/** Hostname for the ingress */
host: string;
};
export class SonarrServer extends Construct {
constructor(scope: Construct, id: string, options: SonarrServerOptions) {
super(scope, id);
const { provider, namespace, mediaPvcName, downloadsPvcName, host } =
options;
const name = "sonarr";
// Config PVC with backup
const configPvc = new LonghornPvc(this, "config", {
provider,
name: "sonarr-config",
namespace,
size: "512Mi",
backup: true,
});
// Service
new ServiceV1(this, "service", {
provider,
metadata: {
name,
namespace,
},
spec: {
selector: {
app: name,
},
port: [
{
name: "http",
port: 80,
targetPort: "8989",
},
],
type: "ClusterIP",
},
});
// Deployment
new DeploymentV1(this, "deployment", {
provider,
metadata: {
name,
namespace,
},
spec: {
replicas: "1",
selector: {
matchLabels: {
app: name,
},
},
template: {
metadata: {
labels: {
app: name,
},
},
spec: {
nodeSelector: getAamil3NodeSelector(),
container: [
{
name,
image: "lscr.io/linuxserver/sonarr:latest",
imagePullPolicy: "IfNotPresent",
port: [
{
containerPort: 8989,
name: "http",
},
],
env: getCommonEnv(),
volumeMount: [
{
name: "config",
mountPath: "/config",
},
{
name: "media",
mountPath: "/media",
},
{
name: "downloads",
mountPath: "/downloads",
},
],
},
],
volume: [
{
name: "config",
persistentVolumeClaim: {
claimName: configPvc.name,
},
},
{
name: "media",
persistentVolumeClaim: {
claimName: mediaPvcName,
},
},
{
name: "downloads",
persistentVolumeClaim: {
claimName: downloadsPvcName,
},
},
],
},
},
},
});
new PrivateCertificate(this, "certificate", {
provider,
namespace,
name,
commonName: host,
dnsNames: [host],
secretName: `${name}-tls`,
});
// Ingress
new InternalIngressRoute(this, "ingress", {
provider,
namespace,
name,
host,
serviceName: name,
servicePort: 80,
tlsSecretName: `${name}-tls`,
});
}
}

32
media-services/types.ts Normal file
View File

@@ -0,0 +1,32 @@
import { KubernetesProvider } from "@cdktf/provider-kubernetes/lib/provider";
/**
* Common options shared across all media service constructs
*/
export type BaseMediaServiceOptions = {
provider: KubernetesProvider;
namespace: string;
};
/**
* Common environment variables for LinuxServer.io containers
*/
export const getCommonEnv = () => [
{ name: "TZ", value: "Asia/Karachi" },
{ name: "PUID", value: "1000" },
{ name: "PGID", value: "1000" },
];
/**
* Node selector for the aamil-3 node
*/
export const getAamil3NodeSelector = () => ({
"kubernetes.io/hostname": "aamil-3",
});
/**
* Node selector for worker nodepool
*/
export const getWorkerNodeSelector = () => ({
nodepool: "worker",
});

View File

@@ -1,231 +0,0 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: server
namespace: media
spec:
replicas: 1
selector:
matchLabels:
app: server
template:
metadata:
labels:
app: server
spec:
nodeSelector:
kubernetes.io/hostname: aamil-3
containers:
- name: server
image: jellyfin/jellyfin:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8096
name: http
env:
- name: TZ
value: "Asia/Karachi"
volumeMounts:
- name: config
mountPath: /config
- name: cache
mountPath: /cache
- name: media
mountPath: /media
volumes:
- name: config
persistentVolumeClaim:
claimName: jellyfin-config
- name: cache
emptyDir: {}
- name: media
persistentVolumeClaim:
claimName: media
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sonarr
namespace: media
spec:
replicas: 1
selector:
matchLabels:
app: sonarr
template:
metadata:
labels:
app: sonarr
spec:
nodeSelector:
kubernetes.io/hostname: aamil-3
containers:
- name: sonarr
image: lscr.io/linuxserver/sonarr:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8989
name: http
env:
- name: TZ
value: "Asia/Karachi"
- name: PUID
value: "1000"
- name: PGID
value: "1000"
volumeMounts:
- name: config
mountPath: /config
- name: media
mountPath: /media
- name: downloads
mountPath: /downloads
volumes:
- name: config
persistentVolumeClaim:
claimName: sonarr-config
- name: media
persistentVolumeClaim:
claimName: media
- name: downloads
persistentVolumeClaim:
claimName: downloads
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: qbittorrent
namespace: media
spec:
replicas: 1
selector:
matchLabels:
app: qbittorrent
template:
metadata:
labels:
app: qbittorrent
spec:
nodeSelector:
kubernetes.io/hostname: aamil-3
containers:
- name: qbittorrent
image: lscr.io/linuxserver/qbittorrent:latest
ports:
- containerPort: 8080 # web UI
name: http
- containerPort: 6881
name: bt
- containerPort: 6881
protocol: UDP
name: bt-udp
env:
- name: TZ
value: "Asia/Karachi"
- name: PUID
value: "1000"
- name: PGID
value: "1000"
- name: WEBUI_PORT
value: "8080"
volumeMounts:
- name: config
mountPath: /config
- name: downloads
mountPath: /downloads
volumes:
- name: config
persistentVolumeClaim:
claimName: qbittorrent-config
- name: downloads
persistentVolumeClaim:
claimName: downloads
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: prowlarr
namespace: media
spec:
replicas: 1
selector:
matchLabels:
app: prowlarr
template:
metadata:
labels:
app: prowlarr
spec:
nodeSelector:
nodepool: worker
containers:
- name: prowlarr
image: lscr.io/linuxserver/prowlarr:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9696
name: http
env:
- name: TZ
value: "Asia/Karachi"
- name: PUID
value: "1000"
- name: PGID
value: "1000"
volumeMounts:
- name: config
mountPath: /config
volumes:
- name: config
persistentVolumeClaim:
claimName: prowlarr-config
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: radarr
namespace: media
spec:
replicas: 1
selector:
matchLabels:
app: radarr
template:
metadata:
labels:
app: radarr
spec:
nodeSelector:
kubernetes.io/hostname: aamil-3
containers:
- name: radarr
image: lscr.io/linuxserver/radarr:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 7878
name: http
env:
- name: TZ
value: "Asia/Karachi"
- name: PUID
value: "1000"
- name: PGID
value: "1000"
volumeMounts:
- name: config
mountPath: /config
- name: media
mountPath: /media
- name: downloads
mountPath: /downloads
volumes:
- name: config
persistentVolumeClaim:
claimName: radarr-config
- name: media
persistentVolumeClaim:
claimName: media
- name: downloads
persistentVolumeClaim:
claimName: downloads

View File

@@ -1,76 +0,0 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: server
namespace: media
annotations:
# cert-manager (Cloudflare DNS-01)
cert-manager.io/cluster-issuer: cloudflare-issuer
cert-manager.io/acme-challenge-type: dns01
cert-manager.io/private-key-size: "4096"
# Jellyfin / streaming friendly nginx settings
nginx.ingress.kubernetes.io/proxy-body-size: "0"
nginx.ingress.kubernetes.io/proxy-buffering: "off"
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
nginx.ingress.kubernetes.io/use-proxy-protocol: "false"
nginx.ingress.kubernetes.io/proxy-request-buffering: "off"
spec:
ingressClassName: nginx-internal
tls:
- hosts:
- media.dogar.dev
secretName: media-tls
- hosts:
- sonarr.dogar.dev
secretName: sonarr-tls
- hosts:
- radarr.dogar.dev
secretName: radarr-tls
- hosts:
- torrent.dogar.dev
secretName: torrent-tls
rules:
- host: media.dogar.dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: server
port:
number: 80
- host: sonarr.dogar.dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: sonarr
port:
number: 80
- host: radarr.dogar.dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: radarr
port:
number: 80
- host: torrent.dogar.dev
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: qbittorrent
port:
number: 80

View File

@@ -1,5 +0,0 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: media

View File

@@ -1,106 +0,0 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jellyfin-config
namespace: media
labels:
recurring-job.longhorn.io/source: "enabled"
recurring-job.longhorn.io/daily-backup: "enabled"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: longhorn
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: media
namespace: media
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Ti
storageClassName: longhorn
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sonarr-config
namespace: media
labels:
recurring-job.longhorn.io/source: "enabled"
recurring-job.longhorn.io/daily-backup: "enabled"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 512Mi
storageClassName: longhorn
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: qbittorrent-config
namespace: media
labels:
recurring-job.longhorn.io/source: "enabled"
recurring-job.longhorn.io/daily-backup: "enabled"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 512Mi
storageClassName: longhorn
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: downloads
namespace: media
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 450Gi
storageClassName: longhorn
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: prowlarr-config
namespace: media
labels:
recurring-job.longhorn.io/source: "enabled"
recurring-job.longhorn.io/daily-backup: "enabled"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 512Mi
storageClassName: longhorn
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: radarr-config
namespace: media
labels:
recurring-job.longhorn.io/source: "enabled"
recurring-job.longhorn.io/daily-backup: "enabled"
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 512Mi
storageClassName: longhorn

View File

@@ -1,69 +0,0 @@
---
apiVersion: v1
kind: Service
metadata:
name: server
namespace: media
spec:
selector:
app: server
ports:
- name: http
port: 80
targetPort: 8096
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: sonarr
namespace: media
spec:
selector:
app: sonarr
ports:
- name: http
port: 80
targetPort: 8989
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: qbittorrent
namespace: media
spec:
selector:
app: qbittorrent
ports:
- name: http
port: 80
targetPort: 8080
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: prowlarr
namespace: media
spec:
selector:
app: prowlarr
ports:
- name: http
port: 80
targetPort: 9696
type: ClusterIP
---
apiVersion: v1
kind: Service
metadata:
name: radarr
namespace: media
spec:
selector:
app: radarr
ports:
- name: http
port: 80
targetPort: 7878

View File

@@ -1,19 +1,6 @@
--- ---
apiVersion: v1 apiVersion: v1
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
metadata:
name: monifactory-data
namespace: minecraft
spec:
storageClassName: longhorn
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata: metadata:
name: atm10-data name: atm10-data
namespace: minecraft namespace: minecraft
@@ -27,19 +14,3 @@ spec:
resources: resources:
requests: requests:
storage: 10Gi storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: star-technology-data
namespace: minecraft
labels:
recurring-job.longhorn.io/source: "enabled"
recurring-job.longhorn.io/daily-backup: "enabled"
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi

View File

@@ -1,21 +1,6 @@
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata:
name: monifactory-server
namespace: minecraft
labels:
app: monifactory-server
spec:
type: ClusterIP
ports:
- name: monifactory
port: 25565
selector:
app: monifactory-server
---
apiVersion: v1
kind: Service
metadata: metadata:
name: atm10-server name: atm10-server
namespace: minecraft namespace: minecraft
@@ -28,18 +13,3 @@ spec:
port: 25565 port: 25565
selector: selector:
app: atm10-server app: atm10-server
---
apiVersion: v1
kind: Service
metadata:
name: star-technology-server
namespace: minecraft
labels:
app: star-technology-server
spec:
type: ClusterIP
ports:
- name: star-technology
port: 25565
selector:
app: star-technology-server

View File

@@ -1,72 +1,6 @@
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: StatefulSet kind: StatefulSet
metadata:
name: monifactory-server
namespace: minecraft
spec:
serviceName: monifactory-server
selector:
matchLabels:
app: monifactory-server
template:
metadata:
labels:
app: monifactory-server
spec:
nodeSelector:
nodepool: worker
containers:
- name: monifactory-server
image: itzg/minecraft-server:java17
env:
- name: EULA
value: "TRUE"
- name: MODE
value: "survival"
- name: DIFFICULTY
value: "peaceful"
- name: MODPACK_PLATFORM
value: "AUTO_CURSEFORGE"
- name: CF_API_KEY
valueFrom:
secretKeyRef:
name: curseforge
key: credential
- name: CF_PAGE_URL
value: "https://www.curseforge.com/minecraft/modpacks/monifactory/"
- name: VERSION
value: "1.20.1"
- name: INIT_MEMORY
value: 4G
- name: MAX_MEMORY
value: 12G
- name: ALLOW_FLIGHT
value: "TRUE"
- name: ENABLE_ROLLING_LOGS
value: "TRUE"
- name: USE_MEOWICE_FLAGS
value: "TRUE"
ports:
- name: minecraft
containerPort: 25565
resources:
requests:
cpu: 4
memory: "4Gi"
limits:
cpu: 8
memory: "12Gi"
volumeMounts:
- name: monifactory-data
mountPath: /data
volumes:
- name: monifactory-data
persistentVolumeClaim:
claimName: monifactory-data
---
apiVersion: apps/v1
kind: StatefulSet
metadata: metadata:
name: atm10-server name: atm10-server
namespace: minecraft namespace: minecraft
@@ -132,71 +66,3 @@ spec:
- name: atm10-data - name: atm10-data
persistentVolumeClaim: persistentVolumeClaim:
claimName: atm10-data claimName: atm10-data
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: star-technology-server
namespace: minecraft
spec:
serviceName: star-technology-server
selector:
matchLabels:
app: star-technology-server
template:
metadata:
labels:
app: star-technology-server
spec:
nodeSelector:
nodepool: worker
containers:
- name: star-technology-server
image: itzg/minecraft-server:java21
env:
- name: EULA
value: "TRUE"
- name: MODE
value: "survival"
- name: MODPACK_PLATFORM
value: "AUTO_CURSEFORGE"
- name: CF_API_KEY
valueFrom:
secretKeyRef:
name: curseforge
key: credential
- name: CF_PAGE_URL
value: "https://www.curseforge.com/minecraft/modpacks/star-technology"
- name: VERSION
value: "1.20.1"
- name: INIT_MEMORY
value: 2G
- name: MAX_MEMORY
value: 15G
- name: ALLOW_FLIGHT
value: "TRUE"
- name: ENABLE_ROLLING_LOGS
value: "TRUE"
- name: USE_MEOWICE_FLAGS
value: "TRUE"
- name: CF_OVERRIDES_EXCLUSIONS
value: |
# Not applicable for server side
shaderpacks/**
ports:
- name: minecraft
containerPort: 25565
resources:
requests:
cpu: 2
memory: "2Gi"
limits:
cpu: 6
memory: "16Gi"
volumeMounts:
- name: star-technology-data
mountPath: /data
volumes:
- name: star-technology-data
persistentVolumeClaim:
claimName: star-technology-data

95
netbird/index.ts Normal file
View File

@@ -0,0 +1,95 @@
import * as fs from "fs";
import * as path from "path";
import { Construct } from "constructs";
import { TerraformStack } from "cdktf";
import { KubernetesProvider } from "@cdktf/provider-kubernetes/lib/provider";
import { NamespaceV1 } from "@cdktf/provider-kubernetes/lib/namespace-v1";
import { DataKubernetesSecretV1 } from "@cdktf/provider-kubernetes/lib/data-kubernetes-secret-v1";
import { HelmProvider } from "@cdktf/provider-helm/lib/provider";
import { SecretV1 } from "@cdktf/provider-kubernetes/lib/secret-v1";
import { Release } from "@cdktf/provider-helm/lib/release";
import { CloudflareCertificate, OnePasswordSecret } from "../utils";
export class Netbird extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id);
const kubernetes = new KubernetesProvider(this, "kubernetes", {
configPath: "~/.kube/config",
});
const helm = new HelmProvider(this, "helm", {
kubernetes: {
configPath: "~/.kube/config",
},
});
const namespace = "netbird";
// Create namespace
new NamespaceV1(this, "namespace", {
metadata: {
name: namespace,
},
});
new OnePasswordSecret(this, "netbird-secret", {
name: "netbird",
namespace,
provider: kubernetes,
itemPath: "vaults/Lab/items/Netbird",
});
const pgClientCert = new DataKubernetesSecretV1(
this,
"netbird-client-cert",
{
provider: kubernetes,
metadata: {
name: "netbird-client-cert",
namespace: "homelab",
},
},
);
const pgCaCert = new DataKubernetesSecretV1(this, "postgres-ca-cert", {
provider: kubernetes,
metadata: {
name: "postgres-server-cert",
namespace: "homelab",
},
});
const pgSslBundle = new SecretV1(this, "netbird-postgres-ssl", {
provider: kubernetes,
metadata: {
name: "netbird-postgres-ssl-bundle",
namespace,
},
data: {
"tls.crt": pgClientCert.data.lookup("tls.crt"),
"tls.key": pgClientCert.data.lookup("tls.key"),
"ca.crt": pgCaCert.data.lookup("ca.crt"),
},
});
new CloudflareCertificate(this, "netbird-cloudflare-cert", {
provider: kubernetes,
name: "netbird",
namespace,
dnsNames: ["vpn.dogar.dev"],
secretName: "netbird-tls",
});
new Release(this, "netbird", {
dependsOn: [pgSslBundle],
provider: helm,
namespace,
createNamespace: true,
name: "netbird",
repository: "https://netbirdio.github.io/helms",
chart: "netbird",
values: [fs.readFileSync(path.join(__dirname, "values.yaml"), "utf8")],
}).importFrom("netbird/netbird");
}
}

218
netbird/values.yaml Normal file
View File

@@ -0,0 +1,218 @@
fullnameOverride: netbird
management:
configmap: |-
{
"Stuns": [
{
"Proto": "udp",
"URI": "{{ .STUN_SERVER }}",
"Username": "",
"Password": ""
}
],
"TURNConfig": {
"TimeBasedCredentials": false,
"CredentialsTTL": "12h0m0s",
"Secret": "secret",
"Turns": [
{
"Proto": "udp",
"URI": "{{ .TURN_SERVER }}",
"Username": "{{ .TURN_SERVER_USER }}",
"Password": "{{ .TURN_SERVER_PASSWORD }}"
}
]
},
"Relay": {
"Addresses": ["rels://vpn.dogar.dev:443/relay"],
"CredentialsTTL": "24h",
"Secret": "{{ .RELAY_PASSWORD }}"
},
"Signal": {
"Proto": "https",
"URI": "vpn.dogar.dev:443",
"Username": "",
"Password": ""
},
"Datadir": "/var/lib/netbird/",
"DataStoreEncryptionKey": "{{ .DATASTORE_ENCRYPTION_KEY }}",
"HttpConfig": {
"LetsEncryptDomain": "",
"CertFile": "",
"CertKey": "",
"AuthAudience": "{{ .IDP_CLIENT_ID }}",
"AuthIssuer": "https://auth.dogar.dev/application/o/netbird/",
"AuthUserIDClaim": "",
"AuthKeysLocation": "https://auth.dogar.dev/application/o/netbird/jwks/",
"OIDCConfigEndpoint": "https://auth.dogar.dev/application/o/netbird/.well-known/openid-configuration",
"IdpSignKeyRefreshEnabled": false
},
"IdpManagerConfig": {
"ManagerType": "authentik",
"ClientConfig": {
"Issuer": "https://auth.dogar.dev/application/o/netbird",
"TokenEndpoint": "https://auth.dogar.dev/application/o/token/",
"ClientID": "{{ .IDP_CLIENT_ID }}",
"ClientSecret": "",
"GrantType": "client_credentials"
},
"ExtraConfig": {
"Password": "{{ .IDP_SERVICE_ACCOUNT_PASSWORD }}",
"Username": "{{ .IDP_SERVICE_ACCOUNT_USER }}"
},
"Auth0ClientCredentials": null,
"AzureClientCredentials": null,
"KeycloakClientCredentials": null,
"ZitadelClientCredentials": null
},
"DeviceAuthorizationFlow": {
"Provider": "hosted",
"ProviderConfig": {
"ClientID": "{{ .IDP_CLIENT_ID }}",
"ClientSecret": "",
"Domain": "auth.dogar.dev",
"Audience": "{{ .IDP_CLIENT_ID }}",
"TokenEndpoint": "https://auth.dogar.dev/application/o/token/",
"DeviceAuthEndpoint": "https://auth.dogar.dev/application/o/device/",
"AuthorizationEndpoint": "",
"Scope": "openid",
"UseIDToken": false,
"RedirectURLs": null
}
},
"PKCEAuthorizationFlow": {
"ProviderConfig": {
"ClientID": "{{ .IDP_CLIENT_ID }}",
"ClientSecret": "",
"Domain": "",
"Audience": "{{ .IDP_CLIENT_ID }}",
"TokenEndpoint": "https://auth.dogar.dev/application/o/token/",
"DeviceAuthEndpoint": "",
"AuthorizationEndpoint": "https://auth.dogar.dev/application/o/authorize/",
"Scope": "openid profile email offline_access api",
"UseIDToken": false,
"RedirectURLs": ["http://localhost:53000"]
}
},
"StoreConfig": {
"Engine": "postgres"
},
"ReverseProxy": {
"TrustedHTTPProxies": null,
"TrustedHTTPProxiesCount": 0,
"TrustedPeers": null
}
}
persistentVolume:
enabled: true
storageClass: longhorn
size: 1Gi
envFromSecret:
NETBIRD_STORE_ENGINE_POSTGRES_DSN: netbird/postgresDSN
STUN_SERVER: netbird/stunServer
TURN_SERVER: netbird/turnServer
TURN_SERVER_USER: netbird/turnServerUser
TURN_SERVER_PASSWORD: netbird/turnServerPassword
RELAY_PASSWORD: netbird/relayPassword
IDP_CLIENT_ID: netbird/idpClientID
IDP_SERVICE_ACCOUNT_USER: netbird/idpServiceAccountUser
IDP_SERVICE_ACCOUNT_PASSWORD: netbird/idpServiceAccountPassword
DATASTORE_ENCRYPTION_KEY: netbird/datastoreEncryptionKey
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 180
periodSeconds: 10
timeoutSeconds: 3
tcpSocket:
port: http
volumes:
- name: postgres-ssl-bundle
secret:
secretName: netbird-postgres-ssl-bundle
volumeMounts:
- name: postgres-ssl-bundle
mountPath: /etc/ssl/certs/postgres-ssl-bundle
readOnly: true
signal:
enabled: true
relay:
envFromSecret:
NB_AUTH_SECRET: netbird/relayPassword
env:
NB_LOG_LEVEL: info
NB_LISTEN_ADDRESS: ":33080"
NB_EXPOSED_ADDRESS: rels://vpn.dogar.dev:443/relay
dashboard:
enabled: true
env:
# Endpoints
NETBIRD_MGMT_API_ENDPOINT: https://vpn.dogar.dev:443
NETBIRD_MGMT_GRPC_API_ENDPOINT: https://vpn.dogar.dev:443
# OIDC
AUTH_CLIENT_SECRET:
AUTH_AUTHORITY: https://auth.dogar.dev/application/o/netbird/
USE_AUTH0: false
AUTH_SUPPORTED_SCOPES: openid profile email offline_access api
AUTH_REDIRECT_URI:
AUTH_SILENT_REDIRECT_URI:
NETBIRD_TOKEN_SOURCE: accessToken
NGINX_SSL_PORT:
LETSENCRYPT_DOMAIN:
LETSENCRYPT_EMAIL:
envFromSecret:
AUTH_CLIENT_ID: netbird/idpClientID
AUTH_AUDIENCE: netbird/idpClientID
extraManifests:
- apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: netbird
namespace: netbird
spec:
entryPoints:
- websecure
routes:
- kind: Rule
match: Host(`vpn.dogar.dev`) && !PathPrefix(`/api`) && !PathPrefix(`/management`) && !PathPrefix(`/signalexchange`) && !PathPrefix(`/relay`)
services:
- name: netbird-dashboard
namespace: netbird
passHostHeader: true
port: 80
- kind: Rule
match: Host(`vpn.dogar.dev`) && PathPrefix(`/api`)
services:
- name: netbird-management
namespace: netbird
passHostHeader: true
port: 80
- kind: Rule
match: Host(`vpn.dogar.dev`) && PathPrefix(`/relay`)
services:
- name: netbird-relay
namespace: netbird
passHostHeader: true
port: 33080
- kind: Rule
match: Host(`vpn.dogar.dev`) && PathPrefix(`/management`)
services:
- name: netbird-management
namespace: netbird
passHostHeader: true
port: 80
scheme: h2c
- kind: Rule
match: Host(`vpn.dogar.dev`) && PathPrefix(`/signalexchange`)
services:
- name: netbird-signal
namespace: netbird
passHostHeader: true
port: 80
scheme: h2c
tls:
secretName: netbird-tls

View File

@@ -7,9 +7,10 @@ import {
RateLimitMiddleware, RateLimitMiddleware,
IpAllowListMiddleware, IpAllowListMiddleware,
IpAllowListMiddlewareTCP, IpAllowListMiddlewareTCP,
TLSOptions,
} from "./traefik"; } from "./traefik";
import { ValkeyCluster } from "./valkey"; import { ValkeyCluster } from "./valkey";
import { InternalIngressRoute } from "../utils"; import { InternalIngressRoute, PrivateCertificate } from "../utils";
export class NetworkSecurity extends TerraformStack { export class NetworkSecurity extends TerraformStack {
constructor(scope: Construct, id: string) { constructor(scope: Construct, id: string) {
@@ -67,6 +68,11 @@ export class NetworkSecurity extends TerraformStack {
name: "rate-limit", name: "rate-limit",
}); });
new TLSOptions(this, "tls-options", {
provider: kubernetes,
namespace,
});
new IpAllowListMiddleware(this, "internal-ip-allow-list", { new IpAllowListMiddleware(this, "internal-ip-allow-list", {
provider: kubernetes, provider: kubernetes,
namespace, namespace,
@@ -81,6 +87,15 @@ export class NetworkSecurity extends TerraformStack {
sourceRanges: ["192.168.18.0/24", "10.42.0.0/16"], sourceRanges: ["192.168.18.0/24", "10.42.0.0/16"],
}); });
new PrivateCertificate(this, "longhorn-cert", {
provider: kubernetes,
namespace: "longhorn-system",
name: "longhorn-ui",
dnsNames: ["longhorn.dogar.dev"],
commonName: "longhorn.dogar.dev",
secretName: "longhorn-tls",
});
new InternalIngressRoute(this, "longhorn-ui", { new InternalIngressRoute(this, "longhorn-ui", {
provider: kubernetes, provider: kubernetes,
namespace: "longhorn-system", namespace: "longhorn-system",
@@ -88,6 +103,16 @@ export class NetworkSecurity extends TerraformStack {
host: "longhorn.dogar.dev", host: "longhorn.dogar.dev",
serviceName: "longhorn-frontend", serviceName: "longhorn-frontend",
servicePort: 80, servicePort: 80,
tlsSecretName: "longhorn-tls",
});
new PrivateCertificate(this, "grafana-cert", {
provider: kubernetes,
namespace: "monitoring",
name: "grafana-ui",
dnsNames: ["grafana.dogar.dev"],
commonName: "grafana.dogar.dev",
secretName: "grafana-tls",
}); });
new InternalIngressRoute(this, "grafana-ui", { new InternalIngressRoute(this, "grafana-ui", {
@@ -97,6 +122,7 @@ export class NetworkSecurity extends TerraformStack {
host: "grafana.dogar.dev", host: "grafana.dogar.dev",
serviceName: "prometheus-operator-grafana", serviceName: "prometheus-operator-grafana",
servicePort: 80, servicePort: 80,
tlsSecretName: "grafana-tls",
}); });
} }
} }

View File

@@ -1,2 +1,3 @@
export { RateLimitMiddleware } from "./rateLimit"; export { RateLimitMiddleware } from "./rateLimit";
export { IpAllowListMiddleware, IpAllowListMiddlewareTCP } from "./ipAllowList"; export { IpAllowListMiddleware, IpAllowListMiddlewareTCP } from "./ipAllowList";
export { TLSOptions } from "./tlsOpts";

View File

@@ -7,8 +7,8 @@ type RateLimitMiddlewareOptions = {
namespace: string; namespace: string;
name: string; name: string;
average?: number; // default 10 average?: number; // default 60
burst?: number; // default 50 burst?: number; // default 120
period?: string; // default "1s" period?: string; // default "1s"
}; };
@@ -18,8 +18,8 @@ export class RateLimitMiddleware extends Construct {
constructor(scope: Construct, id: string, opts: RateLimitMiddlewareOptions) { constructor(scope: Construct, id: string, opts: RateLimitMiddlewareOptions) {
super(scope, id); super(scope, id);
const average = opts.average ?? 10; const average = opts.average ?? 60;
const burst = opts.burst ?? 50; const burst = opts.burst ?? 120;
const period = opts.period ?? "1s"; const period = opts.period ?? "1s";
this.ref = `${opts.namespace}/${opts.name}`; this.ref = `${opts.namespace}/${opts.name}`;

View File

@@ -0,0 +1,31 @@
import { Construct } from "constructs";
import { Manifest } from "@cdktf/provider-kubernetes/lib/manifest";
import { KubernetesProvider } from "@cdktf/provider-kubernetes/lib/provider";
export class TLSOptions extends Construct {
constructor(
scope: Construct,
id: string,
opts: { provider: KubernetesProvider; namespace: string },
) {
super(scope, id);
const { provider, namespace } = opts;
new Manifest(this, "traefik-tls-options", {
provider,
manifest: {
apiVersion: "traefik.io/v1alpha1",
kind: "TLSOption",
metadata: {
namespace,
name: "tls-options",
},
spec: {
minVersion: "VersionTLS13",
sniStrict: true,
},
},
});
}
}

View File

@@ -52,12 +52,9 @@ export class PKI extends TerraformStack {
provider: kubernetes, provider: kubernetes,
namespace, namespace,
apiVersion: "cert-manager.io/v1", apiVersion: "cert-manager.io/v1",
secretName: "root-secret", rootSecretName: "root-secret",
intermediateSecretName: `${namespace}-ca-secret`,
commonName: "Homelab Root CA", commonName: "Homelab Root CA",
privateKey: {
algorithm: "Ed25519",
size: 256,
},
}); });
new PublicIssuer(this, "public-issuer", { new PublicIssuer(this, "public-issuer", {

View File

@@ -7,11 +7,8 @@ type PrivateIssuerOptions = {
namespace: string; namespace: string;
apiVersion: string; apiVersion: string;
commonName: string; commonName: string;
secretName: string; rootSecretName: string;
privateKey: { intermediateSecretName: string;
algorithm: "RSA" | "ECDSA" | "Ed25519";
size: number;
};
}; };
export class PrivateIssuer extends Construct { export class PrivateIssuer extends Construct {
@@ -21,44 +18,41 @@ export class PrivateIssuer extends Construct {
const { const {
provider, provider,
namespace, namespace,
commonName,
privateKey,
secretName,
apiVersion, apiVersion,
commonName,
rootSecretName,
intermediateSecretName,
} = options; } = options;
// Self-signed ClusterIssuer for initial CA //
new Manifest(this, "ca-issuer", { // 1. Root CA (self-signed)
//
new Manifest(this, "root-ca-issuer", {
provider, provider,
manifest: { manifest: {
apiVersion, apiVersion,
kind: "ClusterIssuer", kind: "ClusterIssuer",
metadata: { metadata: { name: "root-ca-selfsigned" },
name: "ca-issuer", spec: { selfSigned: {} },
},
spec: {
selfSigned: {},
},
}, },
}); });
// Self-signed CA Certificate new Manifest(this, "root-ca", {
new Manifest(this, "selfsigned-ca", {
provider, provider,
manifest: { manifest: {
apiVersion, apiVersion,
kind: "Certificate", kind: "Certificate",
metadata: { metadata: { name: "root-ca", namespace },
name: "selfsigned-ca",
namespace,
},
spec: { spec: {
isCA: true, isCA: true,
commonName, commonName: `${commonName} Root CA`,
secretName, secretName: rootSecretName,
privateKey, privateKey: {
algorithm: "RSA",
size: 4096,
},
issuerRef: { issuerRef: {
name: "ca-issuer", name: "root-ca-selfsigned",
kind: "ClusterIssuer", kind: "ClusterIssuer",
group: "cert-manager.io", group: "cert-manager.io",
}, },
@@ -66,19 +60,55 @@ export class PrivateIssuer extends Construct {
}, },
}); });
// CA-based ClusterIssuer //
// 2. Intermediate CA (signed by root CA)
//
new Manifest(this, "intermediate-ca-issuer", {
provider,
manifest: {
apiVersion,
kind: "ClusterIssuer",
metadata: { name: "root-ca-signer" },
spec: {
ca: { secretName: rootSecretName },
},
},
});
new Manifest(this, "intermediate-ca", {
provider,
manifest: {
apiVersion,
kind: "Certificate",
metadata: { name: "intermediate-ca", namespace },
spec: {
isCA: true,
commonName: `${commonName} Intermediate CA`,
secretName: intermediateSecretName,
privateKey: {
algorithm: "ECDSA",
size: 384,
},
issuerRef: {
name: "root-ca-signer",
kind: "ClusterIssuer",
group: "cert-manager.io",
},
},
},
});
//
// 3. Final public cluster issuer (used by your apps)
//
new Manifest(this, "cluster-issuer", { new Manifest(this, "cluster-issuer", {
provider, provider,
manifest: { manifest: {
apiVersion, apiVersion,
kind: "ClusterIssuer", kind: "ClusterIssuer",
metadata: { metadata: { name: "cluster-issuer" },
name: "cluster-issuer",
},
spec: { spec: {
ca: { ca: { secretName: intermediateSecretName },
secretName,
},
}, },
}, },
}); });

View File

@@ -87,23 +87,8 @@ authentik:
server: server:
replicas: 3 replicas: 3
ingress:
enabled: false
annotations:
cert-manager.io/cluster-issuer: cloudflare-issuer
cert-manager.io/acme-challenge-type: dns01
cert-manager.io/private-key-size: "4096"
ingressClassName: traefik
hosts:
- auth.dogar.dev
tls:
- secretName: authentik-tls
hosts:
- auth.dogar.dev
worker: worker:
replicas: 3 replicas: 3
postgresql: postgresql:
enabled: false enabled: false
redis: redis:

View File

@@ -7,7 +7,6 @@ import {
OnePasswordSecret, OnePasswordSecret,
PublicIngressRoute, PublicIngressRoute,
IngressRouteTcp, IngressRouteTcp,
PrivateCertificate,
} from "../../../utils"; } from "../../../utils";
import type { Providers } from "../../../types"; import type { Providers } from "../../../types";
@@ -53,20 +52,6 @@ export class GiteaServer extends Construct {
itemPath: "vaults/Lab/items/cloudflare", itemPath: "vaults/Lab/items/cloudflare",
}); });
new PrivateCertificate(this, "internal-cert", {
provider: kubernetes,
namespace,
name: "gitea-tls-internal",
secretName: "gitea-tls-internal",
dnsNames: [
"git.dogar.dev",
"gitea",
"gitea.homelab.svc",
"gitea.homelab.svc.cluster.local",
],
usages: ["digital signature", "key encipherment", "server auth"],
});
new Release(this, id, { new Release(this, id, {
...options, ...options,
provider: helm, provider: helm,

View File

@@ -179,7 +179,7 @@ extraVolumes:
path: root.crt path: root.crt
- name: gitea-tls-internal - name: gitea-tls-internal
secret: secret:
secretName: gitea-tls-internal secretName: gitea-http-tls-internal
- name: gitea-temp - name: gitea-temp
emptyDir: {} emptyDir: {}
extraInitVolumeMounts: extraInitVolumeMounts:

View File

@@ -78,7 +78,7 @@ export class UtilityServices extends TerraformStack {
name: "postgres-cluster", name: "postgres-cluster",
namespace, namespace,
provider: kubernetes, provider: kubernetes,
users: ["shahab", "budget-tracker", "authentik", "gitea"], users: ["shahab", "budget-tracker", "authentik", "gitea", "netbird"],
primaryUser: "shahab", primaryUser: "shahab",
initSecretName: "postgres-password", initSecretName: "postgres-password",
backupR2EndpointURL: `https://${r2Endpoint}`, backupR2EndpointURL: `https://${r2Endpoint}`,

View File

@@ -357,6 +357,7 @@ export class PostgresCluster extends Construct {
{ {
name: "barman-cloud.cloudnative-pg.io", name: "barman-cloud.cloudnative-pg.io",
isWALArchiver: true, isWALArchiver: true,
enabled: true,
parameters: { parameters: {
barmanObjectName: barmanStoreName, barmanObjectName: barmanStoreName,
serverName: backupServerName, serverName: backupServerName,

View File

@@ -19,7 +19,7 @@ export class CloudflareCertificate extends Certificate {
constructor( constructor(
scope: Construct, scope: Construct,
id: string, id: string,
opts: Omit<CertificateOptions, "issuerRef">, opts: Omit<CertificateOptions, "issuerRef" | "privateKey">,
) { ) {
super(scope, id, { super(scope, id, {
...opts, ...opts,
@@ -27,6 +27,10 @@ export class CloudflareCertificate extends Certificate {
name: "cloudflare-issuer", name: "cloudflare-issuer",
kind: "ClusterIssuer", kind: "ClusterIssuer",
}, },
privateKey: {
algorithm: "RSA",
size: 4096,
},
}); });
} }
} }

View File

@@ -23,7 +23,7 @@ export class PrivateCertificate extends Certificate {
constructor( constructor(
scope: Construct, scope: Construct,
id: string, id: string,
opts: Omit<CertificateOptions, "issuerRef">, opts: Omit<CertificateOptions, "issuerRef" | "privateKey">,
) { ) {
super(scope, id, { super(scope, id, {
...opts, ...opts,
@@ -31,6 +31,11 @@ export class PrivateCertificate extends Certificate {
name: "cluster-issuer", // internal CA name: "cluster-issuer", // internal CA
kind: "ClusterIssuer", kind: "ClusterIssuer",
}, },
privateKey: {
algorithm: "ECDSA",
size: 384,
},
usages: ["digital signature", "key encipherment", "server auth"],
}); });
} }
} }

View File

@@ -2,7 +2,7 @@ import { Construct } from "constructs";
import { Manifest } from "@cdktf/provider-kubernetes/lib/manifest"; import { Manifest } from "@cdktf/provider-kubernetes/lib/manifest";
import { KubernetesProvider } from "@cdktf/provider-kubernetes/lib/provider"; import { KubernetesProvider } from "@cdktf/provider-kubernetes/lib/provider";
import { CloudflareCertificate } from "../../cert-manager"; import { PrivateCertificate } from "../../cert-manager";
export type IngressRouteOptions = { export type IngressRouteOptions = {
provider: KubernetesProvider; provider: KubernetesProvider;
@@ -43,6 +43,19 @@ export class IngressRoute extends Construct {
const { provider, namespace } = opts; const { provider, namespace } = opts;
if (opts.serviceProtocol === "https") { if (opts.serviceProtocol === "https") {
new PrivateCertificate(this, "internal-cert", {
provider,
namespace,
name: `${opts.serviceName}-tls-internal`,
secretName: `${opts.serviceName}-tls-internal`,
dnsNames: [
opts.serviceName,
`${opts.serviceName}.${opts.namespace}.svc`,
`${opts.serviceName}.${opts.namespace}.svc.cluster.local`,
],
usages: ["digital signature", "key encipherment", "server auth"],
});
new Manifest(this, `${name}-https-transport`, { new Manifest(this, `${name}-https-transport`, {
provider, provider,
manifest: { manifest: {
@@ -53,7 +66,7 @@ export class IngressRoute extends Construct {
namespace, namespace,
}, },
spec: { spec: {
serverName: `${opts.name}.${opts.namespace}.svc.cluster.local`, serverName: `${opts.serviceName}.${opts.namespace}.svc.cluster.local`,
rootCAs: [ rootCAs: [
{ {
secret: "root-secret", secret: "root-secret",
@@ -70,6 +83,7 @@ export class IngressRoute extends Construct {
kind: "Rule", kind: "Rule",
services: [ services: [
{ {
namespace,
name: opts.serviceName, name: opts.serviceName,
port: opts.servicePort, port: opts.servicePort,
scheme: opts.serviceProtocol ?? "http", scheme: opts.serviceProtocol ?? "http",
@@ -96,15 +110,11 @@ export class IngressRoute extends Construct {
if (opts.tlsSecretName) { if (opts.tlsSecretName) {
spec.tls = { spec.tls = {
secretName: opts.tlsSecretName, secretName: opts.tlsSecretName,
options: {
name: "tls-options",
namespace: "homelab",
},
}; };
new CloudflareCertificate(this, `${name}-cert`, {
provider,
namespace,
name: opts.host,
secretName: opts.tlsSecretName,
dnsNames: [opts.host],
});
} }
this.manifest = new Manifest(this, name, { this.manifest = new Manifest(this, name, {

View File

@@ -1,63 +1,16 @@
import { Construct } from "constructs"; import { Construct } from "constructs";
import { IngressRoute, IngressRouteOptions } from "./ingress"; import { IngressRoute, IngressRouteOptions } from "./ingress";
import { DataTerraformRemoteStateS3 } from "cdktf";
import { DataKubernetesNamespaceV1 } from "@cdktf/provider-kubernetes/lib/data-kubernetes-namespace-v1";
type InternalIngressRouteOptions = Omit< export class InternalIngressRoute extends IngressRoute {
IngressRouteOptions, constructor(
"entryPoints" | "tlsSecretName" | "middlewares" scope: Construct,
>; id: string,
opts: Omit<IngressRouteOptions, "entryPoints" | "middlewares">,
export class InternalIngressRoute extends Construct { ) {
constructor(scope: Construct, id: string, opts: InternalIngressRouteOptions) { super(scope, id, {
super(scope, id); ...opts,
const r2Endpoint = `${process.env.ACCOUNT_ID!}.r2.cloudflarestorage.com`;
const coreServicesState = new DataTerraformRemoteStateS3(
this,
"core-services-state",
{
usePathStyle: true,
skipRegionValidation: true,
skipCredentialsValidation: true,
skipRequestingAccountId: true,
skipS3Checksum: true,
encrypt: true,
bucket: "terraform-state",
key: "core-services/terraform.tfstate",
endpoints: {
s3: `https://${r2Endpoint}`,
},
region: "auto",
accessKey: process.env.ACCESS_KEY,
secretKey: process.env.SECRET_KEY,
},
);
const namespaceName = coreServicesState.getString("namespace-output");
const namespaceResource = new DataKubernetesNamespaceV1(
this,
"core-services-namespace",
{
provider: opts.provider,
metadata: {
name: namespaceName,
},
},
);
const namespace = namespaceResource.metadata.name;
new IngressRoute(this, opts.name, {
provider: opts.provider,
namespace: opts.namespace,
host: opts.host,
path: opts.path ?? "/",
serviceName: opts.serviceName,
servicePort: opts.servicePort,
entryPoints: ["websecure"], entryPoints: ["websecure"],
tlsSecretName: `${opts.name}-tls`, middlewares: ["homelab/ip-allow-list"],
middlewares: [`${namespace}/ip-allow-list`],
name: opts.name,
}); });
} }
} }

View File

@@ -1,64 +1,33 @@
import { Construct } from "constructs"; import { Construct } from "constructs";
import { IngressRoute, IngressRouteOptions } from "./ingress"; import { IngressRoute, IngressRouteOptions } from "./ingress";
import { DataTerraformRemoteStateS3 } from "cdktf"; import { CloudflareCertificate } from "../../cert-manager";
import { DataKubernetesNamespaceV1 } from "@cdktf/provider-kubernetes/lib/data-kubernetes-namespace-v1";
type PublicIngressRouteOptions = Omit< export class PublicIngressRoute extends IngressRoute {
constructor(
scope: Construct,
id: string,
opts: Omit<
IngressRouteOptions, IngressRouteOptions,
"entryPoints" | "tlsSecretName" | "middlewares" "entryPoints" | "tlsSecretName" | "middlewares"
>; >,
) {
const tlsSecretName = `${opts.name}-tls`;
export class PublicIngressRoute extends Construct { super(scope, id, {
constructor(scope: Construct, id: string, opts: PublicIngressRouteOptions) { ...opts,
super(scope, id); tlsSecretName,
const r2Endpoint = `${process.env.ACCOUNT_ID!}.r2.cloudflarestorage.com`;
const coreServicesState = new DataTerraformRemoteStateS3(
this,
"core-services-state",
{
usePathStyle: true,
skipRegionValidation: true,
skipCredentialsValidation: true,
skipRequestingAccountId: true,
skipS3Checksum: true,
encrypt: true,
bucket: "terraform-state",
key: "core-services/terraform.tfstate",
endpoints: {
s3: `https://${r2Endpoint}`,
},
region: "auto",
accessKey: process.env.ACCESS_KEY,
secretKey: process.env.SECRET_KEY,
},
);
const namespaceName = coreServicesState.getString("namespace-output");
const namespaceResource = new DataKubernetesNamespaceV1(
this,
"core-services-namespace",
{
provider: opts.provider,
metadata: {
name: namespaceName,
},
},
);
const namespace = namespaceResource.metadata.name;
new IngressRoute(this, opts.name, {
provider: opts.provider,
namespace: opts.namespace,
host: opts.host,
path: opts.path ?? "/",
serviceName: opts.serviceName,
servicePort: opts.servicePort,
serviceProtocol: opts.serviceProtocol,
entryPoints: ["websecure"], entryPoints: ["websecure"],
tlsSecretName: `${opts.name}-tls`, middlewares: ["homelab/rate-limit"],
middlewares: [`${namespace}/rate-limit`], });
name: opts.name,
const { provider, name, namespace, host } = opts;
new CloudflareCertificate(this, `${name}-cert`, {
provider,
namespace,
name: host,
secretName: tlsSecretName,
dnsNames: [host],
}); });
} }
} }