Search in sources :

Example 11 with CloudS3View

use of com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View in project cloudbreak by hortonworks.

the class AwsDataAccessRolePermissionValidatorTest method testGetPolicyJsonReplacements.

@Test
@Override
public void testGetPolicyJsonReplacements() {
    String storageLocationBaseStr = "bucket/cluster";
    String bucket = "bucket";
    String dynamodbTableName = "tableName";
    Map<String, String> expectedPolicyJsonReplacements = Map.ofEntries(Map.entry("${ARN_PARTITION}", "aws"), Map.entry("${STORAGE_LOCATION_BASE}", storageLocationBaseStr), Map.entry("${DATALAKE_BUCKET}", bucket), Map.entry("${DYNAMODB_TABLE_NAME}", dynamodbTableName));
    StorageLocationBase storageLocationBase = new StorageLocationBase();
    storageLocationBase.setValue(storageLocationBaseStr);
    CloudS3View cloudFileSystem = new CloudS3View(CloudIdentityType.ID_BROKER);
    cloudFileSystem.setS3GuardDynamoTableName(dynamodbTableName);
    cloudFileSystem.setInstanceProfile("arn:aws:iam::11111111111:instance-profile/instanceprofile");
    Map<String, String> policyJsonReplacements = awsDataAccessRolePermissionValidator.getPolicyJsonReplacements(storageLocationBase, cloudFileSystem);
    assertThat(policyJsonReplacements).isEqualTo(expectedPolicyJsonReplacements);
}
Also used : CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 12 with CloudS3View

use of com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View in project cloudbreak by hortonworks.

the class AwsDataAccessRolePermissionValidatorTest method testCollectPolicies.

@Test
@Override
public void testCollectPolicies() {
    ArgumentCaptor<Map<String, String>> replacementsCaptor = ArgumentCaptor.forClass(Map.class);
    when(awsIamService.getPolicy(eq("policyFile1"), replacementsCaptor.capture())).thenReturn(new Policy());
    CloudS3View cloudFileSystem = new CloudS3View(CloudIdentityType.ID_BROKER);
    StorageLocationBase storageLocationBase1 = new StorageLocationBase();
    storageLocationBase1.setType(CloudStorageCdpService.HIVE_METASTORE_WAREHOUSE);
    storageLocationBase1.setValue("s3a://bucket/cluster/hive/metadata");
    cloudFileSystem.setLocations(List.of(storageLocationBase1));
    cloudFileSystem.setInstanceProfile("arn:aws:iam::11111111111:instance-profile/instanceprofile");
    List<Policy> policies = getValidator().collectPolicies(cloudFileSystem, List.of("policyFile1"));
    assertEquals(1, policies.size());
    Map<String, String> replacements = replacementsCaptor.getValue();
    assertEquals("bucket/cluster/hive/metadata", replacements.get("${STORAGE_LOCATION_BASE}"));
    assertEquals("bucket", replacements.get("${DATALAKE_BUCKET}"));
    assertEquals("", replacements.get("${DYNAMODB_TABLE_NAME}"));
}
Also used : Policy(com.amazonaws.auth.policy.Policy) Map(java.util.Map) CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 13 with CloudS3View

use of com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View in project cloudbreak by hortonworks.

the class AwsRangerAuditRolePermissionValidatorTest method testGetPolicyJsonReplacementsNoDynamodb.

@Test
@Override
public void testGetPolicyJsonReplacementsNoDynamodb() {
    String storageLocationBaseStr = "bucket/cluster";
    String bucket = "bucket";
    Map<String, String> expectedPolicyJsonReplacements = Map.ofEntries(Map.entry("${ARN_PARTITION}", "aws"), Map.entry("${STORAGE_LOCATION_BASE}", storageLocationBaseStr), Map.entry("${DATALAKE_BUCKET}", bucket), Map.entry("${DYNAMODB_TABLE_NAME}", ""));
    StorageLocationBase storageLocationBase = new StorageLocationBase();
    storageLocationBase.setValue(storageLocationBaseStr);
    CloudS3View cloudFileSystem = new CloudS3View(CloudIdentityType.ID_BROKER);
    cloudFileSystem.setInstanceProfile("arn:aws:iam::11111111111:instance-profile/instanceprofile");
    Map<String, String> policyJsonReplacements = awsRangerAuditRolePermissionValidator.getPolicyJsonReplacements(storageLocationBase, cloudFileSystem);
    assertThat(policyJsonReplacements).isEqualTo(expectedPolicyJsonReplacements);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 14 with CloudS3View

use of com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View in project cloudbreak by hortonworks.

the class AwsIDBrokerObjectStorageValidator method validateObjectStorage.

public ValidationResult validateObjectStorage(AmazonIdentityManagementClient iam, SpiFileSystem spiFileSystem, String logsLocationBase, String backupLocationBase, ValidationResultBuilder resultBuilder) {
    List<CloudFileSystemView> cloudFileSystems = spiFileSystem.getCloudFileSystems();
    for (CloudFileSystemView cloudFileSystemView : cloudFileSystems) {
        CloudS3View cloudFileSystem = (CloudS3View) cloudFileSystemView;
        String instanceProfileArn = cloudFileSystem.getInstanceProfile();
        InstanceProfile instanceProfile = awsIamService.getInstanceProfile(iam, instanceProfileArn, cloudFileSystem.getCloudIdentityType(), resultBuilder);
        if (instanceProfile != null) {
            CloudIdentityType cloudIdentityType = cloudFileSystem.getCloudIdentityType();
            if (CloudIdentityType.ID_BROKER.equals(cloudIdentityType)) {
                validateIDBroker(iam, instanceProfile, cloudFileSystem, resultBuilder);
            } else if (CloudIdentityType.LOG.equals(cloudIdentityType)) {
                validateLog(iam, instanceProfile, cloudFileSystem, logsLocationBase, backupLocationBase, resultBuilder);
            }
        }
    }
    return resultBuilder.build();
}
Also used : InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType) CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View)

