Search in sources :

Example 11 with SslConfig

use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.

the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeNone.

@Test
void testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeNone() {
    DatabaseServerConfig server = new DatabaseServerConfig();
    server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    DBStack dbStack = new DBStack();
    dbStack.setSslConfig(new SslConfig());
    initDBStackStatus(dbStack);
    server.setDbStack(dbStack);
    DatabaseServerV4Response response = converter.convert(server);
    assertThat(response).isNotNull();
    SslConfigV4Response sslConfigV4Response = response.getSslConfig();
    assertThat(sslConfigV4Response).isNotNull();
    assertThat(sslConfigV4Response.getSslMode()).isEqualTo(SslMode.DISABLED);
    assertThat(sslConfigV4Response.getSslCertificateType()).isEqualTo(SslCertificateType.NONE);
    assertThat(response.getStatus()).isEqualTo(dbStack.getStatus());
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with SslConfig

use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.

the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwned.

@ParameterizedTest(name = "{0}")
@MethodSource("testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwnedDataProvider")
void testConversionOfSslConfigWhenDbStackPresentAndCertificateTypeCloudProviderOwned(String testCaseName, Integer certActiveVersionInput, String certActiveCloudProviderIdentifierInput, int certActiveVersionExpected, String certActiveCloudProviderIdentifierExpected) {
    DatabaseServerConfig server = new DatabaseServerConfig();
    server.setResourceCrn(TestData.getTestCrn(RESOURCE_TYPE_DATABASE_SERVER, RESOURCE_ID));
    server.setDatabaseVendor(DatabaseVendor.POSTGRES);
    DBStack dbStack = new DBStack();
    dbStack.setCloudPlatform(CLOUD_PLATFORM);
    dbStack.setRegion(REGION);
    SslConfig sslConfig = new SslConfig();
    sslConfig.setSslCertificateType(SslCertificateType.CLOUD_PROVIDER_OWNED);
    sslConfig.setSslCertificates(CERTS);
    sslConfig.setSslCertificateActiveVersion(certActiveVersionInput);
    sslConfig.setSslCertificateActiveCloudProviderIdentifier(certActiveCloudProviderIdentifierInput);
    dbStack.setSslConfig(sslConfig);
    server.setDbStack(dbStack);
    when(databaseServerSslCertificateConfig.getMaxVersionByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_MAX_VERSION);
    when(databaseServerSslCertificateConfig.getLegacyMaxVersionByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_LEGACY_MAX_VERSION);
    when(databaseServerSslCertificateConfig.getLegacyCloudProviderIdentifierByCloudPlatformAndRegion(CLOUD_PLATFORM, REGION)).thenReturn(CERT_LEGACY_CLOUD_PROVIDER_IDENTIFIER);
    DatabaseServerV4Response response = converter.convert(server);
    assertThat(response).isNotNull();
    SslConfigV4Response sslConfigV4Response = response.getSslConfig();
    assertThat(sslConfigV4Response).isNotNull();
    assertThat(sslConfigV4Response.getSslMode()).isEqualTo(SslMode.ENABLED);
    assertThat(sslConfigV4Response.getSslCertificateType()).isEqualTo(SslCertificateType.CLOUD_PROVIDER_OWNED);
    assertThat(sslConfigV4Response.getSslCertificates()).isSameAs(CERTS);
    assertThat(sslConfigV4Response.getSslCertificateHighestAvailableVersion()).isEqualTo(CERT_MAX_VERSION);
    assertThat(sslConfigV4Response.getSslCertificateActiveVersion()).isEqualTo(certActiveVersionExpected);
    assertThat(sslConfigV4Response.getSslCertificateActiveCloudProviderIdentifier()).isEqualTo(certActiveCloudProviderIdentifierExpected);
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) DatabaseServerV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response) DatabaseServerConfig(com.sequenceiq.redbeams.domain.DatabaseServerConfig) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SslConfigV4Response(com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with SslConfig

use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.

the class DatabaseServerSslCertificateSyncService method syncSslCertificateAws.

private void syncSslCertificateAws(CloudContext cloudContext, DBStack dbStack, CloudDatabaseServerSslCertificate activeSslRootCertificate) {
    SslConfig sslConfig = dbStack.getSslConfig();
    String cloudPlatform = dbStack.getCloudPlatform();
    String desiredSslCertificateIdentifier = sslConfig.getSslCertificateActiveCloudProviderIdentifier();
    String activeSslCertificateIdentifier = activeSslRootCertificate.getCertificateIdentifier();
    // The latter case is not, however, handled specially, so that the DBStack of the legacy DB server can be also updated to get rid of legacy null values.
    if (activeSslCertificateIdentifier.equals(desiredSslCertificateIdentifier)) {
        LOGGER.info("Active SSL certificate CloudProviderIdentifier for cloud platform \"{}\" matches the desired one: \"{}\", database stack {}", cloudPlatform, activeSslCertificateIdentifier, cloudContext);
    } else {
        // Always sync CloudProviderIdentifier; this may result in an "SSL certificate outdated" status for the DB server registration.
        sslConfig.setSslCertificateActiveCloudProviderIdentifier(activeSslCertificateIdentifier);
        SslCertificateEntry activeSslCertificateEntry = databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndCloudProviderIdentifier(cloudPlatform, dbStack.getRegion(), activeSslCertificateIdentifier);
        if (activeSslCertificateEntry == null) {
            // This is only possible if the newly launched DB server uses a super-recent SSL root certificate that is yet unknown to CB,
            // or if the DB server SSL root certificate is too old and has already been removed from CB.
            // Neither is a typical scenario, but they will always result in an "SSL certificate outdated" status for the DB server registration.
            LOGGER.warn("Mismatching SSL certificate CloudProviderIdentifier for cloud platform \"{}\": desired=\"{}\", actual=\"{}\", " + "database stack {}. Unable to determine version & PEM for the actual CloudProviderIdentifier, leaving database server " + "registration unchanged.", cloudPlatform, desiredSslCertificateIdentifier, activeSslCertificateIdentifier, cloudContext);
        } else {
            // This makes the DB server registration in sync with the cloud provider DB server instance,
            // but it may also result in an "SSL certificate outdated" status for the DB server registration
            // if the cloud provider side SSL certificate lags behind the highest version supported by CB.
            LOGGER.info("Mismatching SSL certificate CloudProviderIdentifier for cloud platform \"{}\": desired=\"{}\", actual=\"{}\", " + "database stack {}. Updating database server registration with the version & PEM of the actual CloudProviderIdentifier.", cloudPlatform, desiredSslCertificateIdentifier, activeSslCertificateIdentifier, cloudContext);
            validateCert(cloudPlatform, activeSslCertificateIdentifier, activeSslCertificateEntry);
            sslConfig.setSslCertificateActiveVersion(activeSslCertificateEntry.getVersion());
            sslConfig.setSslCertificates(Collections.singleton(activeSslCertificateEntry.getCertPem()));
        }
        dbStackService.save(dbStack);
    }
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) SslCertificateEntry(com.sequenceiq.redbeams.configuration.SslCertificateEntry)

Example 14 with SslConfig

use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.

the class DatabaseServerSslCertificatePrescriptionService method prescribeSslCertificateIfNeeded.

public void prescribeSslCertificateIfNeeded(CloudContext cloudContext, CloudCredential cloudCredential, DBStack dbStack, DatabaseStack databaseStack) {
    SslConfig sslConfig = dbStack.getSslConfig();
    String cloudPlatform = dbStack.getCloudPlatform();
    if (sslConfig != null && SslCertificateType.CLOUD_PROVIDER_OWNED.equals(sslConfig.getSslCertificateType()) && CloudPlatform.AWS.name().equals(cloudPlatform)) {
        prescribeSslCertificateIfNeededAws(cloudContext, cloudCredential, dbStack, databaseStack.getDatabaseServer());
    } else {
        LOGGER.info("SSL not enabled or unsupported cloud platform \"{}\": SslConfig={}. " + "Skipping SSL certificate CloudProviderIdentifier prescription for database stack {}", cloudPlatform, sslConfig, cloudContext);
    }
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig)

Example 15 with SslConfig

use of com.sequenceiq.redbeams.domain.stack.SslConfig in project cloudbreak by hortonworks.

the class AllocateDatabaseServerV4RequestToDBStackConverter method getSslConfig.

// FIXME Potentially extract this whole logic into a service as it might be needed later for cert rotation
private SslConfig getSslConfig(AllocateDatabaseServerV4Request source, DBStack dbStack) {
    SslConfig sslConfig = new SslConfig();
    if (sslEnabled && source.getSslConfig() != null && SslMode.isEnabled(source.getSslConfig().getSslMode())) {
        String cloudPlatform = dbStack.getCloudPlatform();
        String region = dbStack.getRegion();
        // TODO Determine the highest available SSL cert version for GCP; update sslCertificateActiveVersion during provisioning
        int maxVersion = databaseServerSslCertificateConfig.getMaxVersionByCloudPlatformAndRegion(cloudPlatform, region);
        sslConfig.setSslCertificateActiveVersion(maxVersion);
        // TODO Add SslConfig.sslCertificateMaxVersion and keep it up-to-date (mostly for GCP)
        Set<String> certs;
        String cloudProviderIdentifier;
        int numberOfCerts = databaseServerSslCertificateConfig.getNumberOfCertsByCloudPlatformAndRegion(cloudPlatform, region);
        if (numberOfCerts == 0) {
            // TODO Initialize SSL cert & CloudProviderIdentifier for GCP
            // This is possible for cloud platforms where SSL is supported, but the certs are not pre-registered in CB; see e.g. GCP
            certs = Collections.emptySet();
            cloudProviderIdentifier = null;
        } else if (numberOfCerts == 1 || !CloudPlatform.AZURE.equals(source.getCloudPlatform())) {
            SslCertificateEntry cert = databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndVersion(cloudPlatform, region, maxVersion);
            validateCert(cloudPlatform, maxVersion, cert);
            certs = Collections.singleton(cert.getCertPem());
            cloudProviderIdentifier = cert.getCloudProviderIdentifier();
        } else {
            // In Azure and for > 1 certs, include both the most recent cert and the preceding one
            Set<SslCertificateEntry> certsTemp = databaseServerSslCertificateConfig.getCertsByCloudPlatformAndRegionAndVersions(cloudPlatform, region, maxVersion - 1, maxVersion).stream().filter(Objects::nonNull).collect(Collectors.toSet());
            validateNonNullCertsCount(cloudPlatform, maxVersion, certsTemp);
            findAndValidateCertByVersion(cloudPlatform, maxVersion - 1, certsTemp);
            cloudProviderIdentifier = findAndValidateCertByVersion(cloudPlatform, maxVersion, certsTemp).getCloudProviderIdentifier();
            certs = certsTemp.stream().map(SslCertificateEntry::getCertPem).collect(Collectors.toSet());
            validateUniqueCertsCount(cloudPlatform, maxVersion, certs);
        }
        sslConfig.setSslCertificates(certs);
        sslConfig.setSslCertificateActiveCloudProviderIdentifier(cloudProviderIdentifier);
        sslConfig.setSslCertificateType(SslCertificateType.CLOUD_PROVIDER_OWNED);
    }
    return sslConfig;
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) Set(java.util.Set) SslCertificateEntry(com.sequenceiq.redbeams.configuration.SslCertificateEntry) Objects(java.util.Objects)

Aggregations

SslConfig (com.sequenceiq.redbeams.domain.stack.SslConfig)16 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)6 Test (org.junit.jupiter.api.Test)5 DatabaseServerV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response)4 SslConfigV4Response (com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.SslConfigV4Response)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)3 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)3 DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)3 SslCertificateEntry (com.sequenceiq.redbeams.configuration.SslCertificateEntry)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudDatabaseServerSslCertificate (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate)1 Objects (java.util.Objects)1 Set (java.util.Set)1