alex-plekhanov commented on a change in pull request #9290:
URL: https://github.com/apache/ignite/pull/9290#discussion_r686594421
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
##########
@@ -917,13 +927,63 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) {
discoCache,
notification.getTopSnapshot(),
stateFinishMsg,
- notification.getSpanContainer()
+ notification.getSpanContainer(),
+ secCtx
)
);
if (type == EVT_CLIENT_NODE_DISCONNECTED)
discoWrk.awaitDisconnectEvent();
}
+
+ /** */
+ class SecurityAwareNotificationTask extends NotificationTask {
+ /** */
+ public SecurityAwareNotificationTask(DiscoveryNotification
notification) {
+ super(notification);
+ }
+
+ /** */
+ @Override public void run() {
+ DiscoverySpiCustomMessage customMsg =
notification.getCustomMsgData();
+
+ if (customMsg instanceof
SecurityAwareCustomMessageWrapper) {
+ UUID secSubjId =
((SecurityAwareCustomMessageWrapper)customMsg).securitySubjectId();
+
+ try (OperationSecurityContext ignored =
ctx.security().withContext(secSubjId)) {
+ super.run();
+ }
+ }
+ else {
+ SecurityContext initiatorNodeSecCtx =
nodeSecurityContext(
+ marshaller,
+ U.resolveClassLoader(ctx.config()),
+ notification.getNode()
+ );
+
+ try (OperationSecurityContext ignored =
ctx.security().withContext(initiatorNodeSecCtx)) {
Review comment:
Why not `ctx.security().withContext(notification.getNode().id())` ?
Method `nodeSecurityContext()` unmarshalls security context every time, but
`withContext(UUID)` uses cache of contexts.
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/SecurityAwareCustomMessageWrapper.java
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.managers.discovery;
+
+import java.util.UUID;
+import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
+import org.jetbrains.annotations.Nullable;
+
+/** Extends {@link CustomMessageWrapper} with ID of security subject that
initiated the current message. */
+public class SecurityAwareCustomMessageWrapper extends CustomMessageWrapper {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Security subject ID. */
+ private final UUID secSubjId;
+
+ /** */
+ public SecurityAwareCustomMessageWrapper(DiscoveryCustomMessage delegate,
UUID secSubjId) {
+ super(delegate);
+
+ this.secSubjId = secSubjId;
+ }
+
+ /** Gets security Subject ID. */
+ public UUID securitySubjectId() {
+ return secSubjId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public @Nullable DiscoverySpiCustomMessage ackMessage() {
+ DiscoveryCustomMessage ack = delegate().ackMessage();
+
+ return ack == null ? null : new SecurityAwareCustomMessageWrapper(ack,
secSubjId);
+ }
+}
+
Review comment:
Redundant NL
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
##########
@@ -2980,6 +2983,13 @@ public BooleanMetricImpl clusterRebalancedMetric() {
return rebalanced;
}
+ /** Returns current thread security context if security is enabled,
otherwise null. */
+ @Nullable private SecurityContext securityContext() {
+ IgniteSecurity security = cctx.kernalContext().security();
+
+ return security.enabled() ? security.securityContext() : null;
Review comment:
I think it's safe to just return `security.securityContext()` (without
`enabled` check).
##########
File path:
modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
##########
@@ -917,13 +927,63 @@ else if (type == EVT_CLIENT_NODE_RECONNECTED) {
discoCache,
notification.getTopSnapshot(),
stateFinishMsg,
- notification.getSpanContainer()
+ notification.getSpanContainer(),
+ secCtx
)
);
if (type == EVT_CLIENT_NODE_DISCONNECTED)
discoWrk.awaitDisconnectEvent();
}
+
+ /** */
+ class SecurityAwareNotificationTask extends NotificationTask {
+ /** */
+ public SecurityAwareNotificationTask(DiscoveryNotification
notification) {
+ super(notification);
+ }
+
+ /** */
+ @Override public void run() {
+ DiscoverySpiCustomMessage customMsg =
notification.getCustomMsgData();
+
+ if (customMsg instanceof
SecurityAwareCustomMessageWrapper) {
+ UUID secSubjId =
((SecurityAwareCustomMessageWrapper)customMsg).securitySubjectId();
+
+ try (OperationSecurityContext ignored =
ctx.security().withContext(secSubjId)) {
+ super.run();
+ }
+ }
+ else {
+ SecurityContext initiatorNodeSecCtx =
nodeSecurityContext(
+ marshaller,
+ U.resolveClassLoader(ctx.config()),
+ notification.getNode()
+ );
+
+ try (OperationSecurityContext ignored =
ctx.security().withContext(initiatorNodeSecCtx)) {
+ super.run();
+ }
+ }
+ }
+ }
+
+ class NotificationTask implements Runnable {
Review comment:
JavaDoc
##########
File path:
modules/clients/src/test/java/org/apache/ignite/common/ComputeTaskRemoteSecurityContextTest.java
##########
@@ -105,7 +105,7 @@
@RunWith(Parameterized.class)
public class ComputeTaskRemoteSecurityContextTest extends AbstractSecurityTest
{
/** Port for REST client connection. */
- private static final String DFLT_REST_PORT = "11080";
+ static final String DFLT_REST_PORT = "11080";
Review comment:
Let's create a common abstract class instead for event testing with
security enabled. There are some methods which almost copy-pasted or reused in
these tests (`startGrid`, `getConfiguration`, `sendRestRequest`).
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]