Skip to content

Commit 11beed1

Browse files
committed
wip
1 parent ef6a453 commit 11beed1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+4004
-2555
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
### Troubleshooting Guide for Potential Constraint Failures
2+
3+
4+
5+
This guide provides information on potential constraint failures related to the encrypted json payload of EQL.
6+
It explains what the current errors mean and what you can do to fix them.
7+
8+
9+
The database constraint cs_configuration_data_v1_check
10+
11+
1. _cs_config_check_v(VALUE)
12+
Error Message:
13+
14+
Meaning: This error indicates that the version value in the configuration is not valid.
15+
16+
Fix: Ensure that the version value in the configuration JSON is correct and matches the expected format. The version should be a valid integer or string that the function _cs_config_check_v can recognize.
17+
18+
2. _cs_config_check_tables(VALUE)
19+
Error Message:
20+
21+
Meaning: This error indicates that the table structure in the configuration JSON is not valid.
22+
23+
Fix: Verify that the table structure in the configuration JSON is correctly defined. Ensure that all required fields are present and that the structure adheres to the expected schema. The function _cs_config_check_tables checks for the presence and correctness of table definitions.
24+
25+
3. _cs_config_check_cast(VALUE)
26+
Error Message:
27+
28+
Meaning: This error indicates that the cast value in the configuration JSON is not valid.
29+
30+
Fix: Check the cast values in the configuration JSON to ensure they are valid. The function _cs_config_check_cast validates the cast values against a predefined list of acceptable values. Ensure that the cast values are correctly specified and match the expected types.
31+
32+
4. _cs_config_check_indexes(VALUE)
33+
Error Message:
34+
35+
Meaning: This error indicates that the index structure in the configuration JSON is not valid.
36+
37+
Fix: Review the index structure in the configuration JSON to ensure it is correctly defined. The function _cs_config_check_indexes checks for the presence and correctness of index definitions. Ensure that all indexes are either empty or contain only keys from a list of valid values ({match, ore, unique, ste_vec}).
38+
39+
General Steps to Fix Configuration Errors
40+
Validate JSON Structure:
41+
42+
Ensure that the JSON structure is well-formed and adheres to the expected schema.
43+
Use JSON validation tools to check for syntax errors.
44+
Check Required Fields:
45+
46+
Verify that all required fields are present in the configuration JSON.
47+
Ensure that the field names and types match the expected values.
48+
Review Function Definitions:
49+
50+
Review the definitions of the functions _cs_config_check_v, _cs_config_check_tables, _cs_config_check_cast, and _cs_config_check_indexes to understand the validation logic.
51+
Ensure that the configuration JSON meets the criteria defined in these functions.
52+
Test with Sample Data:
53+
54+
Test the configuration JSON with sample data to identify and fix errors.
55+
Use known valid configurations as a reference to compare and correct the current configuration.
56+
By following this troubleshooting guide, you can identify and fix potential constraint failures related to the configuration checks in the 020-config-schema.sql file.

.gitignore

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
2+
3+
.DS_Store
4+
.mise.*
5+
6+
deps.txt
7+
deps-ordered.txt
8+
19
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
210

311
sql/000-version.sql
412

13+
14+
515
# Logs
616

717
logs
@@ -186,7 +196,7 @@ cipherstash-proxy.toml
186196
# build artifacts
187197
release/
188198

189-
.mise.*
199+
190200

191201
# jupyter notebook
192202
.ipynb_checkpoints

.vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"conventionalCommits.scopes": [
3+
"ore"
4+
]
5+
}

