Skip to content

Commit 502cc47

Browse files
committed
fix: remove empty state and troubleshooting docs
1 parent 6bc0e10 commit 502cc47

File tree

3 files changed

+79
-17
lines changed

3 files changed

+79
-17
lines changed

docs/tutorials/proxy-configuration.md

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,62 @@
11
# CipherStash Proxy Configuration with EQL functions
22

3-
Initialize the column using the `eql_v2.add_column` function to enable encryption and decryption via CipherStash Proxy.
3+
## Prerequisites
4+
5+
> [!IMPORTANT]
6+
> Before using any EQL configuration functions, you must first create the encrypted column in your database table:
7+
8+
```sql
9+
-- First, add the encrypted column to your table
10+
ALTER TABLE users ADD COLUMN encrypted_email eql_v2_encrypted;
11+
```
12+
13+
The column **must** be of type `eql_v2_encrypted`.
14+
If you try to configure a column that doesn't exist in the database, you'll get the error:
15+
16+
```
17+
ERROR: Some pending columns do not have an encrypted target
18+
```
19+
20+
## Initializing column configuration
21+
22+
After creating the encrypted column, initialize it for use with CipherStash Proxy using the `eql_v2.add_column` function:
423

524
```sql
6-
SELECT eql_v2.add_column('users', 'encrypted_email', 'text'); -- where users is the table name and encrypted_email is the column name of type eql_v2_encrypted
25+
SELECT eql_v2.add_column('users', 'encrypted_email', 'text'); -- Configure the existing encrypted column
726
```
827

928
**Full signature:**
1029
```sql
1130
SELECT eql_v2.add_column(
1231
'table_name', -- Name of the table
13-
'column_name', -- Name of the column (must be of type eql_v2_encrypted)
32+
'column_name', -- Name of the encrypted column (must already exist as type eql_v2_encrypted)
1433
'cast_as', -- PostgreSQL type to cast decrypted data [optional, defaults to 'text']
1534
migrating -- If true, stages changes without immediate activation [optional, defaults to false]
1635
);
1736
```
1837

