-
Notifications
You must be signed in to change notification settings - Fork 27
[DPE-8395] Remove old revision of secret #1195
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
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1195 +/- ##
==========================================
- Coverage 75.76% 75.73% -0.04%
==========================================
Files 16 16
Lines 4163 4170 +7
Branches 629 629
==========================================
+ Hits 3154 3158 +4
- Misses 789 792 +3
Partials 220 220 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
…ision Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
return self._unit_ip | ||
|
||
def _on_secret_remove(self, event: SecretRemoveEvent) -> None: | ||
event.remove_revision() |
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.
When I was testing an implementation like this with my own charms, I ran into an issue with juju 3.6.9. We have a bugfix prepared that should make this implementation ok, but we might want to be defensive in how we write our charm.
juju/juju#20796 is the bug fix and
juju/juju#20794 is the issue.
Specifically, the issue is that older versions of juju, when a secret is fully-removed, will trigger secret-remove with the old revisions of the secret. However, that secret no longer exists, so that will cause the hook to fail, because it tries to delete something that doesn't exist.
I do see that you have some code to try and handle some of that:
def remove(self, label: str) -> None:
"""Remove a secret from the cache."""
if secret := self.get(label):
try:
secret.remove()
self._secrets.pop(label)
except (SecretsUnavailableError, KeyError):
pass
else:
return
logging.debug("Non-existing Juju Secret was attempted to be removed %s", label)
However, in my testing, because Juju tries to make the removal of a secret revision transaction consistent, it doesn't actually do anything until the hook completes, at which point, the charm has no way of resolving it (hence the above bug).
The fix that I did in my test charm was:
val=`secret-get $JUJU_SECRET_ID`
if [ -n "$val" ] ; then
secret-remove --revision $JUJU_SECRET_REVISION $JUJU_SECRET_ID;
else
juju-log -l WARNING secret $JUJU_SECRET_ID already deleted;
fi
I'm not a huge fan of the workaround. (Not least of which, it means that your application now becomes an observer of the charm content, so it will also get secret-changed
events. I suppose you might be able to use --peek
? I'm not sure if that sets you as an observer.)
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.
src/upgrade.py
Outdated
"--revision", | ||
str(revision), | ||
secret_id, | ||
] |
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.
This also won't work.
I tested this with just manually running hooks, and juju "queues up" a single revision to be removed. So if you just do:
juju exec --unit u/0 -- secret-remove --revision 1 $secret; secret-remove --revision 2 $secret
Then juju will only remove revision 2.
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.
I filed a bug about this behavior:
juju/juju#20805
and a PR to fix it:
juju/juju#20806
I don't know how you would work around this fact for existing versions of juju, as without the PR, you can only delete 1 revision per hook event.
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.
I noticed a different behaviour between the approach you commented about and the one that uses /usr/bin/juju-exec u/0 -- secret-remove --revision 1 $secret; /usr/bin/juju-exec u/0 -- secret-remove --revision 2 $secret
from inside the unit SSH or ops hook context.
The latter approach "queues up" all the revisions to be removed.
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.
I removed this upgrade logic on fec93f2 after syncing with @taurus-forever and agreeing that it's safer not to have it in the charm.
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
This reverts commit 0e29e0e. Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
This reverts commit 0e23c96. Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
@taurus-forever, I removed the upgrade logic on fec93f2 and tested the remaining workaround in the
It's working on all of them (the revisions are correctly removed, and no error happens when a secret is removed entirely, and the charm runs the |
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.
@dragomirp let's merge this to deploy PS6 and see the real production behavior in the test model for 14/edge. Tnx!
Also, @jameinel is not reachable till the end of the week, so assuming his comments have been addressed in full in the latest commits. John, please share your ACK/NACK once you are reachable.
For the history: due to the stable release time pressure and the list of Juju issues with secrets removal, we are NOT going to remove ALL old secrets on charm refresh (at least for now), as the code there was risky longterm. Therefor this PR removes the PREVIOUS revision only (once new secret revision has been applied). It will stop secrets grow.
However, manually cleanup will be necessary from Juju controller for all old revision. It will be necessary once only.
Fixed for 14/edge (merged) and porting to PG16 VM and PG K8s 14+16 (and PGB). P.S. See the last messages: |
This reverts commit 27c5225. Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
Issue
The charm does not remove the old revisions of a secret after updating it.
Solution
Implement the handler for the
secret-remove
event. juju/juju#20794 is taken into account.Implement the removal of the charm secrets' old revision in the upgrade logic. It's possible that not all the old revisions will be removed in an environment due to juju/juju#20782. For example, if the latest revision of a secret is 10 and there is an old one with the revision number equal to 1, that old revision won't be removed because its number is the prefix of the latest one.
Fixes #1180.
Checklist