Skip to content

Validate Authorization header in Azure test fixture#111242

Merged
DaveCTurner merged 2 commits intoelastic:mainfrom
DaveCTurner:2024/07/24/azure-test-fixture-validate-auth
Jul 24, 2024
Merged

Validate Authorization header in Azure test fixture#111242
DaveCTurner merged 2 commits intoelastic:mainfrom
DaveCTurner:2024/07/24/azure-test-fixture-validate-auth

Conversation

@DaveCTurner
Copy link
Copy Markdown
Member

Today the Azure test fixture accepts all requests, but we should be
checking that the Authorization header is at least present and
approximately correct. This commit adds support for this check.

Today the Azure test fixture accepts all requests, but we should be
checking that the `Authorization` header is at least present and
approximately correct. This commit adds support for this check.
@DaveCTurner DaveCTurner added >test Issues or PRs that are addressing/adding tests :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v8.16.0 labels Jul 24, 2024
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-distributed (Team:Distributed)

@elasticsearchmachine elasticsearchmachine added the Team:Distributed Meta label for distributed team. label Jul 24, 2024
Copy link
Copy Markdown
Contributor

@mhl-b mhl-b left a comment

Choose a reason for hiding this comment

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

lgtm

@DaveCTurner DaveCTurner merged commit 97f6294 into elastic:main Jul 24, 2024
@DaveCTurner DaveCTurner deleted the 2024/07/24/azure-test-fixture-validate-auth branch July 24, 2024 18:03
Copy link
Copy Markdown
Contributor

@DiannaHohensee DiannaHohensee left a comment

Choose a reason for hiding this comment

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

Unfamiliar with this code, so I have some questions, mostly.


AzureBlobStoreHttpHandler(final String account, final String container) {
super(account, container);
super(account, container, null /* no auth header validation */);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

might help to explain why we don't want to do header validation here?

Comment on lines +70 to +77
final var authHeader = getAuthHeader(exchange);
if (authHeader == null) {
return false;
}

if (authHeader.size() != 1) {
return false;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So it's OK to not have a header predicate, but it is not OK to skip sending one? What are these decisions based on 🤔

@Override
public void handle(final HttpExchange exchange) throws IOException {
if (isValidAuthHeader(exchange) == false) {
try (exchange; var xcb = XContentBuilder.builder(XContentType.JSON.xContent())) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd understand 'builder' more rapidly than discerning what 'xcb' stands for, my two cents.

AZURE_TEST_ACCOUNT,
AZURE_TEST_CONTAINER
AZURE_TEST_CONTAINER,
AzureHttpFixture.startsWithPredicate("SharedKey " + AZURE_TEST_ACCOUNT + ":")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

where do the headers get generated that we're trying to match here by expecting "SharedKey ....:"?

@DiannaHohensee
Copy link
Copy Markdown
Contributor

DiannaHohensee commented Jul 24, 2024

Oh, looks like Mikhail took care of this before I finished. Cool 👍

DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Jul 24, 2024
Arising from a post-merge review of elastic#111242
@DaveCTurner
Copy link
Copy Markdown
Member Author

Thanks @DiannaHohensee, you raise valid points, we can continue to iterate on them in #111252.

weizijun added a commit to weizijun/elasticsearch that referenced this pull request Jul 25, 2024
* main: (39 commits)
  Update README.asciidoc (elastic#111244)
  ESQL: INLINESTATS (elastic#109583)
  ESQL: Document a little of `DataType` (elastic#111250)
  Relax assertions in segment level field stats (elastic#111243)
  LogsDB data generator - support nested object field (elastic#111206)
  Validate `Authorization` header in Azure test fixture (elastic#111242)
  Fixing HistoryStoreTests.testPut() and testStoreWithHideSecrets() (elastic#111246)
  [ESQL] Remove Named Expcted Types map from testing infrastructure  (elastic#111213)
  Change visibility of createWriter to allow tests from a different package to override it (elastic#111234)
  [ES|QL] Remove EsqlDataTypes (elastic#111089)
  Mute org.elasticsearch.repositories.azure.AzureBlobContainerRetriesTests testReadNonexistentBlobThrowsNoSuchFileException elastic#111233
  Abstract codec lookup by name, to make CodecService extensible (elastic#111007)
  Add HTTPS support to `AzureHttpFixture` (elastic#111228)
  Unmuting tests related to free_context action being processed in ESSingleNodeTestCase (elastic#111224)
  Upgrade Azure SDK (elastic#111225)
  Collapse transport versions for 8.14.0 (elastic#111199)
  Make sure contender uses logs templates (elastic#111183)
  unmute HistogramPercentileAggregationTests.testBoxplotHistogram (elastic#111223)
  Refactor Quality Assurance test infrastructure (elastic#111195)
  Mute org.elasticsearch.xpack.restart.FullClusterRestartIT testDisableFieldNameField {cluster=UPGRADED} elastic#111222
  ...

# Conflicts:
#	server/src/main/java/org/elasticsearch/TransportVersions.java
DaveCTurner added a commit that referenced this pull request Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Meta label for distributed team. >test Issues or PRs that are addressing/adding tests v8.16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants