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

[Key Vault] 'TypeError: string indices must be integers' Raised During Retrieval #20399

Closed
ColtAllen opened this issue Aug 24, 2021 · 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. KeyVault question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Milestone

Comments

@ColtAllen
Copy link

  • Package Names: azure-keyvault-keys (v4.4.0) & azure-keyvault-secrets (v4.3.0)
  • Operating System: Cloud AzureML Service
  • Python Versions: 3.6.9 & 3.8.1

When attempting to retrieve KeyVault keys or secrets using either the SecretClient() or KeyClient() method in an AzureML Notebook, the following error trace is returned:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-51-f5144f2ccb52> in <module>
     63 
     64 client = KeyClient(vault_url=keyVaultName, credential=token)
---> 65 retrieved_key = client.get_key('KEY-NAME')

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azure/core/tracing/decorator.py in wrapper_use_tracer(*args, **kwargs)
     81             span_impl_type = settings.tracing_implementation()
     82             if span_impl_type is None:
---> 83                 return func(*args, **kwargs)
     84 
     85             # Merge span is parameter is set, but only if no explicit parent are passed

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azure/keyvault/keys/_client.py in get_key(self, name, version, **kwargs)
    276                 :dedent: 8
    277         """
--> 278         bundle = self._client.get_key(self.vault_url, name, key_version=version or "", error_map=_error_map, **kwargs)
    279         return KeyVaultKey._from_key_bundle(bundle)
    280 

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azure/keyvault/keys/_generated/_operations_mixin.py in get_key(self, vault_base_url, key_name, key_version, **kwargs)
   1337         mixin_instance._serialize.client_side_validation = False
   1338         mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
-> 1339         return mixin_instance.get_key(vault_base_url, key_name, key_version, **kwargs)
   1340 
   1341     def get_key_versions(

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azure/keyvault/keys/_generated/v7_2/operations/_key_vault_client_operations.py in get_key(self, vault_base_url, key_name, key_version, **kwargs)
    362 
    363         if response.status_code not in [200]:
--> 364             map_error(status_code=response.status_code, response=response, error_map=error_map)
    365             error = self._deserialize.failsafe_deserialize(_models.KeyVaultError, response)
    366             raise HttpResponseError(response=response, model=error)

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azure/core/exceptions.py in map_error(status_code, response, error_map)
     99     if not error_type:
    100         return
--> 101     error = error_type(response=response)
    102     raise error
    103 

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azure/keyvault/keys/_shared/exceptions.py in _get_exception_for_key_vault_error(cls, response)
     22     try:
     23         body = ContentDecodePolicy.deserialize_from_http_generics(response)
---> 24         message = "({}) {}".format(body["error"]["code"], body["error"]["message"])  # type: Optional[str]
     25     except (DecodeError, KeyError):
     26         # Key Vault error response bodies should have the expected shape and be deserializable.

TypeError: string indices must be integers

This type of error is usually raised whenever a list iterator is ran against a dictionary. Do these packages require Python>3.8.1?

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Aug 24, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Aug 26, 2021
@YalinLi0312
Copy link
Member

Thanks for your feedback, we'll investigate asap.

@mccoyp
Copy link
Member

mccoyp commented Aug 27, 2021

Hi @ColtAllen, thank you for opening an issue! Both of these packages support Python 3.6+, so you should be good there. I don't remember having seen this error before, so I'm looking into it now and will try to reproduce this locally. In the meantime, I have a couple of questions that would help me understand the context more:

  • First, are you seeing similar errors with any other SDK packages?
  • Second, are you able to make any successful calls with either client (e.g. setting a secret or listing keys)?
  • Lastly, would it be possible to capture the contents of the erroring response?

@mccoyp mccoyp added the Client This issue points to a problem in the data-plane of the library. label Aug 27, 2021
@ghost ghost added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Aug 27, 2021
@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 Aug 27, 2021
@mccoyp
Copy link
Member

mccoyp commented Aug 27, 2021

Update on this: I created an AzureML Notebook and tried to reproduce the issue, but I was able to successfully get a key and secret. Would it be possible to share a snippet of code from where this error is happening?

@ColtAllen
Copy link
Author

Hey @mccoyp, I appreciate your prompt response.

  • First, are you seeing similar errors with any other SDK packages?

We did not encounter any errors when using the asynchronous azure.keyvault.secrets.aio package, which has an identical code syntax to that of azure-keyvault-secrets. However, the secrets in question are database credentials, and the DB connector was not able to interpret the coroutine objects returned by azure.keyvault.secrets.aio. Asynchronous processes are also outside the scope of our project.

  • Second, are you able to make any successful calls with either client (e.g. setting a secret or listing keys)?

I am not. At this time the Key Vault does not contain any keys, only secrets. However, the same TypeError: string indices must be integers message is being returned for both the key and secret clients. If the resource does not exist, shouldn't a ResourceNotFoundError or HttpResponseError be raised instead?

  • Lastly, would it be possible to capture the contents of the erroring response?

The error trace is provided in my original post for this issue.

Update on this: I created an AzureML Notebook and tried to reproduce the issue, but I was able to successfully get a key and secret. Would it be possible to share a snippet of code from where this error is happening?

Unfortunately the original code was wiped out while resolving a merge conflict and is no longer available. However, after escalating this issue I was granted access to the Key Vault and noticed the secrets I was attempting to retrieve were expired. I'll recreate the secrets and see if I'm still getting the same error.

I will direct any further questions about the Key Vault service to Security Support. However, seeing as this now may be an issue regarding error handling (please see my bolded comments in this post) I would like to keep this open for now.

@ghost ghost 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 Aug 31, 2021
@mccoyp
Copy link
Member

mccoyp commented Aug 31, 2021

You're right that this kind of error response is surprising -- usually an HttpResponseError is raised for general errors relating to service issues, and I would have expected to see a response like that in the case of fetching an expired secret. I don't think I've tried getting an expired secret before, though, so that could be the source of the issue (I'll make a note to try this out!). I'm curious to see if renewing the secrets will resolve the issue, but I agree that leaving this open as a tracker for the error response is a good idea.

@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 Aug 31, 2021
@mccoyp mccoyp added this to the Backlog milestone Sep 1, 2021
@ghost ghost added the no-recent-activity There has been no recent activity on this issue. label Sep 8, 2021
@ghost
Copy link

ghost commented Sep 8, 2021

Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

@mccoyp mccoyp removed no-recent-activity There has been no recent activity on this issue. needs-author-feedback Workflow: More information is needed from author to address the issue. labels Sep 8, 2021
@ColtAllen
Copy link
Author

After working with MS Security and registering an app in the Azure Active Directory, I am now able to access the key vault without issue. However, I can also retrieve expired secrets; shouldn't that raise an error?

The code that raised the original error generated an authentication token via a user-defined function to access the key vault. It's interesting an improper authentication would raise a TypeError, but that seems to be what caused the issue.

I've notified MS Security about the expired secret access. If that is outside the scope of error handling, then this issue can be closed out.

@ColtAllen
Copy link
Author

I was just notified by MS Security that my above inquiry is expected behavior. This issue can now be closed.

azure-sdk pushed a commit to azure-sdk/azure-sdk-for-python that referenced this issue Oct 14, 2022
[2022-04-01-preview] Add New Api-version for Microsoft.ApiManagement (Azure#20399)

* Adds base for updating Microsoft.ApiManagement from version preview/2021-12-01-preview to version 2022-04-01-preview

* Updates readme

* Updates API version in new specs and examples

* APIM Auth Servers (Azure#19234)

* APIM Auth Servers

* adding x-ms-identifiers

* removing some weird, invisible special char

* formatting

* oAuth2AuthenticationSettings moved to AuthSettings

* Formatting

Co-authored-by: Milan Zolota <[email protected]>

* API Management Authorization Endpoints (Azure#19615)

* Add blockchain to latest profile

* Add additional types

* add authorizations definitions

* authorizations operations

* add examples

* update readme

* fix examples

* fix linter delete errors

* address CI validation errors

* prettier fix

* update to 2022-04

* fix readme

* Update specification/apimanagement/resource-manager/Microsoft.ApiManagement/preview/2022-04-01-preview/apimauthorizationproviders.json

Co-authored-by: Sean Kim <[email protected]>

* update versions

* Apply suggestions from code review

Co-authored-by: Mark Cowlishaw <[email protected]>
Co-authored-by: Annaji Sharma Ganti <[email protected]>
Co-authored-by: Annaji Sharma Ganti <[email protected]>

* Move Long running Create Operation from Location based to Azure-AsyncOperation Header (Azure#19733)

* azure-asyncOperation

* prettier

* fix(apim): Add missing 'metrics' property to diagnostics contract in 2022-04-01-preview (Azure#20317)

* apim /PUT apis import add translateRequiredQueryParameters (Azure#20333)

* [2022-04-01-preview] Replace resource with proxyresource and TrackedResource (Azure#20461)

* replace resource with proxyresource

* revert to proxyresource

* Add type object to authorization definitions (Azure#20631)

Authorization definitions were missing "type": "object", and this change adds that key/value pair

* Add type object to policy fragment definition (Azure#20585)

* APIM Open ID Connect providers (Azure#20622)

* APIM Open ID Connect providers

* added new proeprties for update

* prettier

* [APIM] Add Nat Gateway (Azure#19990)

* Update apimdeployment.json

* Create ApiManagementCreateServiceWithNatGatewayEnabled.json

* fix typo in file

* Change Nat Gateway property to enum

* modify type of natgateway state

* update property name

* add example reference

* small fix in example

* rename to  outboundPublicIPAddresses

Co-authored-by: Samir Solanki <[email protected]>

* [2022-04-01-preview] MIgrate2Stv2 API (Azure#20504)

* migrate2stv2

* updated to post

* 202 and location

* add body to 202

* remove body from 202

Co-authored-by: Vatsa Patel <[email protected]>
Co-authored-by: Samir Solanki <[email protected]>
Co-authored-by: [email protected] <[email protected]>

* Address Authorizations MissingTypeObject errors (Azure#20919)

* Add forgotten If-Match header (Azure#20920)

* Add forgotten If-Match header

`If-Match` header for the `DeleteAuthorizationAccessPolicy.json file` was forgotten. This change adds the wildcard character for the `If-Match` header for that file.

* Update ApiManagementDeleteAuthorization.json

* Use common types for specs and count as readonly (Azure#21023)

* common types

* count readonly

* Sasolank/more review comments (Azure#21025)

* XML

* proxy to gateway

* Update Authorizations Spec (Azure#21027)

* Update definitions.json

Update wording for PostGetLoginLink endpoint description

* Update apimauthorizationproviders.json

Add 201 response to all Authorization PUT requests

* Updated examples and fixed formatting

There was a formatting issue within apimauthorizationproviders.json, and the Authorization examples needed to be updated with the new 201 responses for creating/updating Authorization entities.

* Add long-running-operation key/value

Added x-ms-long-running-operation: true to Authorization PUT requests

* Remove long-running-operations

* readonly revert (Azure#21050)

* Set  SchemaContract.Document as required. (Azure#20110)

* Updated documentation of the SchemaContract. Server use to return code 500 in case SchemaContract.Document is null. That issue was fixed in the APIM and server will return proper response code.

* Fix AzureApiValidation

* update field with properties

* revert remaining readonly on collection (Azure#21051)

* Change to camel casing for "accesspolicies" (Azure#21070)

* Change to camel casing for "accesspolicies"

* More camel casing updates for access policies

* list example fixed (Azure#21089)

* fix definition (Azure#21110)

* upgrade to v3 for common types (Azure#21109)

* upgrade to v3

* Space

* revert to v2 proxyResource

Co-authored-by: Milan Zolota <[email protected]>
Co-authored-by: Milan Zolota <[email protected]>
Co-authored-by: Sean D Kim <[email protected]>
Co-authored-by: Mark Cowlishaw <[email protected]>
Co-authored-by: Annaji Sharma Ganti <[email protected]>
Co-authored-by: Annaji Sharma Ganti <[email protected]>
Co-authored-by: Tom Kerkhove <[email protected]>
Co-authored-by: Korolev Dmitry <[email protected]>
Co-authored-by: Logan Zipkes <[email protected]>
Co-authored-by: Rafał Mielowski <[email protected]>
Co-authored-by: malincrist <[email protected]>
Co-authored-by: GuanchenIntern <[email protected]>
Co-authored-by: VatsaPatel <[email protected]>
Co-authored-by: Vatsa Patel <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: Maxim Agapov <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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. KeyVault question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

3 participants