-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Follow-up to Azure auth validation change #111252
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
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 |
|---|---|---|
|
|
@@ -49,16 +49,22 @@ public enum Protocol { | |
| HTTPS | ||
| } | ||
|
|
||
| public static Predicate<String> startsWithPredicate(String expectedPrefix) { | ||
| /** | ||
| * @param account The name of the Azure Blob Storage account against which the request should be authorized.. | ||
| * @return a predicate that matches the {@code Authorization} HTTP header that the Azure SDK sends when using shared key auth (i.e. | ||
| * using a key or SAS token). | ||
| * @see <a href="https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-shared-key">Azure docs on shared key auth</a> | ||
|
Comment on lines
+53
to
+56
Member
Author
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. Hope this helps clarify - the header is coming from the Azure SDK, and I'm working towards a change that should cause it to emit a different kind of auth header, so I want to add these assertions now in order to better support the upcoming change.
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. Very helpful 👍 |
||
| */ | ||
| public static Predicate<String> sharedKeyForAccountPredicate(String account) { | ||
| return new Predicate<>() { | ||
| @Override | ||
| public boolean test(String s) { | ||
| return s.startsWith(expectedPrefix); | ||
| return s.startsWith("SharedKey " + account + ":"); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "startsWith[" + expectedPrefix + "]"; | ||
| return "SharedKey[" + account + "]"; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,27 +82,27 @@ private boolean isValidAuthHeader(HttpExchange exchange) { | |
| @Override | ||
| public void handle(final HttpExchange exchange) throws IOException { | ||
| if (isValidAuthHeader(exchange) == false) { | ||
| try (exchange; var xcb = XContentBuilder.builder(XContentType.JSON.xContent())) { | ||
| xcb.startObject(); | ||
| xcb.field("method", exchange.getRequestMethod()); | ||
| xcb.field("uri", exchange.getRequestURI().toString()); | ||
| xcb.field("predicate", authHeaderPredicate.toString()); | ||
| xcb.field("authorization", Objects.toString(getAuthHeader(exchange))); | ||
| xcb.startObject("headers"); | ||
| try (exchange; var builder = XContentBuilder.builder(XContentType.JSON.xContent())) { | ||
|
Member
Author
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. Renamed 👍 |
||
| builder.startObject(); | ||
| builder.field("method", exchange.getRequestMethod()); | ||
| builder.field("uri", exchange.getRequestURI().toString()); | ||
| builder.field("predicate", authHeaderPredicate.toString()); | ||
| builder.field("authorization", Objects.toString(getAuthHeader(exchange))); | ||
| builder.startObject("headers"); | ||
| for (final var header : exchange.getRequestHeaders().entrySet()) { | ||
| if (header.getValue() == null) { | ||
| xcb.nullField(header.getKey()); | ||
| builder.nullField(header.getKey()); | ||
| } else { | ||
| xcb.startArray(header.getKey()); | ||
| builder.startArray(header.getKey()); | ||
| for (final var value : header.getValue()) { | ||
| xcb.value(value); | ||
| builder.value(value); | ||
| } | ||
| xcb.endArray(); | ||
| builder.endArray(); | ||
| } | ||
| } | ||
| xcb.endObject(); | ||
| xcb.endObject(); | ||
| final var responseBytes = BytesReference.bytes(xcb); | ||
| builder.endObject(); | ||
| builder.endObject(); | ||
| final var responseBytes = BytesReference.bytes(builder); | ||
| exchange.getResponseHeaders().add("Content-Type", "application/json; charset=utf-8"); | ||
| exchange.sendResponseHeaders(RestStatus.FORBIDDEN.getStatus(), responseBytes.length()); | ||
| responseBytes.writeTo(exchange.getResponseBody()); | ||
|
|
||
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.
As the (new) comment says, the
Authorizationheader is sometimes missing in the calls the SDK makes, but apparently only in this specific test suite. I don't know why. I spent a little time investigating without success, but this is not on the critical path for what I'm actually working towards so I don't want to spend too long on it right now. Definitely worth digging deeper later on.