Project details request with long ID causes 500 error with DB2

Bug #1386773 reported by Brant Knudson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
Medium
Brant Knudson

Bug Description

When using DB2 as the database, if you get project details with a really long ID (even if it doesn't exist), the you get a 500 error instead of 404 Not Found:

 $ curl -s -H "X-Auth-Token: $TOKEN" http://localhost:35357/v3/projects/915eb1fb90d34430b1dafbc712889924asldkjsalkfdjlaksdjflkdsajflkdsajfdsasad | python -m json.tool
{
    "error": {
        "code": 500,
        "message": "An unexpected error prevented the server from fulfilling your request: (DataError) ibm_db_dbi::DataError: Statement Execute Failed: [IBM][CLI Driver] CLI0109E String data right truncation. SQLSTATE=22001 SQLCODE=-99999 'SELECT project.id AS project_id, project.name AS project_name, project.domain_id AS project_domain_id, project.description AS project_description, project.enabled AS project_enabled, project.extra AS project_extra \\nFROM project \\nWHERE project.id = ?' ('915eb1fb90d34430b1dafbc712889924asldkjsalkfdjlaksdjflkdsajflkdsajfdsasad',) (Disable debug mode to suppress these details.)",
        "title": "Internal Server Error"
    }
}

I guess DB2 doesn't like getting a parameter that's longer than the column.

This probably applies to other resources, too.

Seems like the right thing to do here is either check the length in the SQL backend or catch this particular exception and reraise it as NotFound. Seems safer and more efficient to check the length in the SQL backend, although it's going to be a lot of changes.

Tags: sql db2
Brant Knudson (blk-u)
Changed in keystone:
assignee: nobody → Brant Knudson (blk-u)
tags: added: sql
Revision history for this message
Morgan Fainberg (mdrnstm) wrote :

This is something we should hit with validation. What is the maximum length of an ID? Or the DB2 driver should perhaps validate the length and raise something back up.

Revision history for this message
Morgan Fainberg (mdrnstm) wrote :

I'm marking this as triaged - I can't confirm db2 issues directly (don't have a means to do so).

Changed in keystone:
importance: Undecided → Medium
status: New → Triaged
Dolph Mathews (dolph)
tags: added: db2
Revision history for this message
Brant Knudson (blk-u) wrote :

Validation doesn't cover the query parameters in the URL.

The DB2 driver validates the length of the parameter and raises. It's the other drivers that don't.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (master)

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

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

Reviewed: https://review.openstack.org/163949
Committed: https://git.openstack.org/cgit/openstack/keystone/commit/?id=e9c44e215a459e13f4d3c2f67a3428a57076652b
Submitter: Jenkins
Branch: master

commit e9c44e215a459e13f4d3c2f67a3428a57076652b
Author: Brant Knudson <email address hidden>
Date: Thu Mar 12 15:14:34 2015 -0500

    Don't query db if criteria longer than col length

    When a long query parameter name is used (such as a name with
    more than 255 characters), this is never going to match a user
    in the SQL backend, because names can only be up to 255
    characters. Keystone doesn't have to bother querying the backend
    in these cases and doing so is unnecessary. With this change,
    these types of requests are short-circuited.

    Some databases (e.g., DB2) return an error if the query string is
    longer than the field.

    Change-Id: I68b3abaabec6cb46a9a320e312c0be7707009170
    Closes-Bug: #1386773

Changed in keystone:
status: In Progress → Fix Committed
Changed in keystone:
milestone: none → liberty-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in keystone:
milestone: liberty-1 → 8.0.0
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.