cinder metadata api's raises TypeError with 400 BadRequest if incorrect formatted metadata is passed

Bug #1674233 reported by Dinesh Bhor
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Undecided
Dinesh Bhor

Bug Description

This issue is there in the common method 'utils.check_metadata_properties' [1] which is not doing metadata validation properly which causes failure in below listed api's:

manage_volume, create_volume, update_volume, create_snapshot, metadata, update_snapshot

[1] https://github.com/openstack/cinder/blob/master/cinder/utils.py#L161-L181

Command:
cinder metadata 6876d9c6-0e3e-48c9-a833-c377591affc9 set sdf

Curl generated:
curl -g -i -X POST http://10.232.48.201:8776/v2/a3fe59b4d05141bf9c1e76d41701c7bc/volumes/6876d9c6-0e3e-48c9-a833-c377591affc9/metadata -H "User-Agent: python-cinderclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}22cc6371f97a4cbffb977ac4650c1cde25f83d07" -d '{"metadata": {"sdf": null}}'

OUTPUT:
ERROR: The server could not comply with the request since it is either malformed or otherwise incorrect. (HTTP 400) (Request-ID: req-1d774817-8671-49cc-bd21-f44f7ad19b06)

c-api logs:

2017-03-19 17:08:55.022 INFO cinder.volume.api [req-1d774817-8671-49cc-bd21-f44f7ad19b06 admin admin] Volume info retrieved success
fully.
2017-03-19 17:08:55.032 ERROR cinder.api.openstack.wsgi [req-1d774817-8671-49cc-bd21-f44f7ad19b06 admin admin] Exception handling r
esource: object of type 'NoneType' has no len()
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi Traceback (most recent call last):
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/api/openstack/wsgi.py", line 902, in _proc
ess_stack
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi action_result = self.dispatch(meth, request, action_args)
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/api/openstack/wsgi.py", line 997, in dispa
tch
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi return method(req=request, **action_args)
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/api/v2/volume_metadata.py", line 55, in cr
eate
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi use_create=True)
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/api/v2/volume_metadata.py", line 96, in _u
pdate_volume_metadata
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi metadata)
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/volume/api.py", line 101, in wrapped
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi return func(self, context, target_obj, *args, **kwargs)
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/volume/api.py", line 1043, in create_volum
e_metadata
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi db_meta = self._update_volume_metadata(context, volume, metadata)
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/volume/api.py", line 1069, in _update_volu
me_metadata
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi utils.check_metadata_properties(metadata)
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi File "/opt/stack/cinder/cinder/utils.py", line 177, in check_metadata_pro
perties
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi if len(v) > 255:
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi TypeError: object of type 'NoneType' has no len()
2017-03-19 17:08:55.032 TRACE cinder.api.openstack.wsgi

The metadata should be of format key=value.

Changed in cinder:
assignee: nobody → Dinesh Bhor (dinesh-bhor)
description: updated
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/452051

Changed in cinder:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/452051
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=4d4ba60f9b284044683eeaa4ca80674a0b7ee6db
Submitter: Jenkins
Branch: master

commit 4d4ba60f9b284044683eeaa4ca80674a0b7ee6db
Author: dineshbhor <email address hidden>
Date: Mon Mar 20 17:00:30 2017 +0530

    Fix metadata api's raises TypeError

    Volume and Snapshot related metadata api's are raising
    "TypeError: object of type 'NoneType' has no len()" if incorrect
    formatted metadata is passed. The common
    'utils.check_metadata_properties' method is not validating the
    metadata properly. This TypeError exception raised is converted
    into HTTPBadRequest at wsgi layer.

    Fixed this issue by raising an 'InvalidVolumeMetadata' exception
    if incorrect formatted metadata is passed to these api's giving
    400 HTTPBadRequest to the user. There will no defference in terms
    of response status code from user's point of view.

    Closes-Bug: #1674233
    Change-Id: Id86bb9d0887cebdb007df973cf87257924560fbe

Changed in cinder:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/cinder 11.0.0.0b2

This issue was fixed in the openstack/cinder 11.0.0.0b2 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.