feat(infra): Delete encoder credentials on teardown - #16
Merged
Conversation
The cleanup section asked the operator to delete every channel before destroying the stacks, or secrets would be left in the account. That is the kind of precondition a reader forgets, and the consequence is an orphaned credential, so teardown now handles it. Namespaces credentials per environment first, because it was a prerequisite. Passwords were stored under a shared /pois/channels prefix while the README states that several environments can coexist in one account and Region, so a purge scoped to that prefix would have deleted another environment's secrets. The prefix is now /pois/<env>/channels, injected through CREDENTIAL_PATH_PREFIX, and the IAM grants are scoped to it. The legacy prefix stays granted so channels created by an earlier deployment keep working: reads and deletes use the path recorded on the channel, not the current prefix. Adds a custom resource to the API stack that deletes everything under the environment's prefix when the stack is destroyed. It is inert on create and update, paginates the lookup, batches deletions in the ten-name limit of DeleteParameters, and logs failures instead of raising, since a cleanup error must not leave the stack in DELETE_FAILED. Verified the shipped handler against Parameter Store with twelve credentials in one environment prefix and two in another: create and update changed nothing, delete removed all twelve across both pages, and the other environment was untouched. Synth confirms the purge grant resolves to parameter/pois/dev/channels/* and parameter/pois/prod/channels/* respectively. Backend suite is at 196 passing, including new coverage for prefix resolution, environment isolation, and reads of credentials written under an earlier prefix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Teardown now deletes the encoder credentials it created, instead of asking the operator to remember a precondition.
The cleanup section told the reader to delete every channel from the dashboard before destroying the stacks, or Parameter Store secrets would be left in the account. That is exactly the kind of instruction a reader forgets, and the consequence is an orphaned credential.
Prerequisite: credentials were not namespaced per environment
Passwords were stored under a shared
/pois/channelsprefix, while the README states that several environments can coexist in one account and Region. A purge scoped to that prefix would have deleted another environment's secrets, so this had to be fixed first.Credentials now live under
/pois/<env>/channels, injected throughCREDENTIAL_PATH_PREFIX, with the IAM grants scoped to it. Synth confirms the isolation:pois-reference-server-dev-apiarn:aws:ssm:...:parameter/pois/dev/channels/*pois-reference-server-prod-apiarn:aws:ssm:...:parameter/pois/prod/channels/*The legacy prefix stays granted so that channels created by an earlier deployment keep working: reads and deletes use the parameter path recorded on the channel, not the current prefix. Existing deployments therefore keep functioning and drain naturally as channels are updated or deleted.
The custom resource
Added to the API stack. It is inert on create and update; the work happens on delete:
GetParametersByPathso more than one page is handledDeleteParameterswithin its ten-name limitDELETE_FAILED, which is worse than a leftover parameterTesting
The shipped handler was extracted from the construct and run against real Parameter Store with twelve credentials under one environment prefix and two under another:
The twelve spanned two pages of
GetParametersByPath, which exercises the pagination, and two batches ofDeleteParameters, which exercises the batching. Test parameters were removed afterwards.Also: infrastructure lint, build and
cdk synthfordevandprod; backend at 196 passing with coverage 72.90%, including new cases for prefix resolution from the environment variable, explicit override, trailing slash, environment isolation, and reading a credential written under an earlier prefix.Documentation
The cleanup section loses the manual step. What remains is the honest residue: log groups that expire on their own, and a note for anyone who deployed before this change that their credentials sit under the old shared prefix and are not covered by the purge.