Wiring DBPAgent into ExternalEncryptorImpl/ExternalDecryptor impl - #68
Conversation
|
Thanks for opening a pull request! If this is not a minor PR. Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose Opening GitHub issues ahead of time contributes to the Openness of the Apache Arrow project. Then could you also rename the pull request title in the following format? or See also: |
9b99922 to
5786d51
Compare
5786d51 to
e3a1a02
Compare
|
@argmarco-tkd I think you meant to put us as Reviewers, not Assignees :) |
avalerio-tkd
left a comment
There was a problem hiding this comment.
Gave it a first pass. Added a few comments. Thanks!
| std::cout << " compression_type: " << CompressName(compression_type) << std::endl; | ||
| std::cout << " encoding: " << encoding << std::endl; | ||
| std::cout << " ext_column_key: " << ext_column_key << std::endl; | ||
| std::cout << " user_id: " << user_id << std::endl; |
There was a problem hiding this comment.
We don't have the user_id at this level, since we moved it inside app_context?
There was a problem hiding this comment.
Correct, but this being miniapp code, I think it's around there.
There was a problem hiding this comment.
This change is based on the mini-app, where the user_id is/was a first class citizen - so we've kept it. In the final version (whatever we eventually merge into dev_phase_2 and/or protegrity/main), we won't have user_id as a first class citizen - and it it will be part of app_context.
There was a problem hiding this comment.
Ah! Yes, of course. Forgot for a minute. All good!
| namespace parquet::encryption { | ||
|
|
||
| // Forward declarations for utility functions | ||
| std::string HackTypeToString(Type::type t); |
There was a problem hiding this comment.
Let's add a TODO note if this is temporary
There was a problem hiding this comment.
All the changes to this file are temporary :). Like I mentioned in the PR description, most of this code (ExternalEncryptorImpl, ExternalDecryptorImpl) will be re-written (as opposed to merged) once we unite the two workstreams we have going on.
There was a problem hiding this comment.
Perfect, that's true that we'll rewrite EEI and EDI when merged. Thanks for that.
|
|
||
| if (!result->success()) { | ||
| std::cout << "[ERROR] Encryption failed: " << result->error_message() << std::endl; | ||
| throw ParquetException(result->error_message()); |
There was a problem hiding this comment.
Where will this exception land, do we know? Will this be part of the error handling afterwards? Let's add a TODO note for that if it's the case.
There was a problem hiding this comment.
Today this is propagated all the way up to the App. This will be covered as part of error handling. Will add a TODO.
There was a problem hiding this comment.
That's what I though. All good. Thanks for the TODO.
Will add a comment on the Issue for error handling to check on the "throw" statements.
| std::cout << " encrypted_footer buffer size: " << encrypted_footer.size() << " bytes" << std::endl; | ||
|
|
||
| std::cout << "[DEBUG] Calling agent_instance_->Encrypt for footer..." << std::endl; | ||
| std::unique_ptr<EncryptionResult> result = agent_instance_->Encrypt(footer); |
There was a problem hiding this comment.
In theory we won't use this encryptor for footers or anything else. Not sure what the datatype would be if any? In that case, should we just throw a NotImplementedExc or something like that?
@sofia-tekdatum thoughts? Do you know if this method is required if we only encrypt column chunks, not metadata?
There was a problem hiding this comment.
This is part of the signature verification done when a parquet file is going to be decrypted.
So we are going to need to implement it, I'll have more details when I finish one of the tasks in this sprint related to that.
There was a problem hiding this comment.
This is remnant of the mini-app code. From what I understand, this (SignedFooterEncrypt()) won't be part of the final solution. The method is used for footer verification inside parquet/metadata.cc, via direct instantiation of AesEncryptor). Created a task to discuss, as this affects the definition of EncryptorInterface but is not exactly relevant to this PR.
https://github.com/protegrity/DataBatchProtectionService/issues/74
There was a problem hiding this comment.
Perfect. Thanks for the tracking task!
| //TODO | ||
| // This is not production code. We know that the one DPBA Agent we have uses XOR encryption. | ||
| // Therefore it's safe to assume that the ciphertext length is the same as the plaintext length. | ||
| // This is not true for all DPBA Agents. |
| std::cout << "Created ExternalDecryptorImpl" << std::endl; | ||
| ExternalDecryptorImpl::ExternalDecryptorImpl( | ||
| std::unique_ptr<DataBatchProtectionAgentInterface> agent_instance) | ||
| : agent_instance_(std::move(agent_instance)) { |
There was a problem hiding this comment.
So the ExternalEncrypt/Decrypt will share an instance of the DBPA ? Can we add a comment on that if it's the case?
There was a problem hiding this comment.
They do not and will not share an instance (at least that's the current plan). Each (EEI, EDI) will make a call to load an independent instance from the DLL.
This does not stop us from having each agent instance share state (via class variables or similar).
Added an FAQ entry (based on earlier discussion on the topic) here
happy to discuss.
There was a problem hiding this comment.
Thanks for the FAQ. We can chat offline. Not a blocker for this PR.
|
|
||
| static std::unique_ptr<ExternalDecryptorImpl> Make(ParquetCipher::type alg_id, int32_t key_len, | ||
| bool metadata); | ||
| static std::unique_ptr<ExternalDecryptorImpl> Make( |
There was a problem hiding this comment.
I have a mental note that we needed to talk about the params of Make, but now I think is ok, right? Let us know if we need to talk further. If not, all good.
There was a problem hiding this comment.
I think we're good (i.e. no discussion needed :) ). The parameters here will change once we have the final implementation - a lot of the current params are just vestigial from the miniapp code.
| static std::unique_ptr<ExternalDecryptorImpl> Make(ParquetCipher::type alg_id, int32_t key_len, | ||
| bool metadata); | ||
| static std::unique_ptr<ExternalDecryptorImpl> Make( | ||
| ParquetCipher::type alg_id, int32_t key_len, std::string column_name, Type::type data_type, |
There was a problem hiding this comment.
Ok, so if I understand the pattern, you're intending for the Arrow code to call this Make, and then within the Make we call the constructor of the DBPAgentInterface, right?
Just checking because I'd rather not leak any of those classes out where the encryptors are created.
There was a problem hiding this comment.
The objective here is for any ExternalEncryptorImpls (final name TBD) to be instantiated the same - regardless of what they do underneath. This should (hopefully) be the same instantiation mechanism as for other encryptors/decryptors. Once the instantiation mechanism is invoked, EEI will internally do its thing.
For this PR (given that the changed to EEI and EDI are mostly throaway) I wanted to minimize the amount of changes and piggy-backed as much as possible onto the current ::Make builder method.
Whether the instantiation happens via ::Make() or via a constructor is somewhat irrelevant (but I believe Arrow currently prefers the utilization of the ::Make() builder method).
| bool metadata); | ||
| static std::unique_ptr<ExternalDecryptorImpl> Make( | ||
| ParquetCipher::type alg_id, int32_t key_len, std::string column_name, Type::type data_type, | ||
| Compression::type compression_type, Encoding::type encoding, std::string ext_column_key, |
There was a problem hiding this comment.
Following the discussion we had over this doc:
https://docs.google.com/document/d/1goKWGR19UsVyXXQrxUPUI-1GBSxN6Yc3qEp2gykVYrg/edit?tab=t.0#heading=h.rdqcrfsd11cy
Encoding is not something you're expecting from Arrow?
There was a problem hiding this comment.
Different type of encoding :)
In that document, the 'encoding' (under the "Format and Encoding" section) refers to a network-transport concept, which is only pertinent to the DBPSClient <-> DBPServer communication.
The Encoding here (in the ::Make) defines how data is physically encoded in the Parquet files.
@avalerio-tkd - please verify.
There was a problem hiding this comment.
I think Marco is right, but also not sure how this Encoding::type encoding propagates on Make. Let me check offline with Sofi and will confirm.
| std::cout << " compression_type: " << CompressName(compression_type) << std::endl; | ||
| std::cout << " encoding: " << encoding << std::endl; | ||
| std::cout << " ext_column_key: " << ext_column_key << std::endl; | ||
| std::cout << " user_id: " << user_id << std::endl; |
There was a problem hiding this comment.
Correct, but this being miniapp code, I think it's around there.
| std::cout << " encrypted_footer buffer size: " << encrypted_footer.size() << " bytes" << std::endl; | ||
|
|
||
| std::cout << "[DEBUG] Calling agent_instance_->Encrypt for footer..." << std::endl; | ||
| std::unique_ptr<EncryptionResult> result = agent_instance_->Encrypt(footer); |
There was a problem hiding this comment.
This is part of the signature verification done when a parquet file is going to be decrypted.
So we are going to need to implement it, I'll have more details when I finish one of the tasks in this sprint related to that.
|
@argmarco-tkd let me confirm with Sofi about the Encoding param in Make. Otherwise it LGTM. |
avalerio-tkd
left a comment
There was a problem hiding this comment.
LGTM+. Will sync with Sofi about the Encoding and we can revisit if needed.
Rationale for this change
In this work, we're wiring the shared library (aka DLL) -loaded DBPAgent instance into both
ExternalEncryptorImplandExternalDecryptorImpl(EEIandEDI, respectively). We're using the miniApp branch for this.As part of this change, the previous implementations of
EEIandEDIare being over-written.As a reminder - this particular PR will never be merged into
dev_phase2nor intomain- an equivalent change will be made once the refactoring work happening indev_phase2is complete.What changes are included in this PR?
dbpa_utils.handdbpa_utils.ccas utils to help translate concepts between the Arrow and DBPA namespace.ExternalEncryptorImplandExternalDecryptorImpl(insideencryption_internal.ccandencryption_internal.h).::Makemethod::Encrypt()::Decrypt()CiphertextLength()andPlaintextLength()AESEncryptor/AESDecryptorEncryptorInterfaceandDecryptorInterfacedefinitions (again, this is the mini-App. We left them as-is).Are these changes tested?
Related
This implements
But in both cases leaves the Executor outside of the implementation. Executor for both will be picked up in a later task:
protegrity/DataBatchProtectionService#73