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

HDDS-6419. Provide better error message for malformed auth header #3167

Merged
merged 6 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion hadoop-ozone/dist/src/main/smoketest/s3/bucketlist.robot
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ ${BUCKET} generated

List buckets
${result} = Execute AWSS3APICli list-buckets | jq -r '.Buckets[].Name'
Should contain ${result} ${BUCKET}
Should contain ${result} ${BUCKET}

List buckets with empty access id
Execute aws configure set aws_access_key_id ''
${result} = Execute AWSS3APICli and checkrc list-buckets 255
Should contain ${result} The authorization header you provided is invalid
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.io.IOException;

import com.google.common.annotations.VisibleForTesting;
Expand All @@ -33,6 +34,7 @@
import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.om.protocol.S3Auth;
import org.apache.hadoop.ozone.s3.exception.OS3Exception;
import org.apache.hadoop.ozone.s3.exception.S3ErrorTable;
import org.apache.hadoop.ozone.s3.signature.SignatureInfo;
import org.apache.hadoop.ozone.s3.signature.SignatureInfo.Version;
import org.apache.hadoop.ozone.s3.signature.SignatureProcessor;
Expand All @@ -43,7 +45,6 @@

import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OM_CLIENT_PROTOCOL_VERSION;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_OM_CLIENT_PROTOCOL_VERSION_KEY;
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.INTERNAL_ERROR;
import static org.apache.hadoop.ozone.s3.exception.S3ErrorTable.ACCESS_DENIED;

/**
Expand Down Expand Up @@ -92,7 +93,7 @@ public S3Auth getSignature() {
String awsAccessId = signatureInfo.getAwsAccessId();
// ONLY validate aws access id when needed.
if (awsAccessId == null || awsAccessId.equals("")) {
LOG.debug("Malformed s3 header. awsAccessID: ", awsAccessId);
LOG.debug("Malformed s3 header. awsAccessID: {}", awsAccessId);
throw ACCESS_DENIED;
}

Expand All @@ -106,7 +107,7 @@ public S3Auth getSignature() {
// For any other critical errors during object creation throw Internal
// error.
LOG.debug("Error during Client Creation: ", e);
throw wrapOS3Exception(INTERNAL_ERROR);
throw wrapOS3Exception(S3ErrorTable.getInternalError(e));
symious marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -138,7 +139,9 @@ public void setSignatureParser(SignatureProcessor awsSignatureProcessor) {
}

private WebApplicationException wrapOS3Exception(OS3Exception os3Exception) {
return new WebApplicationException(os3Exception,
os3Exception.getHttpCode());
return new WebApplicationException(os3Exception.getErrorMessage(),
os3Exception,
Response.status(os3Exception.getHttpCode())
.entity(os3Exception.toXml()).build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.function.Function;

import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
import static java.net.HttpURLConnection.HTTP_CONFLICT;
import static java.net.HttpURLConnection.HTTP_FORBIDDEN;
Expand Down Expand Up @@ -143,4 +145,11 @@ public static OS3Exception newError(OS3Exception e, String resource,
}
return err;
}

private static Function<Exception, OS3Exception> generateInternalError = e ->
new OS3Exception("InternalError", e.getMessage(), HTTP_INTERNAL_ERROR);

public static OS3Exception getInternalError(Exception e) {
return generateInternalError.apply(e);
}
}