You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/11/29 18:11:49 UTC

[GitHub] [ignite] nizhikov opened a new pull request #9616: IGNITE-16019 Fix check of SERVICE_DEPLOY permission

nizhikov opened a new pull request #9616:
URL: https://github.com/apache/ignite/pull/9616


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] nizhikov merged pull request #9616: IGNITE-16019 Fix check of SERVICE_DEPLOY permission

Posted by GitBox <gi...@apache.org>.
nizhikov merged pull request #9616:
URL: https://github.com/apache/ignite/pull/9616


   


-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ololo3000 commented on a change in pull request #9616: IGNITE-16019 Fix check of SERVICE_DEPLOY permission

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #9616:
URL: https://github.com/apache/ignite/pull/9616#discussion_r758667565



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/service/IgniteServiceProcessor.java
##########
@@ -1911,4 +1935,37 @@ private boolean enterBusy() {
     private void leaveBusy() {
         opsLock.readLock().unlock();
     }
+
+    /**
+     * Checks {@link SecurityPermission#SERVICE_DEPLOY} for each service.
+     * This method must use {@link SecurityContext} from node attributes because join not finished in time of validation.
+     * This mean SecurityProcessor doesn't know about joining node and can't return it security context based on node id.
+     *
+     * @param node Node to check.
+     * @param svcs Statically configured services.
+     * @return {@code SecurityException} in case node permissions not enough.
+     * @see ValidationOnNodeJoinUtils
+     */
+    private SecurityException checkDeployPermissionDuringJoin(ClusterNode node, ArrayList<ServiceInfo> svcs) {
+        SecurityContext secCtx;
+
+        try {
+            secCtx = nodeSecurityContext(marsh, U.resolveClassLoader(ctx.config()), node);
+
+            assert secCtx != null;
+        }
+        catch (SecurityException err) {
+            return err;
+        }
+
+        try (OperationSecurityContext ignored = ctx.security().withContext(secCtx)) {
+            for (ServiceInfo desc : svcs) {
+                SecurityException err = checkPermissions(desc.name(), SERVICE_DEPLOY);
+
+                if (err != null)
+                    return err;
+            }
+        }

Review comment:
       New line is missed.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/security/service/ServiceStaticConfigTest.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.processors.security.service;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.security.AbstractSecurityTest;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceConfiguration;
+import org.junit.Test;
+
+/** */
+public class ServiceStaticConfigTest extends AbstractSecurityTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setAuthenticationEnabled(true);
+
+        cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+            .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                .setPersistenceEnabled(true)));
+
+        ServiceConfiguration srvcCfg = new ServiceConfiguration();
+
+        srvcCfg.setName("CounterService");
+        srvcCfg.setMaxPerNodeCount(1);
+        srvcCfg.setTotalCount(1);
+        srvcCfg.setService(new CounterServiceImpl());
+
+        cfg.setServiceConfiguration(srvcCfg);
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testNodeStarted() throws Exception {
+        startGrid(0);
+        startGrid(1);
+
+        assertEquals(2, G.allGrids().size());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        cleanPersistenceDir();
+    }
+
+    /** */
+    public static class CounterServiceImpl implements Service {
+        /** Cntr. */
+        private final AtomicInteger cntr = new AtomicInteger();
+
+        /** Is started. */
+        volatile boolean isStarted;
+
+        /** {@inheritDoc} */
+        @Override public void init() throws Exception {
+            isStarted = true;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void execute() throws Exception {
+            while (isStarted) {

Review comment:
       Do we actually need this loop? It seems that it will be enough just to change some flag and check it in the `testNodeStarted` test.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/service/IgniteServiceProcessor.java
##########
@@ -1604,6 +1616,13 @@ public void onLocalJoin(DiscoveryEvent evt, DiscoCache discoCache) {
             // First node start, method onGridDataReceived(DiscoveryDataBag.GridDiscoveryData) has not been called.
             ArrayList<ServiceInfo> staticServicesInfo = staticallyConfiguredServices(false);
 
+            if (ctx.security().enabled()) {

Review comment:
        Security enabled check can be placed in the `checkDeployPermissionDuringJoin` method.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/service/IgniteServiceProcessor.java
##########
@@ -367,6 +371,27 @@ private void cancelDeployedServices() {
         dataBag.addJoiningNodeData(SERVICE_PROC.ordinal(), new ServiceProcessorJoinNodeDiscoveryData(staticServicesInfo));
     }
 
+    /** {@inheritDoc} */
+    @Override public @Nullable IgniteNodeValidationResult validateNode(
+        ClusterNode node,
+        DiscoveryDataBag.JoiningNodeDiscoveryData data
+    ) {
+        if (data.joiningNodeData() == null)
+            return null;
+
+        if (!ctx.security().enabled())
+            return null;
+
+        ArrayList<ServiceInfo> svcs = ((ServiceProcessorJoinNodeDiscoveryData)data.joiningNodeData()).services();

Review comment:
       `List` can be used here.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/service/IgniteServiceProcessor.java
##########
@@ -367,6 +371,27 @@ private void cancelDeployedServices() {
         dataBag.addJoiningNodeData(SERVICE_PROC.ordinal(), new ServiceProcessorJoinNodeDiscoveryData(staticServicesInfo));
     }
 
+    /** {@inheritDoc} */
+    @Override public @Nullable IgniteNodeValidationResult validateNode(
+        ClusterNode node,
+        DiscoveryDataBag.JoiningNodeDiscoveryData data
+    ) {
+        if (data.joiningNodeData() == null)

Review comment:
       This and the next if statement  can be merged into one.




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ololo3000 commented on a change in pull request #9616: IGNITE-16019 Fix check of SERVICE_DEPLOY permission

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #9616:
URL: https://github.com/apache/ignite/pull/9616#discussion_r758667438



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/service/IgniteServiceProcessor.java
##########
@@ -1604,6 +1616,13 @@ public void onLocalJoin(DiscoveryEvent evt, DiscoCache discoCache) {
             // First node start, method onGridDataReceived(DiscoveryDataBag.GridDiscoveryData) has not been called.
             ArrayList<ServiceInfo> staticServicesInfo = staticallyConfiguredServices(false);
 
+            if (ctx.security().enabled()) {

Review comment:
        Security enabled check can be placed in the `checkDeployPermissionDuringJoin` method.




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ololo3000 commented on a change in pull request #9616: IGNITE-16019 Fix check of SERVICE_DEPLOY permission

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #9616:
URL: https://github.com/apache/ignite/pull/9616#discussion_r758969562



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/service/IgniteServiceProcessor.java
##########
@@ -1911,4 +1932,37 @@ private boolean enterBusy() {
     private void leaveBusy() {
         opsLock.readLock().unlock();
     }
+
+    /**
+     * Checks {@link SecurityPermission#SERVICE_DEPLOY} for each service.
+     * This method must use {@link SecurityContext} from node attributes because join not finished in time of validation.
+     * This mean SecurityProcessor doesn't know about joining node and can't return it security context based on node id.
+     *
+     * @param node Node to check.
+     * @param svcs Statically configured services.
+     * @return {@code SecurityException} in case node permissions not enough.
+     * @see ValidationOnNodeJoinUtils
+     */
+    private SecurityException checkDeployPermissionDuringJoin(ClusterNode node, List<ServiceInfo> svcs) {
+        SecurityContext secCtx;
+
+        try {
+            secCtx = nodeSecurityContext(marsh, U.resolveClassLoader(ctx.config()), node);
+
+            assert secCtx != null;
+        }
+        catch (SecurityException err) {
+            return err;
+        }
+
+        try (OperationSecurityContext ignored = ctx.security().withContext(secCtx)) {
+            for (ServiceInfo desc : svcs) {
+                SecurityException err = checkPermissions(desc.name(), SERVICE_DEPLOY);
+
+                if (err != null)
+                    return err;
+            }
+        }
+        return null;

Review comment:
       New line is missed.




-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org