-
Notifications
You must be signed in to change notification settings - Fork 27
[DPE-6189] Manage passwords with user secrets #926
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
Conversation
… setting system-user passwords via user secrets
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (14.51%) is below the target coverage (33.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## 16/edge #926 +/- ##
===========================================
- Coverage 74.47% 73.52% -0.96%
===========================================
Files 12 12
Lines 3550 3565 +15
Branches 508 510 +2
===========================================
- Hits 2644 2621 -23
- Misses 709 749 +40
+ Partials 197 195 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ger makes sense as this is exactly the way passwords are retrieved with `get_password`
marceloneppel
left a comment
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.
Looks great! Thanks, @reneradoi!
marceloneppel
left a comment
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.
The async replication is failing with the following error after trying to set a secret through the standby cluster:
unit-postgresql-k8s-1: 17:54:38 ERROR unit.postgresql-k8s/1.juju-log Uncaught exception while in charm code:
Traceback (most recent call last):
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/model.py", line 3320, in _run
result = subprocess.run(args, **kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/subprocess.py", line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('/var/lib/juju/tools/unit-postgresql-k8s-1/relation-set', '-r', '3', '--app', '--file', '-')' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/src/charm.py", line 2475, in <module>
main(PostgresqlOperatorCharm, use_juju_for_storage=True)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/__init__.py", line 343, in __call__
return _main.main(charm_class=charm_class, use_juju_for_storage=use_juju_for_storage)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 558, in main
manager.run()
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 543, in run
self._emit()
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 502, in _emit
self._emit_charm_event(self.dispatcher.event_name)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/_main.py", line 530, in _emit_charm_event
event_to_emit.emit(*args, **kwargs)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/framework.py", line 347, in emit
framework._emit(event)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/framework.py", line 906, in _emit
self._reemit(event_path)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/framework.py", line 996, in _reemit
custom_handler(event)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 1109, in wrapped_function
return callable(*args, **kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/src/charm.py", line 1529, in _on_update_status
self.async_replication.update_async_replication_data()
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 1109, in wrapped_function
return callable(*args, **kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/src/relations/async_replication.py", line 725, in update_async_replication_data
self._update_primary_cluster_data()
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 1109, in wrapped_function
return callable(*args, **kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/src/relations/async_replication.py", line 772, in _update_primary_cluster_data
async_relation.data[self.charm.app]["primary-cluster-data"] = json.dumps(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/model.py", line 1908, in __setitem__
self._commit(key, value)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/model.py", line 1912, in _commit
self._backend.update_relation_data(self.relation.id, self._entity, key, value)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/model.py", line 3669, in update_relation_data
self.relation_set(relation_id, key, value, isinstance(_entity, Application))
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/model.py", line 3423, in relation_set
self._run(*args, input_stream=content)
File "/var/lib/juju/agents/unit-postgresql-k8s-1/charm/venv/lib/python3.12/site-packages/ops/model.py", line 3322, in _run
raise ModelError(e.stderr) from e
ops.model.ModelError: ERROR cannot read relation application settings: permission denied (unauthorized access)We'll investigate further next week.
|
Thanks @marceloneppel for finding this. I am not sure how this relates to the change, as it doesn't change how the data is stored internally. We could have a debugging session later today to try to find the root cause for this error. Please let me know how to proceed. |
|
The previous error I commented on here in the PR was related to using a secret with some messy data. So, the PR LGTM! |
This PR introduces juju user secrets for managing passwords. It contains the following changes:
Functionality:
get-passwordandset-passwordactionssystem-usersto configure a secret that includes the system users' password(s)passwordparameter to trigger a password rotation as secrets cannot have empty valuesImplementation:
secret_changedevent tocharm.pyget_secret_from_id()tocharm.pyconfig_changedleader_electedget_passwordhandlerset_passwordhandler with_update_admin_passwords()method_update_admin_passwords()is responsible for the actual business logic:postgresql.update_user_password()methodTesting:
get-passwordis the same as the output ofjuju show-secretget_password()andset_passwordto use secretsget-/set-passwordactions