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

[MISC] Fix secret keys #212

Merged
merged 4 commits into from
Feb 8, 2024
Merged

[MISC] Fix secret keys #212

merged 4 commits into from
Feb 8, 2024

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Feb 6, 2024

Peer secrets were set as peer data.

Comment on lines +75 to +77
self._translate_field_to_secret_key(AUTH_FILE_DATABAG_KEY),
self._translate_field_to_secret_key(CFG_FILE_DATABAG_KEY),
self._translate_field_to_secret_key(MONITORING_PASSWORD_KEY),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed the transformed peer data keys to properly register as secrets.

Choose a reason for hiding this comment

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

Yes, but not just here...

get/set_secret() functions need to have it translated too, when passing the secret key to the lib.

)
assert secret_uri is not None
assert password is None
assert auth_file 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.

Hopefully avoid the same footgun in the future.

@@ -209,7 +209,6 @@ def _on_changed(self, event: HookEvent):
event.defer()
return

self.update_cfg(cfg)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Caused update secrets restart loop.

Comment on lines -273 to -282
tls_enabled = all(self.tls.get_tls_files())
if self.model.relations.get("certificates", []) and not tls_enabled:
logger.debug(
"pgbouncer_pebble_ready: Deferring as certificates files are not yet populated for existing certificates relation"
)
self.unit.status = WaitingStatus("Waiting for certificates")
event.defer()
return
# in case of pod restart
elif tls_enabled:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TLS test fails when deferring.

Comment on lines -133 to -153
@patch("charm.PostgreSQLTLS.get_tls_files")
@patch("ops.model.Container.make_dir")
def test_on_pgbouncer_pebble_ready_defer_tls(self, _mkdir, get_tls_files):
get_tls_files.return_value = (None, None, None)

self.harness.add_relation(BACKEND_RELATION_NAME, "postgres")
self.harness.add_relation("certificates", "tls_op")
self.harness.set_leader(True)
# emit on start to ensure config file render
self.charm.on.start.emit()
initial_plan = self.harness.get_container_pebble_plan(PGB)
self.assertEqual(initial_plan.to_yaml(), "{}\n")

container = self.harness.model.unit.get_container(PGB)
self.charm.on.pgbouncer_pebble_ready.emit(container)

assert not len(self.harness.model.unit.get_container(PGB).get_services())
get_tls_files.assert_called_once_with()
self.assertIsInstance(self.harness.model.unit.status, WaitingStatus)
self.assertEqual(self.harness.model.unit.status.message, "Waiting for certificates")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No longer deferring in on_pebble_ready

Copy link

@juditnovak juditnovak left a comment

Choose a reason for hiding this comment

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

LGTM

@juditnovak juditnovak self-requested a review February 7, 2024 11:14
Comment on lines +75 to +77
self._translate_field_to_secret_key(AUTH_FILE_DATABAG_KEY),
self._translate_field_to_secret_key(CFG_FILE_DATABAG_KEY),
self._translate_field_to_secret_key(MONITORING_PASSWORD_KEY),

Choose a reason for hiding this comment

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

Yes, but not just here...

get/set_secret() functions need to have it translated too, when passing the secret key to the lib.

Copy link

@juditnovak juditnovak left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

LGTM!

@dragomirp dragomirp merged commit d5233a5 into main Feb 8, 2024
29 checks passed
@dragomirp dragomirp deleted the secrets-fix branch February 8, 2024 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants