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

Many versions of one secret in Key Vault #35923

Closed
jasperkpi opened this issue Jun 5, 2024 · 8 comments
Closed

Many versions of one secret in Key Vault #35923

jasperkpi opened this issue Jun 5, 2024 · 8 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. KeyVault question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@jasperkpi
Copy link

jasperkpi commented Jun 5, 2024

Is your feature request related to a problem? Please describe.
I'm using Azure Key Vault for API keys that rotate every 10 minutes. It uses an OAuth2 flow, where the access_token is valid for 600 seconds. We safe the new refresh_token that is generated every rotation in the key vault. This means I have secrets with as much as 20.000 versions. When I use the SecretClient.list_properties_of_secret_versions it takes minutes to load all the versions. Is there any way to fix this?

Describe the solution you'd like
How can I prevent having to load so many versions? I try to get the latest 10 versions, not all 20k.

Describe alternatives you've considered
I've considered:

  • Deleting old versions, which seems not to be possible. There's no "retention time" for versions. Only completely soft-delete the secret manually and rewrite as the same name - maybe?
  • Sorting the request, but versions don't come date-sorted on the Get Secret Versions as I've found. They come hexadecimally sorted based on the version id, which is kinda useless?

I don't care there are 20k versions, I'm fine Azure apparently wants to keep them. I just want to view the last 10 or so. How would this be possible? Am I forgetting about an option? Thanks.

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. KeyVault needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team. labels Jun 5, 2024
Copy link

github-actions bot commented Jun 5, 2024

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jlichwa @RandalliLama @schaabs.

@mccoyp
Copy link
Member

mccoyp commented Jun 15, 2024

Hi @jasperkpi, thank you for opening an issue -- I see how this scenario could be frustrating. @jlichwa, do you know if there's an option on the service's end to restrict the number of results we get from this operation?

@mccoyp
Copy link
Member

mccoyp commented Jun 17, 2024

@jasperkpi I tried reproducing your issue and found the same behavior; iterating over the full set of versions (after I had created 20,000) took a long time, and the sorting was deterministic but not chronological.

If your primary goal is just to get a small batch of secret versions for inspection, I would recommend using the by_page() method on the ItemPaged object you get back from list_properties_of_secret_versions. This will group the response into smaller pages that can be rapidly inspected. For example:

versions = client.list_properties_of_secret_versions(secret_name)
pages = versions.by_page()
single_page = next(pages)
for secret_properties in single_page:
    print(secret_properties.version)

The default page size is 25 entries, but you can change this by passing a smaller integer through a max_page_size keyword argument to list_properties_of_secret_versions.

If you specifically need the most recent versions of the secret, this seems to unfortunately require manual sorting (unless @jlichwa can comment on an alternative once he's back in the office). The other alternative could be to create new secrets instead of a new version of the same secret, though I understand how having a single secret name could be a requirement for shared referencing and simplicity.

@mccoyp mccoyp added needs-author-feedback Workflow: More information is needed from author to address the issue. and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Jun 18, 2024
Copy link

Hi @jasperkpi. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@jasperkpi
Copy link
Author

@mccoyp Thanks for your answer. I thought this would be the case. Unfortunately, I am looking for the most recent versions just to recover the not-current-but-last key. So only the recent 2 or 3 would be enough... This now means I have to get all 17.000 secret versions (with a OAuth refresh time of 10 minutes, versions are made at a rapid pace) and then sort them on changeddate.

versionlist = []
versions = client.list_properties_of_secret_versions(secret_name)
for version in versions:
    versionlist += [f'{str(version.created_on)[:19]} {{{version.version}}} ']
sortedversionlist = sorted(versionlist, reverse=1)

I just hoped I was completely missing out a function of list_properties_of_secret_versions that delivered a sorted list or something. Thanks!

@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. labels Jun 18, 2024
@mccoyp
Copy link
Member

mccoyp commented Jun 19, 2024

@jasperkpi it may be more performant to use metadata, such as tags, to record recent versions of the secret. That way you could fetch the most recent version of the key, inspect the tags, and then fetch the specific versions that are recorded. It would require multiple service requests, but it may save time overall.

I did discuss this with the service team and chronological version sorting unfortunately doesn't appear to be an option at this time. I'll mark this issue as resolved, but we'll be sure to incorporate this feedback into future planning. Thank you again for opening an issue!

@mccoyp mccoyp added issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. and removed needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Jun 19, 2024
Copy link

Hi @jasperkpi. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

Copy link

Hi @jasperkpi, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. KeyVault question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
Archived in project
Development

No branches or pull requests

2 participants