[ 
https://issues.apache.org/jira/browse/KNOX-2200?focusedWorklogId=377802&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-377802
 ]

ASF GitHub Bot logged work on KNOX-2200:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Jan/20 18:40
            Start Date: 27/Jan/20 18:40
    Worklog Time Spent: 10m 
      Work Description: pzampino commented on pull request #243: KNOX-2200 - 
DefaultKeystoreService can lose entries under concurrent access
URL: https://github.com/apache/knox/pull/243#discussion_r371412749
 
 

 ##########
 File path: 
gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultKeystoreService.java
 ##########
 @@ -286,18 +287,21 @@ public KeyStore getCredentialStoreForCluster(String 
clusterName)
   @Override
   public void addCredentialForCluster(String clusterName, String alias, String 
value)
       throws KeystoreServiceException {
-    removeFromCache(clusterName, alias);
-    KeyStore ks = getCredentialStoreForCluster(clusterName);
-    if (ks != null) {
-      try {
-        final Key key = new 
SecretKeySpec(value.getBytes(StandardCharsets.UTF_8), "AES");
-        ks.setKeyEntry(alias, key, masterService.getMasterSecret(), null);
-
-        final Path keyStoreFilePath = keyStoreDirPath.resolve(clusterName + 
CREDENTIALS_SUFFIX);
-        writeKeyStoreToFile(ks, keyStoreFilePath, 
masterService.getMasterSecret());
-        addToCache(clusterName, alias, value);
-      } catch (KeyStoreException | IOException | CertificateException | 
NoSuchAlgorithmException e) {
-        LOG.failedToAddCredentialForCluster(clusterName, e);
+    // Needed to prevent read then write synchronization issue where alias is 
not added
+    synchronized (this) {
 
 Review comment:
   Sounds good to me
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 377802)
    Time Spent: 50m  (was: 40m)

> DefaultKeystoreService can lose entries under concurrent access
> ---------------------------------------------------------------
>
>                 Key: KNOX-2200
>                 URL: https://issues.apache.org/jira/browse/KNOX-2200
>             Project: Apache Knox
>          Issue Type: Bug
>            Reporter: Kevin Risden
>            Assignee: Kevin Risden
>            Priority: Major
>             Fix For: 1.4.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> DefaultKeystoreService can lose entires under concurrent access due to read 
> then write synchronization issues. There are cases where the keystore is 
> read, modified and then written back. This is not synchronized or handled 
> with a lock.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to