Skip to content

Commit b0f70cc

Browse files
committed
fix: correctly select SteVec index for JsonPath and JsonAccessor encryption
- Tokenized now uses EqlOperation::Store to generate full EQL payload - JsonPath finds SteVec index specifically, uses QueryOp::SteVecSelector - JsonAccessor finds SteVec index specifically, uses QueryOp::SteVecTerm - Fixes bug where .first() could return wrong index type when multiple indexes are configured on a column
1 parent a0bd39b commit b0f70cc

1 file changed

Lines changed: 22 additions & 26 deletions

File tree

  • packages/cipherstash-proxy/src/proxy/zerokms

packages/cipherstash-proxy/src/proxy/zerokms/zerokms.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use cipherstash_client::{
1212
decrypt_eql, encrypt_eql, EqlCiphertext, EqlDecryptOpts, EqlEncryptOpts, EqlOperation,
1313
PreparedPlaintext,
1414
},
15+
schema::column::IndexType,
1516
};
1617
use eql_mapper::EqlTermVariant;
1718
use metrics::counter;
@@ -155,35 +156,30 @@ impl EncryptionService for ZeroKms {
155156
if let (Some(plaintext), Some(col)) = (plaintext_opt, col_opt) {
156157
// Determine the EQL operation based on the term variant
157158
let eql_op = match col.eql_term {
158-
// Full and Partial terms store encrypted data with all indexes
159-
EqlTermVariant::Full | EqlTermVariant::Partial => EqlOperation::Store,
160-
161-
// JsonPath generates a selector term for SteVec queries
162-
EqlTermVariant::JsonPath => {
163-
if let Some(index) = col.config.indexes.first() {
164-
EqlOperation::Query(&index.index_type, QueryOp::SteVecSelector)
165-
} else {
166-
EqlOperation::Store
167-
}
159+
// Full, Partial, and Tokenized terms store encrypted data with all indexes
160+
EqlTermVariant::Full | EqlTermVariant::Partial | EqlTermVariant::Tokenized => {
161+
EqlOperation::Store
168162
}
169163

170-
// JsonAccessor generates a selector term for SteVec field access (-> operator)
171-
EqlTermVariant::JsonAccessor => {
172-
if let Some(index) = col.config.indexes.first() {
164+
// JsonPath generates a selector term for SteVec queries (e.g., jsonb_path_query)
165+
EqlTermVariant::JsonPath => col
166+
.config
167+
.indexes
168+
.iter()
169+
.find(|i| matches!(i.index_type, IndexType::SteVec { .. }))
170+
.map(|index| {
173171
EqlOperation::Query(&index.index_type, QueryOp::SteVecSelector)
174-
} else {
175-
EqlOperation::Store
176-
}
177-
}
178-
179-
// Tokenized generates match index terms for LIKE/ILIKE
180-
EqlTermVariant::Tokenized => {
181-
if let Some(index) = col.config.indexes.first() {
182-
EqlOperation::Query(&index.index_type, QueryOp::Default)
183-
} else {
184-
EqlOperation::Store
185-
}
186-
}
172+
})
173+
.unwrap_or(EqlOperation::Store),
174+
175+
// JsonAccessor generates a term for SteVec field access (-> operator)
176+
EqlTermVariant::JsonAccessor => col
177+
.config
178+
.indexes
179+
.iter()
180+
.find(|i| matches!(i.index_type, IndexType::SteVec { .. }))
181+
.map(|index| EqlOperation::Query(&index.index_type, QueryOp::SteVecTerm))
182+
.unwrap_or(EqlOperation::Store),
187183
};
188184

189185
let prepared = PreparedPlaintext::new(

0 commit comments

Comments
 (0)