-
Notifications
You must be signed in to change notification settings - Fork 12
Propagate requested entity secret for OpenSearch #267
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -458,7 +458,7 @@ def _on_subject_requested(self, event: SubjectRequestedEvent): | |
|
|
||
| # Increment this PATCH version before using `charmcraft publish-lib` or reset | ||
| # to 0 if you are raising the major API version | ||
| LIBPATCH = 59 | ||
| LIBPATCH = 60 | ||
|
|
||
| PYDEPS = ["ops>=2.0.0"] | ||
|
|
||
|
|
@@ -5422,6 +5422,8 @@ def __init__( | |
| extra_group_roles: Optional[str] = None, | ||
| entity_type: Optional[str] = None, | ||
| entity_permissions: Optional[str] = None, | ||
| requested_entity_name: Optional[str] = None, | ||
| requested_entity_password: Optional[str] = None, | ||
| ): | ||
| """Manager of OpenSearch client relations.""" | ||
| super().__init__( | ||
|
|
@@ -5432,6 +5434,9 @@ def __init__( | |
| extra_group_roles, | ||
| entity_type, | ||
| entity_permissions, | ||
| None, | ||
| requested_entity_name, | ||
| requested_entity_password, | ||
| ) | ||
| self.index = index | ||
|
|
||
|
|
@@ -5466,6 +5471,18 @@ def _on_relation_created_event(self, event: RelationCreatedEvent) -> None: | |
| if self.relation_data.entity_permissions: | ||
| data["entity-permissions"] = self.relation_data.entity_permissions | ||
|
|
||
| if self.relation_data.requested_entity_name: | ||
| content = {"entity-name": self.relation_data.requested_entity_name} | ||
| if self.relation_data.requested_entity_password: | ||
| content["password"] = self.relation_data.requested_entity_password | ||
| secret = self.charm.app.add_secret( | ||
| content, label=f"{self.model.uuid}-{event.relation.id}-requested-entity" | ||
| ) | ||
| secret.grant(event.relation) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will fail in cross-model relations, due to a constraint in Juju: Cross-model relations could be more relevant for Opensearch than they are for the current users of this feature, therefor I would recommend to take this into consideration before going forward with this PR. With #266 a solution was added for the mTLS certificate that could be adapted for the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For context, when I implemented this originally for Postgresql I followed the same approach as mTLS. Since mTLS itself switched, it makes sense to port this as well. I lack the context to say if it is a strict requirement for Opensearch or not. |
||
| if not secret.id: | ||
| raise SecretError("Secret helper missing Id") | ||
| data["requested-entity-secret"] = secret.id | ||
|
|
||
| self.relation_data.update_relation_data(event.relation.id, data) | ||
|
|
||
| def _on_secret_changed_event(self, event: SecretChangedEvent): | ||
|
|
@@ -5545,6 +5562,17 @@ def _on_relation_changed_event(self, event: RelationChangedEvent) -> None: | |
| event.relation, app=event.app, unit=event.unit | ||
| ) | ||
|
|
||
| if ( | ||
| self.relation_data.local_unit.is_leader() | ||
| and self.relation_data.requested_entity_name | ||
| and (secret_uri := app_databag.get("requested-entity-secret")) | ||
| ): | ||
| try: | ||
| secret = self.framework.model.get_secret(id=secret_uri) | ||
| secret.remove_all_revisions() | ||
| except ModelError: | ||
| logger.debug("Unable to remove helper secret") | ||
|
|
||
| # To avoid unnecessary application restarts do not trigger other events. | ||
| return | ||
|
|
||
|
|
@@ -5574,6 +5602,8 @@ def __init__( | |
| extra_group_roles: Optional[str] = None, | ||
| entity_type: Optional[str] = None, | ||
| entity_permissions: Optional[str] = None, | ||
| requested_entity_name: Optional[str] = None, | ||
| requested_entity_password: Optional[str] = None, | ||
| ) -> None: | ||
| OpenSearchRequiresData.__init__( | ||
| self, | ||
|
|
@@ -5585,6 +5615,8 @@ def __init__( | |
| extra_group_roles, | ||
| entity_type, | ||
| entity_permissions, | ||
| requested_entity_name, | ||
| requested_entity_password, | ||
| ) | ||
| OpenSearchRequiresEventHandlers.__init__(self, charm, self) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better pass keyword arguments instead of just
Noneto make it easier to read/understand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sharing a secret directly most probably won't be supported in v1, so it is OK to skip, but it is better to use keywords as requested.