Search in sources :

Example 36 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class HealthCheckAvailabilityCheckerTest method testAppVersionIsBlank.

@Test
public void testAppVersionIsBlank() {
    Stack stack = new Stack();
    assertFalse(underTest.isCdpFreeIpaHeathAgentAvailable(stack));
    stack.setAppVersion("");
    assertFalse(underTest.isCdpFreeIpaHeathAgentAvailable(stack));
    stack.setAppVersion(" ");
    assertFalse(underTest.isCdpFreeIpaHeathAgentAvailable(stack));
}
Also used : Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 37 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class KeytabCleanupService method deleteServicePrincipal.

public void deleteServicePrincipal(ServicePrincipalRequest request, String accountId) throws FreeIpaClientException, DeleteException {
    LOGGER.debug("Request to delete service principal for account {}: {}", accountId, request);
    Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
    String realm = keytabCommonService.getRealm(freeIpaStack);
    String canonicalPrincipal = keytabCommonService.constructPrincipal(request.getServiceName(), request.getServerHostName(), realm);
    FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
    deleteService(canonicalPrincipal, ipaClient);
    VaultPathBuilder vaultPathBuilder = new VaultPathBuilder().withSecretType(VaultPathBuilder.SecretType.SERVICE_KEYTAB).withAccountId(accountId).withEnvironmentCrn(request.getEnvironmentCrn()).withClusterCrn(request.getClusterCrn()).withServerHostName(request.getServerHostName()).withServiceName(request.getServiceName());
    vaultComponent.recursivelyCleanupVault(vaultPathBuilder.withSubType(VaultPathBuilder.SecretSubType.SERVICE_PRINCIPAL).build());
    vaultComponent.recursivelyCleanupVault(vaultPathBuilder.withSubType(VaultPathBuilder.SecretSubType.KEYTAB).build());
    roleComponent.deleteRoleIfItIsNoLongerUsed(request.getRoleName(), ipaClient);
    keytabCacheService.deleteByEnvironmentCrnAndPrincipal(request.getEnvironmentCrn(), canonicalPrincipal);
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 38 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class ServiceKeytabService method getExistingServiceKeytab.

public ServiceKeytabResponse getExistingServiceKeytab(ServiceKeytabRequest request, String accountId) throws FreeIpaClientException {
    LOGGER.debug("Request to get service keytab for account {}: {}", accountId, request);
    validateRoleRequestNotPresent(request);
    Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
    String realm = keytabCommonService.getRealm(freeIpaStack);
    String servicePrincipal = keytabCommonService.constructPrincipal(request.getServiceName(), request.getServerHostName(), realm);
    Optional<KeytabCache> keytabCacheOptional = keytabCacheService.findByEnvironmentCrnAndPrincipal(request.getEnvironmentCrn(), servicePrincipal);
    if (keytabCacheOptional.isPresent()) {
        LOGGER.debug("Keytab is found in cache, using it");
        return createServiceKeytabResponse(keytabCacheOptional.get());
    } else {
        LOGGER.debug("Keytab is not found in cache.");
        FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
        KeytabCache serviceKeytab = keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), servicePrincipal, request.getServerHostName(), ipaClient);
        return createServiceKeytabResponse(serviceKeytab);
    }
}
Also used : KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 39 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class HostKeytabService method generateHostKeytab.

public HostKeytabResponse generateHostKeytab(HostKeytabRequest request, String accountId) throws FreeIpaClientException {
    LOGGER.debug("Request to generate host keytab: {}", request);
    Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
    FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
    if (!roleComponent.privilegesExist(request.getRoleRequest(), ipaClient)) {
        throw new BadRequestException(PRIVILEGE_DOES_NOT_EXIST);
    } else {
        Host host = keytabCommonService.addHost(request.getServerHostName(), request.getRoleRequest(), ipaClient);
        KeytabCache hostKeytab = fetchKeytab(request, ipaClient, host);
        return createHostKeytabResponse(hostKeytab);
    }
}
Also used : KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Host(com.sequenceiq.freeipa.client.model.Host) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 40 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class HostKeytabService method getExistingHostKeytab.

public HostKeytabResponse getExistingHostKeytab(HostKeytabRequest request, String accountId) throws FreeIpaClientException {
    LOGGER.debug("Request to get host keytab for account {}: {}", accountId, request);
    if (request.getRoleRequest() != null) {
        throw new BadRequestException(ROLE_NOT_ALLOWED);
    } else {
        Stack freeIpaStack = keytabCommonService.getFreeIpaStackWithMdcContext(request.getEnvironmentCrn(), accountId);
        FreeIpaClient ipaClient = freeIpaClientFactory.getFreeIpaClientForStack(freeIpaStack);
        String hostPrincipal = ipaClient.showHost(request.getServerHostName()).getKrbprincipalname();
        KeytabCache hostKeytab = keytabCommonService.getExistingKeytab(request.getEnvironmentCrn(), hostPrincipal, request.getServerHostName(), ipaClient);
        return createHostKeytabResponse(hostKeytab);
    }
}
Also used : KeytabCache(com.sequenceiq.freeipa.entity.KeytabCache) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)468 Test (org.junit.jupiter.api.Test)237 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)107 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)63 Map (java.util.Map)63 Bean (org.springframework.context.annotation.Bean)50 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)45 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)41 List (java.util.List)37 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)34 Inject (javax.inject.Inject)30 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)29 Collectors (java.util.stream.Collectors)29 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 Set (java.util.Set)28 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)25 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)25 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)24 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)23