Skip to content

[DPE-5306][SECURITY] No write before protocol init#194

Merged
delgod merged 5 commits intomainfrom
DPE-5306/no_write_before_protocol_init
Sep 27, 2024
Merged

[DPE-5306][SECURITY] No write before protocol init#194
delgod merged 5 commits intomainfrom
DPE-5306/no_write_before_protocol_init

Conversation

@juditnovak
Copy link
Contributor

@juditnovak juditnovak commented Sep 8, 2024

Issue

#193

In case any write operation may take place before the protocol is established the Provider may not yet be aware whether secrets are to be used or not. Thus, the write operation may end up as plain text in the databag, instead of secrets.

Example:

A charm may receive TLS certs anytime, that are to be shared on a client relation.
When the charm got the TLS secrest, it just "blindly" writes them using update_relation_data() on update-status or certificate-available or so.
Which technically could be executed BEFORE the Requirer (!!!!) relation-created handler would put the requested-secrets list -- highlighting that TLS certs are stored as a Juju Secret on this relation.

Solution

No Provider write operation is allowed before the initial part of the protocol is finished.

This can be assured by waiting until the Requirer would add the database field to the Relation Data. By this time the Requirer must have executed its relation-created hook (where requested-secrets is written to the databag)

NOTE: Given that the change is straightforward, while the scenario is non-trivial to reproduce. I believe that unittest coverage is sufficient.

NOTE2: This may be a breaking change for charms that were publishing sensitive data premature. Clearly corresponding charm code is to be fixed.

See PG corresponding fix with healthy pipelines: canonical/postgresql-operator#615

@juditnovak juditnovak force-pushed the DPE-5306/no_write_before_protocol_init branch 2 times, most recently from 11d633e to 0ceadda Compare September 8, 2024 22:53
@juditnovak juditnovak marked this pull request as ready for review September 8, 2024 23:47
@juditnovak juditnovak force-pushed the DPE-5306/no_write_before_protocol_init branch from 0ceadda to 40e2d13 Compare September 9, 2024 08:45
"""Set values for fields not caring whether it's a secret or not."""
req_secret_fields = []

if self.fetch_relation_field(relation.id, self.DATABASE_FIELD) is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: As for current conventions, the field MUST exist, but may be empty.

https://github.com/canonical/postgresql-test-app/blob/main/src/charm.py#L155

@juditnovak juditnovak force-pushed the DPE-5306/no_write_before_protocol_init branch from 40e2d13 to 5ed6b51 Compare September 9, 2024 12:35
@juditnovak juditnovak force-pushed the DPE-5306/no_write_before_protocol_init branch from 084987f to a95b6f5 Compare September 23, 2024 20:39
@juditnovak juditnovak force-pushed the DPE-5306/no_write_before_protocol_init branch from a95b6f5 to a46672c Compare September 23, 2024 21:13
Copy link
Contributor

@welpaolo welpaolo left a comment

Choose a reason for hiding this comment

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

Look good to me!

class ProviderData(Data):
"""Base provides-side of the data products relation."""

DATABASE_FIELD = "database"
Copy link
Contributor

Choose a reason for hiding this comment

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

DATABASE_FIELD is a little bit misleading maybe we can find a better name such as RESOURCE_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.

Done

@delgod delgod merged commit c569673 into main Sep 27, 2024
@delgod delgod deleted the DPE-5306/no_write_before_protocol_init branch September 27, 2024 07:44
tonyandrewmeyer pushed a commit to tonyandrewmeyer/data-platform-libs that referenced this pull request Jan 28, 2025
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.

[Missing] data interfaces should provide a property to ensure database_requested has run

4 participants