-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-18183. s3a audit logs to publish range start/end of GET requests in audit header #5110
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 10 commits
1cd860e
cdc0685
9d2fd43
2d3eb86
216db7c
74ad528
7c8b3f1
cf06569
5150698
6837be9
2be27c9
620059c
732fd00
deddad4
46d371c
c17dc77
2122eaf
9ecfee5
783ac9d
f242288
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import java.util.Map; | ||
|
|
||
| import com.amazonaws.AmazonWebServiceRequest; | ||
| import com.amazonaws.services.s3.model.GetObjectRequest; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -35,6 +36,7 @@ | |
| import org.apache.hadoop.fs.s3a.audit.AWSRequestAnalyzer; | ||
| import org.apache.hadoop.fs.s3a.audit.AuditFailureException; | ||
| import org.apache.hadoop.fs.s3a.audit.AuditSpanS3A; | ||
| import org.apache.hadoop.fs.store.LogExactlyOnce; | ||
| import org.apache.hadoop.fs.store.audit.HttpReferrerAuditHeader; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
|
|
||
|
|
@@ -110,6 +112,14 @@ public class LoggingAuditor | |
| */ | ||
| private Collection<String> filters; | ||
|
|
||
| /** | ||
| * Log for warning of problems getting the range of GetObjectRequest | ||
| * will only log of a problem once per process instance. | ||
| * This is to avoid logs being flooded with errors. | ||
| */ | ||
| private static final LogExactlyOnce WARN_INCORRECT_RANGE = | ||
| new LogExactlyOnce(LOG); | ||
|
|
||
| /** | ||
| * Create the auditor. | ||
| * The UGI current user is used to provide the principal; | ||
|
|
@@ -230,6 +240,25 @@ private class LoggingAuditSpan extends AbstractAuditSpanImpl { | |
|
|
||
| private final HttpReferrerAuditHeader referrer; | ||
|
|
||
| /** | ||
| * Attach Range of data for GetObject Request | ||
| * @param request given get object request | ||
| */ | ||
| private void attachRangeFromRequest(AmazonWebServiceRequest request) { | ||
| if (request instanceof GetObjectRequest) { | ||
| long[] rangeValue = ((GetObjectRequest) request).getRange(); | ||
| if (rangeValue == null || rangeValue.length == 0) { | ||
| return; | ||
| } | ||
| if (rangeValue.length != 2) { | ||
| WARN_INCORRECT_RANGE.warn("Expected range to contain 0 or 2 elements. Got " | ||
| + rangeValue.length + ". Ignoring"); | ||
| } | ||
| String combinedRangeValue = String.format("bytes=%d-%d", rangeValue[0], rangeValue[1]); | ||
sauraank marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| referrer.set(AuditConstants.PARAM_RANGE, combinedRangeValue); | ||
| } | ||
| } | ||
|
|
||
| private final String description; | ||
|
|
||
| private LoggingAuditSpan( | ||
|
|
@@ -314,6 +343,8 @@ public void set(final String key, final String value) { | |
| @Override | ||
| public <T extends AmazonWebServiceRequest> T beforeExecution( | ||
| final T request) { | ||
| // attach range for GetObject requests | ||
| attachRangeFromRequest(request); | ||
| // build the referrer header | ||
| final String header = referrer.buildHttpReferrer(); | ||
| // update the outer class's field. | ||
|
|
||
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.
We don't actually ignore the value here. We should return or put the next few lines in an
elseblock.We'd get an IndexOutOfBoundsException when we access
rangeValue[1]when there's only one element, for example.