Skip to content

Add API key authentication to ApiServer#13

Open
thechibuikem wants to merge 2 commits into
hyphae:vertex-4from
thechibuikem:vertex-4
Open

Add API key authentication to ApiServer#13
thechibuikem wants to merge 2 commits into
hyphae:vertex-4from
thechibuikem:vertex-4

Conversation

@thechibuikem

Copy link
Copy Markdown

Addresses hyphae/APIS#91 (item 1: Unauthenticated Control APIs)

Adds timing-safe X-API-Key header check to ApiServer's HTTP request handler, covering all three handlers (ErrorGeneration, DealGeneration, LogConfiguration) since the check runs before dispatch. Returns 500 if apiKey unconfigured, 401 on missing/invalid key.

Tests

ApiServerAuthTest: missing key, empty key, missing header, wrong
header, valid header.

Follow-up (separate PRs)

  • apis-common: method to read API key from config
  • Update callers to send X-API-Key header
  • Remaining #91 items (2–7) tracked separately

@FlawzyByte

Copy link
Copy Markdown
Member

Interesting insight, I provided my answer through zulip
@subhramit Hi subha again, I appreciate your feedback on this. Thanks!

Comment thread Makefile

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please revert the formatting changes to this file

when(req.getHeader("X-API-Key")).thenReturn("secret");
assertNull(ApiServer.checkAuth(req, "secret"));
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a newline here. This can also be covered by Checkstyle eventually.

Comment on lines +5 to +6
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't import *, just import the required methods

@subhramit subhramit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey, can you provide some steps to manually test this?
Also can you look into if assertEquals needs explicit boxing for comparison? (Integer.valueOf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants