Files
conversation-history/SquareMCP/2026-06-19-per-customer-vault-deployment-handoff.md

11 KiB

Per-Customer Vault Deployment Handoff

Date: 2026-06-19 Server: art0 Repo path: /home/garfield/hermes-mcp Vault folder: /home/garfield/obsidian/vaults/SquareMCP Status: ready for implementation agent

Objective

Implement and deploy per-customer vault isolation for SquareMCP Obsidian/Living Brief access.

The current security issue is that Obsidian access is authenticated but not tenant-scoped. The code uses one global vault path, and customer-authenticated requests can potentially reach the operator vault unless blocked elsewhere.

The fix must make every customer Obsidian read/search/write resolve through a server-owned customer vault binding.

Source Documents

Read these before editing code:

  1. /home/garfield/hermes-mcp/AGENTS.md
  2. /home/garfield/hermes-mcp/docs/per-customer-vault-design.md
  3. /home/garfield/hermes-mcp/DEPLOY.md
  4. /home/garfield/hermes-mcp/ARCHITECTURE.md
  5. /home/garfield/hermes-mcp/TODOS.md

If docs/per-customer-vault-design.md is missing on the server, copy it from the local working machine before starting implementation.

Production Safety Rules

This is a production server.

Do not start Docker containers, Docker Compose stacks, dev servers, or services that bind public or existing production ports.

Do not run:

  • docker compose up
  • docker run -p ...
  • npm run dev
  • any long-running process that binds a port
  • any command that restarts Docker, Traefik, MicroK8s, MySQL, Redis, Poste, or production app services without explicit approval

Do not interfere with:

  • Traefik on ports 80/443
  • MicroK8s workloads
  • MySQL on 127.0.0.1:3306
  • Redis on 127.0.0.1:6379
  • Poste/mail services
  • existing Docker containers

Allowed without extra approval:

  • npm test
  • npm run build
  • docker build with no published ports
  • docker push localhost:32000/...
  • read-only microk8s kubectl get/describe/logs

Deployment actions that restart the Hermes pod are allowed only after tests and build pass:

  • microk8s kubectl apply -f hermes-k8s.yaml
  • microk8s kubectl rollout status deployment/hermes-mcp -n fetcherpay

If a command might bind a port, create a bridge network, restart a service, or touch live infrastructure outside the Hermes deployment, stop and ask first.

Implementation Requirements

1. Add customer vault binding support

Add persistence for customer_vaults:

