Skip to content

Error or warn if encrypt config missing#196

Merged
yujiyokoo merged 12 commits intomainfrom
error-or-warn-if-encrypt-config-missing
Mar 31, 2025
Merged

Error or warn if encrypt config missing#196
yujiyokoo merged 12 commits intomainfrom
error-or-warn-if-encrypt-config-missing

Conversation

@yujiyokoo
Copy link
Contributor

@yujiyokoo yujiyokoo commented Mar 27, 2025

This changes the missing config logic to:

IF mapping is disabled
  pass through the query
ELSE IF column is to be encrypted but no config for it is found
  IF mapping_errors_enabled
    return error
  ELSE
    output warning and pass through the query
  END
END

It also adds a single test for the warning behaviour. There is no test for the error as those integration tests increase the CI time (I have tested manually though).

Acknowledgment

By submitting this pull request, I confirm that CipherStash can use, modify, copy, and redistribute this contribution, under the terms of CipherStash's choice.

Now Proxy warns or raises error (depending on enable_mapping_errors)
if configuration is missing for an encrypted column when mapping is
not disabled.
Warning for missing encrypt config test assumes mapping enabled
and mapping errors disabled.
@yujiyokoo yujiyokoo force-pushed the error-or-warn-if-encrypt-config-missing branch from 4590c39 to 5eee78f Compare March 28, 2025 07:23
@yujiyokoo yujiyokoo marked this pull request as ready for review March 28, 2025 07:23
// returns cs_encrypted_v1 and the client cannot convert to a string.
// If mapping errors are enabled (enable_mapping_errors or CS_DEVELOPMENT__ENABLE_MAPPING_ERRORS),
// then Proxy will return an error that says "Column X in table Y has no Encrypt configuration"
assert_eq!(msg, "error serializing parameter 1: cannot convert between the Rust type `&str` and the Postgres type `cs_encrypted_v1`");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is not as clear now, but with mapping errors disabled (default, and how it is here) we emit a warning, and return the value to the client in cs_encrypted_v1, and this is the client (tokio-postgres) reporting an error. Not sure what else we can do to improve

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've run into this a couple of times with tokio-postgres and it can be a bit confusing.
Not much we can do, because is actually tokio enforcing type correctness - the statement types have not been rewritten.

# This is EQL catching the error and returning it. Details are in docs/errors.md
# When mapping errors are enabled, (enable_mapping_errors or CS_DEVELOPMENT__ENABLE_MAPPING_ERRORS)
# Proxy will return an error that says "Column X in table Y has no Encrypt configuration"
with pytest.raises(psycopg.Error, match=r"Encrypted column missing \w+ \(\w+\) field"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to the other test above, we show EQL's error here when trying to insert, as we emit the warning and let the unencrypted record pass through to be caught by Postgres.

counter!(CLIENTS_BYTES_RECEIVED_TOTAL).increment(sent);

if self.encrypt.is_passthrough() {
if self.encrypt.config.mapping_disabled() {
Copy link
Contributor Author

@yujiyokoo yujiyokoo Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_passthrough checks if mapping is disabled or encrypt config is empty. Here it's updated to only one of them

// returns cs_encrypted_v1 and the client cannot convert to a string.
// If mapping errors are enabled (enable_mapping_errors or CS_DEVELOPMENT__ENABLE_MAPPING_ERRORS),
// then Proxy will return an error that says "Column X in table Y has no Encrypt configuration"
assert_eq!(msg, "error serializing parameter 1: cannot convert between the Rust type `&str` and the Postgres type `cs_encrypted_v1`");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've run into this a couple of times with tokio-postgres and it can be a bit confusing.
Not much we can do, because is actually tokio enforcing type correctness - the statement types have not been rewritten.

@yujiyokoo yujiyokoo merged commit 6e7f0b2 into main Mar 31, 2025
1 check passed
@yujiyokoo yujiyokoo deleted the error-or-warn-if-encrypt-config-missing branch March 31, 2025 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants