-
Notifications
You must be signed in to change notification settings - Fork 0
fix: config functions remove process #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29ff0ff
fix: config functions remove process
calvinbrewer 6bc0e10
chore: update tests to new config behavior
calvinbrewer 502cc47
fix: remove empty state and troubleshooting docs
calvinbrewer 85c7b14
Update proxy-configuration.md
calvinbrewer b48efa0
Update proxy-configuration.md
calvinbrewer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
default_version = 2.1.2 | ||
default_version = 2.1.3 | ||
comment = 'Index and search encrypted data in PostgreSQL with SQL' | ||
relocatable = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,62 @@ | ||
# CipherStash Proxy Configuration with EQL functions | ||
|
||
Initialize the column using the `eql_v2.add_column` function to enable encryption and decryption via CipherStash Proxy. | ||
## Prerequisites | ||
|
||
> [!IMPORTANT] | ||
> Before using any EQL configuration functions, you must first create the encrypted column in your database table: | ||
|
||
```sql | ||
SELECT eql_v2.add_column('users', 'encrypted_email'); -- where users is the table name and encrypted_email is the column name of type eql_v2_encrypted | ||
-- First, add the encrypted column to your table | ||
ALTER TABLE users ADD COLUMN encrypted_email eql_v2_encrypted; | ||
``` | ||
|
||
The column **must** be of type `eql_v2_encrypted`. | ||
If you try to configure a column that doesn't exist in the database, you'll get the error: | ||
|
||
``` | ||
ERROR: Some pending columns do not have an encrypted target | ||
``` | ||
|
||
## Initializing column configuration | ||
|
||
After creating the encrypted column, initialize it for use with CipherStash Proxy using the `eql_v2.add_column` function: | ||
|
||
```sql | ||
SELECT eql_v2.add_column('users', 'encrypted_email', 'text'); -- Initialize the new encrypted column | ||
``` | ||
|
||
**Full signature:** | ||
```sql | ||
SELECT eql_v2.add_column( | ||
'table_name', -- Name of the table | ||
'column_name', -- Name of the encrypted column (must already exist as type eql_v2_encrypted) | ||
'cast_as', -- PostgreSQL type to cast decrypted data [optional, defaults to 'text'] | ||
migrating -- If true, stages changes without immediate activation [optional, defaults to false] | ||
); | ||
``` | ||
|
||
**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. | ||
|
||
## Refreshing CipherStash Proxy Configuration | ||
## Complete setup workflow | ||
|
||
Here's the complete workflow to set up an encrypted column with search capabilities: | ||
|
||
```sql | ||
-- Step 1: Create the encrypted column in your table | ||
ALTER TABLE users ADD COLUMN encrypted_email eql_v2_encrypted; | ||
|
||
-- Step 2: Configure the column for encryption/decryption | ||
SELECT eql_v2.add_column('users', 'encrypted_email', 'text'); | ||
|
||
-- Step 3: Add search indexes as needed | ||
SELECT eql_v2.add_search_config('users', 'encrypted_email', 'unique', 'text'); | ||
SELECT eql_v2.add_search_config('users', 'encrypted_email', 'match', 'text'); | ||
|
||
-- Step 4: Verify configuration | ||
SELECT * FROM eql_v2.config(); | ||
``` | ||
|
||
## Refreshing CipherStash Proxy configuration | ||
|
||
CipherStash Proxy refreshes the configuration every 60 seconds. To force an immediate refresh, run: | ||
|
||
|
@@ -25,7 +73,7 @@ Encrypted data is stored as `jsonb` values in the PostgreSQL database, regardles | |
|
||
You can read more about the data format [here](docs/reference/payload.md). | ||
|
||
### Inserting Data | ||
### Inserting data | ||
|
||
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. | ||
|
||
|
@@ -54,7 +102,7 @@ Data is stored in the PostgreSQL database as: | |
} | ||
``` | ||
|
||
### Reading Data | ||
### Reading data | ||
|
||
When querying data, select the encrypted column. CipherStash Proxy will **decrypt** the data automatically. | ||
|
||
|
@@ -90,15 +138,18 @@ In order to perform searchable operations on encrypted data, you must configure | |
|
||
### Adding an index | ||
|
||
**Prerequisites:** The encrypted column must already exist in the database (see [Prerequisites](#prerequisites)) and be configured with `eql_v2.add_column`. | ||
|
||
Add an index to an encrypted column using the `eql_v2.add_search_config` function: | ||
|
||
```sql | ||
SELECT eql_v2.add_search_config( | ||
'table_name', -- Name of the table | ||
'column_name', -- Name of the column | ||
'index_name', -- Index kind ('unique', 'match', 'ore', 'ste_vec') | ||
'cast_as', -- PostgreSQL type to cast decrypted data ('text', 'int', etc.) | ||
'opts' -- Index options as JSONB (optional) | ||
'cast_as', -- PostgreSQL type to cast decrypted data ('text', 'int', etc.) [optional, defaults to 'text'] | ||
'opts', -- Index options as JSONB [optional, defaults to '{}'] | ||
migrating -- If true, stages changes without immediate activation [optional, defaults to false] | ||
); | ||
``` | ||
|
||
|
@@ -115,7 +166,20 @@ SELECT eql_v2.add_search_config( | |
); | ||
``` | ||
|
||
Configuration changes are automatically migrated and activated. | ||
**Example (With custom options and staging):** | ||
|
||
```sql | ||
SELECT eql_v2.add_search_config( | ||
'users', | ||
'encrypted_name', | ||
'match', | ||
'text', | ||
'{"k": 6, "bf": 4096}', | ||
true -- Stage changes without immediate activation | ||
); | ||
``` | ||
|
||
Configuration changes are automatically migrated and activated unless the `migrating` parameter is set to `true`. | ||
|
||
## Searching data with EQL | ||
|
||
|
@@ -322,9 +386,43 @@ EQL supports the following index types: | |
|
||
Use these functions to manage your EQL configurations: | ||
|
||
- `eql_v2.add_column()` - Add a new encrypted column | ||
- `eql_v2.remove_column()` - Remove an encrypted column | ||
- `eql_v2.add_search_config()` - Add a search index | ||
- `eql_v2.remove_search_config()` - Remove a search index | ||
- `eql_v2.modify_search_config()` - Modify an existing search index | ||
- `eql_v2.config()` - View current configuration in tabular format | ||
**Column Management:** | ||
- `eql_v2.add_column(table_name, column_name, cast_as DEFAULT 'text', migrating DEFAULT false)` - Add a new encrypted column | ||
- `eql_v2.remove_column(table_name, column_name, migrating DEFAULT false)` - Remove an encrypted column completely | ||
|
||
**Index Management:** | ||
- `eql_v2.add_search_config(table_name, column_name, index_name, cast_as DEFAULT 'text', opts DEFAULT '{}', migrating DEFAULT false)` - Add a search index to a column | ||
- `eql_v2.remove_search_config(table_name, column_name, index_name, migrating DEFAULT false)` - Remove a specific search index (preserves column configuration) | ||
- `eql_v2.modify_search_config(table_name, column_name, index_name, cast_as DEFAULT 'text', opts DEFAULT '{}', migrating DEFAULT false)` - Modify an existing search index | ||
|
||
**Configuration Management:** | ||
- `eql_v2.migrate_config()` - Manually migrate pending configuration to encrypting state | ||
- `eql_v2.activate_config()` - Manually activate encrypting configuration | ||
- `eql_v2.discard()` - Discard pending configuration changes | ||
- `eql_v2.config()` - View current configuration in tabular format (returns a table with columns: state, relation, col_name, decrypts_as, indexes) | ||
Comment on lines
+389
to
+402
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice way of denoting which functions do what. |
||
|
||
> [!NOTE] | ||
> All configuration functions automatically migrate and activate changes unless `migrating` is set to `true`. | ||
> | ||
> When `migrating` is `true`, changes are staged but not immediately applied, allowing for batch configuration updates. | ||
|
||
**Important Behavior Differences:** | ||
- `remove_search_config()` removes only the specified index but preserves the column configuration (including `cast_as` setting) | ||
- `remove_column()` removes the entire column configuration including all its indexes | ||
- Empty configurations (no tables/columns) are automatically maintained as active to reflect the current state | ||
|
||
## Troubleshooting | ||
|
||
### Common errors | ||
|
||
**Error: "Some pending columns do not have an encrypted target"** | ||
- **Cause**: You're trying to configure a column that doesn't exist as `eql_v2_encrypted` type in the database | ||
- **Solution**: First create the encrypted column with `ALTER TABLE table_name ADD COLUMN column_name eql_v2_encrypted;` | ||
|
||
**Error: "Config exists for column: table_name column_name"** | ||
- **Cause**: You're trying to add a column that's already configured | ||
- **Solution**: Use `eql_v2.add_search_config()` to add indexes to existing columns, or `eql_v2.remove_column()` first if you want to reconfigure | ||
|
||
**Error: "No configuration exists for column: table_name column_name"** | ||
- **Cause**: You're trying to add search config to a column that hasn't been configured with `add_column` yet | ||
- **Solution**: First run `eql_v2.add_column()` to configure the column, then add search indexes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a step 5 to show a successful query of the
encrypted_email
column.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to keep this section focused on config with EQL