Search in sources :

Example 1 with S3Secret

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret in project ozone by apache.

the class OzoneManagerProtocolClientSideTranslatorPB method setS3Secret.

@Override
public S3SecretValue setS3Secret(String accessId, String secretKey) throws IOException {
    final SetS3SecretRequest request = SetS3SecretRequest.newBuilder().setAccessId(accessId).setSecretKey(secretKey).build();
    OMRequest omRequest = createOMRequest(Type.SetS3Secret).setSetS3SecretRequest(request).build();
    final SetS3SecretResponse resp = handleError(submitRequest(omRequest)).getSetS3SecretResponse();
    final S3Secret accessIdSecretKeyPair = S3Secret.newBuilder().setKerberosID(resp.getAccessId()).setAwsSecret(resp.getSecretKey()).build();
    return S3SecretValue.fromProtobuf(accessIdSecretKeyPair);
}
Also used : OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) SetS3SecretResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetS3SecretResponse) SetS3SecretRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetS3SecretRequest) S3Secret(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret)

Example 2 with S3Secret

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret in project ozone by apache.

the class TestS3GetSecretRequest method testGetOwnSecretAsNonAdmin.

@Test
public void testGetOwnSecretAsNonAdmin() throws IOException {
    // This effectively makes alice a regular user.
    when(ozoneManager.isAdmin(ugiAlice)).thenReturn(false);
    // 1. Get secret of "alice" (as herself).
    long txLogIndex = 1;
    // Run preExecute
    S3GetSecretRequest s3GetSecretRequest1 = new S3GetSecretRequest(new S3GetSecretRequest(s3GetSecretRequest(USER_ALICE)).preExecute(ozoneManager));
    // Run validateAndUpdateCache
    OMClientResponse omClientResponse = s3GetSecretRequest1.validateAndUpdateCache(ozoneManager, txLogIndex, ozoneManagerDoubleBufferHelper);
    // Check response type and cast
    Assert.assertTrue(omClientResponse instanceof S3GetSecretResponse);
    final S3GetSecretResponse s3GetSecretResponse = (S3GetSecretResponse) omClientResponse;
    // Check response
    final S3SecretValue s3SecretValue = s3GetSecretResponse.getS3SecretValue();
    Assert.assertEquals(USER_ALICE, s3SecretValue.getKerberosID());
    final String awsSecret1 = s3SecretValue.getAwsSecret();
    Assert.assertNotNull(awsSecret1);
    final GetS3SecretResponse getS3SecretResponse = s3GetSecretResponse.getOMResponse().getGetS3SecretResponse();
    // The secret inside should be the same.
    final S3Secret s3Secret1 = getS3SecretResponse.getS3Secret();
    Assert.assertEquals(USER_ALICE, s3Secret1.getKerberosID());
    Assert.assertEquals(awsSecret1, s3Secret1.getAwsSecret());
    // 2. Get secret of "alice" (as herself) again.
    ++txLogIndex;
    // Run preExecute
    S3GetSecretRequest s3GetSecretRequest2 = new S3GetSecretRequest(new S3GetSecretRequest(s3GetSecretRequest(USER_ALICE)).preExecute(ozoneManager));
    // Run validateAndUpdateCache
    OMClientResponse omClientResponse2 = s3GetSecretRequest2.validateAndUpdateCache(ozoneManager, txLogIndex, ozoneManagerDoubleBufferHelper);
    // Check response type and cast
    Assert.assertTrue(omClientResponse2 instanceof S3GetSecretResponse);
    final S3GetSecretResponse s3GetSecretResponse2 = (S3GetSecretResponse) omClientResponse2;
    // Check response
    Assert.assertNull(s3GetSecretResponse2.getS3SecretValue());
    final GetS3SecretResponse getS3SecretResponse2 = s3GetSecretResponse2.getOMResponse().getGetS3SecretResponse();
    // The secret inside should be the same.
    final S3Secret s3Secret2 = getS3SecretResponse2.getS3Secret();
    Assert.assertEquals(USER_ALICE, s3Secret2.getKerberosID());
    // Should get the same secret as the first request's.
    Assert.assertEquals(awsSecret1, s3Secret2.getAwsSecret());
}
Also used : S3GetSecretResponse(org.apache.hadoop.ozone.om.response.s3.security.S3GetSecretResponse) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) S3SecretValue(org.apache.hadoop.ozone.om.helpers.S3SecretValue) GetS3SecretResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetS3SecretResponse) S3Secret(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret) Test(org.junit.Test)

Example 3 with S3Secret

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret in project ozone by apache.

the class TestS3GetSecretRequest method testGetSecretWithTenant.

