Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-23749: add NO_PERMISSIONS to CancelServiceTask #11815

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@
import org.apache.ignite.Ignite;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.client.thin.ServicesTest;
import org.apache.ignite.internal.processors.security.impl.TestSecurityData;
import org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.plugin.security.SecurityPermission;
import org.apache.ignite.plugin.security.SecurityPermissionSet;
import org.apache.ignite.plugin.security.SecurityPermissionSetBuilder;
import org.apache.ignite.services.ServiceConfiguration;
import org.apache.ignite.services.ServiceDescriptor;
import org.apache.ignite.util.GridCommandHandlerAbstractTest;
import org.junit.Test;
import org.junit.runners.Parameterized;
Expand All @@ -47,6 +50,7 @@
import static org.apache.ignite.plugin.security.SecurityPermission.CACHE_DESTROY;
import static org.apache.ignite.plugin.security.SecurityPermission.CACHE_READ;
import static org.apache.ignite.plugin.security.SecurityPermission.CACHE_REMOVE;
import static org.apache.ignite.plugin.security.SecurityPermission.SERVICE_CANCEL;
import static org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.ALL_PERMISSIONS;
import static org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.NO_PERMISSIONS;
import static org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.systemPermissions;
Expand Down Expand Up @@ -134,6 +138,38 @@ public void testCacheCreate() throws Exception {
);
}

/** */
@Test
public void testServiceCancel() throws Exception {
String srvcName = "testService";
Collection<String> cmdArgs = asList("--kill", "service", srvcName);

Ignite ignite = startGrid(
0,
userData(TEST_NO_PERMISSIONS_LOGIN, NO_PERMISSIONS),
userData(TEST_LOGIN, servicePermission(srvcName, SERVICE_CANCEL))
);

ServiceConfiguration srvcCfg = new ServiceConfiguration();

srvcCfg.setName(srvcName);
srvcCfg.setMaxPerNodeCount(1);
srvcCfg.setTotalCount(1);
srvcCfg.setService(new ServicesTest.TestService());

ignite.services().deploy(srvcCfg);

Collection<ServiceDescriptor> svcs = ignite.services().serviceDescriptors();

assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute(enrichWithConnectionArguments(cmdArgs, TEST_NO_PERMISSIONS_LOGIN)));
assertEquals(1, svcs.size());

assertEquals(EXIT_CODE_OK, execute(enrichWithConnectionArguments(cmdArgs, TEST_LOGIN)));

svcs = ignite.services().serviceDescriptors();
assertEquals(0, svcs.size());
}

/** */
protected IgniteEx startGrid(int idx, TestSecurityData... userData) throws Exception {
String login = getTestIgniteInstanceName(idx);
Expand Down Expand Up @@ -186,6 +222,14 @@ private SecurityPermissionSet cachePermission(SecurityPermission... perms) {
.build();
}

/** */
private SecurityPermissionSet servicePermission(String name, SecurityPermission... perms) {
return SecurityPermissionSetBuilder.create()
.defaultAllowAll(false)
.appendServicePermissions(name, perms)
.build();
}

/** */
private TestSecurityData userData(String login, SecurityPermissionSet perms) {
return new TestSecurityData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.visor.VisorJob;
import org.apache.ignite.internal.visor.VisorOneNodeTask;
import org.apache.ignite.plugin.security.SecurityPermissionSet;

import static org.apache.ignite.plugin.security.SecurityPermissionSetBuilder.NO_PERMISSIONS;

/**
* Task for cancel services with specified name.
Expand Down Expand Up @@ -60,6 +63,13 @@ protected CancelServiceJob(KillServiceCommandArg arg, boolean debug) {
return null;
}

/** {@inheritDoc} */
@Override public SecurityPermissionSet requiredPermissions() {
// This task does nothing but delegates the call to the Ignite public API.
// Therefore, it is safe to execute task without any additional permissions check.
return NO_PERMISSIONS;
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(CancelServiceJob.class, this);
Expand Down