Introduce spawner app with sandboxing support and client protocol implementation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
571f43457d
commit
7b1df2607e
26 files changed
+2438
-5
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import type { SpawnerConfig } from './config.ts';
|
||||
import { containerSpec } from './sandbox.ts';
|
||||
|
||||
const config: SpawnerConfig = {
|
||||
dockerSocket: '/docker.sock',
|
||||
listenSocket: '/spawner.sock',
|
||||
image: 'registry/homepage-sandbox@sha256:abc',
|
||||
contentDir: '/srv/content',
|
||||
statusDir: '/srv/status',
|
||||
maxSandboxes: 16,
|
||||
allowNonGvisor: false,
|
||||
};
|
||||
|
||||
describe('containerSpec', () => {
|
||||
const spec = containerSpec(config, 'session123', 1_800_000_000);
|
||||
const host = spec.HostConfig;
|
||||
|
||||
it('isolates the sandbox', () => {
|
||||
expect(host.Privileged).toBe(false);
|
||||
expect(host.ReadonlyRootfs).toBe(true);
|
||||
expect(host.NetworkMode).toBe('none');
|
||||
expect(spec.NetworkDisabled).toBe(true);
|
||||
expect(host.CapDrop).toEqual(['ALL']);
|
||||
expect(host.SecurityOpt).toContain('no-new-privileges');
|
||||
expect(spec.User).toBe('guest');
|
||||
});
|
||||
|
||||
it('limits resources', () => {
|
||||
expect(host.Memory).toBe(80 * 1024 * 1024);
|
||||
expect(host.MemorySwap).toBe(host.Memory);
|
||||
expect(host.NanoCpus).toBe(500_000_000);
|
||||
expect(host.PidsLimit).toBe(50);
|
||||
expect(host.LogConfig.Type).toBe('none');
|
||||
});
|
||||
|
||||
it('mounts host paths read only', () => {
|
||||
expect(host.Binds).toEqual(['/srv/content:/srv/www:ro', '/srv/status:/var/status:ro']);
|
||||
expect(Object.values(host.Tmpfs).every((options) => options.includes('noexec'))).toBe(true);
|
||||
});
|
||||
|
||||
it('passes only the session id and expiry into the container', () => {
|
||||
expect(spec.Env).toEqual(['SESSION_ID=session123', 'SESSION_EXPIRES_AT=1800000000', 'TERM=xterm-256color']);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user