Skip to content

[DPE-5269] Add passwords to Syncobj and Patroni #596

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

Merged
merged 18 commits into from
Aug 29, 2024

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Aug 27, 2024

  • Add passwords to Patroni and Syncobj
  • Update libs

Closes #27

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 68.57143% with 11 lines in your changes missing coverage. Please review.

Project coverage is 70.85%. Comparing base (0c855f4) to head (e16a2f6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/relations/async_replication.py 16.66% 5 Missing ⚠️
src/cluster.py 75.00% 4 Missing ⚠️
src/upgrade.py 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #596      +/-   ##
==========================================
- Coverage   70.89%   70.85%   -0.04%     
==========================================
  Files          12       12              
  Lines        3030     3043      +13     
  Branches      536      538       +2     
==========================================
+ Hits         2148     2156       +8     
- Misses        768      771       +3     
- Partials      114      116       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@taurus-forever taurus-forever changed the title [DPE-5269] Add passowrds to Syncobj and Patroni [DPE-5269] Add passwords to Syncobj and Patroni Aug 27, 2024
@@ -27,7 +27,7 @@ get-password:
username:
type: string
description: The username, the default value 'operator'.
Possible values - operator, replication, rewind.
Possible values - operator, replication, rewind, patroni.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Users and tests need to be able to get at least the patroni password.

Comment on lines +901 to +910
for key in (
USER_PASSWORD_KEY,
REPLICATION_PASSWORD_KEY,
REWIND_PASSWORD_KEY,
MONITORING_PASSWORD_KEY,
RAFT_PASSWORD_KEY,
PATRONI_PASSWORD_KEY,
):
if self.get_secret(APP_SCOPE, key) is None:
self.set_secret(APP_SCOPE, key, new_password())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Loop to reduce McCabe.

@@ -164,6 +174,7 @@ def cluster_members(self) -> set:
f"{self._patroni_url}/{PATRONI_CLUSTER_STATUS_ENDPOINT}",
verify=self.verify,
timeout=API_REQUEST_TIMEOUT,
auth=self._patroni_auth,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

GETs are usually open, but adding for consistency.

Comment on lines +305 to +306
if self.charm.unit.is_leader():
return self.charm.model.app.add_secret(content=shared_content, label=SECRET_LABEL)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Started hitting this on follower units

@dragomirp dragomirp marked this pull request as ready for review August 28, 2024 11:08
@dragomirp dragomirp requested review from delgod, a team, taurus-forever, marceloneppel and lucasgameiroborges and removed request for a team August 28, 2024 11:08
Comment on lines +96 to +103
if self.charm.unit.is_leader() and self.charm._peers:
for key in (
RAFT_PASSWORD_KEY,
PATRONI_PASSWORD_KEY,
):
if self.charm.get_secret(APP_SCOPE, key) is None:
self.charm.set_secret(APP_SCOPE, key, new_password())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the correct place for generating the passes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's ok to put it here.

Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for the quick fix!
Let's wait @marceloneppel before merging.
P.S. we need to backport Patroni part to K8s charm :-(

Comment on lines +96 to +103
if self.charm.unit.is_leader() and self.charm._peers:
for key in (
RAFT_PASSWORD_KEY,
PATRONI_PASSWORD_KEY,
):
if self.charm.get_secret(APP_SCOPE, key) is None:
self.charm.set_secret(APP_SCOPE, key, new_password())

Copy link
Contributor

Choose a reason for hiding this comment

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

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! Thanks @dragomirp!

Comment on lines +96 to +103
if self.charm.unit.is_leader() and self.charm._peers:
for key in (
RAFT_PASSWORD_KEY,
PATRONI_PASSWORD_KEY,
):
if self.charm.get_secret(APP_SCOPE, key) is None:
self.charm.set_secret(APP_SCOPE, key, new_password())

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's ok to put it here.

Comment on lines +430 to +436
# If raft is getting encrypted some of the calls will fail
if member_status.status_code == 503 and raft_encryption:
logger.warning(
"Failed replication check for %s during raft encryption"
% members_ip
)
continue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still executing to have warnings in the log

Comment on lines +161 to +168
raft_encryption = (
int(
json.loads(self.peer_relation.data[self.charm.app].get("dependencies", "{}"))
.get("charm", {})
.get("version", 0)
)
< 3
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check for versions that don't encrypt RAFT. Seems to be only an issue for 1 (current 14/stable) but adding both previous version just in case.

Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you!

@dragomirp dragomirp merged commit 1ed5706 into main Aug 29, 2024
83 checks passed
@dragomirp dragomirp deleted the dpe-5269-add-patroni-passwords branch August 29, 2024 09:23
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.

Secure Patroni REST API from unauthorized access
5 participants