CREATE TABLE customer_vaults (
  customer_id VARCHAR(64) PRIMARY KEY,
  vault_root VARCHAR(512) NOT NULL,
  sync_folder_id VARCHAR(128) NULL,
  enabled BOOLEAN NOT NULL DEFAULT TRUE,
  readonly BOOLEAN NOT NULL DEFAULT FALSE,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

The application should use a server-owned base such as:

OBSIDIAN_CUSTOMER_VAULTS_ROOT=/vaults/customers

Customer requests must never supply an absolute vault root.

Missing or disabled binding must fail closed with 403.

2. Refactor Obsidian client

Replace global VAULT_PATH behavior with an explicit VaultContext:

export interface VaultContext {
  customerId: string;
  rootPath: string;
  syncFolderId?: string;
  readonly?: boolean;
}

Every operation must receive the context:

searchNotes(ctx, query, tags, limit, pathFilter)
getNote(ctx, path)
appendToNote(ctx, path, content, createIfMissing, header)
updateNote(ctx, path, content)
getSyncStatus(ctx)

Add one centralized path resolver:

  • Reject absolute paths.
  • Reject ../ traversal.
  • Reject symlink escapes where possible.
  • Add .md only after validation.
  • Ensure final path stays inside ctx.rootPath.
  • Return relative paths only.

3. Enforce authorization everywhere

Customer-facing Obsidian access requires all three:

  1. authenticated customer
  2. obsidian capability
  3. enabled customer vault binding

Apply this to:

  • /api/obsidian/search
  • /api/obsidian/note
  • /api/obsidian/note/append
  • /api/obsidian/sync
  • generic /mcp tool calls that invoke Obsidian tools
  • ChatGPT-style /hermes-mcp/:linkSegment/:toolName Obsidian tool calls, if those can reach the same tools

Legacy bearer tokens without customer binding must not access customer vault routes.

If global/operator vault access is kept, make it explicit and separate from customer vault access. Do not let customer auth fall back to the operator vault.

4. Tests required

Add or update:

  • src/clients/obsidian.test.ts
  • src/capability-routes.test.ts
  • src/tools.test.ts

Required regressions:

  • Customer A cannot search/read Customer B notes.
  • Customer with obsidian capability and enabled vault binding can access only their own notes.
  • Customer with no vault binding gets 403.
  • Customer without obsidian capability gets 403.
  • Legacy bearer token gets 403 for Obsidian customer vault access.
  • Absolute paths are rejected.
  • ../ traversal is rejected.
  • Symlink escape is rejected where possible.
  • Generic /mcp cannot bypass Obsidian authorization.

Verification Before Deployment

Run:

cd /home/garfield/hermes-mcp
npm test -- src/clients/obsidian.test.ts
npm test -- src/capability-routes.test.ts
npm test -- src/tools.test.ts
npm test
npm run build

Do not start the dev server.

Do not run Docker Compose.

Deployment Steps

Only do this after tests and build pass.

Hermes deployment pattern from the repo:

cd /home/garfield/hermes-mcp

# Build and push image. This must not publish ports.
docker build -t localhost:32000/hermes-mcp:latest .
docker push localhost:32000/hermes-mcp:latest

# Get pushed digest.
docker inspect localhost:32000/hermes-mcp:latest \
  --format='{{index .RepoDigests 0}}'

Update the gitignored production manifest:

/home/garfield/hermes-mcp/hermes-k8s.yaml

Change the Hermes image to the new digest form:

image: localhost:32000/hermes-mcp@sha256:<digest>

Never commit hermes-k8s.yaml. It contains plaintext secrets.

Apply and watch rollout:

microk8s kubectl apply -f hermes-k8s.yaml
microk8s kubectl rollout status deployment/hermes-mcp -n fetcherpay
microk8s kubectl get pods -n fetcherpay -l app=hermes-mcp

Post-Deploy Verification

Run read-only checks:

curl -fsS https://hermes.squaremcp.com/health
curl -fsS https://squaremcp.com/.well-known/ai-plugin.json >/tmp/squaremcp-plugin.json
microk8s kubectl logs -n fetcherpay -l app=hermes-mcp --tail=100

Verify security behavior with test credentials if available:

  • Customer without vault binding gets 403 on /api/obsidian/search.
  • Customer without obsidian capability gets 403.
  • Customer with valid binding can search only their configured test vault.
  • Absolute path and traversal attempts fail.

Do not test using real customer vault content unless explicitly authorized.

Rollback

If rollout fails:

  1. Do not restart unrelated services.
  2. Inspect Hermes pod logs:
microk8s kubectl logs -n fetcherpay -l app=hermes-mcp --tail=200
  1. Revert hermes-k8s.yaml image digest to the previous known-good digest.
  2. Re-apply only the Hermes manifest:
microk8s kubectl apply -f hermes-k8s.yaml
microk8s kubectl rollout status deployment/hermes-mcp -n fetcherpay

Kimi CLI Prompt

You are on production server art0. Work in `/home/garfield/hermes-mcp`.

Read these first:
- `AGENTS.md`
- `docs/per-customer-vault-design.md`
- `DEPLOY.md`
- `ARCHITECTURE.md`
- `TODOS.md`

Goal: implement and deploy per-customer vault isolation for SquareMCP Obsidian/Living Brief access.

Security problem:
- `src/clients/obsidian.ts` uses one global `VAULT_PATH`.
- Obsidian handlers in `src/tools.ts` ignore `customer`.
- `/api/obsidian/*` authenticates but is not enough for tenant isolation.
- Absolute note paths are currently accepted.
- Generic `/mcp` tool calls must not bypass Obsidian authorization.

Production safety:
- This is a production server.
- Do not start Docker containers, Docker Compose stacks, dev servers, or services that bind public or existing production ports.
- Do not run `docker compose up`, `docker run -p ...`, `npm run dev`, or any long-running port-binding process.
- Do not restart Docker, Traefik, MicroK8s, MySQL, Redis, Poste, or production app services unless explicitly instructed.
- Do not interfere with ports 80, 443, 3306, or 6379.
- If a command might bind a port, create a bridge network, restart a service, or touch live infrastructure outside the Hermes deployment, stop and ask first.
- `docker build` and `docker push localhost:32000/...` are allowed only for the Hermes deployment and must not publish ports.

Implement:
1. Add `customer_vaults` persistence and helpers. Customer vault roots are server-owned. Missing/disabled binding returns 403.
2. Refactor `src/clients/obsidian.ts` to require `VaultContext` for search/read/append/update/sync.
3. Add one safe path resolver. Reject absolute paths, `../` traversal, and symlink escapes where possible. Return relative paths only.
4. Enforce customer-facing Obsidian access requires authenticated customer + `obsidian` capability + enabled vault binding.
5. Apply enforcement to `/api/obsidian/*`, generic `/mcp` Obsidian tool execution, and ChatGPT-style tool routes if they can invoke Obsidian tools.
6. Legacy bearer tokens without customer binding must not access customer vault routes.
7. If global/operator vault access is kept, make it explicit and separate. Customer auth must never fall back to the operator vault.
8. Update stale docs/TODOs only where the implementation makes them inaccurate.

Tests:
- Add/update `src/clients/obsidian.test.ts`, `src/capability-routes.test.ts`, and `src/tools.test.ts`.
- Cover Customer A cannot access Customer B notes.
- Cover missing vault binding returns 403.
- Cover missing `obsidian` capability returns 403.
- Cover legacy bearer token returns 403 for Obsidian.
- Cover absolute path and `../` traversal rejection.
- Cover generic `/mcp` cannot bypass authorization.

Verification before deploy:
```bash
cd /home/garfield/hermes-mcp
npm test -- src/clients/obsidian.test.ts
npm test -- src/capability-routes.test.ts
npm test -- src/tools.test.ts
npm test
npm run build

Deployment after tests/build pass:

cd /home/garfield/hermes-mcp
docker build -t localhost:32000/hermes-mcp:latest .
docker push localhost:32000/hermes-mcp:latest
docker inspect localhost:32000/hermes-mcp:latest --format='{{index .RepoDigests 0}}'

Update gitignored /home/garfield/hermes-mcp/hermes-k8s.yaml to use:

image: localhost:32000/hermes-mcp@sha256:<new-digest>

Do not commit hermes-k8s.yaml.

Then:

microk8s kubectl apply -f hermes-k8s.yaml
microk8s kubectl rollout status deployment/hermes-mcp -n fetcherpay
microk8s kubectl get pods -n fetcherpay -l app=hermes-mcp
curl -fsS https://hermes.squaremcp.com/health
microk8s kubectl logs -n fetcherpay -l app=hermes-mcp --tail=100

Final response:

  • List files changed.
  • State exactly how tenant isolation is enforced.
  • State tests run and results.
  • State image digest deployed.
  • State post-deploy verification results.
  • State any remaining manual migration or credential steps.