Skip to content

Commit 18dfeaa

Browse files
committed
add new "insert test mode" site setting
- it makes it so ANY account that gets created is an admin - soon it will add some UI element to emphasize the lack of security
1 parent 70f0a31 commit 18dfeaa

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/packages/database/settings/server-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export async function load_server_settings_from_env(
9090
db: PostgreSQL,
9191
): Promise<void> {
9292
const PREFIX = SERVER_SETTINGS_ENV_PREFIX;
93+
L.debug("load_server_settings_from_env variables prefixed by ", PREFIX);
9394
// reset all readonly values
9495
await db.async_query({
9596
query: "UPDATE server_settings",

src/packages/hub/hub.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { callback } from "awaiting";
1212
import blocked from "blocked";
1313
import { spawn } from "child_process";
1414
import { program as commander, Option } from "commander";
15-
1615
import basePath from "@cocalc/backend/base-path";
1716
import {
1817
pghost as DEFAULT_DB_HOST,
@@ -149,13 +148,14 @@ async function startServer(): Promise<void> {
149148
// in those cases where we initialize the database upon startup
150149
// (essentially only relevant for kucalc's hub-websocket)
151150
if (program.mode === "kucalc") {
152-
// set server settings based on environment variables
153-
await load_server_settings_from_env(database);
154151
// and for on-prem setups, also initialize the admin account, set a registration token, etc.
155152
await initialOnPremSetup(database);
156153
}
157154
}
158155

156+
// set server settings based on environment variables
157+
await load_server_settings_from_env(database);
158+
159159
if (program.agentPort) {
160160
winston.info("Configure agent port");
161161
set_agent_endpoint(program.agentPort, program.hostname);

src/packages/server/accounts/create-account.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import accountCreationActions, {
1010
creationActionsDone,
1111
} from "./account-creation-actions";
1212
import { getLogger } from "@cocalc/backend/logger";
13+
import { getServerSettings } from "@cocalc/database/settings/server-settings";
1314
const log = getLogger("server:accounts:create");
1415

1516
interface Params {
@@ -54,6 +55,15 @@ export default async function createAccount({
5455
signupReason,
5556
],
5657
);
58+
const { insecure_test_mode } = await getServerSettings();
59+
if (insecure_test_mode) {
60+
log.debug("Creating account in insecure_test_mode!");
61+
await pool.query("UPDATE accounts SET groups=$1 WHERE account_id=$2", [
62+
["admin"],
63+
account_id,
64+
]);
65+
}
66+
5767
if (email) {
5868
await accountCreationActions({ email_address: email, account_id, tags });
5969
}

src/packages/util/db-schema/site-defaults.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import jsonic from "jsonic";
99
import { isEqual } from "lodash";
10-
1110
import { LOCALE } from "@cocalc/util/consts/locale";
1211
import { is_valid_email_address } from "@cocalc/util/misc";
1312
import {
@@ -42,6 +41,7 @@ export const TAGS = [
4241
"Theme",
4342
"On-Prem",
4443
"I18N",
44+
"Security",
4545
] as const;
4646

4747
export type Tag = (typeof TAGS)[number];
@@ -116,7 +116,8 @@ export type SiteSettingsKeys =
116116
| "compute_servers_dns_enabled"
117117
| "compute_servers_dns"
118118
| "compute_servers_hyperstack_enabled"
119-
| "cloud_filesystems_enabled";
119+
| "cloud_filesystems_enabled"
120+
| "insecure_test_mode";
120121

121122
//| "compute_servers_lambda-cloud_enabled"
122123

@@ -953,4 +954,12 @@ export const site_settings_conf: SiteSettings = {
953954
to_bool(conf.compute_servers_dns_enabled),
954955
tags: ["Compute Servers"],
955956
},
957+
insecure_test_mode: {
958+
name: "Insecure Test Mode",
959+
desc: "Put this server in a highly insecure test mode that is suitable for evaluating CoCalc, but **CANNOT BE USED IN PRODUCTION**.",
960+
default: "no",
961+
valid: only_booleans,
962+
to_val: to_bool,
963+
tags: ["Security"],
964+
},
956965
} as const;

0 commit comments

Comments
 (0)