@Test
public void testGetSecretWithTenant() throws IOException {
    // This effectively makes alice an admin.
    when(ozoneManager.isAdmin(ugiAlice)).thenReturn(true);
    // Make alice a non-delegated admin
    when(omMultiTenantManager.isTenantAdmin(ugiAlice, TENANT_ID, false)).thenReturn(true);
    // Init LayoutVersionManager to prevent NPE in checkLayoutFeature
    final OMLayoutVersionManager lvm = new OMLayoutVersionManager(OMLayoutVersionManager.maxLayoutVersion());
    when(ozoneManager.getVersionManager()).thenReturn(lvm);
    // 1. CreateTenantRequest: Create tenant "finance".
    long txLogIndex = 1;
    // Run preExecute
    OMTenantCreateRequest omTenantCreateRequest = new OMTenantCreateRequest(new OMTenantCreateRequest(createTenantRequest(TENANT_ID)).preExecute(ozoneManager));
    // Run validateAndUpdateCache
    OMClientResponse omClientResponse = omTenantCreateRequest.validateAndUpdateCache(ozoneManager, txLogIndex, ozoneManagerDoubleBufferHelper);
    // Check response type and cast
    Assert.assertTrue(omClientResponse instanceof OMTenantCreateResponse);
    final OMTenantCreateResponse omTenantCreateResponse = (OMTenantCreateResponse) omClientResponse;
    // Check response
    Assert.assertTrue(omTenantCreateResponse.getOMResponse().getSuccess());
    Assert.assertEquals(TENANT_ID, omTenantCreateResponse.getOmDBTenantState().getTenantId());
    // 2. AssignUserToTenantRequest: Assign "bob@EXAMPLE.COM" to "finance".
    ++txLogIndex;
    // Additional mock setup needed to pass accessId check
    when(ozoneManager.getMultiTenantManager()).thenReturn(omMultiTenantManager);
    // Run preExecute
    OMTenantAssignUserAccessIdRequest omTenantAssignUserAccessIdRequest = new OMTenantAssignUserAccessIdRequest(new OMTenantAssignUserAccessIdRequest(assignUserToTenantRequest(TENANT_ID, USER_BOB, ACCESS_ID_BOB)).preExecute(ozoneManager));
    when(omMultiTenantManager.getTenantVolumeName(TENANT_ID)).thenReturn(TENANT_ID);
    // Run validateAndUpdateCache
    omClientResponse = omTenantAssignUserAccessIdRequest.validateAndUpdateCache(ozoneManager, txLogIndex, ozoneManagerDoubleBufferHelper);
    // Check response type and cast
    Assert.assertTrue(omClientResponse instanceof OMTenantAssignUserAccessIdResponse);
    final OMTenantAssignUserAccessIdResponse omTenantAssignUserAccessIdResponse = (OMTenantAssignUserAccessIdResponse) omClientResponse;
    // Check response
    Assert.assertTrue(omTenantAssignUserAccessIdResponse.getOMResponse().getSuccess());
    Assert.assertTrue(omTenantAssignUserAccessIdResponse.getOMResponse().hasTenantAssignUserAccessIdResponse());
    final OmDBAccessIdInfo omDBAccessIdInfo = omTenantAssignUserAccessIdResponse.getOmDBAccessIdInfo();
    Assert.assertNotNull(omDBAccessIdInfo);
    final S3SecretValue originalS3Secret = omTenantAssignUserAccessIdResponse.getS3Secret();
    Assert.assertNotNull(originalS3Secret);
    // 3. S3GetSecretRequest: Get secret of "bob@EXAMPLE.COM" (as an admin).
    ++txLogIndex;
    // Run preExecute
    S3GetSecretRequest s3GetSecretRequest = new S3GetSecretRequest(new S3GetSecretRequest(s3GetSecretRequest(ACCESS_ID_BOB)).preExecute(ozoneManager));
    // Run validateAndUpdateCache
    omClientResponse = s3GetSecretRequest.validateAndUpdateCache(ozoneManager, txLogIndex, ozoneManagerDoubleBufferHelper);
    // Check response type and cast
    Assert.assertTrue(omClientResponse instanceof S3GetSecretResponse);
    final S3GetSecretResponse s3GetSecretResponse = (S3GetSecretResponse) omClientResponse;
    // Check response
    Assert.assertTrue(s3GetSecretResponse.getOMResponse().getSuccess());
    /*
       getS3SecretValue() should be null in this case because
       the entry is already inserted to DB in the previous request.
       The entry will get overwritten if it isn't null.
       See {@link S3GetSecretResponse#addToDBBatch}.
     */
    Assert.assertNull(s3GetSecretResponse.getS3SecretValue());
    // The secret retrieved should be the same as previous response's.
    final GetS3SecretResponse getS3SecretResponse = s3GetSecretResponse.getOMResponse().getGetS3SecretResponse();
    final S3Secret s3Secret = getS3SecretResponse.getS3Secret();
    Assert.assertEquals(ACCESS_ID_BOB, s3Secret.getKerberosID());
    Assert.assertEquals(originalS3Secret.getAwsSecret(), s3Secret.getAwsSecret());
    Assert.assertEquals(originalS3Secret.getKerberosID(), s3Secret.getKerberosID());
}
Also used : OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) OMTenantAssignUserAccessIdRequest(org.apache.hadoop.ozone.om.request.s3.tenant.OMTenantAssignUserAccessIdRequest) OMTenantAssignUserAccessIdResponse(org.apache.hadoop.ozone.om.response.s3.tenant.OMTenantAssignUserAccessIdResponse) S3SecretValue(org.apache.hadoop.ozone.om.helpers.S3SecretValue) S3Secret(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret) OMLayoutVersionManager(org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager) S3GetSecretResponse(org.apache.hadoop.ozone.om.response.s3.security.S3GetSecretResponse) OmDBAccessIdInfo(org.apache.hadoop.ozone.om.helpers.OmDBAccessIdInfo) OMTenantCreateRequest(org.apache.hadoop.ozone.om.request.s3.tenant.OMTenantCreateRequest) GetS3SecretResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetS3SecretResponse) OMTenantCreateResponse(org.apache.hadoop.ozone.om.response.s3.tenant.OMTenantCreateResponse) Test(org.junit.Test)

