cloudstack icon indicating copy to clipboard operation
cloudstack copied to clipboard

Moving User with API key fails through MySQLIntegrityConstraintViolationException

Open mdesaive opened this issue 8 years ago • 7 comments

ISSUE TYPE
  • Bug Report
COMPONENT NAME

CLOUDSTACK VERSION
Advanced Networking, Cloudstack 4.11.0.0 on Ubuntu 14.04 LTS,
MySQL 5.5.59-0ubuntu0.14.04.1
CONFIGURATION
OS / ENVIRONMENT
SUMMARY

The API call "moveUser" on a user with an API key fails with a MySQLIntegrityConstraintViolationException.

Moving a user without API key works perfectly.

Looks to me, as if there is a constraint on mySQL not allowing to have a new user with the same API key to be prepared.

STEPS TO REPRODUCE
Prepare user with an API key.
Call "move user id=<user-id> account=<destination account name>"
EXPECTED RESULTS
The user to be moved to the destination account.
ACTUAL RESULTS
API call returns with:
--
(rz-admin) :D > move user id=56fab0c7-6724-46c0-9904-eff4020485ad account=AdminTeam-Intern-Individuell
Error 530: Entity already exists:
{
  "cserrorcode": 9999,
  "errorcode": 530,
  "errortext": "Entity already exists: ",
  "uuidList": []
} 
--
Exception in /var/log/cloudstack/management/management-server.log:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '<the api key>' for key 'i_user__api_key'
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

mdesaive avatar Jun 12 '18 07:06 mdesaive

thanks @mdesaive

DaanHoogland avatar Jun 13 '18 14:06 DaanHoogland

@DaanHoogland thanks a lot for taking care of this!

mdesaive avatar Jun 15 '18 07:06 mdesaive

welcome @mdesaive care to do a review of the code in return?

DaanHoogland avatar Jun 15 '18 09:06 DaanHoogland

Hi @DaanHoogland I did have a look at the code and it looks reasonable to me, although I have no Java Knowledge or IDE on hand. ;) If you like me to review it I can confirm it looks reasonable to me, assuming the following:

I understand the steps to move a user to another account like this:

  • create a new user with the neccesary data in the table "user"
  • put the foreign key for the destination account in "account_id"
  • do "some magic" to take care that all resources of the user are now assigned to the destination account. (Is the connection made by UUID?)

Reading your discussion with @rafaelweingartner in PR #2710 the reason for creating a new entry in the database is that you do not want to loose information that is connected to old user.

Looking in the code with a texteditor, I see, that you erase API-key and API-secret for one of the users. I assume it is the old user? So the user attached to the destination domain will still have the old API-key available?

mdesaive avatar Jun 15 '18 12:06 mdesaive

@mdesaive one of your assumptions is wrong; resources do not belong to users but to accounts, which means that a 'moved' user will loose all of it assets. The reasong for this change was to allow for a configuration change directed by a configured LDAP.

DaanHoogland avatar Jun 15 '18 14:06 DaanHoogland

@DaanHoogland I approved the changes for the PR. Hope I did that correctly, as it was my first time I reviewed code on GitHub. Please get back for me, if something more needs to be done.

mdesaive avatar Jun 15 '18 19:06 mdesaive

Fixed by PR: https://github.com/apache/cloudstack/pull/2710

PaulAngus avatar Jun 19 '18 14:06 PaulAngus