DEVELOPMENT.md

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
3+
4+
5+
====
6+
7+
8+
###
9+
10+
EQL is installed into the `eql_v1` schema.
11+
12+
13+
14+
15+
16+
## Types
17+
18+
19+
eql_v1_encrypted - Column Type
20+
21+
eql_v1.unique_index;
22+
eql_v1.match;
23+
eql_v1.ore_64_8_v1;
24+
eql_v1.ore_64_8_v1_term;
25+
26+
27+
## Operators
28+
29+
Operators are provided for the `eql_v1_encrypted` column type and `jsonb`.
30+
31+
```
32+
eql_v1_encrypted - eql_v1_encrypted
33+
jsonb - eql_v1_encrypted
34+
eql_v1_encrypted - jsonb
35+
```
36+
37+
The index types and functions are internal implementation details and should not need to be exposed as operators on the `eql_v1_encrypted` type.
38+
39+
40+
-- eql_v1_encrypted = eql_v1_encrypted
41+
-- eql_v1_encrypted = jsonb
42+
-- jsonb = eql_v1_encrypted
43+
-- ore_64_8_v1 = ore_64_8_v1
44+
The jsonb comparison is handy as it automates casting.
45+
Comparing ore_64_8_v1 index values requires that sides are functionalated:
46+
eql_v1.ore_64_8_v1(...) = eql_v1.ore_64_8_v1(...)
47+
In the spirit of aggressive simplification, however, I am not going to add operators to compare eql_v1_encrypted with the ore_64_8_v1 type.
48+
In an operator world, the index types and functions are internal implementation details.
49+
Customers should never need to think about the internals.
50+
I can't think of a reason to need it that isn't a version of "holding it wrong". (edited)
51+
52+
53+
54+
55+
## Working without operators
56+
57+
58+
### Equality
59+
60+
```sql
61+
eql_v1.eq(a eql_v1_encrypted, b eql_v1_encrypted);
62+
```
63+
64+
65+
66+
67+
68+
## Organisation
69+
70+
Break SQL into small modules, aligned with the core domains and types where possible
71+
72+
- types.sql
73+
- casts.sql
74+
- constraints.sql
75+
- functions.sql
76+
- operators.sql
77+
78+
Operators are also functions, so some judgement is required.
79+
The intent is to reduce file size and cognitive load.
80+
81+
In general, operator functions should be thin wrappers around a larger function that does the work.
82+
Put the wrapper functions in `operators.sql` and the "heavy lifting" functions in `functions.sql`.
83+
84+
Tests should follow a similar pattern.
85+
86+
87+
88+
### Dependencies
89+
90+
SQL sources are split into smaller files.
91+
Dependencies are resolved at build time to construct a single SQL file with the correct ordering.
92+
93+
Dependencies between files are declared in a comment at the top of the file.
94+
All SQL files should `REQUIRE` the source file of any other object they reference.
95+
96+
All files must have at least one declaration, and the default is to reference the schema
97+
98+
```
99+
-- REQUIRE: src/schema.sql
100+
```
101+
102+
103+
104+
### Tables
105+
106+
### Configuration
107+
108+
109+
`public.eql_v1_configuration`
110+
111+
112+
113+
EQL Design Note
114+
Experimenting with using a Composite type instead of a Domain type for the encrypted column.
115+
Composite types are a bit more capable. Domain types are more like an alias for the underlying type (in this case jsonb)
116+
The consequence of using a Composite type is that the data is stored in the column as a Tuple - effectively the data is wrapped in ()
117+
This means
118+
on insert/update the data needs to be cast to eql_v1_encrypted (proxy mapping will handle)
119+
on read the data needs to be cast back to jsonb if a customer needs the raw json (for data lake transfer etc etc)
120+
Already built cast helpers so syntax is something like
121+
INSERT INTO encrypted (e) VALUES (
122+
eql_v1.to_encrypted('{}')
123+
);
124+
125+
INSERT INTO encrypted (e) VALUES (
126+
'{}'::jsonb::eql_v1_encrypted
127+
);
128+

REFERENCE.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
4+
5+
### cs_encrypt_v1
6+
7+
Marks the currently `pending` configuration as `encrypting`.
8+
9+
Validates the database schema and returns an error if the configured columns are not of `jsonb` or `cs_encrypted_v1` type.
10+
11+
12+
13+
14+
15+
16+
```
17+
SELECT cs_encrypt_v1(true);
18+
```

0 commit comments

Comments
 (0)