1938
**Note:** This function allows you to encrypt and decrypt data but does not enable searchable encryption. See [Searching data with EQL](#searching-data-with-eql) for enabling searchable encryption.
2039

21-
## Refreshing CipherStash Proxy Configuration
40+
## Complete setup workflow
41+
42+
Here's the complete workflow to set up an encrypted column with search capabilities:
43+
44+
```sql
45+
-- Step 1: Create the encrypted column in your table
46+
ALTER TABLE users ADD COLUMN encrypted_email eql_v2_encrypted;
47+
48+
-- Step 2: Configure the column for encryption/decryption
49+
SELECT eql_v2.add_column('users', 'encrypted_email', 'text');
50+
51+
-- Step 3: Add search indexes as needed
52+
SELECT eql_v2.add_search_config('users', 'encrypted_email', 'unique', 'text');
53+
SELECT eql_v2.add_search_config('users', 'encrypted_email', 'match', 'text');
54+
55+
-- Step 4: Verify configuration
56+
SELECT * FROM eql_v2.config();
57+
```
58+
59+
## Refreshing CipherStash Proxy configuration
2260

2361
CipherStash Proxy refreshes the configuration every 60 seconds. To force an immediate refresh, run:
2462

@@ -35,7 +73,7 @@ Encrypted data is stored as `jsonb` values in the PostgreSQL database, regardles
3573

3674
You can read more about the data format [here](docs/reference/payload.md).
3775

38-
### Inserting Data
76+
### Inserting data
3977

4078
When inserting data into the encrypted column, wrap the plaintext in the appropriate EQL payload. These statements must be run through the CipherStash Proxy to **encrypt** the data.
4179

@@ -64,7 +102,7 @@ Data is stored in the PostgreSQL database as:
64102
}
65103
```
66104

67-
### Reading Data
105+
### Reading data
68106

69107
When querying data, select the encrypted column. CipherStash Proxy will **decrypt** the data automatically.
70108

@@ -100,6 +138,8 @@ In order to perform searchable operations on encrypted data, you must configure
100138
101139
### Adding an index
102140

141+
**Prerequisites:** The encrypted column must already exist in the database (see [Prerequisites](#prerequisites)) and be configured with `eql_v2.add_column`.
142+
103143
Add an index to an encrypted column using the `eql_v2.add_search_config` function:
104144

105145
```sql
@@ -366,4 +406,20 @@ Use these functions to manage your EQL configurations:
366406
**Important Behavior Differences:**
367407
- `remove_search_config()` removes only the specified index but preserves the column configuration (including `cast_as` setting)
368408
- `remove_column()` removes the entire column configuration including all its indexes
369-
- Empty configurations (no tables/columns) are automatically maintained as active to reflect the current state
409+
- Empty configurations (no tables/columns) are automatically maintained as active to reflect the current state
410+
411+
## Troubleshooting
412+
413+
### Common errors
414+
415+
**Error: "Some pending columns do not have an encrypted target"**
416+
- **Cause**: You're trying to configure a column that doesn't exist as `eql_v2_encrypted` type in the database
417+
- **Solution**: First create the encrypted column with `ALTER TABLE table_name ADD COLUMN column_name eql_v2_encrypted;`
418+
419+
**Error: "Config exists for column: table_name column_name"**
420+
- **Cause**: You're trying to add a column that's already configured
421+
- **Solution**: Use `eql_v2.add_search_config()` to add indexes to existing columns, or `eql_v2.remove_column()` first if you want to reconfigure
422+
423+
**Error: "No configuration exists for column: table_name column_name"**
424+
- **Cause**: You're trying to add search config to a column that hasn't been configured with `add_column` yet
425+
- **Solution**: First run `eql_v2.add_column()` to configure the column, then add search indexes

src/config/config_test.sql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,13 @@ DO $$
218218

219219
PERFORM eql_v2.remove_column('encrypted', 'e', migrating => true);
220220

221-
PERFORM assert_no_result(
222-
'Pending configuration was removed',
223-
'SELECT * FROM eql_v2_configuration c WHERE c.state = ''pending''');
221+
PERFORM assert_count(
222+
'Pending configuration exists but is empty',
223+
'SELECT * FROM eql_v2_configuration c WHERE c.state = ''pending''',
224+
1);
225+
226+
-- Verify the config is empty
227+
ASSERT (SELECT data #> array['tables'] = '{}' FROM eql_v2_configuration c WHERE c.state = 'pending');
224228

225229
END;
226230
$$ LANGUAGE plpgsql;

src/config/functions.sql

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,15 @@ AS $$
285285

286286
PERFORM eql_v2.remove_encrypted_constraint(table_name, column_name);
287287

288-
-- if config is completely empty, delete it; otherwise update it
289-
IF _config #> array['tables'] = '{}' THEN
290-
DELETE FROM public.eql_v2_configuration WHERE state = 'pending';
291-
ELSE
292-
UPDATE public.eql_v2_configuration SET data = _config WHERE state = 'pending';
293-
294-
IF NOT migrating THEN
288+
-- update the config (even if empty) and activate
289+
UPDATE public.eql_v2_configuration SET data = _config WHERE state = 'pending';
290+
291+
IF NOT migrating THEN
292+
-- For empty configs, skip migration validation and directly activate
293+
IF _config #> array['tables'] = '{}' THEN
294+
UPDATE public.eql_v2_configuration SET state = 'inactive' WHERE state = 'active';
295+
UPDATE public.eql_v2_configuration SET state = 'active' WHERE state = 'pending';
296+
ELSE
295297
PERFORM eql_v2.migrate_config();
296298
PERFORM eql_v2.activate_config();
297299
END IF;

0 commit comments

Comments
 (0)