This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
feat(ibm): Support looking up secrets in IBM Cloud Secret Manager by name #850
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.
This PR adds support for using names, instead of IDs, as the
key
s inExternalSecret
s with IBM Cloud Secrets Manager.With the current backend implementation, the
key
on eachdata
item is assumed to be an ID, which is assigned to each secret by Secrets Manager on creation. Secrets Manager's API and CLI are totally oriented around these IDs, which are generally not meaningful or useful to users. Users assign a name, not an ID, to secrets, and they should be able to reference them by that name. Fortunately, Secrets Manager's API does allow you to search for a secret by name and get its ID, so clients can use that to support referencing secrets by name.If I am defining
ExternalSecret
s in YAML and committing it to Git, I definitely want to put the names of the secrets in those YAMLs, not the IDs, which are specific to a particular instance of Secrets Manager (so they will always be different across different environments) and even a particular instance of the secret (if I have to delete a secret and create a new one with the same name, it will have a new ID). If I can't use names, I will have to update my YAMLs every time after adding the secrets to Secrets Manager, and I will be unable to share the same YAMLs across environments.My approach was not to change the default behaviour, since it has been released and is probably in use already. Rather, I added support for a new
keyByName
property on thespec
. If true, keys will be treated as names, and the backend will do the two-step lookup to find the ID by name and then the secret value by ID.While I was developing this, I really wanted the ability to test the backend code against a real instance of Secrets Manager, so I modified the unit tests to allow them to run with our without the stubs. A developer can set a few environment variables to disable the stubs and talk to a real Secrets Manager instance. By default, they'll run with the stubs for a fast, dependency-free unit test. I also added a few missing test cases to cover secret types that are supported by the existing code (
arbitrary
andiam_credentials
).I am currently using this successfully in a project, so I am confident that it works, at least.