@omnibase/cli 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ -- Add relations_metadata JSONB column to permissions.definitions
2
+ -- Stores enriched relation metadata including JSDoc annotations (@group, @subGroup, @displayName, @role)
3
+ ALTER TABLE permissions.definitions
4
+ ADD COLUMN IF NOT EXISTS relations_metadata JSONB DEFAULT '[]';
5
+
6
+ -- Create GIN index for efficient JSONB queries on relations_metadata
7
+ CREATE INDEX IF NOT EXISTS idx_definitions_relations_metadata ON permissions.definitions USING GIN(relations_metadata);
@@ -0,0 +1,92 @@
1
+ -- Migration: rls-permission-helpers
2
+ -- Description: Add auth.has_relation() for ReBAC-based RLS policies and
3
+ -- replace auth.active_user_role() with DB lookup.
4
+ --
5
+ -- auth.has_relation() queries Keto relation tuples directly in the database,
6
+ -- enabling ReBAC checks in RLS policies. This uses the same source of truth
7
+ -- as the API middleware permission checks (keto_service.go / rbac.go).
8
+ --
9
+ -- auth.active_user_role() is updated to query permissions.roles directly,
10
+ -- so role changes take effect immediately without requiring a new JWT.
11
+
12
+ -- Grant anon_user read access to the permissions schema.
13
+ -- The permissions schema is NOT in PGRST_DB_SCHEMAS, so these tables are not
14
+ -- directly queryable via PostgREST — they can only be accessed through auth.* functions.
15
+ GRANT USAGE ON SCHEMA permissions TO anon_user;
16
+ GRANT SELECT ON permissions.roles TO anon_user;
17
+
18
+ -- Keto creates keto_relation_tuples AFTER our migrations run, so we can't GRANT
19
+ -- on it directly. ALTER DEFAULT PRIVILEGES grants SELECT on any future tables
20
+ -- created in the permissions schema (by postgres, which is also Keto's DB user).
21
+ ALTER DEFAULT PRIVILEGES IN SCHEMA permissions GRANT SELECT ON TABLES TO anon_user;
22
+
23
+ -- Replace auth.active_user_role() to query the database instead of JWT claims.
24
+ -- Looks up the user's role_name from permissions.roles using tenant_id + user_id.
25
+ CREATE OR REPLACE FUNCTION auth.active_user_role()
26
+ RETURNS text AS $$
27
+ BEGIN
28
+ RETURN (
29
+ SELECT role_name FROM permissions.roles
30
+ WHERE tenant_id = auth.active_tenant_id()::uuid
31
+ AND auth.user_id()::uuid = ANY(user_ids)
32
+ LIMIT 1
33
+ );
34
+ END;
35
+ $$ LANGUAGE plpgsql STABLE;
36
+
37
+ -- Check if the current user has a relation (permission) on a specific resource.
38
+ -- Queries Keto relation tuples directly — the same source of truth the API uses.
39
+ --
40
+ -- Usage in RLS policies:
41
+ -- auth.has_relation('Tenant', tenant_id::text, 'delete_tenant')
42
+ -- auth.has_relation('Storage', tenant_id::text, 'manage_all')
43
+ -- auth.has_relation('Project', project_id::text, 'view')
44
+ CREATE OR REPLACE FUNCTION auth.has_relation(
45
+ check_namespace text,
46
+ check_object text,
47
+ check_relation text
48
+ ) RETURNS boolean AS $$
49
+ BEGIN
50
+ RETURN EXISTS(
51
+ SELECT 1 FROM permissions.keto_relation_tuples t
52
+ JOIN permissions.keto_uuid_mappings obj_map
53
+ ON t.object = obj_map.id AND obj_map.string_representation = check_object
54
+ JOIN permissions.keto_uuid_mappings sub_map
55
+ ON sub_map.string_representation = auth.user_id()
56
+ WHERE t.namespace = check_namespace
57
+ AND t.relation = check_relation
58
+ AND (
59
+ t.subject_id = sub_map.id
60
+ OR (t.subject_set_namespace = 'User' AND t.subject_set_object = sub_map.id)
61
+ )
62
+ );
63
+ END;
64
+ $$ LANGUAGE plpgsql STABLE;
65
+
66
+ -- Check if the current user has ANY of the specified relations on a resource.
67
+ -- Single query for multiple relations — more efficient than multiple has_relation() calls.
68
+ --
69
+ -- Usage in RLS policies:
70
+ -- auth.has_any_relation('StorageObject', id::text, ARRAY['owner', 'can_read'])
71
+ -- auth.has_any_relation('StorageObject', id::text, ARRAY['owner', 'can_delete'])
72
+ CREATE OR REPLACE FUNCTION auth.has_any_relation(
73
+ check_namespace text,
74
+ check_object text,
75
+ check_relations text[]
76
+ ) RETURNS boolean AS $$
77
+ BEGIN
78
+ RETURN EXISTS(
79
+ SELECT 1 FROM permissions.keto_relation_tuples t
80
+ JOIN permissions.keto_uuid_mappings obj_map
81
+ ON t.object = obj_map.id AND obj_map.string_representation = check_object
82
+ JOIN permissions.keto_uuid_mappings sub_map
83
+ ON sub_map.string_representation = auth.user_id()
84
+ WHERE t.namespace = check_namespace
85
+ AND t.relation = ANY(check_relations)
86
+ AND (
87
+ t.subject_id = sub_map.id
88
+ OR (t.subject_set_namespace = 'User' AND t.subject_set_object = sub_map.id)
89
+ )
90
+ );
91
+ END;
92
+ $$ LANGUAGE plpgsql STABLE;
@@ -0,0 +1,38 @@
1
+ -- Migration: storage-rebac-rls
2
+ -- Description: Replace path-based storage RLS with ReBAC policies.
3
+ --
4
+ -- Default policies are minimal — users add more permissive policies for
5
+ -- tenant-wide access etc. PostgreSQL permissive policies are OR'd:
6
+ -- if ANY policy passes, the row is visible.
7
+
8
+ -- Drop all old path-based and column-based policies
9
+ DROP POLICY IF EXISTS storage_objects_public_read ON storage.objects;
10
+ DROP POLICY IF EXISTS storage_objects_public_insert ON storage.objects;
11
+ DROP POLICY IF EXISTS storage_objects_user_all ON storage.objects;
12
+ DROP POLICY IF EXISTS storage_objects_tenant_read ON storage.objects;
13
+
14
+ -- INSERT: tenant members can create files (Keto can't check — object doesn't exist yet)
15
+ CREATE POLICY storage_objects_insert ON storage.objects
16
+ FOR INSERT TO anon_user
17
+ WITH CHECK (
18
+ tenant_id::text = auth.active_tenant_id()
19
+ AND user_id::text = auth.user_id()
20
+ );
21
+
22
+ -- SELECT: owner or can_read via Keto (default — minimal)
23
+ -- Users can add additional permissive policies for tenant-wide access
24
+ -- e.g. auth.has_relation('Tenant', tenant_id::text, 'manage_all')
25
+ CREATE POLICY storage_objects_read ON storage.objects
26
+ FOR SELECT TO anon_user
27
+ USING (
28
+ tenant_id::text = auth.active_tenant_id()
29
+ AND auth.has_any_relation('StorageObject', id::text, ARRAY['owner', 'can_read'])
30
+ );
31
+
32
+ -- DELETE: owner or can_delete via Keto (safety net — Go handler also checks Keto)
33
+ CREATE POLICY storage_objects_delete ON storage.objects
34
+ FOR DELETE TO anon_user
35
+ USING (
36
+ tenant_id::text = auth.active_tenant_id()
37
+ AND auth.has_any_relation('StorageObject', id::text, ARRAY['owner', 'can_delete'])
38
+ );
@@ -0,0 +1,8 @@
1
+
2
+ ALTER TABLE storage.objects ADD COLUMN is_public BOOLEAN NOT NULL DEFAULT FALSE;
3
+
4
+ CREATE INDEX idx_storage_objects_is_public ON storage.objects (is_public) WHERE is_public = TRUE;
5
+
6
+ CREATE POLICY storage_objects_public_read ON storage.objects
7
+ FOR SELECT TO anon_user
8
+ USING (is_public = TRUE);
@@ -29,7 +29,7 @@ services:
29
29
  DATABASE_URL: postgres://postgres:postgres@postgres:5432/db
30
30
  AUTH_TYPE: scram-sha-256
31
31
  volumes:
32
- - ./pgbouncer/pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini:ro
32
+ - ./pgbouncer/pgbouncer.ini:/etc/pgbouncer/pgbouncer.ini:z
33
33
  depends_on:
34
34
  postgres:
35
35
  condition: service_healthy
@@ -45,7 +45,7 @@ services:
45
45
  db-migrate:
46
46
  image: migrate/migrate:latest
47
47
  volumes:
48
- - ./db:/migrations
48
+ - ./db:/migrations:z
49
49
  command:
50
50
  [
51
51
  "-path",
@@ -61,7 +61,7 @@ services:
61
61
  condition: service_healthy
62
62
 
63
63
  auth-migrate:
64
- image: phoenixsolutionsgroup/omnibase-auth:0.4.0
64
+ image: phoenixsolutionsgroup/omnibase-auth:0.4.1
65
65
  environment:
66
66
  - DSN=postgres://postgres:postgres@postgres:5432/db?sslmode=disable&max_conns=20&max_idle_conns=4&search_path=auth
67
67
  - AUTH_JWT_JWKS=${AUTH_JWT_JWKS-{}}
@@ -82,7 +82,7 @@ services:
82
82
  - auth-migrate
83
83
  - rest-api
84
84
  - pgbouncer
85
- image: phoenixsolutionsgroup/omnibase-auth:0.4.0
85
+ image: phoenixsolutionsgroup/omnibase-auth:0.4.1
86
86
  restart: unless-stopped
87
87
  env_file:
88
88
  - ${OMNIBASE_ENV_FILE}
@@ -213,7 +213,7 @@ services:
213
213
 
214
214
  # REST API Service
215
215
  rest-api:
216
- image: phoenixsolutionsgroup/omnibase-api:0.17.0
216
+ image: phoenixsolutionsgroup/omnibase-api:0.19.0
217
217
  ports:
218
218
  - "8080:8080"
219
219
  depends_on:
@@ -270,10 +270,12 @@ services:
270
270
  - LOG_LEVEL=${LOG_LEVEL:-TRACE}
271
271
  - LOG_FORMAT=${LOG_FORMAT:-pretty}
272
272
 
273
+ - CORS_ALLOWED_ORIGINS=${CORS_ALLOWED_ORIGINS:-*}
274
+
273
275
  - AUTH_JWT_JWKS=${AUTH_JWT_JWKS}
274
276
 
275
277
  permissions-migrate:
276
- image: phoenixsolutionsgroup/omnibase-permissions:0.3.0
278
+ image: phoenixsolutionsgroup/omnibase-permissions:0.4.0
277
279
  environment:
278
280
  - DSN=postgres://postgres:postgres@postgres:5432/db?sslmode=disable&max_conns=20&max_idle_conns=4&search_path=permissions
279
281
  command: migrate up -c /etc/config/permissions/permissions.yml --yes
@@ -291,7 +293,7 @@ services:
291
293
  depends_on:
292
294
  - permissions-migrate
293
295
  - pgbouncer
294
- image: phoenixsolutionsgroup/omnibase-permissions:0.3.0
296
+ image: phoenixsolutionsgroup/omnibase-permissions:0.4.0
295
297
  restart: unless-stopped
296
298
  environment:
297
299
  - DSN=postgres://permissions:permissions@pgbouncer:6432/db?sslmode=disable&max_conns=20&max_idle_conns=4
@@ -324,7 +326,7 @@ services:
324
326
  image: oven/bun:latest
325
327
  working_dir: /app
326
328
  volumes:
327
- - ${OMNIBASE_PROJECT_DIR}/omnibase/workers:/app
329
+ - ${OMNIBASE_PROJECT_DIR}/omnibase/workers:/app:z
328
330
  ports:
329
331
  - "8787:8787"
330
332
  environment:
@@ -9,6 +9,8 @@ services:
9
9
  - type: bind
10
10
  source: ../../../docker/auth
11
11
  target: /etc/config/auth
12
+ bind:
13
+ selinux: z
12
14
 
13
15
  auth:
14
16
  image: ""
@@ -19,6 +21,8 @@ services:
19
21
  - type: bind
20
22
  source: ../../../docker/auth
21
23
  target: /etc/config/auth
24
+ bind:
25
+ selinux: z
22
26
 
23
27
  rest-api:
24
28
  image: ""
@@ -28,7 +32,7 @@ services:
28
32
  environment:
29
33
  - ENABLE_PPROF=true
30
34
  volumes:
31
- - ../../../apps/api:/app
35
+ - ../../../apps/api:/app:z
32
36
 
33
37
  permissions-migrate:
34
38
  image: ""
@@ -9,6 +9,8 @@ services:
9
9
  - type: bind
10
10
  source: ../../../docker/auth
11
11
  target: /etc/config/auth
12
+ bind:
13
+ selinux: z
12
14
 
13
15
  auth:
14
16
  image: ""
@@ -19,6 +21,8 @@ services:
19
21
  - type: bind
20
22
  source: ../../../docker/auth
21
23
  target: /etc/config/auth
24
+ bind:
25
+ selinux: z
22
26
 
23
27
  rest-api:
24
28
  image: ""
@@ -28,7 +32,7 @@ services:
28
32
  environment:
29
33
  - ENABLE_PPROF=true
30
34
  volumes:
31
- - ../../../apps/api:/app
35
+ - ../../../apps/api:/app:z
32
36
 
33
37
  permissions-migrate:
34
38
  image: ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnibase/cli",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "OmniBase CLI - Manage Docker Compose services and environment configuration",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
33
  "@inquirer/prompts": "^8.1.0",
34
- "@omnibase/core-js": "0.17.0",
34
+ "@omnibase/core-js": "0.18.1",
35
35
  "@ory/client": "^1.14.3",
36
36
  "adm-zip": "^0.5.16",
37
37
  "axios": "^1.6.0",
@@ -0,0 +1,50 @@
1
+ import { Tenant, User } from "./tenants";
2
+ import { Context, Namespace } from "./types";
3
+
4
+ export class StorageObject implements Namespace {
5
+ related: {
6
+ /**
7
+ * @group Storage Objects
8
+ * @displayName Owner
9
+ * @hidden
10
+ */
11
+ owner: User[];
12
+
13
+ /**
14
+ * @group Storage Objects
15
+ * @displayName Read Access
16
+ */
17
+ can_read: User[];
18
+
19
+ /**
20
+ * @group Storage Objects
21
+ * @displayName Delete Access
22
+ */
23
+ can_delete: User[];
24
+
25
+ /**
26
+ * @group Storage Objects
27
+ * @displayName Make Public
28
+ */
29
+ can_make_public: User[];
30
+
31
+ /**
32
+ * @hidden — parent link for OPL traversal
33
+ */
34
+ tenant: Tenant[];
35
+ };
36
+
37
+ permits = {
38
+ read: (ctx: Context): boolean =>
39
+ this.related.owner.includes(ctx.subject) ||
40
+ this.related.can_read.includes(ctx.subject),
41
+
42
+ delete: (ctx: Context): boolean =>
43
+ this.related.owner.includes(ctx.subject) ||
44
+ this.related.can_delete.includes(ctx.subject),
45
+
46
+ make_public: (ctx: Context): boolean =>
47
+ this.related.owner.includes(ctx.subject) ||
48
+ this.related.can_make_public.includes(ctx.subject),
49
+ };
50
+ }
@@ -1,19 +1,89 @@
1
- import { Context, KetoArray, Namespace, SubjectSet } from "./types";
1
+ import { Context, Namespace } from "./types";
2
2
 
3
- class User implements Namespace {}
3
+ export class User implements Namespace {}
4
4
 
5
- class Tenant implements Namespace {
5
+ export class Tenant implements Namespace {
6
6
  related: {
7
+ /**
8
+ * @group Tenant Administration
9
+ * @displayName Delete Tenant
10
+ * @role owner
11
+ */
7
12
  can_delete_tenant: User[];
13
+
14
+ /**
15
+ * @group User Management
16
+ * @displayName Invite Users
17
+ * @role owner
18
+ * @role admin
19
+ */
8
20
  can_invite_user: User[];
21
+
22
+ /**
23
+ * @group User Management
24
+ * @subGroup Role Assignment
25
+ * @displayName Update User Roles
26
+ * @role owner
27
+ * @role admin
28
+ */
9
29
  can_update_user_role: User[];
30
+
31
+ /**
32
+ * @group User Management
33
+ * @subGroup Role Assignment
34
+ * @displayName Promote to Owner
35
+ * @role owner
36
+ */
37
+ can_update_user_role_to_owner: User[];
38
+
39
+ /**
40
+ * @group User Management
41
+ * @subGroup Role Assignment
42
+ * @displayName Demote Owner
43
+ * @role owner
44
+ */
45
+ can_remove_owner_role: User[];
46
+
47
+ /**
48
+ * @group User Management
49
+ * @displayName Remove Users
50
+ * @role owner
51
+ * @role admin
52
+ */
10
53
  can_remove_user: User[];
54
+
55
+ /**
56
+ * @group User Management
57
+ * @displayName View Users
58
+ * @role owner
59
+ * @role admin
60
+ * @role member
61
+ */
11
62
  can_view_users: User[];
63
+
64
+ /**
65
+ * @group Roles & Permissions
66
+ * @displayName Create Roles
67
+ * @role owner
68
+ * @role admin
69
+ */
12
70
  can_create_roles: User[];
71
+
72
+ /**
73
+ * @group Roles & Permissions
74
+ * @displayName Update Roles
75
+ * @role owner
76
+ * @role admin
77
+ */
13
78
  can_update_roles: User[];
79
+
80
+ /**
81
+ * @group Roles & Permissions
82
+ * @displayName Delete Roles
83
+ * @role owner
84
+ * @role admin
85
+ */
14
86
  can_delete_roles: User[];
15
- can_remove_owner_role: User[];
16
- can_update_user_role_to_owner: User[];
17
87
  };
18
88
 
19
89
  permits = {
@@ -29,6 +99,12 @@ class Tenant implements Namespace {
29
99
  update_user_role: (ctx: Context): boolean =>
30
100
  this.related.can_update_user_role.includes(ctx.subject),
31
101
 
102
+ update_user_role_to_owner: (ctx: Context): boolean =>
103
+ this.related.can_update_user_role_to_owner.includes(ctx.subject),
104
+
105
+ remove_owner_role: (ctx: Context): boolean =>
106
+ this.related.can_remove_owner_role.includes(ctx.subject),
107
+
32
108
  view_users: (ctx: Context): boolean =>
33
109
  this.related.can_view_users.includes(ctx.subject),
34
110
 
@@ -40,11 +116,5 @@ class Tenant implements Namespace {
40
116
 
41
117
  delete_roles: (ctx: Context): boolean =>
42
118
  this.related.can_delete_roles.includes(ctx.subject),
43
-
44
- remove_owner_role: (ctx: Context): boolean =>
45
- this.related.can_remove_owner_role.includes(ctx.subject),
46
-
47
- update_user_role_to_owner: (ctx: Context): boolean =>
48
- this.related.can_update_user_role_to_owner.includes(ctx.subject),
49
119
  };
50
120
  }
@@ -1,38 +0,0 @@
1
- {
2
- "roles": [
3
- {
4
- "role": "owner",
5
- "permissions": [
6
- "tenant#can_delete_tenant",
7
- "tenant#can_invite_user",
8
- "tenant#can_remove_user",
9
- "tenant#can_update_user_role",
10
- "tenant#can_view_users",
11
- "tenant#can_create_roles",
12
- "tenant#can_update_roles",
13
- "tenant#can_delete_roles"
14
- ],
15
- "immutable": true
16
- },
17
- {
18
- "role": "admin",
19
- "permissions": [
20
- "tenant#can_invite_user",
21
- "tenant#can_remove_user",
22
- "tenant#can_update_user_role",
23
- "tenant#can_view_users",
24
- "tenant#can_create_roles",
25
- "tenant#can_update_roles",
26
- "tenant#can_delete_roles"
27
- ],
28
- "immutable": false
29
- },
30
- {
31
- "role": "member",
32
- "permissions": [
33
- "tenant#can_view_users"
34
- ],
35
- "immutable": false
36
- }
37
- ]
38
- }