Skip to content

Commit 31d17bf

Browse files
committed
IGNITE-12843 Don't send statically configured encrypted cache on join.
1 parent 48c62c7 commit 31d17bf

File tree

4 files changed

+29
-45
lines changed

4 files changed

+29
-45
lines changed

modules/core/src/main/java/org/apache/ignite/internal/managers/encryption/GridEncryptionManager.java

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadOnlyMetastorage;
5555
import org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadWriteMetastorage;
5656
import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
57-
import org.apache.ignite.internal.util.GridConcurrentHashSet;
5857
import org.apache.ignite.internal.util.distributed.DistributedProcess;
5958
import org.apache.ignite.internal.util.future.GridFinishedFuture;
6059
import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -164,9 +163,6 @@ public class GridEncryptionManager extends GridManagerAdapter<EncryptionSpi> imp
164163
/** Group encryption keys. */
165164
private final ConcurrentHashMap<Integer, Serializable> grpEncKeys = new ConcurrentHashMap<>();
166165

167-
/** Cache groups for which the key has been generated (updates on client node). */
168-
private final Set<Integer> readyToStartOnClientGrps = new GridConcurrentHashSet<>();
169-
170166
/** Pending generate encryption key futures. */
171167
private ConcurrentMap<IgniteUuid, GenerateEncryptionKeyFuture> genEncKeyFuts = new ConcurrentHashMap<>();
172168

