@mrsimpson/homelab-core-components 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # @mrsimpson/homelab-core-components
2
+
3
+ Reusable Pulumi components for deploying containerized applications.
4
+
5
+ ## What Goes Here
6
+
7
+ - **ExposedWebApp** - Component for deploying HTTP/HTTPS web applications
8
+ - Kubernetes Deployment + Service + Ingress
9
+ - Optional TLS (via cert-manager)
10
+ - Optional OAuth2 protection
11
+ - Optional persistent storage
12
+ - Security hardened by default
13
+
14
+ - **HomelabContext** - Dependency injection for infrastructure dependencies
15
+ - Wires together CloudFlare, cert-manager, ingress, secrets
16
+ - Provides convenient methods for app creation
17
+
18
+ ## Usage
19
+
20
+ ```typescript
21
+ import { ExposedWebApp, HomelabContext } from "@mrsimpson/homelab-core-components";
22
+
23
+ // ExposedWebApp component
24
+ const app = homelab.createExposedWebApp("my-app", {
25
+ image: "nginx:latest",
26
+ domain: "app.example.com",
27
+ port: 8080,
28
+ replicas: 2,
29
+ storage: {
30
+ size: "10Gi",
31
+ mountPath: "/data"
32
+ },
33
+ oauth: {
34
+ provider: "google",
35
+ clientId: "...",
36
+ clientSecret: "..."
37
+ }
38
+ });
39
+ ```
40
+
41
+ ## Publishing
42
+
43
+ This package can be published to npm for reuse in external Pulumi projects.
44
+
45
+ ```bash
46
+ npm publish
47
+ ```
@@ -0,0 +1,242 @@
1
+ import * as cloudflare from "@pulumi/cloudflare";
2
+ import * as k8s from "@pulumi/kubernetes";
3
+ import * as pulumi from "@pulumi/pulumi";
4
+ /**
5
+ * ExposedWebApp — reusable Pulumi component for deploying web apps with secure internet exposure.
6
+ *
7
+ * Handles the full stack: Deployment → Service → HTTPRoute/IngressRoute → TLS → DNS.
8
+ *
9
+ * ## Authentication modes
10
+ * - `AuthType.NONE` — no auth, public access
11
+ * - `AuthType.FORWARD` — Authelia forward-auth via Traefik ForwardAuth middleware
12
+ * - `AuthType.OAUTH2_PROXY` — GitHub OAuth via the shared oauth2-proxy IngressRoute
13
+ *
14
+ * ## What gets created automatically
15
+ * - `Namespace` (with Pod Security Standards labels, unless you pass your own)
16
+ * - `Deployment` + `Service` (ClusterIP)
17
+ * - `HTTPRoute` or `IngressRoute[]` depending on auth mode
18
+ * - Optional `PersistentVolumeClaim` (when `storage` is set)
19
+ * - Optional Cloudflare DNS `Record` (when `cloudflare` is set)
20
+ * - Optional `ExternalSecret` for GHCR pull credentials (when `imagePullSecrets` references `ghcr-pull-secret`)
21
+ *
22
+ * ## Key options
23
+ *
24
+ * ### Container overrides
25
+ * - `command` / `args` — override entrypoint / arguments (e.g. `args: ["web", "--port", "4096"]`)
26
+ *
27
+ * ### Extra volumes
28
+ * - `extraVolumes` / `extraVolumeMounts` — inject additional volumes (ConfigMaps, hostPath, etc.)
29
+ * alongside the built-in storage PVC mount.
30
+ *
31
+ * ### Node pinning
32
+ * - `nodeSelector` — pin the pod to specific node(s) by label.
33
+ * **Required when using hostPath volumes**, which are node-local by definition.
34
+ * Example: `{ "kubernetes.io/hostname": "flinker" }`
35
+ *
36
+ * ### Security context
37
+ * - `securityContext.runAsUser/Group/fsGroup` — UID/GID for the container and volume ownership.
38
+ * - `securityContext.allowRoot` — set to `true` only when the image genuinely requires UID 0.
39
+ * Automatically relaxes the namespace Pod Security Standard from `restricted` to `baseline`.
40
+ * Also disables `runAsNonRoot` on the pod and container security contexts.
41
+ * Prefer fixing the image to run as non-root instead of using this flag.
42
+ * - `extraVolumes` with `hostPath` — automatically relaxes the namespace PSS to `privileged`
43
+ * (the only level that permits hostPath volumes per the Kubernetes PSS spec).
44
+ * The pod itself still runs as non-root with all capabilities dropped.
45
+ *
46
+ * ### Service account
47
+ * - `serviceAccountName` — set the pod's ServiceAccount (must already exist in the namespace).
48
+ * Useful when the app needs RBAC permissions (e.g. managing pods via the K8s API).
49
+ *
50
+ * ### Health probes
51
+ * - `probes.readinessProbe` / `probes.livenessProbe` — standard Kubernetes probe objects
52
+ * applied to the main app container. Omit to use no probes (Kubernetes default).
53
+ *
54
+ * ## OAuth2-Proxy middleware naming
55
+ *
56
+ * When `auth` is `AuthType.OAUTH2_PROXY`, three Traefik middlewares are created in the
57
+ * app's namespace with deterministic names:
58
+ * - `<name>-oauth2-forwardauth` — ForwardAuth check against oauth2-proxy
59
+ * - `<name>-oauth2-errors` — 401 → redirect to sign-in
60
+ * - `<name>-oauth2-chain` — chains errors + forwardauth
61
+ *
62
+ * Apps that need **additional IngressRoutes** (e.g. wildcard subdomain routes) can
63
+ * reference the chain middleware by name to share the same auth flow:
64
+ * ```yaml
65
+ * middlewares:
66
+ * - name: <name>-oauth2-chain
67
+ * namespace: <app-namespace>
68
+ * ```
69
+ *
70
+ * ## Example
71
+ * ```typescript
72
+ * homelab.createExposedWebApp("blog", {
73
+ * image: "ghost:5",
74
+ * domain: pulumi.interpolate`blog.${homelabConfig.domain}`,
75
+ * port: 2368,
76
+ * auth: AuthType.OAUTH2_PROXY,
77
+ * storage: { size: "10Gi", mountPath: "/var/lib/ghost/content" },
78
+ * nodeSelector: { "kubernetes.io/hostname": "flinker" },
79
+ * extraVolumes: [{ name: "cfg", configMap: { name: "blog-config" } }],
80
+ * extraVolumeMounts: [{ name: "cfg", mountPath: "/etc/blog" }],
81
+ * });
82
+ * ```
83
+ */
84
+ /**
85
+ * Authentication type for ExposedWebApp
86
+ */
87
+ export declare enum AuthType {
88
+ /** No authentication required */
89
+ NONE = "none",
90
+ /** Authelia forward authentication via Traefik ForwardAuth middleware */
91
+ FORWARD = "forward",
92
+ /** OAuth2-Proxy authentication via GitHub OAuth (uses IngressRoute instead of HTTPRoute) */
93
+ OAUTH2_PROXY = "oauth2"
94
+ }
95
+ export interface StorageConfig {
96
+ size: string;
97
+ mountPath: string;
98
+ storageClass?: string;
99
+ }
100
+ export interface CloudflareConfig {
101
+ /** Cloudflare Zone ID for creating DNS records */
102
+ zoneId: string | pulumi.Output<string>;
103
+ /** CNAME value for DNS record (usually the Cloudflare Tunnel hostname) */
104
+ tunnelCname: string | pulumi.Output<string>;
105
+ }
106
+ export interface TLSConfig {
107
+ /** ClusterIssuer resource for automatic TLS certificate provisioning */
108
+ clusterIssuer?: k8s.apiextensions.CustomResource;
109
+ /** Name of the ClusterIssuer (if not providing the resource) */
110
+ clusterIssuerName?: string | pulumi.Output<string>;
111
+ }
112
+ export interface GatewayApiConfig {
113
+ /** Gateway class name (defaults to "traefik") */
114
+ gatewayClass?: string;
115
+ /** Gateway name (defaults to "homelab-gateway") */
116
+ gatewayName?: string;
117
+ /** Gateway namespace (defaults to "traefik-system") */
118
+ gatewayNamespace?: string;
119
+ /** ForwardAuth middleware name for authentication (defaults to "authelia-forwardauth") */
120
+ forwardAuthMiddleware?: string;
121
+ /** Gateway controller resource to depend on */
122
+ controller?: pulumi.Resource;
123
+ }
124
+ export interface ExternalSecretsConfig {
125
+ /** External Secrets Operator resource to depend on */
126
+ operator?: pulumi.Resource;
127
+ /** ClusterSecretStore name (defaults to "pulumi-esc") */
128
+ storeName?: string;
129
+ }
130
+ export interface OAuth2ProxyConfig {
131
+ /** Which oauth2-proxy group to use (defaults to "users") */
132
+ group?: string;
133
+ /** Namespace where oauth2-proxy is deployed (defaults to "oauth2-proxy") */
134
+ namespace?: string;
135
+ }
136
+ export interface ExposedWebAppArgs {
137
+ /** Container image to deploy */
138
+ image: string | pulumi.Output<string>;
139
+ /** Fully qualified domain name */
140
+ domain: string | pulumi.Output<string>;
141
+ /** Container port */
142
+ port: number;
143
+ /** Number of replicas (defaults to 1) */
144
+ replicas?: number;
145
+ /** Override the container entrypoint (maps to K8s container.command) */
146
+ command?: string[];
147
+ /** Container arguments (maps to K8s container.args) */
148
+ args?: string[];
149
+ /** Environment variables */
150
+ env?: Array<{
151
+ name: string;
152
+ value: string | pulumi.Output<string>;
153
+ }>;
154
+ /** Authentication type (defaults to "none") */
155
+ auth?: AuthType;
156
+ /** Persistent storage configuration */
157
+ storage?: StorageConfig;
158
+ /** Resource requests and limits */
159
+ resources?: {
160
+ requests?: {
161
+ cpu?: string;
162
+ memory?: string;
163
+ };
164
+ limits?: {
165
+ cpu?: string;
166
+ memory?: string;
167
+ };
168
+ };
169
+ /** Tags for organizing resources */
170
+ tags?: string[];
171
+ /** ImagePullSecrets for private container registries (e.g., GHCR, ECR) */
172
+ imagePullSecrets?: Array<{
173
+ name: string;
174
+ }>;
175
+ /** Security context configuration for pod and container */
176
+ securityContext?: {
177
+ runAsUser?: number;
178
+ runAsGroup?: number;
179
+ fsGroup?: number;
180
+ /**
181
+ * Set to true only when the container image requires root (UID 0) to function.
182
+ * This disables the `runAsNonRoot` enforcement on both the pod and container security
183
+ * contexts, and relaxes the namespace Pod Security Standard to "baseline".
184
+ * Use with caution — prefer fixing the image to run as non-root instead.
185
+ */
186
+ allowRoot?: boolean;
187
+ };
188
+ /** Optional pre-created namespace (if not provided, will create one) */
189
+ namespace?: k8s.core.v1.Namespace;
190
+ /**
191
+ * Pin the pod to specific node(s) using Kubernetes nodeSelector labels.
192
+ * Required when using hostPath volumes (which are node-local by definition).
193
+ * Example: { "kubernetes.io/hostname": "flinker" }
194
+ */
195
+ nodeSelector?: Record<string, string>;
196
+ /** Extra volumes to add to the pod spec (in addition to the optional storage PVC) */
197
+ extraVolumes?: object[];
198
+ /** Extra volume mounts to add to the app container (in addition to the optional storage mount) */
199
+ extraVolumeMounts?: object[];
200
+ /**
201
+ * Init containers to run before the main app container starts.
202
+ * Useful for seeding files into emptyDir volumes or other pre-start setup.
203
+ * Each entry is a full Kubernetes container spec object.
204
+ */
205
+ initContainers?: object[];
206
+ /**
207
+ * Additional sidecar containers to run alongside the main app container.
208
+ * Each entry is a full Kubernetes container spec object.
209
+ * Sidecars share the pod's ServiceAccount, imagePullSecrets, and network namespace.
210
+ * Useful for operator sidecars, log shippers, proxies, etc.
211
+ */
212
+ extraContainers?: object[];
213
+ /** ServiceAccount name to set on the pod spec (must already exist in the namespace) */
214
+ serviceAccountName?: string;
215
+ /** Container probes for the main app container */
216
+ probes?: {
217
+ readinessProbe?: object;
218
+ livenessProbe?: object;
219
+ };
220
+ /** Cloudflare DNS configuration */
221
+ cloudflare?: CloudflareConfig;
222
+ /** TLS/cert-manager configuration */
223
+ tls?: TLSConfig;
224
+ /** Gateway API configuration */
225
+ gatewayApi?: GatewayApiConfig;
226
+ /** External Secrets Operator configuration */
227
+ externalSecrets?: ExternalSecretsConfig;
228
+ /** OAuth2-Proxy configuration (required when auth is OAUTH2_PROXY) */
229
+ oauth2Proxy?: OAuth2ProxyConfig;
230
+ }
231
+ export declare class ExposedWebApp extends pulumi.ComponentResource {
232
+ readonly namespace: k8s.core.v1.Namespace;
233
+ readonly deployment: k8s.apps.v1.Deployment;
234
+ readonly service: k8s.core.v1.Service;
235
+ /** Route resource(s): single HTTPRoute (Authelia/NONE) or IngressRoute[] (OAuth2-Proxy) */
236
+ readonly route: k8s.apiextensions.CustomResource | k8s.apiextensions.CustomResource[];
237
+ readonly forwardAuthMiddleware?: k8s.apiextensions.CustomResource;
238
+ readonly dnsRecord?: cloudflare.Record;
239
+ readonly pvc?: k8s.core.v1.PersistentVolumeClaim;
240
+ constructor(name: string, args: ExposedWebAppArgs, opts?: pulumi.ComponentResourceOptions);
241
+ }
242
+ //# sourceMappingURL=ExposedWebApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExposedWebApp.d.ts","sourceRoot":"","sources":["../src/ExposedWebApp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,gBAAgB,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AAEH;;GAEG;AACH,oBAAY,QAAQ;IAClB,iCAAiC;IACjC,IAAI,SAAS;IACb,yEAAyE;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