Example 15 with CloudS3View

use of com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View in project cloudbreak by hortonworks.

the class CloudFormationTemplateBuilderTest method buildTestWithVPCAndIGWAndVpcSubnets.

@Test
public void buildTestWithVPCAndIGWAndVpcSubnets() {
    String vpcSubnet = "10.0.0.0/24";
    List<String> vpcSubnets = List.of(vpcSubnet);
    Security security = new Security(getDefaultSecurityRules(), List.of(), true);
    CloudS3View logView = new CloudS3View(CloudIdentityType.LOG);
    logView.setInstanceProfile(INSTANCE_PROFILE);
    List<Group> groups = List.of(createDefaultGroup("master", InstanceGroupType.CORE, ROOT_VOLUME_SIZE, security, Optional.of(logView)));
    cloudStack = createDefaultCloudStack(groups, getDefaultCloudStackParameters(), getDefaultCloudStackTags());
    // WHEN
    modelContext = new ModelContext().withAuthenticatedContext(authenticatedContext).withStack(cloudStack).withExistingVpc(true).withExistingIGW(true).withExistingSubnetCidr(singletonList(existingSubnetCidr)).withExistinVpcCidr(vpcSubnets).mapPublicIpOnLaunch(false).withEnableInstanceProfile(true).withInstanceProfileAvailable(true).withOutboundInternetTraffic(OutboundInternetTraffic.ENABLED).withTemplate(awsCloudFormationTemplate);
    String templateString = cloudFormationTemplateBuilder.build(modelContext);
    // THEN
    Assertions.assertThat(JsonUtil.isValid(templateString)).overridingErrorMessage("Invalid JSON: " + templateString).isTrue();
    assertThat(templateString, containsString("InstanceProfile"));
    assertThat(templateString, containsString("VPCId"));
    assertThat(templateString, not(containsString("SubnetCIDR")));
    assertThat(templateString, containsString("SubnetId"));
    assertThat(templateString, not(containsString("SubnetConfig")));
    assertThat(templateString, not(containsString("\"AttachGateway\"")));
    assertThat(templateString, not(containsString("\"InternetGateway\"")));
    assertThat(templateString, containsString("AvailabilitySet"));
    assertThat(templateString, containsString("SecurityGroupIngress"));
    assertThat(templateString, not(containsString("EIP")));
    assertThat(templateString, containsString("{ \"IpProtocol\" : \"icmp\", \"FromPort\" : \"-1\", \"ToPort\" : \"-1\", \"CidrIp\" : " + "\"10.0.0.0/24\"} ,{ \"IpProtocol\" : \"tcp\", \"FromPort\" : \"0\", \"ToPort\" : \"65535\", \"CidrIp\" : \"10.0.0.0/24\"} ,{ \"IpProtocol\" " + ": \"udp\", \"FromPort\" : \"0\", \"ToPort\" : \"65535\", \"CidrIp\" : \"10.0.0.0/24\"}"));
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Matchers.containsString(org.hamcrest.Matchers.containsString) Security(com.sequenceiq.cloudbreak.cloud.model.Security) CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) Test(org.junit.jupiter.api.Test)

Aggregations

CloudS3View (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View)15 Test (org.junit.jupiter.api.Test)7 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Policy (com.amazonaws.auth.policy.Policy)2 Group (com.sequenceiq.cloudbreak.cloud.model.Group)2 CloudAdlsGen2View (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudAdlsGen2View)2 CloudGcsView (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudGcsView)2 AdlsGen2CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.AdlsGen2CloudStorageV1Parameters)2 Map (java.util.Map)2 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)1 ModelContext (com.sequenceiq.cloudbreak.cloud.aws.common.resource.ModelContext)1 Security (com.sequenceiq.cloudbreak.cloud.model.Security)1 CloudFileSystemView (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView)1 S3Identity (com.sequenceiq.cloudbreak.domain.cloudstorage.S3Identity)1 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1