Files
wekan/models/cloudPanel.js
T
Lauri Ojansivu ac856dd38f Cloud Panel: only with the CLOUD environment variable; its Cloud Admins, customer login, support boards and allowed addresses.
CloudPanelBleed. Any site administrator of any WeKan could set the Cloud
Panel Domain and its SuperAdmin in Admin Panel / People / Cloud and then
make the server connect to any MongoDB server with credentials of their
choosing - Test connection and Import build a MongoClient from the
domain's database settings. A customer is the administrator of their own
WeKan container, so a customer could reach MongoDB servers on the internal
network.

The Cloud Panel now exists only where the server has CLOUD=<its domain>
(models/lib/cloudPanel.js cloudDomainFromEnv). The domain is never read
from the database, the browser or the REST API; the People / Cloud pane is
gone and cloudPanelGetSettings / cloudPanelSetSettings always refuse. Every
cloudPanel* method except cloudPanelWhoAmI passes the CLOUD gate before
anything else, its argument checks included, and the one MongoClient built
from data that is not the environment (withSource) has the gate in its own
body. A refusal is recorded in Admin Panel / Problems under the new keys
authz.cloud-panel-off, authz.cloud-panel-access and
authn.cloud-admin-address (bleed CloudPanelBleed; none disables an
account).

- Cloud Admins: on the CLOUD container its site administrators - the first
  registered user is one - not disabled, never a customer's account. They
  have Admin Panel / Cloud (/admin/cloud/<pane>, a tab shown only for a
  Cloud Admin at the CLOUD address): Domains, Invoices, Tickets, Chat,
  Cloudflare, Caddy, Allowed addresses. /cloud stays the customers' panel.
- Customer login: a password login handler, ahead of accounts-password's
  and after the timing normalization, only at the CLOUD address, only for a
  name exactly one domain with its own database lists, never for a name an
  account of the panel's own has. The password is checked against that
  customer's own database hash with Accounts._checkPasswordAsync, under an
  id no local account has; a disabled or password-less account there is
  refused, and so is a wrong 2FA code. On success a local non-admin account
  without a password, services.cloudCustomer, which sees exactly its own
  domain: info, invoices, tickets and chat.
- Support boards: one WeKan board per domain, "Support: <domain>", lists
  Open / In progress / Done for tickets and Chat with one card whose
  comments are the support chat (Board View / Chat shows them as a chat).
  Cloud Admins are board admins, customers Comment only: they read and
  comment but cannot create, edit, move, archive or delete a card nor
  manage the board; the panel adds their tickets into Open. The earlier
  cloudChatMessages are moved once into the chat card; imported
  Rocket.Chat and SandChat conversations go there too.
- Allowed addresses: IPv4, IPv6 and CIDR ranges (models/lib/cloudAddresses.js).
  When set, a Cloud Admin login (resume included) from elsewhere is refused
  and recorded, and so is a Cloud Admin method. A list without the saver's
  own address is refused; CLOUD_ADMIN_ANY_ADDRESS=true sets it aside for a
  locked-out operator.

Tests: tests/cloudPanel.test.cjs, tests/cloudAddresses.test.cjs,
tests/cloudPanelAccess.test.cjs (the real methods and login handler without
and with CLOUD), tests/cloudPanelGate.test.cjs (the MongoClient source scan),
server/lib/tests/cloudPanel.security.tests.js and
tests/playwright/specs/cloud-panel.e2e.js (negative without CLOUD; the
positive part runs with CLOUD=localhost WEKAN_TEST_CLOUD=true). The guards
that pin board inserts, comment inserts, card-reading paths, copy/move
methods, the Admin Panel tabs and method areas list the panel's support
board and its methods, with the reason.

Thanks to xet7 !
2026-11-22 18:49:51 +02:00

102 lines
5.3 KiB
JavaScript