@@ -465,14 +461,8 @@ public void onLocalJoin() {
465461
@Override public void onJoiningNodeDataReceived(JoiningNodeDiscoveryData data) {
466462
NodeEncryptionKeys nodeEncryptionKeys = (NodeEncryptionKeys)data.joiningNodeData();
467463

468-
if (nodeEncryptionKeys == null || nodeEncryptionKeys.newKeys == null)
469-
return;
470-
471-
if (ctx.clientNode()) {
472-
readyToStartOnClientGrps.addAll(nodeEncryptionKeys.newKeys.keySet());
473-
464+
if (nodeEncryptionKeys == null || nodeEncryptionKeys.newKeys == null || ctx.clientNode())
474465
return;
475-
}
476466

477467
for (Map.Entry<Integer, byte[]> entry : nodeEncryptionKeys.newKeys.entrySet()) {
478468
if (groupKey(entry.getKey()) == null) {
@@ -514,16 +504,13 @@ else if (newKeys != null) {
514504

515505
/** {@inheritDoc} */
516506
@Override public void onGridDataReceived(GridDiscoveryData data) {
517-
Map<Integer, byte[]> encKeysFromCluster = (Map<Integer, byte[]>)data.commonData();
518-
519-
if (F.isEmpty(encKeysFromCluster))
507+
if (ctx.clientNode())
520508
return;
521509

522-
if (ctx.clientNode()) {
523-
readyToStartOnClientGrps.addAll(encKeysFromCluster.keySet());
510+
Map<Integer, byte[]> encKeysFromCluster = (Map<Integer, byte[]>)data.commonData();
524511

512+
if (F.isEmpty(encKeysFromCluster))
525513
return;
526-
}
527514

528515
for (Map.Entry<Integer, byte[]> entry : encKeysFromCluster.entrySet()) {
529516
if (groupKey(entry.getKey()) == null) {
@@ -538,17 +525,6 @@ else if (newKeys != null) {
538525
}
539526
}
540527

541-
/**
542-
* @param grpId Cache group ID.
543-
* @return {@code True} if for specified cache group encryption key has been generated.
544-
*/
545-
public boolean hasEncryptionKeyForGroup(int grpId) {
546-
if (ctx.clientNode())
547-
return readyToStartOnClientGrps.contains(grpId);
548-
549-
return groupKey(grpId) != null;
550-
}
551-
552528
/**
553529
* Returns group encryption key.
554530
*

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,15 @@ public void validateNoNewCachesWithNewFormat(CacheNodeCommonDiscoveryData cluste
14051405
}
14061406
}
14071407

1408+
for (CacheConfiguration<?, ?> cfg : ctx.config().getCacheConfiguration()) {
1409+
if (!cfg.isEncryptionEnabled() || registeredCaches.containsKey(cfg.getName()))
1410+
continue;
1411+
1412+
log.warning("Encrypted cache statically configured on a client node " +
1413+
"cannot be started when the node joining to the cluster, it will " +
1414+
"start dynamically after the node will be joined [cacheName=" + cfg.getName() + ']');
1415+
}
1416+
14081417
return conflictErr;
14091418
}
14101419

@@ -2003,12 +2012,6 @@ private String processJoiningNode(CacheJoinNodeDiscoveryData joinData, UUID node
20032012
if (!registeredCaches.containsKey(cfg.getName())) {
20042013
String conflictErr = checkCacheConflict(cfg);
20052014

2006-
if (conflictErr == null && !locJoin && cfg.isEncryptionEnabled() &&
2007-
!ctx.encryption().hasEncryptionKeyForGroup(CU.cacheGroupId(cfg.getName(), cfg.getGroupName()))) {
2008-
conflictErr = "Encryption key for the cache cannot be generated on the client node, this node " +
2009-
"will dynamically start this cache after join to topology [cacheName=" + cfg.getName() + ']';
2010-
}
2011-
20122015
if (conflictErr != null) {
20132016
if (locJoin)
20142017
return conflictErr;

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridLocalConfigManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ private void restoreCaches(
159159
CacheConfiguration[] cfgs = config.getCacheConfiguration();
160160

161161
for (int i = 0; i < cfgs.length; i++) {
162+
// Encrypted cache statically configured on a client node cannot be started when the node joining
163+
// to the cluster, it will start dynamically after the node will be joined.
164+
if (cfgs[i].isEncryptionEnabled() && ctx.clientNode())
165+
continue;
166+
162167
CacheConfiguration<?, ?> cfg = new CacheConfiguration(cfgs[i]);
163168

164169
// Replace original configuration value.

modules/core/src/test/java/org/apache/ignite/internal/encryption/EncryptedCacheNodeJoinTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,7 @@ public void testClientNodeJoinWithStaticCacheConfig() throws Exception {
241241
/** */
242242
@Test
243243
public void testClientNodeJoinWithNewStaticCacheConfig() throws Exception {
244-
listeningLog = new ListeningTestLogger(log);
245-
246-
LogListener lsnr = LogListener.matches(s -> s.contains("Ignore cache received from joining node. " +
247-
"Encryption key for the cache cannot be generated on the client node, this node will dynamically start " +
248-
"this cache after join to topology [cacheName=" + cacheName() + ']')).times(3).build();
249-
250-
listeningLog.registerListener(lsnr);
251-
252244
checkNodeJoinWithNewStaticCacheConfig(true);
253-
254-
// An encrypted cache statically defined on the client must be dynamically started.
255-
assertTrue(lsnr.check());
256245
}
257246

258247
/** */
@@ -265,6 +254,14 @@ public void testServerNodeJoinWithNewStaticCacheConfig() throws Exception {
265254
* @param client {@code True} to test client node join, {@code False} to test server node join.
266255
*/
267256
public void checkNodeJoinWithNewStaticCacheConfig(boolean client) throws Exception {
257+
listeningLog = new ListeningTestLogger(log);
258+
259+
LogListener lsnr = LogListener.matches(s -> s.contains("Encrypted cache statically configured on a client " +
260+
"node cannot be started when the node joining to the cluster, it will start dynamically after the node " +
261+
"will be joined [cacheName=" + cacheName() + ']')).times(client ? 1 : 0).build();
262+
263+
listeningLog.registerListener(lsnr);
264+
268265
startGrid(GRID_0);
269266
startGrid(GRID_3);
270267

@@ -299,6 +296,9 @@ public void checkNodeJoinWithNewStaticCacheConfig(boolean client) throws Excepti
299296
}
300297

301298
checkEncryptedCaches(node, grid(GRID_0));
299+
300+
// An encrypted cache statically defined on the client must be dynamically started.
301+
assertTrue(lsnr.check());
302302
}
303303

304304
/** */

0 commit comments

Comments
 (0)