Example 4 with S3Secret

use of org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret in project ozone by apache.

the class TestS3GetSecretRequest method testGetSecretOfAnotherUserAsAdmin.

@Test
public void testGetSecretOfAnotherUserAsAdmin() throws IOException {
    // This effectively makes alice an admin.
    when(ozoneManager.isAdmin(ugiAlice)).thenReturn(true);
    // 1. Get secret of "bob@EXAMPLE.COM" (as an admin).
    long txLogIndex = 1;
    // Run preExecute
    S3GetSecretRequest s3GetSecretRequest = new S3GetSecretRequest(new S3GetSecretRequest(s3GetSecretRequest(ACCESS_ID_BOB)).preExecute(ozoneManager));
    // Run validateAndUpdateCache
    OMClientResponse omClientResponse = s3GetSecretRequest.validateAndUpdateCache(ozoneManager, txLogIndex, ozoneManagerDoubleBufferHelper);
    // Check response type and cast
    Assert.assertTrue(omClientResponse instanceof S3GetSecretResponse);
    final S3GetSecretResponse s3GetSecretResponse = (S3GetSecretResponse) omClientResponse;
    // Check response
    final S3SecretValue s3SecretValue = s3GetSecretResponse.getS3SecretValue();
    Assert.assertEquals(ACCESS_ID_BOB, s3SecretValue.getKerberosID());
    final String awsSecret = s3SecretValue.getAwsSecret();
    Assert.assertNotNull(awsSecret);
    final GetS3SecretResponse getS3SecretResponse = s3GetSecretResponse.getOMResponse().getGetS3SecretResponse();
    // The secret inside should be the same.
    final S3Secret s3Secret = getS3SecretResponse.getS3Secret();
    Assert.assertEquals(ACCESS_ID_BOB, s3Secret.getKerberosID());
    Assert.assertEquals(awsSecret, s3Secret.getAwsSecret());
}
Also used : S3GetSecretResponse(org.apache.hadoop.ozone.om.response.s3.security.S3GetSecretResponse) OMClientResponse(org.apache.hadoop.ozone.om.response.OMClientResponse) S3SecretValue(org.apache.hadoop.ozone.om.helpers.S3SecretValue) GetS3SecretResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetS3SecretResponse) S3Secret(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret) Test(org.junit.Test)

Aggregations

S3Secret (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.S3Secret)4 S3SecretValue (org.apache.hadoop.ozone.om.helpers.S3SecretValue)3 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)3 S3GetSecretResponse (org.apache.hadoop.ozone.om.response.s3.security.S3GetSecretResponse)3 GetS3SecretResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.GetS3SecretResponse)3 Test (org.junit.Test)3 OmDBAccessIdInfo (org.apache.hadoop.ozone.om.helpers.OmDBAccessIdInfo)1 OMTenantAssignUserAccessIdRequest (org.apache.hadoop.ozone.om.request.s3.tenant.OMTenantAssignUserAccessIdRequest)1 OMTenantCreateRequest (org.apache.hadoop.ozone.om.request.s3.tenant.OMTenantCreateRequest)1 OMTenantAssignUserAccessIdResponse (org.apache.hadoop.ozone.om.response.s3.tenant.OMTenantAssignUserAccessIdResponse)1 OMTenantCreateResponse (org.apache.hadoop.ozone.om.response.s3.tenant.OMTenantCreateResponse)1 OMLayoutVersionManager (org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager)1 OMRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest)1 SetS3SecretRequest (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetS3SecretRequest)1 SetS3SecretResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.SetS3SecretResponse)1