Secret PUT with base64 binary secret fails with sqlalchemy error

Bug #1374270 reported by John Wood
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Barbican
Fix Released
Critical
John Wood

Bug Description

Trying to perform these operations fails with the stacktrace below:

curl -X POST -H 'content-type:application/json' -H 'X-Project-Id:12345' -d '{}' http://localhost:9311/v1/secrets
curl -X PUT -H 'content-type:application/octet-stream' -H 'content-encoding:base64' -H 'X-Project-Id:12345' -d 'bXktc2VjcmV0LWhlcmU=' http://localhost:9311/v1/secrets/<UUID>

----
Stacktrace:
2014-09-25 16:32:17.308 704 ERROR barbican.api.controllers [-] Secret update failure seen - please contact site administrator.
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers Traceback (most recent call last):
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 96, in handler
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 82, in enforcer
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/__init__.py", line 130, in content_types_enforcer
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers return fn(inst, *args, **kwargs)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/api/controllers/secrets.py", line 171, in on_put
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers transport_key_id=transport_key_id)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/plugin/resources.py", line 125, in store_secret
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers _save_secret(secret_model, tenant_model, repos)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/plugin/resources.py", line 365, in _save_secret
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers repos.secret_repo.save(secret_model)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/model/repositories.py", line 386, in save
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers entity.save(session=session)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/Repositories/github/Barbican/barbican/model/models.py", line 111, in save
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers session.add(self)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1492, in add
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._save_or_update_state(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1504, in _save_or_update_state
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._save_or_update_impl(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1761, in _save_or_update_impl
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._update_impl(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1755, in _update_impl
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers self._attach(state)
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers File "/home/john/.virtualenvs/Barbican/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1849, in _attach
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers state.session_id, self.hash_key))
2014-09-25 16:32:17.308 704 TRACE barbican.api.controllers InvalidRequestError: Object '<Secret at 0x7f662af1b450>' is already attached to session '90' (this is '94')

John Wood (john-wood-w)
Changed in barbican:
assignee: nobody → John Wood (john-wood-w)
Changed in barbican:
status: New → In Progress
Changed in barbican:
importance: Undecided → Critical
milestone: none → juno-rc1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to barbican (master)

Reviewed: https://review.openstack.org/124274
Committed: https://git.openstack.org/cgit/openstack/barbican/commit/?id=6b384e083059247ae29062f524b6c32a500d822b
Submitter: Jenkins
Branch: master

commit 6b384e083059247ae29062f524b6c32a500d822b
Author: jfwood <email address hidden>
Date: Fri Sep 26 00:17:03 2014 -0500

    Fix error in two-step secret PUT with base64

    An attempt to PUT base64-encoded binary data as the 2nd step in storing
    a secret resulted in a SQLAlchemy 'already attached in another session'
    error with the secret model. This CR moves to the SQLAlchemy scoped
    session which ensures one session per thread. This CR also adds a
    simple 'smoke test' script that was used to exercise the API during the
    development of this CR, and could be helpful for others looking for a
    simple way to test and evaluate their local Barbican API instances.

    Closes-Bug: #1374270
    Change-Id: Ie50e5f03be7b9b12d82a285a71e2f1b5c2483ea0

Changed in barbican:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in barbican:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in barbican:
milestone: juno-rc1 → 2014.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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