Search in sources :

Example 1 with SecurityConfig

use of com.sequenceiq.cloudbreak.domain.SecurityConfig in project cloudbreak by hortonworks.

the class TlsSecurityService method storeSSHKeys.

public SecurityConfig storeSSHKeys() {
    SecurityConfig securityConfig = new SecurityConfig();
    generateClientKeys(securityConfig);
    generateTempSshKeypair(securityConfig);
    generateSaltSignKeypair(securityConfig);
    return securityConfig;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig)

Example 2 with SecurityConfig

use of com.sequenceiq.cloudbreak.domain.SecurityConfig in project cloudbreak by hortonworks.

the class TlsSecurityService method getCertificates.

public CertificateResponse getCertificates(Long stackId) {
    SecurityConfig securityConfig = securityConfigRepository.findOneByStackId(stackId);
    if (securityConfig == null) {
        throw new NotFoundException("Security config doesn't exist.");
    }
    String serverCert = instanceMetaDataRepository.getServerCertByStackId(stackId);
    if (serverCert == null) {
        throw new NotFoundException("Server certificate was not found.");
    }
    return new CertificateResponse(decodeBase64(serverCert), securityConfig.getClientKeyDecoded().getBytes(), securityConfig.getClientCertDecoded().getBytes());
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CertificateResponse(com.sequenceiq.cloudbreak.api.model.CertificateResponse) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException)

Example 3 with SecurityConfig

use of com.sequenceiq.cloudbreak.domain.SecurityConfig in project cloudbreak by hortonworks.

the class TestUtil method stack.

public static Stack stack(Status stackStatus, Credential credential) {
    Stack stack = new Stack();
    stack.setStackStatus(new StackStatus(stack, stackStatus, "statusReason", DetailedStackStatus.UNKNOWN));
    stack.setCredential(credential);
    stack.setName("simplestack");
    stack.setOwner("userid");
    stack.setAccount("account");
    stack.setId(1L);
    stack.setInstanceGroups(generateGcpInstanceGroups(3));
    stack.setRegion("region");
    stack.setCreated(123L);
    stack.setCloudPlatform(credential.cloudPlatform());
    stack.setOrchestrator(orchestrator());
    switch(credential.cloudPlatform()) {
        case AWS:
            stack.setInstanceGroups(generateAwsInstanceGroups(3));
            break;
        case GCP:
            stack.setInstanceGroups(generateGcpInstanceGroups(3));
            break;
        case OPENSTACK:
            stack.setInstanceGroups(generateOpenStackInstanceGroups(3));
            break;
        default:
            break;
    }
    stack.setSecurityConfig(new SecurityConfig());
    return stack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 4 with SecurityConfig

use of com.sequenceiq.cloudbreak.domain.SecurityConfig in project cloudbreak by hortonworks.

the class StackCreationService method saveTlsInfo.

public Stack saveTlsInfo(StackContext context, TlsInfo tlsInfo) {
    boolean usePrivateIpToTls = tlsInfo.usePrivateIpToTls();
    Stack stack = context.getStack();
    if (usePrivateIpToTls) {
        SecurityConfig securityConfig = stack.getSecurityConfig();
        securityConfig.setUsePrivateIpToTls(usePrivateIpToTls);
        stackUpdater.updateStackSecurityConfig(stack, securityConfig);
        stack = stackService.getByIdWithLists(stack.getId());
        LOGGER.info("Update Stack and it's SecurityConfig to use private ip when TLS is built.");
    }
    return stack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 5 with SecurityConfig

use of com.sequenceiq.cloudbreak.domain.SecurityConfig in project cloudbreak by hortonworks.

the class StackService method create.

@Transactional(TxType.NEVER)
public Stack create(IdentityUser user, Stack stack, String imageCatalog, Optional<String> imageId, Optional<Blueprint> blueprint) {
    Stack savedStack;
    stack.setOwner(user.getUserId());
    stack.setAccount(user.getAccount());
    stack.setGatewayPort(nginxPort);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    try {
        if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
            long start = System.currentTimeMillis();
            rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
            LOGGER.info("RSA key has been validated in {} ms fot stack {}", System.currentTimeMillis() - start, stackName);
        }
        if (stack.getOrchestrator() != null) {
            orchestratorRepository.save(stack.getOrchestrator());
        }
        stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
        long start = System.currentTimeMillis();
        String template = connector.getTemplate(stack);
        LOGGER.info("Get cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        savedStack = stackRepository.save(stack);
        LOGGER.info("Stackrepository save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addTemplateForStack(stack, template);
        LOGGER.info("Save cluster template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        addCloudbreakDetailsForStack(stack);
        LOGGER.info("Add Cloudbreak template took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        MDCBuilder.buildMdcContext(savedStack);
        start = System.currentTimeMillis();
        instanceGroupRepository.save(savedStack.getInstanceGroups());
        LOGGER.info("Instance groups saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        SecurityConfig securityConfig = tlsSecurityService.storeSSHKeys();
        LOGGER.info("Generating SSH keys took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        start = System.currentTimeMillis();
        securityConfig.setSaltPassword(PasswordUtil.generatePassword());
        securityConfig.setSaltBootPassword(PasswordUtil.generatePassword());
        securityConfig.setKnoxMasterSecret(PasswordUtil.generatePassword());
        LOGGER.info("Generating salt passwords took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        securityConfig.setStack(stack);
        start = System.currentTimeMillis();
        securityConfigRepository.save(securityConfig);
        LOGGER.info("Security config save took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
        savedStack.setSecurityConfig(securityConfig);
        start = System.currentTimeMillis();
        imageService.create(savedStack, connector.getPlatformParameters(stack), imageCatalog, imageId, blueprint);
        LOGGER.info("Image creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    } catch (DataIntegrityViolationException ex) {
        String msg = String.format("Error with resource [%s], error: [%s]", APIResourceType.STACK, getProperSqlErrorMessage(ex));
        throw new BadRequestException(msg);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.error("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.error("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    return savedStack;
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) CloudbreakApiException(com.sequenceiq.cloudbreak.controller.CloudbreakApiException) Stack(com.sequenceiq.cloudbreak.domain.Stack) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Transactional(javax.transaction.Transactional)

Aggregations

SecurityConfig (com.sequenceiq.cloudbreak.domain.SecurityConfig)7 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 Transactional (javax.transaction.Transactional)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 CertificateResponse (com.sequenceiq.cloudbreak.api.model.CertificateResponse)1 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)1 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)1 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)1 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 CloudbreakApiException (com.sequenceiq.cloudbreak.controller.CloudbreakApiException)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 Component (com.sequenceiq.cloudbreak.domain.Component)1 StackStatus (com.sequenceiq.cloudbreak.domain.StackStatus)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1