Skip to content

Wiring up encryption metadata to the DBPA remote and local agents.#167

Merged
avalerio-tkd merged 7 commits into
mainfrom
av_wire_encr_meta_05
Nov 28, 2025
Merged

Wiring up encryption metadata to the DBPA remote and local agents.#167
avalerio-tkd merged 7 commits into
mainfrom
av_wire_encr_meta_05

Conversation

@avalerio-tkd

Copy link
Copy Markdown
Collaborator
  • Update API server to return encryption metadata in the response.
  • Populate server version as encryption metadata during Encryption and check it back during Decryption.
  • Updated unitests.
  • Fixed hidden error when parsing empty Json strings.

- Update API server to return encryption metadata in the response.
- Populate server version as encryption metadata during Encryption and check it back during Decryption.
- Updated unitests.
- Fixed hidden error when parsing empty Json strings.
Comment thread src/common/dbpa_local.cpp Outdated
user_id_,
app_context_
app_context_,
{}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add // encryption_metadata comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/common/dbpa_local.h
private:
std::vector<uint8_t> ciphertext_;
bool success_;
std::map<std::string, std::string> encryption_metadata_;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure if it should be in this header file or in another, but can you add a comment with an example of what may be contained in here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added comments on the dbpa_interface.h file.

Comment thread src/server/encryption_sequencer.cpp Outdated
auto it = encryption_metadata_.find(DBPS_VERSION_KEY);
if (it == encryption_metadata_.end()) {
std::cerr << "ERROR: EncryptionSequencer - encryption_metadata must contain key '" << DBPS_VERSION_KEY << "'" << std::endl;
// ++++ remove the hard error before merging ++++

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do you want to remove this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was to prevent breaking the Arrow flow until we know for sure the metadata is saved on the Parquet files correctly. But this is probably not needed since that was tested already on Arrow and this is now tested on DPBA flow, so will merge with it.

"test_user", // user_id
"{}" // application_context
"{}", // application_context
{} // encryption_metadata

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure I could see a test where you verify that the sequencer stops if there's a mismatch in the expected encryption metadata?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching the test gap. Added.

- Updated dbpa_remote_testapp to use the new version checking.

@argmarco-tkd argmarco-tkd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this. Overall LGTM, but left a few comments around

Comment thread src/common/dbpa_interface.h
Comment thread src/common/dbpa_local.cpp Outdated
user_id_,
app_context_
app_context_,
{}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

+1

Comment on lines +35 to +40
const auto& response_attrs = response_->GetResponseAttributes();
if (!response_attrs.encryption_metadata_.empty()) {
cached_encryption_metadata_ = response_attrs.encryption_metadata_;
} else {
cached_encryption_metadata_ = std::nullopt;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's document what's going on here - it's a bit hard to grasp

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. You can let me know if the comment is sufficient and I can expand more if needed.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

it's a clearer, thanks - but the whole concept of 'cached metadata' is a bit confusing. maybe let's add a short note on that? (in particular, why is it 'cached' ?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

cached was probably a bad choice, so changed the variable names to parsed. I think that captures better the usage.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thank you! it's much clearer now.

Comment thread src/common/dbpa_remote.h Outdated
// The caching of this is possible because the API response `response_` doesn't change after construction.
mutable std::string cached_error_message_;
mutable std::map<std::string, std::string> cached_error_fields_;
mutable std::optional<std::map<std::string, std::string>> cached_encryption_metadata_;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's add a note for the future, where we state that this is cacheable only because the metadata is identical across requests (but that may change)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this is the RemoteEncryptionResult, not the RemoteDPBA. A new instance is returned on each call to RemoteDBPA.Encrypt().

This is cached separately on each RemoteEncryptionResult instance, to avoid parsing the Json with every call to encryption_metadata(). It isn't statically cached for the class.

But let me know if something is unclear, and we can discuss.

Comment thread src/common/json_request.cpp
Comment thread src/common/json_request.cpp
Comment thread src/server/encryption_sequencer.cpp Outdated
using namespace dbps::enum_utils;

namespace {
constexpr const char* DBPS_VERSION_KEY = "dbps_version";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should discuss this property name. Let's create a task to discuss the naming (or discuss offline when you have a chance). I.e. DBPS is technically 'server' related, but we have a local agent. Maybe dbpa_agent_version or similar is more appropriate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Renamed it to dbpa_agent_version as suggested.

Comment thread src/server/encryption_sequencer.cpp Outdated
Comment on lines +393 to +394
std::cerr << "ERROR: EncryptionSequencer - encryption_metadata['" << DBPS_VERSION_KEY << "'] must start with '"
<< DBPS_VERSION_VALUE << "', but got '" << it->second << "'" << std::endl;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The 'must start' terminology may be confusing. Can we just say "must match" ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@avalerio-tkd avalerio-tkd left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the reviews @argmarco-tkd @sofia-tekdatum . Could you PTAL?

Comment thread src/common/dbpa_interface.h
Comment thread src/common/dbpa_local.cpp Outdated
user_id_,
app_context_
app_context_,
{}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/common/dbpa_local.h
private:
std::vector<uint8_t> ciphertext_;
bool success_;
std::map<std::string, std::string> encryption_metadata_;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added comments on the dbpa_interface.h file.

Comment thread src/server/encryption_sequencer.cpp Outdated
auto it = encryption_metadata_.find(DBPS_VERSION_KEY);
if (it == encryption_metadata_.end()) {
std::cerr << "ERROR: EncryptionSequencer - encryption_metadata must contain key '" << DBPS_VERSION_KEY << "'" << std::endl;
// ++++ remove the hard error before merging ++++

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was to prevent breaking the Arrow flow until we know for sure the metadata is saved on the Parquet files correctly. But this is probably not needed since that was tested already on Arrow and this is now tested on DPBA flow, so will merge with it.

"test_user", // user_id
"{}" // application_context
"{}", // application_context
{} // encryption_metadata

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching the test gap. Added.

Comment thread src/common/dbpa_remote.h Outdated
// The caching of this is possible because the API response `response_` doesn't change after construction.
mutable std::string cached_error_message_;
mutable std::map<std::string, std::string> cached_error_fields_;
mutable std::optional<std::map<std::string, std::string>> cached_encryption_metadata_;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Actually, this is the RemoteEncryptionResult, not the RemoteDPBA. A new instance is returned on each call to RemoteDBPA.Encrypt().

This is cached separately on each RemoteEncryptionResult instance, to avoid parsing the Json with every call to encryption_metadata(). It isn't statically cached for the class.

But let me know if something is unclear, and we can discuss.

Comment thread src/common/json_request.cpp
Comment thread src/common/json_request.cpp
Comment thread src/server/encryption_sequencer.cpp Outdated
using namespace dbps::enum_utils;

namespace {
constexpr const char* DBPS_VERSION_KEY = "dbps_version";

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Renamed it to dbpa_agent_version as suggested.

Comment thread src/server/encryption_sequencer.cpp Outdated
Comment on lines +393 to +394
std::cerr << "ERROR: EncryptionSequencer - encryption_metadata['" << DBPS_VERSION_KEY << "'] must start with '"
<< DBPS_VERSION_VALUE << "', but got '" << it->second << "'" << std::endl;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@argmarco-tkd argmarco-tkd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the changes. Left a couple of comments - in particular, I think we need a bit of clarification/improved description on the 'cache' for metadata.

Comment thread src/common/dbpa_local_test.cpp Outdated
using namespace dbps::external;

namespace {
const std::map<std::string, std::string> VALID_ENCRYPTION_METADATA = {{"dbps_agent_version", "v0.01"}};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: "Valid" hints that there is a counterpart, "invalid". Consider a different name. (maybe just a plain ENCRYPTION_METADATA or DBPS_ENCRYPTION_METADATA?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +35 to +40
const auto& response_attrs = response_->GetResponseAttributes();
if (!response_attrs.encryption_metadata_.empty()) {
cached_encryption_metadata_ = response_attrs.encryption_metadata_;
} else {
cached_encryption_metadata_ = std::nullopt;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

it's a clearer, thanks - but the whole concept of 'cached metadata' is a bit confusing. maybe let's add a short note on that? (in particular, why is it 'cached' ?)

…tionResult for clarity.

- Added DBPS_ENCRYPTION_METADATA constant to dbpa_local_test.cpp for clarity.
@avalerio-tkd

Copy link
Copy Markdown
Collaborator Author

@argmarco-tkd @sofia-tekdatum could you PTAL? I renamed the cached variables to parsed that I think captures the intention best, but let me know if we'd like another clarification for those.

@argmarco-tkd argmarco-tkd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM - thanks for all the changes!

@avalerio-tkd avalerio-tkd merged commit 9bf39b6 into main Nov 28, 2025
2 checks passed
@avalerio-tkd avalerio-tkd deleted the av_wire_encr_meta_05 branch November 28, 2025 00:09
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.

3 participants