Skip to content
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

Reset encryptor configs on query processing #628

Merged
merged 7 commits into from
Jan 30, 2023

Conversation

Lagovas
Copy link
Collaborator

@Lagovas Lagovas commented Jan 28, 2023

Brief overview how Acra process transparent decryption. At first, it captures query from the application to the database, tries to match it to the encryptor_config and remembers which columns requested from db and which of them should be decrypted/detokenized. In case of simple decryption, Acra can decrypt even without configs, because parses everything that looks like AcraStruct/AcraBlock. In the case of tokenization, it should know token type.
Then, when database returns DataRow with data, Acra remembers the order of columns and which of them should be processed, and what rules to apply.

This PR fixes the situation, when Acra remembers the configuration for the decryption after processing the valid query and applies second time for the next query if it wasn't parsed correctly and previous configuration wasn't flushed.

So, here is added resetting querySelectSetting on every OnQuery call that flushes the previously saved list of settings to not apply it on the wrong query. Before that, we expected that every OnQuery will execute parts at end of onSelect/onReturning with assigning new allocated slice to the variable but omitted cases with not parsed queries. So it allows cases when after correctly processed query with some transparent encryption, Acra will try to apply same config on the next query even because weren't executed parts with re-assigning.

This fix is first part of whole fix that cover simple case with one query per TCP packet. But it doesn't cover case when one TCP packet will have several Parse + Bind + Execute db packets, when the second will override previously remembered setting and Acra will apply second config for the first Parse packet... It will be fixed in next PRs because required refactoring and some re-designing.

Checklist

@Lagovas Lagovas requested a review from Zhaars January 28, 2023 00:03
tests/test.py Outdated
# insert data data
self.insert_via_1(default_client_id_table.insert(), data)

# expect that data was not encrypted with client_id which specified in ignore_client_id block
Copy link
Contributor

@Zhaars Zhaars Jan 28, 2023

Choose a reason for hiding this comment

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

ignore_client_id? Just invalid comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's redundant copy-paste which was the source of bug reproducing but now redundant. already removed it.

be applied for the next query and will be cleared
"""
if not base.TEST_POSTGRESQL:
self.skipTest("MySQL doesn't support returning statement for insert")
Copy link
Contributor

Choose a reason for hiding this comment

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

MariaDB should support returning. Does it make sense to test for Maria too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you are right, added via raw sql because current version of sqlalchemy doesn't allow such expressions for mariadb and upgrading to 2.x requires changes and updating tests and should be done in separate PR, imho

Copy link
Contributor

@Zhaars Zhaars left a comment

Choose a reason for hiding this comment

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

Looks good for me

@Lagovas Lagovas requested a review from Zhaars January 29, 2023 23:09
@Lagovas
Copy link
Collaborator Author

Lagovas commented Jan 29, 2023

@Zhaars , please look one more time on added new changes for MySQL side of testing with returning expression.

@Zhaars
Copy link
Contributor

Zhaars commented Jan 30, 2023

@Zhaars , please look one more time on added new changes for MySQL side of testing with returning expression.

@Lagovas, Good to go, as for me.

@Lagovas Lagovas merged commit 2862716 into master Jan 30, 2023
@Lagovas Lagovas deleted the lagovas/reset-encryptor-setting-for-queries branch January 30, 2023 10:38
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.

None yet

2 participants