Skip to content

Commit 5fc9bf7

Browse files
authored
Merge pull request #129 from cipherstash/docs/eql-components
Document eql components & permissions
2 parents 77b8935 + 42f6e20 commit 5fc9bf7

File tree

1 file changed

+118
-1
lines changed

1 file changed

+118
-1
lines changed

README.md

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Encrypt Query Language (EQL) is a set of abstractions for transmitting, storing, and interacting with encrypted data and indexes in PostgreSQL.
77

88
> [!TIP]
9-
> **New to EQL?**
9+
> **New to EQL?**
1010
> EQL is the basis for searchable encryption functionality when using [Protect.js](https://github.com/cipherstash/protectjs) and/or [CipherStash Proxy](https://github.com/cipherstash/proxy).
1111
1212
Store encrypted data alongside your existing data:
@@ -43,6 +43,123 @@ The simplest way to get up and running with EQL is to execute the install SQL fi
4343
psql -f cipherstash-encrypt.sql
4444
```
4545

46+
47+
## EQL Components
48+
49+
EQL installs and manages the following components
50+
51+
| Name | Entity Type
52+
| ---------------------------------- | --------------- |
53+
| eql_v2.* | Schema |
54+
| public.eql_v2_encrypted | Type |
55+
| public.eql_v2_configuration_state | Type |
56+
| public.eql_v2_configuration | Table |
57+
58+
59+
### `eql_v2` Schema
60+
61+
The `eql_v2` schema holds all of the functions, types and operators required to query and interact with encrypted data.
62+
The schema is stateless and the schema can be dropped without risk of data loss.
63+
64+
Updating EQL will drop and re-create the schema.
65+
Unless otherwise documented this is a safe operation that requires no data migration or changes.
66+
67+
68+
### Configuration Table & Type
69+
70+
The `public.eql_v2_configuration` table holds the searchable encryption configuration.
71+
The `public.eql_v2_configuration_state` type is used by the configuration table.
72+
73+
The table and associated type are created in the `public` schema to avoid any risk of data loss when updating or uninstalling EQL.
74+
75+
EQL updates will automatically migrate the configuration if the internal structure changes.
76+
77+
On uninstall the configuration table is renamed with a timestamp suffix
78+
The table is not automatically dropped to avoid any potential risk of data loss.
79+
80+
Renaming avoids potential conflicts in CI pipelines that may repeatedly install and uninstall EQL.
81+
82+
83+
### `public.eql_v2_encrypted` Type
84+
85+
The `public.eql_v2_encrypted` is the type used to define encrypted columns, and is used in customer table definitions.
86+
The type is created in the `public` schema to avoid any risk of data loss when updating or uninstalling EQL.
87+
88+
Dropping the `public.eql_v2_encrypted` type will remove any associated columns from the database.
89+
90+
Uninstalling EQL will not drop the `public.eql_v2_encrypted` type to avoid risk of data loss.
91+
92+
93+
## Database Permissions
94+
95+
EQL requires specific database privileges to install and operate correctly. The permissions needed depend on your deployment pattern.
96+
97+
### Default Permissions (Recommended)
98+
99+
For most use cases, grant the following permissions to the database user that will install and use EQL:
100+
101+
```sql
102+
-- Database-level permissions
103+
GRANT CREATE ON DATABASE your_database TO your_eql_user;
104+
105+
-- Schema permissions
106+
GRANT USAGE ON SCHEMA public TO your_eql_user;
107+
GRANT CREATE ON SCHEMA public TO your_eql_user;
108+
109+
-- Configuration table permissions
110+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.eql_v2_configuration TO your_eql_user;
111+
112+
-- User table permissions (for encrypted column constraints)
113+
GRANT ALTER ON ALL TABLES IN SCHEMA public TO your_eql_user;
114+
-- Or grant ALTER on specific tables that will have encrypted columns:
115+
-- GRANT ALTER ON TABLE your_table TO your_eql_user;
116+
```
117+
118+
**Why these permissions are needed:**
119+
120+
- **CREATE ON DATABASE**: Required to create the `eql_v2` schema, types, and functions during installation
121+
- **CREATE ON SCHEMA public**: Required to create types and tables in the public schema
122+
- **Configuration table access**: EQL manages searchable encryption configuration in `public.eql_v2_configuration`
123+
- **ALTER on user tables**: EQL adds check constraints to encrypted columns for data validation
124+
125+
### Splitting Read and Write Access
126+
127+
A common production pattern separates setup/migration permissions from runtime permissions:
128+
129+
#### Setup/Migration User (Write Access)
130+
131+
Use during database migrations and EQL installation:
132+
133+
```sql
134+
-- All default permissions above, plus:
135+
GRANT CREATE ON DATABASE your_database TO your_migration_user;
136+
GRANT CREATE ON SCHEMA public TO your_migration_user;
137+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE public.eql_v2_configuration TO your_migration_user;
138+
GRANT ALTER ON ALL TABLES IN SCHEMA public TO your_migration_user;
139+
```
140+
141+
#### Runtime User (Read Access)
142+
143+
Use for application queries in production:
144+
145+
```sql
146+
-- Configuration read access
147+
GRANT SELECT ON TABLE public.eql_v2_configuration TO your_app_user;
148+
149+
-- EQL schema usage
150+
GRANT USAGE ON SCHEMA eql_v2 TO your_app_user;
151+
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA eql_v2 TO your_app_user;
152+
153+
-- User table access (normal application permissions)
154+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE your_tables TO your_app_user;
155+
```
156+
157+
**Migration Workflow:**
158+
1. Use the migration user to install EQL and configure encrypted columns
159+
2. Use the runtime user for normal application operations
160+
3. Configuration changes (adding/removing encrypted columns) require the migration user
161+
162+
46163
### dbdev
47164

48165
> [!WARNING]

0 commit comments

Comments
 (0)