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

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

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

 ##########
 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:
   Changes the method signature. There isn't necessarily a need to synchronize 
the public method. This only comes up because we read the keystore then write 
to it. Other implementations can just add (ie: if this was a map we could 
update in place)
 
----------------------------------------------------------------
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: 377795)
    Time Spent: 40m  (was: 0.5h)

> 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: 40m
>  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