-
Notifications
You must be signed in to change notification settings - Fork 593
HDDS-10014. Fixed internal error on generating S3 secret #5887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9147e74
3e4dfa9
0086789
ab962e7
cd067da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,30 +21,37 @@ Library String | |
| Resource ../commonlib.robot | ||
| Resource ./commonawslib.robot | ||
| Test Timeout 5 minutes | ||
| Suite Setup Setup s3 tests | ||
| Default Tags no-bucket-type | ||
| Test Setup Run Keywords Kinit test user testuser testuser.keytab | ||
| ... AND Revoke S3 secrets | ||
| Test Teardown Run Keyword Revoke S3 secrets | ||
|
|
||
| *** Variables *** | ||
| ${ENDPOINT_URL} http://s3g:9878 | ||
| ${SECURITY_ENABLED} true | ||
|
|
||
| *** Test Cases *** | ||
|
|
||
| S3 Gateway Generate Secret | ||
| Run Keyword if '${SECURITY_ENABLED}' == 'true' Kinit HTTP user | ||
| Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled | ||
| ${result} = Execute curl -X PUT --negotiate -u : -v ${ENDPOINT_URL}/secret | ||
| IF '${SECURITY_ENABLED}' == 'true' | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| Should Match Regexp ${result} <awsAccessKey>.*</awsAccessKey><awsSecret>.*</awsSecret> | ||
| ELSE | ||
| Should contain ${result} S3 Secret endpoint is disabled. | ||
| END | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| Should Match Regexp ${result} <awsAccessKey>.*</awsAccessKey><awsSecret>.*</awsSecret> | ||
|
|
||
| S3 Gateway Secret Already Exists | ||
| Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled | ||
| Execute ozone s3 getsecret ${OM_HA_PARAM} | ||
| ${result} = Execute curl -X PUT --negotiate -u : -v ${ENDPOINT_URL}/secret | ||
| Should contain ${result} HTTP/1.1 400 S3_SECRET_ALREADY_EXISTS ignore_case=True | ||
|
|
||
| S3 Gateway Generate Secret By Username | ||
| Run Keyword if '${SECURITY_ENABLED}' == 'true' Kinit test user testuser testuser.keytab | ||
| Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled | ||
| ${result} = Execute curl -X PUT --negotiate -u : -v ${ENDPOINT_URL}/secret/testuser | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here, can we keep |
||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| Should Match Regexp ${result} <awsAccessKey>.*</awsAccessKey><awsSecret>.*</awsSecret> | ||
|
|
||
| S3 Gateway Generate Secret By Username For Other User | ||
| Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled | ||
| ${result} = Execute curl -X PUT --negotiate -u : -v ${ENDPOINT_URL}/secret/testuser2 | ||
| IF '${SECURITY_ENABLED}' == 'true' | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| Should Match Regexp ${result} <awsAccessKey>.*</awsAccessKey><awsSecret>.*</awsSecret> | ||
| ELSE | ||
| Should contain ${result} S3 Secret endpoint is disabled. | ||
| END | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| Should Match Regexp ${result} <awsAccessKey>.*</awsAccessKey><awsSecret>.*</awsSecret> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,9 @@ Library String | |
| Resource ../commonlib.robot | ||
| Resource ./commonawslib.robot | ||
| Test Timeout 5 minutes | ||
| Suite Setup Setup s3 tests | ||
| Default Tags no-bucket-type | ||
| Test Setup Run Keywords Kinit test user testuser testuser.keytab | ||
| ... AND Revoke S3 secrets | ||
|
|
||
| *** Variables *** | ||
| ${ENDPOINT_URL} http://s3g:9878 | ||
|
|
@@ -31,19 +32,19 @@ ${SECURITY_ENABLED} true | |
| *** Test Cases *** | ||
|
|
||
| S3 Gateway Revoke Secret | ||
| Run Keyword if '${SECURITY_ENABLED}' == 'true' Kinit HTTP user | ||
| Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled | ||
| Execute ozone s3 getsecret ${OM_HA_PARAM} | ||
| ${result} = Execute curl -X DELETE --negotiate -u : -v ${ENDPOINT_URL}/secret | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @ivanzlenko is right, |
||
| IF '${SECURITY_ENABLED}' == 'true' | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| ELSE | ||
| Should contain ${result} S3 Secret endpoint is disabled. | ||
| END | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
|
|
||
| S3 Gateway Revoke Secret By Username | ||
| Run Keyword if '${SECURITY_ENABLED}' == 'true' Kinit test user testuser testuser.keytab | ||
| Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled | ||
| Execute ozone s3 getsecret -u testuser ${OM_HA_PARAM} | ||
| ${result} = Execute curl -X DELETE --negotiate -u : -v ${ENDPOINT_URL}/secret/testuser | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we keep "by username" test case generate/revoke for |
||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
|
|
||
| S3 Gateway Revoke Secret By Username For Other User | ||
| Pass Execution If '${SECURITY_ENABLED}' == 'false' Skipping this check as security is not enabled | ||
| Execute ozone s3 getsecret -u testuser2 ${OM_HA_PARAM} | ||
| ${result} = Execute curl -X DELETE --negotiate -u : -v ${ENDPOINT_URL}/secret/testuser2 | ||
| IF '${SECURITY_ENABLED}' == 'true' | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| ELSE | ||
| Should contain ${result} S3 Secret endpoint is disabled. | ||
| END | ||
| Should contain ${result} HTTP/1.1 200 OK ignore_case=True | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import java.security.Principal; | ||
| import javax.ws.rs.container.ContainerRequestContext; | ||
| import javax.ws.rs.core.MultivaluedHashMap; | ||
| import javax.ws.rs.core.Response; | ||
| import javax.ws.rs.core.SecurityContext; | ||
| import javax.ws.rs.core.UriInfo; | ||
|
|
||
|
|
@@ -30,6 +31,7 @@ | |
| import org.apache.hadoop.ozone.client.OzoneClient; | ||
| import org.apache.hadoop.ozone.client.OzoneClientStub; | ||
| import org.apache.hadoop.ozone.client.protocol.ClientProtocol; | ||
| import org.apache.hadoop.ozone.om.exceptions.OMException; | ||
| import org.apache.hadoop.ozone.om.helpers.S3SecretValue; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
@@ -38,6 +40,7 @@ | |
| import org.mockito.invocation.InvocationOnMock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
|
|
||
| import static javax.ws.rs.core.Response.Status.BAD_REQUEST; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.when; | ||
|
|
@@ -96,6 +99,21 @@ void testSecretGenerate() throws IOException { | |
| assertEquals(USER_NAME, response.getAwsAccessKey()); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test to check 500 will be thrown for other exceptions?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be done in follow-up if needed. |
||
| @Test | ||
| void testIfSecretAlreadyExists() throws IOException { | ||
| when(principal.getName()).thenReturn(USER_NAME); | ||
| when(securityContext.getUserPrincipal()).thenReturn(principal); | ||
| when(context.getSecurityContext()).thenReturn(securityContext); | ||
| when(proxy.getS3Secret(any())).thenThrow(new OMException("Secret already exists", | ||
| OMException.ResultCodes.S3_SECRET_ALREADY_EXISTS)); | ||
|
|
||
| Response response = endpoint.generate(); | ||
|
|
||
| assertEquals(BAD_REQUEST.getStatusCode(), response.getStatus()); | ||
| assertEquals(OMException.ResultCodes.S3_SECRET_ALREADY_EXISTS.toString(), | ||
| response.getStatusInfo().getReasonPhrase()); | ||
| } | ||
|
|
||
| @Test | ||
| void testSecretGenerateWithUsername() throws IOException { | ||
| S3SecretResponse response = | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should revoke secret for testuser as well, just in case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanzlenko
Revoke S3 secrets(called in the next line) does revoke fortestuser, too, so this is fine.