feat(client): implement per-client storage and security controls
- Added storage quota, IP allowlisting, and expiration logic to client management APIs. - Updated CSV storage manager to support auto-compression and improved partition file parsing. - Integrated security checks into event ingestion and data retrieval routes.
This commit is contained in:
1 parent
89e4d68690
commit
2873b9904a
32 files changed
+6075
-241
No files matched your search
@@ -47,6 +47,9 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
const [editClient, setEditClient] = useState<ClientItem | null>(null);
|
||||
const [editName, setEditName] = useState('');
|
||||
const [editRateLimit, setEditRateLimit] = useState('100');
|
||||
const [editStorageQuotaMb, setEditStorageQuotaMb] = useState('0');
|
||||
const [editAllowedIps, setEditAllowedIps] = useState('');
|
||||
const [editExpiresAt, setEditExpiresAt] = useState('');
|
||||
const [editError, setEditError] = useState('');
|
||||
const [processing, setProcessing] = useState(false);
|
||||
|
||||
@@ -59,6 +62,18 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
setEditClient(client);
|
||||
setEditName(client.name);
|
||||
setEditRateLimit(String(client.rateLimit || 100));
|
||||
setEditStorageQuotaMb(String(client.storageQuotaMb ?? 0));
|
||||
setEditAllowedIps(client.allowedIps || '');
|
||||
if (client.expiresAt) {
|
||||
const parsedDate = new Date(client.expiresAt);
|
||||
setEditExpiresAt(
|
||||
!Number.isNaN(parsedDate.getTime())
|
||||
? parsedDate.toISOString().slice(0, 16)
|
||||
: '',
|
||||
);
|
||||
} else {
|
||||
setEditExpiresAt('');
|
||||
}
|
||||
setEditError('');
|
||||
};
|
||||
|
||||
@@ -68,6 +83,9 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
|
||||
const trimmedName = editName.trim();
|
||||
const numericRateLimit = Number(editRateLimit);
|
||||
const numericQuotaMb = Number(
|
||||
editStorageQuotaMb.trim() === '' ? '0' : editStorageQuotaMb,
|
||||
);
|
||||
if (!trimmedName) {
|
||||
setEditError('Display name is required.');
|
||||
return;
|
||||
@@ -76,6 +94,19 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
setEditError('Rate limit must be an integer between 1 and 100,000 events/s.');
|
||||
return;
|
||||
}
|
||||
if (!Number.isInteger(numericQuotaMb) || numericQuotaMb < 0 || numericQuotaMb > 1048576) {
|
||||
setEditError('Storage quota must be an integer between 0 and 1,048,576 MB (0 = unlimited).');
|
||||
return;
|
||||
}
|
||||
let normalizedExpiresAt: string | null = null;
|
||||
if (editExpiresAt.trim()) {
|
||||
const parsedDate = new Date(editExpiresAt.trim());
|
||||
if (Number.isNaN(parsedDate.getTime())) {
|
||||
setEditError('Expiration date/time is invalid.');
|
||||
return;
|
||||
}
|
||||
normalizedExpiresAt = parsedDate.toISOString();
|
||||
}
|
||||
|
||||
setEditError('');
|
||||
setProcessing(true);
|
||||
@@ -86,6 +117,9 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
body: JSON.stringify({
|
||||
name: trimmedName,
|
||||
rateLimit: Math.floor(numericRateLimit),
|
||||
storageQuotaMb: Math.floor(numericQuotaMb),
|
||||
allowedIps: editAllowedIps.trim(),
|
||||
expiresAt: normalizedExpiresAt,
|
||||
}),
|
||||
});
|
||||
if (response.status === 401) {
|
||||
@@ -224,17 +258,32 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
) : (
|
||||
clients.map((client) => {
|
||||
const revoked = client.status === 'revoked';
|
||||
const online = client.status === 'active' && Boolean(client.lastActive) &&
|
||||
const expired =
|
||||
Boolean(client.expiresAt) &&
|
||||
now >= new Date(client.expiresAt!).getTime();
|
||||
const online =
|
||||
client.status === 'active' &&
|
||||
!expired &&
|
||||
Boolean(client.lastActive) &&
|
||||
now - new Date(client.lastActive!).getTime() < 60_000;
|
||||
const pending = client.status === 'active' && !client.lastActive;
|
||||
const label = revoked ? 'revoked' : pending ? 'pending' : online ? 'online' : 'offline';
|
||||
const dotClass = revoked
|
||||
? 'bg-[var(--danger)]'
|
||||
: online
|
||||
? 'bg-[var(--accent)]'
|
||||
const pending = client.status === 'active' && !expired && !client.lastActive;
|
||||
const label = revoked
|
||||
? 'revoked'
|
||||
: expired
|
||||
? 'expired'
|
||||
: pending
|
||||
? 'bg-[var(--warning)]'
|
||||
: 'bg-[var(--text-faint)]';
|
||||
? 'pending'
|
||||
: online
|
||||
? 'online'
|
||||
: 'offline';
|
||||
const dotClass =
|
||||
revoked || expired
|
||||
? 'bg-[var(--danger)]'
|
||||
: online
|
||||
? 'bg-[var(--accent)]'
|
||||
: pending
|
||||
? 'bg-[var(--warning)]'
|
||||
: 'bg-[var(--text-faint)]';
|
||||
|
||||
return (
|
||||
<TableRow key={client.clientId}>
|
||||
@@ -249,6 +298,11 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
revoked
|
||||
</span>
|
||||
)}
|
||||
{expired && (
|
||||
<span className="border border-[var(--danger)] bg-[var(--danger-soft)] px-1 py-0 text-[9px] uppercase tracking-wider text-[var(--danger)]">
|
||||
expired
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-0.5 truncate font-mono text-[10.5px] text-[var(--text-faint)]">{client.clientId}</div>
|
||||
</div>
|
||||
@@ -259,7 +313,11 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
{client.tokenPreview || 'JWT Active'}
|
||||
</div>
|
||||
<div className="mt-0.5 text-[10px] text-[var(--text-faint)]">
|
||||
{client.rateLimit}/s limit
|
||||
{client.rateLimit}/s · {(client.storageQuotaMb ?? 0) > 0 ? `${client.storageQuotaMb}MB quota` : 'Unlimited'}
|
||||
{client.allowedIps ? ` · IP: ${client.allowedIps}` : ''}
|
||||
{client.expiresAt
|
||||
? ` · Exp: ${new Date(client.expiresAt).toISOString().slice(0, 10)}`
|
||||
: ''}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono tabular-nums">
|
||||
@@ -375,6 +433,46 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
onChange={(event) => setEditRateLimit(event.target.value)}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Storage quota (MB, 0 = unlimited)"
|
||||
compact
|
||||
type="number"
|
||||
min="0"
|
||||
max="1048576"
|
||||
value={editStorageQuotaMb}
|
||||
onChange={(event) => setEditStorageQuotaMb(event.target.value)}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Allowed IPs / CIDR (blank = allow all)"
|
||||
compact
|
||||
value={editAllowedIps}
|
||||
onChange={(event) => setEditAllowedIps(event.target.value)}
|
||||
placeholder="203.0.113.10, 10.0.0.0/8"
|
||||
className="font-mono text-[11px]"
|
||||
/>
|
||||
<div className="flex items-end gap-1.5">
|
||||
<div className="min-w-0 flex-1">
|
||||
<Input
|
||||
label="Token expiration (optional)"
|
||||
compact
|
||||
type="datetime-local"
|
||||
value={editExpiresAt}
|
||||
onChange={(event) => setEditExpiresAt(event.target.value)}
|
||||
className="font-mono text-[11px]"
|
||||
/>
|
||||
</div>
|
||||
{editExpiresAt && (
|
||||
<Button
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
onClick={() => setEditExpiresAt('')}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{editError && (
|
||||
<p role="alert" className="text-[11px] text-[var(--danger)]">
|
||||
{editError}
|
||||
|
||||
@@ -33,7 +33,7 @@ interface StorageFile {
|
||||
modifiedAt: string;
|
||||
}
|
||||
|
||||
type ExportFormat = 'csv' | 'json';
|
||||
type ExportFormat = 'csv' | 'json' | 'ndjson';
|
||||
type RangePreset = 'today' | '7d' | '30d' | 'all' | 'custom';
|
||||
|
||||
function formatBytes(bytes: number) {
|
||||
@@ -368,7 +368,7 @@ export function ExportWorkspace() {
|
||||
Format
|
||||
</legend>
|
||||
<div
|
||||
className="grid grid-cols-2 gap-2"
|
||||
className="grid grid-cols-3 gap-2"
|
||||
role="radiogroup"
|
||||
aria-label="Export format"
|
||||
>
|
||||
@@ -384,6 +384,12 @@ export function ExportWorkspace() {
|
||||
label="JSON"
|
||||
onSelect={setFormat}
|
||||
/>
|
||||
<FormatOption
|
||||
value="ndjson"
|
||||
selected={format === 'ndjson'}
|
||||
label="NDJSON"
|
||||
onSelect={setFormat}
|
||||
/>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps
|
||||
const [clientId, setClientId] = useState('');
|
||||
const [name, setName] = useState('');
|
||||
const [rateLimit, setRateLimit] = useState('100');
|
||||
const [storageQuotaMb, setStorageQuotaMb] = useState('0');
|
||||
const [allowedIps, setAllowedIps] = useState('');
|
||||
const [expiresAt, setExpiresAt] = useState('');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [credentials, setCredentials] = useState<ClientCredentials | null>(null);
|
||||
|
||||
@@ -35,12 +38,33 @@ export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps
|
||||
error('Validation error', 'Rate limit must be an integer between 1 and 100,000 events/s.');
|
||||
return;
|
||||
}
|
||||
const numericQuotaMb = Number(storageQuotaMb.trim() === '' ? '0' : storageQuotaMb);
|
||||
if (!Number.isInteger(numericQuotaMb) || numericQuotaMb < 0 || numericQuotaMb > 1048576) {
|
||||
error('Validation error', 'Storage quota must be an integer between 0 and 1,048,576 MB (0 = unlimited).');
|
||||
return;
|
||||
}
|
||||
let normalizedExpiresAt: string | null = null;
|
||||
if (expiresAt.trim()) {
|
||||
const parsedDate = new Date(expiresAt.trim());
|
||||
if (Number.isNaN(parsedDate.getTime())) {
|
||||
error('Validation error', 'Token expiration must be a valid date/time.');
|
||||
return;
|
||||
}
|
||||
normalizedExpiresAt = parsedDate.toISOString();
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const response = await fetch('/api/clients', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ clientId: trimmedId, name: trimmedName, rateLimit: numericRate }),
|
||||
body: JSON.stringify({
|
||||
clientId: trimmedId,
|
||||
name: trimmedName,
|
||||
rateLimit: numericRate,
|
||||
storageQuotaMb: numericQuotaMb,
|
||||
allowedIps: allowedIps.trim(),
|
||||
expiresAt: normalizedExpiresAt,
|
||||
}),
|
||||
});
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
@@ -53,6 +77,9 @@ export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps
|
||||
setClientId('');
|
||||
setName('');
|
||||
setRateLimit('100');
|
||||
setStorageQuotaMb('0');
|
||||
setAllowedIps('');
|
||||
setExpiresAt('');
|
||||
onClose();
|
||||
success('Client registered', `${data.client.clientId} is ready to connect.`);
|
||||
await onCreated();
|
||||
@@ -103,6 +130,31 @@ export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps
|
||||
value={rateLimit}
|
||||
onChange={(event) => setRateLimit(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
compact
|
||||
label="Storage quota (MB, 0 = unlimited)"
|
||||
type="number"
|
||||
min="0"
|
||||
max="1048576"
|
||||
value={storageQuotaMb}
|
||||
onChange={(event) => setStorageQuotaMb(event.target.value)}
|
||||
/>
|
||||
<Input
|
||||
compact
|
||||
label="Allowed IPs / CIDR (blank = allow all)"
|
||||
placeholder="203.0.113.10, 10.0.0.0/8"
|
||||
value={allowedIps}
|
||||
onChange={(event) => setAllowedIps(event.target.value)}
|
||||
className="font-mono text-[11px]"
|
||||
/>
|
||||
<Input
|
||||
compact
|
||||
label="Token expiration (optional)"
|
||||
type="datetime-local"
|
||||
value={expiresAt}
|
||||
onChange={(event) => setExpiresAt(event.target.value)}
|
||||
className="font-mono text-[11px]"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -2,6 +2,9 @@ export interface ClientItem {
|
||||
clientId: string;
|
||||
name: string;
|
||||
rateLimit: number;
|
||||
storageQuotaMb?: number;
|
||||
allowedIps?: string;
|
||||
expiresAt?: string | null;
|
||||
status: "active" | "revoked";
|
||||
totalEvents: number;
|
||||
lastActive?: string;
|
||||
|
||||
Reference in new issue
Block a user