Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14513 from wallyworld/secret-rotation
#14513 Update the secret rotation infrastructure to work as per the spec. A few other changes were needed as well. Because the unit agent tracks the secret revision before the rotate hook runs, a new api call was added to fetch this info - but because this was also used for secret-ids outout and will also be used later for secret-get metadata, the api call was made to fit those use cases. And thus secret-ids was also updated. We will also need a expiry watcher later, so the guts of the rotation watcher was made generic to fit that too. ## Checklist - [X] Code style: imports ordered, good names, simple structure, etc - [X] Comments saying why design decisions were made - [X] Go unit tests, with comments saying what you're testing - ~[ ] [Integration tests](https://github.com/juju/juju/tree/develop/tests), with comments saying what you're testing~ - ~[ ] [doc.go](https://discourse.charmhub.io/t/readme-in-packages/451) added or updated in changed packages~ ## QA steps I hacked the hourly rotate policy to set the rotation time to 3 minutes deploy a charm with a secret-rotated hook ``` #!/bin/bash echo "secret-rotate" juju-log "secret-rotate uri=$JUJU_SECRET_ID label=$JUJU_SECRET_LABEL" secret-update $JUJU_SECRET_ID data2=foobar exit 0 ``` Add a secret and update its rotation policy. Check that no rotations happen until the policy is set. ``` juju exec --unit ubuntu/0 "secret-add data=foo" secret:cc2qophp7r7234v7clh0 juju exec --unit ubuntu/0 "secret-update secret:cc2qophp7r7234v7clh0 --rotate hourly" ``` After a few minutes, check debug-log to see the secret was rotated ``` unit-ubuntu-0: 14:46:42 INFO unit.ubuntu/0.juju-log secret-rotate uri=secret:cc2qophp7r7234v7clh0 label= ``` Also check the hook was run ``` juju show-status-log ubuntu/0 Time Type Status Message 24 Aug 2022 14:43:10+10:00 juju-unit allocating 24 Aug 2022 14:43:10+10:00 workload waiting waiting for machine 24 Aug 2022 14:43:10+10:00 workload waiting installing agent 24 Aug 2022 14:43:10+10:00 workload waiting agent initializing 24 Aug 2022 14:43:10+10:00 workload maintenance installing charm software 24 Aug 2022 14:43:10+10:00 juju-unit executing running install hook 24 Aug 2022 14:43:11+10:00 juju-unit executing running leader-elected hook 24 Aug 2022 14:43:11+10:00 juju-unit executing running config-changed hook 24 Aug 2022 14:43:11+10:00 juju-unit executing running start hook 24 Aug 2022 14:43:11+10:00 workload unknown 24 Aug 2022 14:43:11+10:00 juju-unit idle 24 Aug 2022 14:43:18+10:00 juju-unit executing running action juju-exec 24 Aug 2022 14:43:18+10:00 juju-unit idle 24 Aug 2022 14:43:41+10:00 juju-unit executing running action juju-exec 24 Aug 2022 14:43:41+10:00 juju-unit idle 24 Aug 2022 14:46:42+10:00 juju-unit executing running secret-rotate hook for secret:cc2qophp7r7234v7clh0 24 Aug 2022 14:46:42+10:00 juju-unit idle 24 Aug 2022 14:49:42+10:00 juju-unit executing running secret-rotate hook for secret:cc2qophp7r7234v7clh0 24 Aug 2022 14:49:42+10:00 juju-unit idle ``` And the revisions were updated ``` juju show-secret --revisions secret:cc2qophp7r7234v7clh0 cc2qophp7r7234v7clh0: revision: 3 rotation: hourly rotates: 2022-08-24T04:52:42Z owner: ubuntu created: 2022-08-24T04:43:18Z updated: 2022-08-24T04:49:42Z revisions: - revision: 1 created: 2022-08-24T04:43:18Z updated: 2022-08-24T04:43:18Z - revision: 2 created: 2022-08-24T04:46:42Z updated: 2022-08-24T04:46:42Z - revision: 3 created: 2022-08-24T04:49:42Z updated: 2022-08-24T04:49:42Z ```
- Loading branch information