fix(hardened): Restore RLS policies and remove hardcoded credentials (v3) - #479
Conversation
This commit restores critical security fixes that were lost in the 6-tier refactor (commit 8c22298) of feat/submodule-restructure. **Security Issues Fixed:** 1. **RLS Policies Deleted**: The 6-tier refactor deleted hardened RLS files: - pmoves/supabase/initdb/06_media_analysis.sql (restored) - pmoves/supabase/initdb/09_geometry_rls.sql (restored) - These tables had NO tenant isolation in base branch 2. **Hardcoded Credentials**: Base branch introduced actual credentials: - Replaced with empty values + REQUIRED comments - Added shell-style defaults for development compatibility **Changes:** - **RLS Hardening**: TO authenticated, removed 'pmoves' fallback - **Media Analysis**: detections, segments, emotions tables - **Geometry Bus**: anchors, constellations, shape_points, shape_index - **Env Files**: NEO4J_AUTH=neo4j/none, POSTGRES_PASSWORD with fallback **Security Impact:** - CRITICAL: Media and geometry tables were accessible without auth - MEDIUM: Hardcoded credentials in git (now removed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@coderabbitai review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis PR updates tiered environment configurations to replace hardcoded production secrets with development-friendly placeholders and defaults, adds GitHub Runner Controller configuration, introduces new database tables for media analysis and geometry bus structures, and implements row-level security (RLS) policies for tenant-scoped data isolation across Supabase. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pmoves/env.tier-worker (1)
36-36: AddOPEN_NOTEBOOK_PASSWORDto maintain token-password synchronization.The
OPEN_NOTEBOOK_API_TOKENon line 36 requires alignment withOPEN_NOTEBOOK_PASSWORD. AlthoughOPEN_NOTEBOOK_PASSWORDis defined inpmoves/env.shared.example, it should be explicitly present in this tier configuration so both values remain synchronized. The scriptpmoves/scripts/open_notebook_seed.pyrelies on either the token or password being available, and the Open Notebook integration requires they remain identical across all deployments (seepmoves/docs/services/open-notebook/README.md).Add
OPEN_NOTEBOOK_PASSWORD=and ensure both variables are set to the same value.
🤖 Fix all issues with AI agents
In @pmoves/supabase/sql/001_init.sql:
- Around line 1-3: Enable RLS on agent_memory, extractions, and studio_board by
issuing ALTER TABLE ... ENABLE ROW LEVEL SECURITY; ensure each table has a
tenant_id column (add it if missing) and create tenant-scoped policies (e.g.,
CREATE POLICY ... ON <table> FOR ALL TO authenticated USING (tenant_id =
auth.uid()) or the project’s JWT tenant claim expression) so only the owning
tenant can access rows; grant necessary privileges to the authenticated role and
add an index on tenant_id for performance.
In @pmoves/supabase/sql/007_geometry_bus.sql:
- Around line 4-49: All geometry tables are missing the tenant column used by
RLS; add a namespace column (text NOT NULL) to public.anchors,
public.constellations, public.shape_points and public.shape_index (e.g.,
namespace text NOT NULL DEFAULT current_setting('app.current_tenant', true)) in
their CREATE TABLE statements and then create indexes for fast filtering using
the names suggested: idx_anchors_namespace, idx_constellations_namespace,
idx_shape_points_namespace and idx_shape_index_namespace on the respective
namespace columns. Ensure the namespace column is included before any PRIMARY
KEY or FOREIGN KEY declarations so constraints and references remain valid.
🧹 Nitpick comments (1)
pmoves/supabase/initdb/06_media_analysis.sql (1)
72-78: Exception handler duplicates policy creation logic.The policy creation code is duplicated in the exception handler. Consider extracting to a helper function or using
CREATE OR REPLACE POLICYif supported by your PostgreSQL version (PG 15+).Alternative: Use DROP + CREATE unconditionally
DO $$ BEGIN + DROP POLICY IF EXISTS detections_tenant_isolation ON public.detections; CREATE POLICY detections_tenant_isolation ON public.detections FOR ALL TO authenticated USING (namespace = current_setting('app.current_tenant', true)) WITH CHECK (namespace = current_setting('app.current_tenant', true)); -EXCEPTION WHEN duplicate_object THEN - DROP POLICY IF EXISTS detections_tenant_isolation ON public.detections; - CREATE POLICY detections_tenant_isolation ON public.detections FOR ALL - TO authenticated - USING (namespace = current_setting('app.current_tenant', true)) - WITH CHECK (namespace = current_setting('app.current_tenant', true)); END $$;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
pmoves/env.tier-agentpmoves/env.tier-apipmoves/env.tier-datapmoves/env.tier-llmpmoves/env.tier-mediapmoves/env.tier-workerpmoves/supabase/initdb/06_media_analysis.sqlpmoves/supabase/initdb/09_geometry_rls.sqlpmoves/supabase/sql/001_init.sqlpmoves/supabase/sql/006_media_analysis.sqlpmoves/supabase/sql/007_geometry_bus.sql
🧰 Additional context used
📓 Path-based instructions (1)
**/{migrations,supabase}/**/*.sql
📄 CodeRabbit inference engine (GEMINI.md)
Perform Supabase RLS (Row-Level Security) hardening according to checklist
Files:
pmoves/supabase/sql/001_init.sqlpmoves/supabase/initdb/09_geometry_rls.sqlpmoves/supabase/sql/007_geometry_bus.sqlpmoves/supabase/sql/006_media_analysis.sqlpmoves/supabase/initdb/06_media_analysis.sql
🧠 Learnings (16)
📓 Common learnings
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-07T11:03:07.638Z
Learning: Applies to **/{migrations,supabase}/**/*.sql : Perform Supabase RLS (Row-Level Security) hardening according to checklist
📚 Learning: 2025-12-15T12:03:17.291Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-15T12:03:17.291Z
Learning: Applies to {.env,.env.local,pmoves/env.shared,pmoves/.env} : Never commit secrets; keep personal scratch in ignored files only, and store shared credentials in GitHub Actions secrets with environment scoping
Applied to files:
pmoves/env.tier-mediapmoves/env.tier-data
📚 Learning: 2025-12-15T12:03:17.291Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-15T12:03:17.291Z
Learning: Mandatory context before changes: read pmoves/docs/PMOVES.AI PLANS/ROADMAP.md and pmoves/docs/NEXT_STEPS.md to align with current sprint focus
Applied to files:
pmoves/env.tier-llmpmoves/env.tier-datapmoves/env.tier-agent
📚 Learning: 2025-12-07T11:03:07.638Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-07T11:03:07.638Z
Learning: Applies to **/pmoves/**/*{qwen,gemma,audio,summary}*.py : Integrate Qwen2-Audio provider and add Gemma summaries to PMOVES.YT endpoints
Applied to files:
pmoves/env.tier-llm
📚 Learning: 2025-12-07T11:03:07.638Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-07T11:03:07.638Z
Learning: Applies to **/{migrations,supabase}/**/*.sql : Perform Supabase RLS (Row-Level Security) hardening according to checklist
Applied to files:
pmoves/supabase/sql/001_init.sqlpmoves/supabase/initdb/09_geometry_rls.sqlpmoves/supabase/sql/006_media_analysis.sqlpmoves/supabase/initdb/06_media_analysis.sql
📚 Learning: 2025-12-15T12:03:17.291Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-15T12:03:17.291Z
Learning: Applies to pmoves/env.shared.example : Copy env.shared.example → env.shared and fill in secrets; never commit real secrets in env.shared
Applied to files:
pmoves/env.tier-data
📚 Learning: 2025-12-07T11:03:07.638Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-07T11:03:07.638Z
Learning: Applies to **/.env* : Update `.env` with new feature toggles for personas, packs, and geometry support
Applied to files:
pmoves/env.tier-data
📚 Learning: 2025-12-15T12:03:17.291Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-15T12:03:17.291Z
Learning: Applies to services/**/README.md : Update services/*/README.md and pmoves/docs/PMOVES.AI PLANS/ runbooks when touching service operational code
Applied to files:
pmoves/env.tier-agent
📚 Learning: 2025-12-15T12:03:17.291Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-15T12:03:17.291Z
Learning: Agents/Archon: for full-stack validation, follow the 'All Services Up, Then Tests' section in pmoves/docs/SMOKETESTS.md and the Archon service guide
Applied to files:
pmoves/env.tier-agent
📚 Learning: 2025-12-15T12:03:17.291Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-15T12:03:17.291Z
Learning: UI updates: run make -C pmoves notebook-workbench-smoke ARGS='--thread=<uuid>' to lint the Next.js bundle and validate Supabase connectivity; reference pmoves/docs/UI_NOTEBOOK_WORKBENCH.md
Applied to files:
pmoves/env.tier-agentpmoves/env.tier-worker
📚 Learning: 2025-12-07T11:03:53.415Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: pmoves/AGENTS.md:0-0
Timestamp: 2025-12-07T11:03:53.415Z
Learning: Applies to pmoves/services/{agent-zero,archon}/**/*.py : For Agents/Archon full-stack validation, follow the 'All Services Up, Then Tests' section in `pmoves/docs/SMOKETESTS.md` and use `make -C pmoves agents-headless-smoke`, `make -C pmoves smoke-gpu`, and `make -C pmoves verify-all`
Applied to files:
pmoves/env.tier-agent
📚 Learning: 2025-12-07T11:03:53.415Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: pmoves/AGENTS.md:0-0
Timestamp: 2025-12-07T11:03:53.415Z
Learning: Register MCP servers for Agent Zero with `A0_MCP_SERVERS` in `pmoves/env.shared` using format: fs: "mcp://filesystem?roots=/data"; archon: "mcp://http?endpoint=http://archon-server:8051"
Applied to files:
pmoves/env.tier-agent
📚 Learning: 2025-12-07T11:03:53.415Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: pmoves/AGENTS.md:0-0
Timestamp: 2025-12-07T11:03:53.415Z
Learning: Pin agent images by setting `AGENT_ZERO_IMAGE`, `ARCHON_IMAGE`, `ARCHON_UI_IMAGE`, and `PMOVES_YT_IMAGE` in `pmoves/env.shared`
Applied to files:
pmoves/env.tier-agent
📚 Learning: 2025-12-07T11:03:53.415Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: pmoves/AGENTS.md:0-0
Timestamp: 2025-12-07T11:03:53.415Z
Learning: Applies to pmoves/ui/**/*.{js,jsx,ts,tsx} : UI updates: run `make -C pmoves notebook-workbench-smoke ARGS="--thread=<uuid>"` to lint the Next.js bundle and validate Supabase connectivity; reference `pmoves/docs/UI_NOTEBOOK_WORKBENCH.md`
Applied to files:
pmoves/env.tier-worker
📚 Learning: 2025-12-07T11:03:53.415Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: pmoves/AGENTS.md:0-0
Timestamp: 2025-12-07T11:03:53.415Z
Learning: Branded Open Notebook deployments reuse the UI password as the API bearer token; keep `OPEN_NOTEBOOK_API_TOKEN` aligned with `OPEN_NOTEBOOK_PASSWORD`
Applied to files:
pmoves/env.tier-worker
📚 Learning: 2025-12-07T11:03:07.638Z
Learnt from: CR
Repo: POWERFULMOVES/PMOVES.AI PR: 0
File: GEMINI.md:0-0
Timestamp: 2025-12-07T11:03:07.638Z
Learning: Applies to **/pmoves/**/*{geometry,shape,cache,store}*.py : Confirm geometry bus emissions populate the ShapeStore cache
Applied to files:
pmoves/supabase/sql/007_geometry_bus.sql
🔇 Additional comments (17)
pmoves/env.tier-llm (1)
95-110: LGTM! Optional provider keys added appropriately.The three new provider keys (Moonshot AI, Venice AI, Z.AI) follow the established pattern of empty placeholders with descriptive comments, consistent with the file's security-conscious approach.
pmoves/env.tier-media (2)
10-13: LGTM! Hardcoded credentials properly removed.The MinIO credentials have been correctly replaced with empty placeholders and explicit production guidance, including the recommended
openssl rand -base64 32command for secure key generation.
20-20: LGTM! Service role key placeholder added.The Supabase service role key is now a placeholder, aligning with the PR's security hardening objectives.
pmoves/env.tier-worker (2)
24-27: LGTM! MinIO credentials properly secured.The hardcoded MinIO credentials have been correctly replaced with empty placeholders and production guidance, consistent with the security hardening approach across environment files.
32-32: LGTM! Service role key placeholder added.The Supabase service role key is now a placeholder, aligning with the PR's credential removal objectives.
pmoves/env.tier-agent (2)
19-21: LGTM! Service endpoints updated to use Kong gateway.The Supabase endpoints have been consistently updated to route through
supabase_kong_PMOVES.AI:8000instead of directpostgrest:3000access. This routing through Kong provides better API management, rate limiting, and security controls.Also applies to: 52-52
67-74: LGTM! GitHub Runner Controller configuration added.The GitHub Runner Controller configuration is properly structured with sensible defaults (INFO log level, 60-second refresh interval) and correctly references the repository. No sensitive tokens are hardcoded, which aligns with the PR's security objectives.
pmoves/env.tier-api (2)
12-19: Good security practice: credentials cleared with generation guidance.The hardcoded production secrets have been properly replaced with empty values and clear
opensslcommands for production deployment. This aligns with the PR objective of removing hardcoded credentials.
45-51: Neo4j configuration added correctly.The new Neo4j connection block follows the same pattern as other credentials in this file. Consider adding a note that
NEO4J_AUTHformat should matchNEO4J_USER/NEO4J_PASSWORD(i.e.,neo4j/<password>).pmoves/env.tier-data (2)
14-16: Shell-style defaults may not expand in all contexts.The syntax
${POSTGRES_PASSWORD:-pmoves_dev}relies on shell expansion. Verify this works with your Docker Compose version and environment file loading mechanism—some versions require explicit shell evaluation.
20-22: Development auth disabled correctly.Using
neo4j/nonedisables Neo4j authentication for local development, which is appropriate for health check compatibility as noted.pmoves/supabase/initdb/06_media_analysis.sql (2)
54-61: Correctly hardened: anonymous grants removed and RLS enabled.Good security posture—anonymous access is commented out, and RLS is enabled on all three tables. This ensures data access requires authentication. Based on coding guidelines for Supabase RLS hardening.
67-79: Tenant isolation policy correctly implemented.The policy enforces namespace-based isolation with
TO authenticated. Note: whenapp.current_tenantis unset,current_setting(..., true)returns NULL, causingnamespace = NULLto fail (NULL ≠ NULL in SQL). This is secure-by-default behavior—access denied until tenant is explicitly set.pmoves/supabase/sql/006_media_analysis.sql (1)
1-1: Clarify deployment scope for dev RLS file.This file is labeled "dev RLS" but contradicts the hardened policies in
initdb/06_media_analysis.sql. Ensure this file is excluded from production deployments. Consider adding a prominent warning or deploying only the hardened version.pmoves/supabase/initdb/09_geometry_rls.sql (2)
5-13: Verifypmoves_uirole can access data with RLS enabled.The
pmoves_uirole is granted SELECT on the geometry tables, but the RLS policies only applyTO authenticated. When RLS is enabled, this role won't match any policy and will be denied access (unless usingBYPASSRLSorSECURITY DEFINERfunctions).If this role is intended for direct DB queries (non-Supabase), either:
- Add a separate policy
TO pmoves_ui, or- Grant
BYPASSRLSto the role (less secure), or- Document that this role must use service-role connections
21-47: Read policies correctly implement tenant isolation.Good RLS implementation: SELECT-only policies with namespace isolation via
app.current_tenant. The hardened approach (no fallback, authenticated only) aligns with PR objectives and coding guidelines.pmoves/supabase/sql/007_geometry_bus.sql (1)
51-60: Indexes are well-designed for query patterns.Good index coverage for lookups (modality, ref_id), time-based queries, FK traversal, and JSONB metadata filtering via GIN indexes.
| create table if not exists agent_memory(id bigserial primary key); | ||
| create table if not exists extractions(id bigserial primary key); | ||
| create table if not exists studio_board(id bigserial primary key); |
There was a problem hiding this comment.
CRITICAL: Missing RLS policies on Supabase tables.
These three tables (agent_memory, extractions, studio_board) are created without Row-Level Security (RLS) policies, leaving them completely open to all authenticated users. This directly violates the coding guidelines and contradicts the PR's stated objective to restore RLS policies.
According to the PR summary, other SQL files (06_media_analysis.sql, 09_geometry_rls.sql) correctly implement RLS policies for tenant isolation. This file should follow the same pattern.
Required actions:
- Enable RLS on each table:
ALTER TABLE <table_name> ENABLE ROW LEVEL SECURITY; - Define appropriate policies for tenant isolation (typically "TO authenticated" with tenant_id checks)
- Grant necessary privileges (e.g., to authenticated role)
- Consider adding indexes if these tables will store significant data
As per coding guidelines, all Supabase tables must implement RLS hardening.
🔒 Proposed RLS hardening template
-- Enable RLS on all tables
ALTER TABLE agent_memory ENABLE ROW LEVEL SECURITY;
ALTER TABLE extractions ENABLE ROW LEVEL SECURITY;
ALTER TABLE studio_board ENABLE ROW LEVEL SECURITY;
-- Example tenant-scoped policy (adjust based on your tenant_id column)
-- Note: You'll need to add tenant_id column first if using tenant isolation
CREATE POLICY "Users can access their own data"
ON agent_memory
FOR ALL
TO authenticated
USING (tenant_id = auth.uid());
-- Repeat for other tables with appropriate policies🤖 Prompt for AI Agents
In @pmoves/supabase/sql/001_init.sql around lines 1 - 3, Enable RLS on
agent_memory, extractions, and studio_board by issuing ALTER TABLE ... ENABLE
ROW LEVEL SECURITY; ensure each table has a tenant_id column (add it if missing)
and create tenant-scoped policies (e.g., CREATE POLICY ... ON <table> FOR ALL TO
authenticated USING (tenant_id = auth.uid()) or the project’s JWT tenant claim
expression) so only the owning tenant can access rows; grant necessary
privileges to the authenticated role and add an index on tenant_id for
performance.
| GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.detections TO anon; | ||
| GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.segments TO anon; | ||
| GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.emotions TO anon; | ||
|
|
||
| ALTER TABLE public.detections ENABLE ROW LEVEL SECURITY; | ||
| ALTER TABLE public.segments ENABLE ROW LEVEL SECURITY; | ||
| ALTER TABLE public.emotions ENABLE ROW LEVEL SECURITY; | ||
|
|
||
| DO $$ BEGIN | ||
| CREATE POLICY detections_anon_all ON public.detections FOR ALL TO anon USING (true) WITH CHECK (true); | ||
| EXCEPTION WHEN duplicate_object THEN NULL; END $$; | ||
| DO $$ BEGIN | ||
| CREATE POLICY segments_anon_all ON public.segments FOR ALL TO anon USING (true) WITH CHECK (true); | ||
| EXCEPTION WHEN duplicate_object THEN NULL; END $$; | ||
| DO $$ BEGIN | ||
| CREATE POLICY emotions_anon_all ON public.emotions FOR ALL TO anon USING (true) WITH CHECK (true); | ||
| EXCEPTION WHEN duplicate_object THEN NULL; END $$; |
There was a problem hiding this comment.
Security concern: anon role granted full access with permissive RLS.
This grants SELECT, INSERT, UPDATE, DELETE to anon with USING (true) policies, allowing unrestricted access to all rows. This directly contradicts the hardened RLS in initdb/06_media_analysis.sql which:
- Removes anon grants (commented out)
- Restricts to
authenticatedrole only - Enforces tenant isolation via
namespace
If both files can be applied, the order matters—whichever runs last wins. Per coding guidelines for RLS hardening, ensure the production deployment path only uses the hardened version.
#!/bin/bash
# Verify which SQL files are applied during deployment and their order
echo "=== Checking for deployment scripts referencing these SQL files ==="
rg -n "006_media_analysis" --type-add 'deploy:*.{sh,yaml,yml,json,toml}' --type deploy
rg -n "initdb.*sql" --type-add 'deploy:*.{sh,yaml,yml,json,toml}' --type deploy
echo "=== Checking docker-compose or init scripts ==="
fd -e yaml -e yml | xargs grep -l "initdb\|\.sql" 2>/dev/null | head -10| CREATE TABLE IF NOT EXISTS public.anchors ( | ||
| id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| kind text NOT NULL CHECK (kind IN ('text','audio','video','image','latent','multi')), | ||
| dim integer NOT NULL CHECK (dim > 0), | ||
| anchor float4[] NULL, | ||
| anchor_enc jsonb NULL, | ||
| meta jsonb NOT NULL DEFAULT '{}'::jsonb, | ||
| created_at timestamptz NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS public.constellations ( | ||
| id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| anchor_id uuid NOT NULL REFERENCES public.anchors(id) ON DELETE CASCADE, | ||
| summary text NULL, | ||
| radial_min double precision NULL, | ||
| radial_max double precision NULL, | ||
| spectrum float4[] NULL, | ||
| meta jsonb NOT NULL DEFAULT '{}'::jsonb, | ||
| created_at timestamptz NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS public.shape_points ( | ||
| id uuid PRIMARY KEY DEFAULT gen_random_uuid(), | ||
| constellation_id uuid NOT NULL REFERENCES public.constellations(id) ON DELETE CASCADE, | ||
| modality text NOT NULL CHECK (modality IN ('text','audio','video','image','latent')), | ||
| ref_id text NOT NULL, | ||
| t_start double precision NULL, | ||
| t_end double precision NULL, | ||
| frame_idx integer NULL, | ||
| token_start integer NULL, | ||
| token_end integer NULL, | ||
| proj double precision NULL, | ||
| conf double precision NULL, | ||
| meta jsonb NOT NULL DEFAULT '{}'::jsonb, | ||
| created_at timestamptz NOT NULL DEFAULT now() | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS public.shape_index ( | ||
| shape_id uuid NOT NULL, | ||
| modality text NOT NULL, | ||
| ref_id text NOT NULL, | ||
| loc_hash text NOT NULL, | ||
| meta jsonb NOT NULL DEFAULT '{}'::jsonb, | ||
| created_at timestamptz NOT NULL DEFAULT now(), | ||
| PRIMARY KEY (shape_id, modality, ref_id, loc_hash) | ||
| ); |
There was a problem hiding this comment.
Critical: Missing namespace column required by RLS policies.
The RLS policies in initdb/09_geometry_rls.sql filter on namespace = current_setting('app.current_tenant', true), but these tables do not define a namespace column. This will cause runtime errors when the policies are evaluated.
Add a namespace column to each table for tenant isolation:
Proposed fix: Add namespace column to all geometry tables
CREATE TABLE IF NOT EXISTS public.anchors (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
+ namespace text NOT NULL DEFAULT 'pmoves',
kind text NOT NULL CHECK (kind IN ('text','audio','video','image','latent','multi')),
...
);
CREATE TABLE IF NOT EXISTS public.constellations (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
+ namespace text NOT NULL DEFAULT 'pmoves',
anchor_id uuid NOT NULL REFERENCES public.anchors(id) ON DELETE CASCADE,
...
);
CREATE TABLE IF NOT EXISTS public.shape_points (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
+ namespace text NOT NULL DEFAULT 'pmoves',
constellation_id uuid NOT NULL REFERENCES public.constellations(id) ON DELETE CASCADE,
...
);
CREATE TABLE IF NOT EXISTS public.shape_index (
shape_id uuid NOT NULL,
+ namespace text NOT NULL DEFAULT 'pmoves',
modality text NOT NULL,
...
);Also add indexes for namespace filtering:
CREATE INDEX IF NOT EXISTS idx_anchors_namespace ON public.anchors (namespace);
CREATE INDEX IF NOT EXISTS idx_constellations_namespace ON public.constellations (namespace);
CREATE INDEX IF NOT EXISTS idx_shape_points_namespace ON public.shape_points (namespace);
CREATE INDEX IF NOT EXISTS idx_shape_index_namespace ON public.shape_index (namespace);🤖 Prompt for AI Agents
In @pmoves/supabase/sql/007_geometry_bus.sql around lines 4 - 49, All geometry
tables are missing the tenant column used by RLS; add a namespace column (text
NOT NULL) to public.anchors, public.constellations, public.shape_points and
public.shape_index (e.g., namespace text NOT NULL DEFAULT
current_setting('app.current_tenant', true)) in their CREATE TABLE statements
and then create indexes for fast filtering using the names suggested:
idx_anchors_namespace, idx_constellations_namespace, idx_shape_points_namespace
and idx_shape_index_namespace on the respective namespace columns. Ensure the
namespace column is included before any PRIMARY KEY or FOREIGN KEY declarations
so constraints and references remain valid.
Restored pmoves/supabase/initdb/07_geometry_bus.sql with CREATE TABLE statements for anchors, constellations, shape_points, shape_index. This file contains the core CHIT Geometry Bus schema and was missed in the initial v3 commit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
CHIT Contract Check Results (Local)Due to VPS runner being offline (3+ hours), ran CHIT contract checks locally. Results
Files VerifiedSchema:
RLS Policies:
Environment Security:
Recommendation✅ Merge approved. The CHIT contract checks that can run locally pass:
Submodule-specific checks (geometry.cgp.v1 event, CHIT env vars) will be validated when submodules are initialized during service bring-up. |
586e9dd
into
feat/submodule-restructure
…(v3) (#479) * fix(hardened): Restore RLS policies and env security fixes v3 This commit restores critical security fixes that were lost in the 6-tier refactor (commit 8c22298) of feat/submodule-restructure. **Security Issues Fixed:** 1. **RLS Policies Deleted**: The 6-tier refactor deleted hardened RLS files: - pmoves/supabase/initdb/06_media_analysis.sql (restored) - pmoves/supabase/initdb/09_geometry_rls.sql (restored) - These tables had NO tenant isolation in base branch 2. **Hardcoded Credentials**: Base branch introduced actual credentials: - Replaced with empty values + REQUIRED comments - Added shell-style defaults for development compatibility **Changes:** - **RLS Hardening**: TO authenticated, removed 'pmoves' fallback - **Media Analysis**: detections, segments, emotions tables - **Geometry Bus**: anchors, constellations, shape_points, shape_index - **Env Files**: NEO4J_AUTH=neo4j/none, POSTGRES_PASSWORD with fallback **Security Impact:** - CRITICAL: Media and geometry tables were accessible without auth - MEDIUM: Hardcoded credentials in git (now removed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(hardened): Add missing geometry bus schema Restored pmoves/supabase/initdb/07_geometry_bus.sql with CREATE TABLE statements for anchors, constellations, shape_points, shape_index. This file contains the core CHIT Geometry Bus schema and was missed in the initial v3 commit. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Codex Agent <codex-agent@example.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Summary
This PR restores critical security fixes that were lost in the 6-tier refactor of
feat/submodule-restructure.🔴 Critical Security Issues Fixed
RLS Policies Deleted - The 6-tier refactor (commit
8c22298f) deleted hardened RLS files:pmoves/supabase/initdb/06_media_analysis.sql(media analysis tables)pmoves/supabase/initdb/09_geometry_rls.sql(geometry bus tables)Hardcoded Credentials - Base branch introduced actual credentials in env files:
POSTGRES_PASSWORD=A7sX9kL2mN4pQ8rT...(hardcoded password)NEO4J_AUTH=neo4j/7kJtbpJ1n1x...(hardcoded password)Changes
06_media_analysis.sql,09_geometry_rls.sqlTO authenticated, removed'pmoves'fallbackpmoves/env.tier-*env.tier-data${VAR:-default})Security Posture
detectionsTO authenticatedsegmentsTO authenticatedemotionsTO authenticatedanchorsTO authenticatedconstellationsTO authenticatedshape_pointsTO authenticatedshape_indexTO authenticatedTest Plan
Context
feat/submodule-restructure🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Security
Configuration
✏️ Tip: You can customize this high-level summary in your review settings.