Embed a [short lived] JWT token into the test console #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
This PR continues the series of PRs enabling JWT-based authorization for
scrape
. Prior PRs in this series:What's Here
This PR embeds a JWT Token into the source of the test console's html, so that the test console has a token to pass in along with its API request. This token is a short-lived token and is intended to provide spot access to the test console without requiring key interactions, and also to provide a way to exercise/develop the end-to-end token interactions easlily and without system disruptions (In an IAP future, IAP would be participating in this interaction and there's likely a scoping mechanism applied to this token).
In order to support configuring authorization, an argument/env variable for a signing key has been added to
scrape-server
. If this key is provided and valid, authorization will be enabled.At this time, enabling authorization just gets a token embedded in the page source and passed into the server on form submits. Authorization is not checked or enforced in this PR, that will come in a follow-on PR.
Steps To Test
From the root directory of this branch:
make
make test
- if you want to confirm that the tests pass./build/scrape-server
(-h
if you want to see the docs)View Source
you will see an empty token assignment in the JS function near the bottom, it'll look like this:Now, make a signing key and restart the server using that key:
./build/scrape-server -signing-key [the key you got above]
or set a shell variable ofSCRAPE_SIGNING_KEY
to the key value and start the server without arguments.View Source
you will see a populated token assignment in the JS function near the bottom, it'll look like this:That's it! (You can also do the above from the Docker build)
If you don't have go installed, you'll need to install go (on the Mac easiest to do with
brew
. You'll also need togo install honnef.co/go/tools/cmd/staticcheck@latest
to run static analysis (which happens as part ofmake
)