// Cloud Panel (docs/Features/Admin-Panel/Cloud-Panel.md): the collections of
// the hosting operator's panel. Every write goes through a method in
// server/cloudPanel.js and nothing here is published: a database password or a
// Cloudflare token must never reach a browser, and a customer sees only their
// own invoices and chat, through those methods.
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { createdAtAutoValue, modifiedAtAutoValue } from '/models/lib/schemaTimestamps';
const { SimpleSchema } = require('/imports/simpleSchema');
const day = /^\d{4}-\d\d-\d\d$/;
// One document, _id 'cloud': Cloudflare, Caddy and the addresses a Cloud Admin
// may sign in from (models/lib/cloudPanel.js normalizeCloudflare,
// normalizeCaddy; models/lib/cloudAddresses.js). The panel's domain is NOT
// here: it is the CLOUD environment variable. `settings` is where an earlier
// version kept a domain and SuperAdmin set from the browser; nothing reads it.
export const CloudSettings = new Mongo.Collection('cloudSettings');
CloudSettings.attachSchema(new SimpleSchema({
settings: { type: Object, optional: true, blackbox: true },
allowedAddresses: { type: Array, optional: true, maxCount: 200 },
'allowedAddresses.$': { type: String, max: 60 },
cloudflare: { type: Object, optional: true, blackbox: true },
caddy: { type: Object, optional: true, blackbox: true },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
modifiedAt: { type: Date, optional: true, autoValue: modifiedAtAutoValue },
}));
// The customer domains: each with its own database and container, or shared
// with this WeKan as an Organization.
export const CloudDomains = new Mongo.Collection('cloudDomains');
CloudDomains.attachSchema(new SimpleSchema({
domain: { type: String, max: 253 },
customerName: { type: String, optional: true, max: 200 },
// As Weddy's Domains table has them: who the customer is, where their
// invoices go, and the hosting's first and last day.
customerEmail: { type: String, optional: true, max: 254 },
billingEmail: { type: String, optional: true, max: 254 },
startDate: { type: String, optional: true, regEx: day },
endDate: { type: String, optional: true, regEx: day },
mode: { type: String, allowedValues: ['own', 'shared'] },
upstream: { type: String, optional: true, max: 260 },
database: { type: Object, optional: true, blackbox: true },
customerUsernames: { type: Array, optional: true },
'customerUsernames.$': { type: String, max: 100 },
notes: { type: String, optional: true, max: 2000 },
cloudflare: { type: Boolean, optional: true },
// The Organization a shared domain is (models/org.js), and the last import.
orgId: { type: String, optional: true },
importedAt: { type: Date, optional: true },
importReport: { type: Object, optional: true, blackbox: true },
// Its support board (server/cloudPanel.js ensureSupportBoard):
// { boardId, swimlaneId, lists: { open, progress, done, chat }, chatCardId }.
support: { type: Object, optional: true, blackbox: true },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
modifiedAt: { type: Date, optional: true, autoValue: modifiedAtAutoValue },
}));
// The hosting invoices of a domain's customer, kept here - also the ones from
// before the panel, recorded by a Cloud Admin.
export const CloudInvoices = new Mongo.Collection('cloudInvoices');
CloudInvoices.attachSchema(new SimpleSchema({
domainId: { type: String },
number: { type: String, max: 50 },
issueDate: { type: String, regEx: day },
dueDate: { type: String, optional: true, regEx: day },
amountMinor: { type: Number, min: 0 },
currency: { type: String, regEx: /^[A-Z]{3}$/ },
status: { type: String, allowedValues: ['open', 'paid', 'void'] },
paidDate: { type: String, optional: true, regEx: day },
description: { type: String, optional: true, max: 1000 },
link: { type: String, optional: true, max: 500 },
createdBy: { type: String, optional: true },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
modifiedAt: { type: Date, optional: true, autoValue: modifiedAtAutoValue },
}));
// The chat of a domain's customer with the Cloud Admins, and the Rocket.Chat
// and SandChat conversations imported into it, as the panel kept it before the
// chat became the support board's chat card. Each message is copied there once
// and marked `migratedAt`; nothing new is written here.
export const CloudChatMessages = new Mongo.Collection('cloudChatMessages');
CloudChatMessages.attachSchema(new SimpleSchema({
domainId: { type: String },
userId: { type: String, optional: true },
authorName: { type: String, optional: true, max: 200 },
text: { type: String, max: 20000 },
// Where an imported message came from, and its room there.
source: { type: String, optional: true, allowedValues: ['rocketchat', 'sandchat'] },
room: { type: String, optional: true, max: 200 },
at: { type: Date },
migratedAt: { type: Date, optional: true },
createdAt: { type: Date, optional: true, autoValue: createdAtAutoValue },
}));
// No client writes, to any of them: the methods are the only way in.
if (Meteor.isServer) {
for (const collection of [CloudSettings, CloudDomains, CloudInvoices, CloudChatMessages]) {
collection.deny({ insert: () => true, update: () => true, remove: () => true });
}
}