Skip to content
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

Improvement/osis 147 stop osis failure on decryption 7.10 #142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @scality/object-lead @XinLiScality
* @scality/object
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
osisVersion = '2.1.2'
osisVersion = '2.1.3'
vaultclientVersion = '1.1.2'
springBootVersion = '2.7.6'
}
Expand Down Expand Up @@ -120,4 +120,4 @@ task app {
}
}
}
compileJava.dependsOn app
compileJava.dependsOn app
Original file line number Diff line number Diff line change
Expand Up @@ -1391,14 +1391,19 @@ private String retrieveSecretKey(String repoKey) throws Exception {
String secretKey = null;

if (repoVal != null) {
try {
// Using `repoKey` for Associated Data during decryption
secretKey = cipherFactory.getCipherByID(repoVal.getKeyID())
.decrypt(repoVal,
cipherFactory.getSecretCipherKeyByID(repoVal.getKeyID()),
repoKey);

// Using `repoKey` for Associated Data during encryption
secretKey = cipherFactory.getCipherByID(repoVal.getKeyID())
.decrypt(repoVal,
cipherFactory.getSecretCipherKeyByID(repoVal.getKeyID()),
repoKey);

logger.debug("[Cache] Retrieve Secret Key successful");
logger.debug("[Cache] Retrieve Secret Key successful");
} catch (Exception e) {
logger.error("Error: Unable to decrypt secret key data for Redis key: {}. Error details: {}", repoKey, e.getMessage());
logger.debug("Full stack trace:", e);
deleteSecretKey(repoKey);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is relevant but should we log something in case this fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we should, in fact we do not log anything for any redis operations.
I created a ticket for this tech debt: https://scality.atlassian.net/browse/S3C-8885

}
}
return secretKey;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.mockito.stubbing.Answer;
import org.springframework.http.HttpStatus;

import javax.crypto.AEADBadTagException;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import static com.scality.osis.utils.ScalityConstants.*;
import static com.scality.osis.utils.ScalityTestUtils.*;
Expand Down Expand Up @@ -451,6 +453,15 @@ void testGetS3CredentialWithNullTenantIdAndUserId() {
assertTrue(result.getActive());
}

@Test
void testGetS3CredentialsKeyPresentInRedisUnableToDecrypt() throws Exception {
when(baseCipherMock.decrypt(any(), any(), any())).thenThrow(new AEADBadTagException("Decryption failed"));
final OsisS3Credential result = scalityOsisServiceUnderTest.getS3Credential(SAMPLE_TENANT_ID, TEST_USER_ID, TEST_ACCESS_KEY);
// When decryption fails, the API call should succeed, and we should return the result with secret key listed as
// "Not Available"
assertEquals("Not Available", result.getSecretKey());
}

@Test
void testListS3Credentials() {
// Setup
Expand Down Expand Up @@ -526,6 +537,15 @@ void testListS3CredentialsWithNoKeyOnRedis() {

}

@Test
void testListS3CredentialsKeyPresentInRedisUnableToDecrypt() throws Exception {
when(baseCipherMock.decrypt(any(), any(), any())).thenThrow(new AEADBadTagException("Decryption failed"));
final List<OsisS3Credential> result = scalityOsisServiceUnderTest.listS3Credentials(TEST_TENANT_ID,
TEST_USER_ID, 0L, 1000L).getItems();
// When decryption fails, the API call should succeed, and we should get a new access key in the result
assertEquals(2, result.size());
}

@Test
void testListS3CredentialsErr() {
// Setup
Expand Down
Loading