Search in sources :

Example 6 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method runMightForkTest.

private void runMightForkTest(final BootstrapChecks.MightForkCheck check, final AtomicBoolean isSystemCallFilterInstalled, final Runnable disableMightFork, final Runnable enableMightFork, final Consumer<NodeValidationException> consumer) throws NodeValidationException {
    // if system call filter is disabled, nothing should happen
    isSystemCallFilterInstalled.set(false);
    if (randomBoolean()) {
        disableMightFork.run();
    } else {
        enableMightFork.run();
    }
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
    // if system call filter is enabled, but we will not fork, nothing should
    // happen
    isSystemCallFilterInstalled.set(true);
    disableMightFork.run();
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
    // if system call filter is enabled, and we might fork, the check should be enforced, regardless of bootstrap checks being enabled
    // or not
    isSystemCallFilterInstalled.set(true);
    enableMightFork.run();
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, randomBoolean(), Collections.singletonList(check)));
    consumer.accept(e);
}
Also used : NodeValidationException(org.opensearch.node.NodeValidationException)

Example 7 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testUseSerialGCCheck.

public void testUseSerialGCCheck() throws NodeValidationException {
    final AtomicReference<String> useSerialGC = new AtomicReference<>("true");
    final BootstrapCheck check = new BootstrapChecks.UseSerialGCCheck() {

        @Override
        String getUseSerialGC() {
            return useSerialGC.get();
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, true, Collections.singletonList(check)));
    assertThat(e.getMessage(), containsString("JVM is using the serial collector but should not be for the best performance; " + "" + "either it's the default for the VM [" + JvmInfo.jvmInfo().getVmName() + "] or -XX:+UseSerialGC was explicitly specified"));
    useSerialGC.set("false");
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
}
Also used : NodeValidationException(org.opensearch.node.NodeValidationException) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 8 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testMaxFileSizeCheck.

public void testMaxFileSizeCheck() throws NodeValidationException {
    final long rlimInfinity = Constants.MAC_OS_X ? 9223372036854775807L : -1L;
    final AtomicLong maxFileSize = new AtomicLong(randomIntBetween(0, Integer.MAX_VALUE));
    final BootstrapChecks.MaxFileSizeCheck check = new BootstrapChecks.MaxFileSizeCheck() {

        @Override
        long getMaxFileSize() {
            return maxFileSize.get();
        }

        @Override
        long getRlimInfinity() {
            return rlimInfinity;
        }
    };
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, true, Collections.singletonList(check)));
    assertThat(e.getMessage(), containsString("max file size"));
    maxFileSize.set(rlimInfinity);
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
    // nothing should happen if max file size is not available
    maxFileSize.set(Long.MIN_VALUE);
    BootstrapChecks.check(emptyContext, true, Collections.singletonList(check));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NodeValidationException(org.opensearch.node.NodeValidationException)

Example 9 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testMlockallCheck.

public void testMlockallCheck() throws NodeValidationException {
    class MlockallCheckTestCase {

        private final boolean mlockallSet;

        private final boolean isMemoryLocked;

        private final boolean shouldFail;

        MlockallCheckTestCase(final boolean mlockallSet, final boolean isMemoryLocked, final boolean shouldFail) {
            this.mlockallSet = mlockallSet;
            this.isMemoryLocked = isMemoryLocked;
            this.shouldFail = shouldFail;
        }
    }
    final List<MlockallCheckTestCase> testCases = new ArrayList<>();
    testCases.add(new MlockallCheckTestCase(true, true, false));
    testCases.add(new MlockallCheckTestCase(true, false, true));
    testCases.add(new MlockallCheckTestCase(false, true, false));
    testCases.add(new MlockallCheckTestCase(false, false, false));
    for (final MlockallCheckTestCase testCase : testCases) {
        final BootstrapChecks.MlockallCheck check = new BootstrapChecks.MlockallCheck() {

            @Override
            boolean isMemoryLocked() {
                return testCase.isMemoryLocked;
            }
        };
        BootstrapContext bootstrapContext = createTestContext(Settings.builder().put("bootstrap.memory_lock", testCase.mlockallSet).build(), null);
        if (testCase.shouldFail) {
            final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(bootstrapContext, true, Collections.singletonList(check)));
            assertThat(e.getMessage(), containsString("memory locking requested for opensearch process but memory is not locked"));
        } else {
            // nothing should happen
            BootstrapChecks.check(bootstrapContext, true, Collections.singletonList(check));
        }
    }
}
Also used : NodeValidationException(org.opensearch.node.NodeValidationException) ArrayList(java.util.ArrayList)

Example 10 with NodeValidationException

use of org.opensearch.node.NodeValidationException in project OpenSearch by opensearch-project.

the class BootstrapChecksTests method testAllPermissionCheck.

public void testAllPermissionCheck() throws NodeValidationException {
    final AtomicBoolean isAllPermissionGranted = new AtomicBoolean(true);
    final BootstrapChecks.AllPermissionCheck allPermissionCheck = new BootstrapChecks.AllPermissionCheck() {

        @Override
        boolean isAllPermissionGranted() {
            return isAllPermissionGranted.get();
        }
    };
    final List<BootstrapCheck> checks = Collections.singletonList(allPermissionCheck);
    final NodeValidationException e = expectThrows(NodeValidationException.class, () -> BootstrapChecks.check(emptyContext, true, checks));
    assertThat(e, hasToString(containsString("granting the all permission effectively disables security")));
    // if all permissions are not granted, nothing should happen
    isAllPermissionGranted.set(false);
    BootstrapChecks.check(emptyContext, true, checks);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) NodeValidationException(org.opensearch.node.NodeValidationException)

Aggregations

NodeValidationException (org.opensearch.node.NodeValidationException)22 Matchers.hasToString (org.hamcrest.Matchers.hasToString)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 Logger (org.apache.logging.log4j.Logger)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Settings (org.opensearch.common.settings.Settings)3 Path (java.nio.file.Path)2 DeprecationLogger (org.opensearch.common.logging.DeprecationLogger)2 SecureSettings (org.opensearch.common.settings.SecureSettings)2 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1