Uploaded image for project: 'Sentry (Retired)'
  1. Sentry (Retired)
  2. SENTRY-1474

createSentryRole() isn't thread-safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Bug
    • 1.7.0, 2.0.0
    • None
    • Core
    • None

    Description

      Here is the function createSentryRole():

        public CommitContext createSentryRole(String roleName)
            throws SentryAlreadyExistsException, SentryStandbyException {
          boolean rollbackTransaction = true;
          PersistenceManager pm = null;
          try {
            pm = openTransaction();
            createSentryRoleCore(pm, roleName);
            CommitContext commit = commitUpdateTransaction(pm);
            rollbackTransaction = false;
            return commit;
          } finally {
             ...
          }
        }
      

      And here is createSentryRoleCore():

        private void createSentryRoleCore(PersistenceManager pm, String roleName)
            throws SentryAlreadyExistsException {
          String trimmedRoleName = trimAndLower(roleName);
          MSentryRole mSentryRole = getMSentryRole(pm, trimmedRoleName);
          if (mSentryRole == null) {
            MSentryRole mRole = new MSentryRole(trimmedRoleName, System.currentTimeMillis());
            pm.makePersistent(mRole);
          } else {
            throw new SentryAlreadyExistsException("Role: " + trimmedRoleName);
          }
        }
      

      The problem is that after the call to getMSentryRole() the role can be added by another thread. So we will successfully add two instances of a role with the same name. After that calls to getMSentryRole() with this name will fail because we have two instances with the same name.

      Attachments

        Issue Links

          Activity

            People

              awleblang Alex Leblang
              akolb Alex Kolbasov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: