swadhinbiswas feat: implement air-gapped mode, UI fixes, and project management integrations Β· 7/9/2026
e3bd4a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/**
* Environment Variable Validation
* Run this at application startup to ensure all required configuration is present
*/
import { logger } from "@/lib/logger";
interface EnvConfig {
name: string;
required: boolean;
defaultValue?: string;
validator?: (value: string) => boolean;
errorMessage?: string;
}
const envVars: EnvConfig[] = [
// Security (Critical)
{
name: "JWT_SECRET",
required: true,
validator: (v) => v.length >= 32,
errorMessage: "JWT_SECRET must be at least 32 characters for production security",
},
{
name: "SESSION_SECRET",
required: true,
validator: (v) => v.length >= 32,
errorMessage: "SESSION_SECRET must be at least 32 characters",
},
{
name: "INTERNAL_HOOK_SECRET",
required: true,
validator: (v) => v.length >= 16,
errorMessage: "INTERNAL_HOOK_SECRET must be set for git hook security",
},
{
name: "CRON_SECRET",
required: true,
validator: (v) => v.length >= 16,
errorMessage: "CRON_SECRET must be set for cron endpoint security",
},
{
name: "RUNNER_SECRET",
required: true,
validator: (v) => v.length >= 32,
errorMessage: "RUNNER_SECRET must be at least 32 characters",
},
{
name: "RUNNER_REGISTRATION_TOKEN_TTL_DAYS",
required: false,
validator: (v) => Number.isFinite(Number(v)) && Number(v) > 0,
errorMessage: "RUNNER_REGISTRATION_TOKEN_TTL_DAYS must be a positive number",
},
{
name: "AI_CONFIG_ENCRYPTION_KEY",
required: false,
validator: (v) => v.length >= 32,
errorMessage: "AI_CONFIG_ENCRYPTION_KEY should be at least 32 characters",
},
{
name: "WORKFLOW_SECRET_ENCRYPTION_KEY",
required: false,
validator: (v) => v.length >= 32,
errorMessage: "WORKFLOW_SECRET_ENCRYPTION_KEY should be at least 32 characters",
},
{
name: "REDIS_URL",
required: false,
validator: (v) => v.startsWith("redis://") || v.startsWith("rediss://"),
errorMessage: "REDIS_URL must be a valid redis:// or rediss:// URL",
},
// Application URLs (Critical)
{
name: "SITE_URL",
required: true,
validator: (v) => v.startsWith("http://") || v.startsWith("https://"),
errorMessage: "SITE_URL must be a valid URL (http:// or https://)",
},
// Database
{
name: "DATABASE_DRIVER",
required: false,
defaultValue: "sqlite",
},
{
name: "DATABASE_URL",
required: false,
defaultValue: "./data/opencodehub.db",
},
// Storage
{
name: "STORAGE_TYPE",
required: false,
defaultValue: "local",
validator: (v) => ["local", "s3"].includes(v.toLowerCase()),
errorMessage:
"STORAGE_TYPE must be one of: local, s3. (Other backends like Google Drive, OneDrive, Dropbox, FTP, Azure, GCS, rclone-as-adapter have been removed; use the s3 driver with a compatible endpoint for object storage, or local for a filesystem path.)",
},
{
name: "STORAGE_PATH",
required: false,
defaultValue: "./data/storage",
},
// S3 Storage (Required if STORAGE_TYPE=s3)
{
name: "STORAGE_BUCKET",
required: false,
},
{
name: "STORAGE_ENDPOINT",
required: false,
},
{
name: "STORAGE_ACCESS_KEY_ID",
required: false,
},
{
name: "STORAGE_SECRET_ACCESS_KEY",
required: false,
},
{
name: "STORAGE_REGION",
required: false,
defaultValue: "us-east-1",
},
// Git
{
name: "GIT_REPOS_PATH",
required: false,
defaultValue: "./data/repositories",
},
{
name: "GIT_SSH_PORT",
required: false,
defaultValue: "2222",
},
// Features
{
name: "ENABLE_REGISTRATION",
required: false,
defaultValue: "true",
},
{
name: "AIR_GAPPED_MODE",
required: false,
defaultValue: "false",
validator: (v) => ["0", "1", "true", "false", "yes", "no"].includes(v.toLowerCase()),
errorMessage: "AIR_GAPPED_MODE must be one of: true/false/1/0/yes/no",
},
// Grafana Cloud Loki
{
name: "LOKI_HOST",
required: false,
},
{
name: "LOKI_USER",
required: false,
},
{
name: "LOKI_PASSWORD",
required: false,
},
];
export function validateEnvironment(exitOnError: boolean = true): boolean {
logger.info("π Validating environment configuration...");
// Auto-configure all paths if DATA_DIR is provided (All-in-one VPS/NAS mode)
if (process.env.DATA_DIR) {
const dataDir = process.env.DATA_DIR.replace(/\/$/, "");
if (!process.env.DATABASE_URL) process.env.DATABASE_URL = `${dataDir}/opencodehub.db`;
if (!process.env.STORAGE_PATH) process.env.STORAGE_PATH = `${dataDir}/storage`;
if (!process.env.GIT_REPOS_PATH) process.env.GIT_REPOS_PATH = `${dataDir}/repositories`;
if (!process.env.SSH_HOST_KEY_PATH) process.env.SSH_HOST_KEY_PATH = `${dataDir}/ssh/host_key`;
logger.info(`π¦ DATA_DIR mode enabled. All local data mapped to ${dataDir}`);
}
const errors: string[] = [];
const warnings: string[] = [];
for (const config of envVars) {
const value = process.env[config.name];
// Check required variables
if (config.required && !value) {
errors.push(`β Missing required environment variable: ${config.name}`);
if (config.errorMessage) {
errors.push(` ${config.errorMessage}`);
}
continue;
}
// Apply defaults
if (!value && config.defaultValue) {
process.env[config.name] = config.defaultValue;
warnings.push(`β οΈ Using default for ${config.name}: ${config.defaultValue}`);
continue;
}
// Run custom validators
if (value && config.validator) {
if (!config.validator(value)) {
errors.push(`β Invalid value for ${config.name}`);
if (config.errorMessage) {
errors.push(` ${config.errorMessage}`);
}
}
}
}
// Security checks for production
if (process.env.NODE_ENV === "production") {
// Check for weak secrets
if (process.env.JWT_SECRET?.includes("change") || process.env.JWT_SECRET?.includes("dev")) {
errors.push("β JWT_SECRET appears to contain default/weak value. Change it for production!");
}
if (process.env.INTERNAL_HOOK_SECRET?.includes("dev") || process.env.INTERNAL_HOOK_SECRET?.includes("change")) {
errors.push("β INTERNAL_HOOK_SECRET appears to contain default value. Change it for production!");
}
if (process.env.CRON_SECRET?.includes("default") || process.env.CRON_SECRET?.includes("dev")) {
errors.push("β CRON_SECRET appears to contain default/weak value. Change it for production!");
}
if (!process.env.AI_CONFIG_ENCRYPTION_KEY && !process.env.APP_ENCRYPTION_KEY) {
errors.push("β AI_CONFIG_ENCRYPTION_KEY (or APP_ENCRYPTION_KEY) is required in production for encrypted AI config storage");
}
if (
!process.env.WORKFLOW_SECRET_ENCRYPTION_KEY &&
!process.env.APP_ENCRYPTION_KEY &&
!process.env.AI_CONFIG_ENCRYPTION_KEY
) {
errors.push("β WORKFLOW_SECRET_ENCRYPTION_KEY (or APP_ENCRYPTION_KEY) is required in production for encrypted workflow secret storage");
}
if (!process.env.REDIS_URL) {
errors.push("β REDIS_URL is required in production for distributed locking and rate limiting");
}
// Ensure HTTPS in production
if (process.env.SITE_URL && !process.env.SITE_URL.startsWith("https://")) {
warnings.push("β οΈ SITE_URL should use HTTPS in production");
}
}
if (["1", "true", "yes"].includes((process.env.AIR_GAPPED_MODE || "").toLowerCase())) {
warnings.push("β οΈ AIR_GAPPED_MODE is enabled: external integrations (AI/cloud/third-party webhooks) should be disabled");
}
// S3 Validation
if (process.env.STORAGE_TYPE === "s3") {
if (!process.env.STORAGE_BUCKET) errors.push("β STORAGE_BUCKET is required when STORAGE_TYPE is 's3'");
if (!process.env.STORAGE_ACCESS_KEY_ID) errors.push("β STORAGE_ACCESS_KEY_ID is required when STORAGE_TYPE is 's3'");
if (!process.env.STORAGE_SECRET_ACCESS_KEY) errors.push("β STORAGE_SECRET_ACCESS_KEY is required when STORAGE_TYPE is 's3'");
// Endpoint is optional for AWS S3 but required for MinIO/R2/Garage/etc.
}
// Print results
if (warnings.length > 0) {
logger.info("\nβ οΈ Warnings:");
warnings.forEach((w) => logger.info(w));
}
if (errors.length > 0) {
logger.error("\nβ Environment validation failed:");
errors.forEach((e) => logger.error(e));
logger.error("\nPlease fix the above errors before starting the application.");
logger.error("See .env.example for reference.\n");
if (exitOnError) {
process.exit(1);
}
return false;
}
logger.info("β
Environment validation passed\n");
return true;
}
// Auto-run validation if this file is executed directly
if (import.meta.url === `file://${process.argv[1]}`) {
validateEnvironment();
}