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

[DPE-3705, DPE-3542] Reintroduce fallback keys and fix TLS secrets initialization #427

Merged
merged 6 commits into from
Apr 4, 2024

Conversation

shayancanonical
Copy link
Contributor

Issue

  1. We are not correctly initializing some TLS secret keys (e.g. cert instead of certificate, cauth instead of certificate-authority)
  2. As part of PR 385, we got rid of the secret fallback keys. However, this is necessary for clients who are upgrading from old versions of the charm (without secrets) to this version of the charm (with secrets)

Solution

  1. Correctly initialize the TLS secret keys
  2. Re-introduce fallback keys in the framework of the new secrets lib (data_interfaces) (see Jira ticket for link to conversation for more context)

Copy link

codecov bot commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 60.86957% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 66.25%. Comparing base (2bd2bcc) to head (9126174).
Report is 2 commits behind head on main.

Files Patch % Lines
lib/charms/mysql/v0/mysql.py 59.09% 5 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #427      +/-   ##
==========================================
- Coverage   66.39%   66.25%   -0.14%     
==========================================
  Files          17       17              
  Lines        3169     3180      +11     
  Branches      419      424       +5     
==========================================
+ Hits         2104     2107       +3     
- Misses        930      935       +5     
- Partials      135      138       +3     

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

Copy link
Contributor

@paulomach paulomach left a comment

Choose a reason for hiding this comment

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

It looks correct. Two things:

  1. Did you've tests with some older charm revision?
  2. The mandatory libpatch bump!

@shayancanonical
Copy link
Contributor Author

Updated libpatch in 9cddb26

I tried testing upgrades from previous stable versions:

  • Rev 151 fails upgrade as the charm does not have pre-upgrade-check action
  • Rev 196 already stores the TLS keys in the appropriate secrets (with no chance to test fallback key)
  • The revision for when upgrades feature was merged is no longer accessible in CI due to expired logs

@carlcsaposs-canonical
Copy link
Contributor

  • The revision for when upgrades feature was merged is no longer accessible in CI due to expired logs

it's available from releases page (e.g. https://github.com/canonical/mysql-operator/releases?q=292&expanded=true)
also available as git tag on that commit

Copy link
Contributor

@carlcsaposs-canonical carlcsaposs-canonical left a comment

Choose a reason for hiding this comment

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

question (not sure if this is in scope): when upgrading to this version of the charm, is it safe to rollback to previous version?

self.peer_relation_unit.update_relation_data(peers.id, {key: value})

fallback_key_to_secret_key = {v: k for k, v in SECRET_KEY_FALLBACKS.items()}
if key in fallback_key_to_secret_key:
Copy link
Contributor

Choose a reason for hiding this comment

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

question: when would this be true on the new charm?

my naive thought is that the new charm would always use the new keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this would be true when an old charm (running on juju <= 3.1.4 when secrets were not introduced) would upgrade to the new charm. in this case, the value from the old fallback_key should be deleted, and new value should be stored in juju secrets with the new key

this functionality was present in the charm, but was accidentally removed with a refactor

Copy link
Contributor

Choose a reason for hiding this comment

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

does the new charm code ever call set_secret with key=old key name?

like, we're checking the key passed as an argument to see if it's a fallback key—we're not (I think) checking the key in the databag/secret

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i believe that the old (pre backups) code called set_secret with keys like (root_password) -> this is incompatible with juju secrets due to the underscore. in the this old code, set_secret set password in peer databag

the logic is as follows:

  • if the old/fallback key exists in either the databag (or secret - but cannot exist in secret), then delete it
  • update the new key in either the secret or the databag using data_interfaces

@shayancanonical shayancanonical changed the title [DPE-3705] Reintroduce fallback keys and fix TLS secrets initialization [DPE-3705, DPE-3542] Reintroduce fallback keys and fix TLS secrets initialization Apr 2, 2024
@shayancanonical shayancanonical merged commit e7c1809 into main Apr 4, 2024
43 of 45 checks passed
@shayancanonical shayancanonical deleted the fix/secrets_fallback_key branch April 4, 2024 21:00
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.

4 participants