You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "anton-vinogradov (via GitHub)" <gi...@apache.org> on 2023/01/30 17:17:38 UTC

[GitHub] [ignite] anton-vinogradov commented on a diff in pull request #10226: IGNITE-15322 WIP

anton-vinogradov commented on code in PR #10226:
URL: https://github.com/apache/ignite/pull/10226#discussion_r1090814381


##########
modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java:
##########
@@ -203,7 +203,7 @@ public void setKernalContext(GridKernalContext ctx) {
     /**
      * @return {@link IgniteCompute} for this cluster group.
      */
-    public final IgniteCompute compute() {
+    public final IgniteComputeImpl compute() {

Review Comment:
   Keep interfaces at API when possible.
   No need to provide implementation here.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/security/SecurityPermissionAware.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.apache.ignite.plugin.security.SecurityPermissionSet;
+import org.apache.ignite.plugin.security.SecurityPermissionSetBuilder;
+
+/** */
+public interface SecurityPermissionAware {
+    /** */
+    public SecurityPermissionSet NO_PERMISSIONS = SecurityPermissionSetBuilder.create().build();

Review Comment:
   Incorrect definition place.
   Should be relocated to SecurityPermissionSetBuilder.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java:
##########
@@ -1736,4 +1763,51 @@ else if (!getLocJobStatistics && locNodeId.equals(jobResult.getNode().id()))
             return S.toString(GridTaskWorker.class, this);
         }
     }
+
+    /** */
+    private void authorizeSystemJobStart(ComputeJob job) {
+        Object executable = unwrap(job);
+
+        if (!isSystemType(ctx, executable.getClass())) {
+            ctx.security().authorize(executable.getClass().getName(), TASK_EXECUTE);
+
+            return;
+        }
+
+        if (executable instanceof SecurityPermissionAware)
+            authorizeAll(ctx.security(), ((SecurityPermissionAware)executable).requiredPermissions());
+        else if (opts.isSystemTaskGuard()) {
+            throw new SecurityException("Access to Ignite Internal tasks is restricted" +
+                " [task=" + task.getClass().getName() + ", job=" + executable.getClass() + "]");
+        }
+    }
+
+    /** */
+    public void authorizeTaskCancel() {
+        if (!ctx.security().enabled())
+            return;
+
+        if (!isSystemType(ctx, task.getClass())) {
+            ctx.security().authorize(task.getClass().getName(), TASK_CANCEL);
+
+            return;
+        }

Review Comment:
   Lines above are duplicated several times (5) in different forms.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/security/SecurityPermissionAware.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.apache.ignite.plugin.security.SecurityPermissionSet;
+import org.apache.ignite.plugin.security.SecurityPermissionSetBuilder;
+
+/** */
+public interface SecurityPermissionAware {
+    /** */
+    public SecurityPermissionSet NO_PERMISSIONS = SecurityPermissionSetBuilder.create().build();
+
+    /** */
+    public SecurityPermissionSet requiredPermissions();
+
+   /** */
+    public static SecurityPermissionSet cachePermissions(String cacheName, SecurityPermission... perms) {

Review Comment:
   Incorrect definition place.
   Should be relocated to SecurityPermissionSetBuilder.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java:
##########
@@ -1736,4 +1763,51 @@ else if (!getLocJobStatistics && locNodeId.equals(jobResult.getNode().id()))
             return S.toString(GridTaskWorker.class, this);
         }
     }
+
+    /** */
+    private void authorizeSystemJobStart(ComputeJob job) {
+        Object executable = unwrap(job);
+
+        if (!isSystemType(ctx, executable.getClass())) {
+            ctx.security().authorize(executable.getClass().getName(), TASK_EXECUTE);
+
+            return;
+        }
+
+        if (executable instanceof SecurityPermissionAware)
+            authorizeAll(ctx.security(), ((SecurityPermissionAware)executable).requiredPermissions());
+        else if (opts.isSystemTaskGuard()) {
+            throw new SecurityException("Access to Ignite Internal tasks is restricted" +
+                " [task=" + task.getClass().getName() + ", job=" + executable.getClass() + "]");
+        }
+    }
+
+    /** */
+    public void authorizeTaskCancel() {
+        if (!ctx.security().enabled())
+            return;
+
+        if (!isSystemType(ctx, task.getClass())) {
+            ctx.security().authorize(task.getClass().getName(), TASK_CANCEL);
+
+            return;

Review Comment:
   Could return be replaced with else if?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/task/TaskExecutionOptions.java:
##########
@@ -176,13 +176,13 @@ public TaskExecutionOptions asSystemTask() {
     }
 
     /** */
-    public boolean isAuthenticationDisabled() {
-        return isAuthDisabled;
+    public boolean isSystemTaskGuard() {
+        return isSystemTaskGuard;
     }
 
     /** */
-    public TaskExecutionOptions withAuthenticationDisabled() {
-        isAuthDisabled = true;
+    public TaskExecutionOptions withSystemTaskGuard() {
+        isSystemTaskGuard = true;
 
         return this;
     }

Review Comment:
   Looks like, this spetifies option for current thread only, is it safe?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskWorker.java:
##########
@@ -1736,4 +1763,51 @@ else if (!getLocJobStatistics && locNodeId.equals(jobResult.getNode().id()))
             return S.toString(GridTaskWorker.class, this);
         }
     }
+
+    /** */
+    private void authorizeSystemJobStart(ComputeJob job) {
+        Object executable = unwrap(job);
+
+        if (!isSystemType(ctx, executable.getClass())) {
+            ctx.security().authorize(executable.getClass().getName(), TASK_EXECUTE);
+
+            return;

Review Comment:
   Could return be replaced with else if?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java:
##########
@@ -1589,4 +1579,36 @@ public Map<ComputeJobStatusEnum, Long> jobStatuses(IgniteUuid sesId) {
         else
             return taskWorker.jobStatuses();
     }
+
+    /** */
+    private void authorizeTaskExecution(String taskName, Class<?> taskCls, ComputeTask<?, ?> task) {
+        taskCls = resolveTaskClass(taskName, taskCls, task);
+
+        if (taskCls != null && SecurityUtils.isSystemType(ctx, taskCls))
+            return;

Review Comment:
   Could return be replaced with else if?



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/security/SecurityPermissionAware.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.apache.ignite.plugin.security.SecurityPermissionSet;
+import org.apache.ignite.plugin.security.SecurityPermissionSetBuilder;
+
+/** */
+public interface SecurityPermissionAware {

Review Comment:
   Looks like correct mnemonic is about what it may do/be.
   For example, PublicJob.



##########
modules/core/src/main/java/org/apache/ignite/internal/IgniteComputeImpl.java:
##########
@@ -68,10 +68,11 @@ public class IgniteComputeImpl extends AsyncSupportAdapter<IgniteCompute>
     /** Custom executor name. */
     private String execName;
 
+    /** */
+    private boolean isSysTaskGuard;

Review Comment:
   Could this be replaced with something explains it's a public/private api?



-- 
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