Search in sources :

Example 6 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.

the class PassThroughProxyProvisioner method constructSignatureKeyPair.

/**
 * Constructs a key pair to satisfy JWT proxy which needs a key pair in its configuration. In case
 * of pass-through proxy, this key pair is unused so we just generate a random one.
 *
 * @return a random key pair
 * @throws InternalInfrastructureException if RSA is not available as a key pair generator. This
 *     should not happen.
 */
private static KeyPair constructSignatureKeyPair() throws InternalInfrastructureException {
    try {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
        kpg.initialize(512);
        return kpg.generateKeyPair();
    } catch (NoSuchAlgorithmException e) {
        throw new InternalInfrastructureException("Could not generate a fake key pair to support JWT proxy in single-user mode.");
    }
}
Also used : KeyPairGenerator(java.security.KeyPairGenerator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 7 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.

the class StartSynchronizerTest method shouldWrapExceptionIntoInternalExcWhenItIsCompletedWithNonInfraException.

@Test
public void shouldWrapExceptionIntoInternalExcWhenItIsCompletedWithNonInfraException() {
    // given
    RuntimeException toThrow = new RuntimeException("test exception");
    startSynchronizer.completeExceptionally(toThrow);
    // when
    InfrastructureException startFailure = startSynchronizer.getStartFailureNow();
    // then
    assertTrue(startFailure instanceof InternalInfrastructureException);
    assertEquals(startFailure.getCause(), toThrow);
}
Also used : InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Test(org.testng.annotations.Test)

Example 8 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.

the class TerminalServerLivenessProbeConfigFactory method get.

@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
    URI uri;
    try {
        uri = new URI(server.getUrl());
    } catch (URISyntaxException e) {
        throw new InternalInfrastructureException("Terminal agent server liveness probe url is invalid. Error: " + e.getMessage());
    }
    String protocol;
    if ("wss".equals(uri.getScheme())) {
        protocol = "https";
    } else {
        protocol = "http";
    }
    int port;
    if (uri.getPort() == -1) {
        if ("http".equals(protocol)) {
            port = 80;
        } else {
            port = 443;
        }
    } else {
        port = uri.getPort();
    }
    String path = uri.getPath().replaceFirst("/pty$", "/liveness");
    return new HttpProbeConfig(port, uri.getHost(), protocol, path, null, successThreshold, 3, 120, 10, 10);
}
Also used : URISyntaxException(java.net.URISyntaxException) HttpProbeConfig(org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig) URI(java.net.URI) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 9 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project devspaces-images by redhat-developer.

the class WsAgentServerLivenessProbeConfigFactory method get.

@Override
public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException {
    try {
        // add check path
        URI uri = UriBuilder.fromUri(server.getUrl()).path("/liveness").build();
        int port;
        if (uri.getPort() == -1) {
            if ("http".equals(uri.getScheme())) {
                port = 80;
            } else {
                port = 443;
            }
        } else {
            port = uri.getPort();
        }
        return new HttpProbeConfig(port, uri.getHost(), uri.getScheme(), uri.getPath(), singletonMap(HttpHeaders.AUTHORIZATION, "Bearer " + machineTokenProvider.getToken(userId, workspaceId)), successThreshold, 3, 120, 10, 10);
    } catch (MachineTokenException e) {
        throw new InternalInfrastructureException("Failed to retrieve workspace token for ws-agent server liveness probe. Error: " + e.getMessage());
    } catch (UriBuilderException e) {
        throw new InternalInfrastructureException("Wsagent server liveness probe url is invalid. Error: " + e.getMessage());
    }
}
Also used : MachineTokenException(org.eclipse.che.api.workspace.server.token.MachineTokenException) HttpProbeConfig(org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig) UriBuilderException(jakarta.ws.rs.core.UriBuilderException) URI(java.net.URI) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Example 10 with InternalInfrastructureException

use of org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException in project che-server by eclipse-che.

the class JwtProxyConfigBuilder method build.

public String build() throws InternalInfrastructureException {
    List<VerifierProxyConfig> proxyConfigs = new ArrayList<>();
    Config config = new Config().withJWTProxy(new JWTProxy().withSignerProxy(new SignerProxyConfig().withEnabled(false)).withVerifiedProxyConfigs(proxyConfigs));
    for (VerifierProxy verifierProxy : verifierProxies) {
        VerifierConfig verifierConfig = new VerifierConfig().withAudience(workspaceId).withUpstream(verifierProxy.upstream).withMaxSkew("1m").withMaxTtl(ttl).withKeyServer(new RegistrableComponentConfig().withType("preshared").withOptions(ImmutableMap.of("issuer", issuer, "key_id", workspaceId, "public_key_path", JWT_PROXY_CONFIG_FOLDER + '/' + JWT_PROXY_PUBLIC_KEY_FILE))).withCookiesEnabled(verifierProxy.cookiesAuthEnabled).withCookiePath(ensureStartsWithSlash(verifierProxy.cookiePath)).withClaimsVerifier(Collections.singleton(new RegistrableComponentConfig().withType("static").withOptions(ImmutableMap.of("iss", issuer)))).withNonceStorage(new RegistrableComponentConfig().withType("void"));
        if (!verifierProxy.excludes.isEmpty()) {
            verifierConfig.setExcludes(verifierProxy.excludes);
        }
        if (verifierProxy.cookiesAuthEnabled && authPageUrl != null) {
            verifierConfig.setAuthUrl(authPageUrl.toString());
        }
        if (verifierProxy.publicBasePath != null) {
            verifierConfig.setPublicBasePath(verifierProxy.publicBasePath);
        }
        VerifierProxyConfig proxyConfig = new VerifierProxyConfig().withListenAddr(":" + verifierProxy.listenPort).withVerifierConfig(verifierConfig);
        proxyConfigs.add(proxyConfig);
    }
    try {
        return YAML_PARSER.writeValueAsString(config);
    } catch (JsonProcessingException e) {
        throw new InternalInfrastructureException("Error during creation of JWTProxy config YAML: " + e.getMessage(), e);
    }
}
Also used : SignerProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.SignerProxyConfig) VerifierConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierConfig) Config(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.Config) RegistrableComponentConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.RegistrableComponentConfig) SignerProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.SignerProxyConfig) VerifierProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierProxyConfig) RegistrableComponentConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.RegistrableComponentConfig) ArrayList(java.util.ArrayList) VerifierProxyConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierProxyConfig) VerifierConfig(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.VerifierConfig) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JWTProxy(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.model.JWTProxy) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)

Aggregations

InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)18 ArrayList (java.util.ArrayList)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 MalformedURLException (java.net.MalformedURLException)4 URI (java.net.URI)4 URL (java.net.URL)4 List (java.util.List)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 ExecutionException (java.util.concurrent.ExecutionException)4 TimeoutException (java.util.concurrent.TimeoutException)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 HttpProbeConfig (org.eclipse.che.api.workspace.server.hc.probe.HttpProbeConfig)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Assisted (com.google.inject.assistedinject.Assisted)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)2 Service (io.fabric8.kubernetes.api.model.Service)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2