Skip to content
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

Retrieve the API Key from the url parameters #416

Merged
merged 4 commits into from
Mar 20, 2023
Merged

Retrieve the API Key from the url parameters #416

merged 4 commits into from
Mar 20, 2023

Conversation

qdequele
Copy link
Member

@qdequele qdequele commented Mar 6, 2023

What does this PR do?

This PR allow the mini-dashboard to receive an API Key (admin or master key) from an url parameter. This url parameter is api_key. So you if you call the dashboard {url}/?api_key={admin_key}, the mini-dashboard will never show the popup that is asking for the API Key.

See it live:
https://user-images.githubusercontent.com/6064892/223150249-a7492569-bff9-4523-acc8-cf17fc1a3e8a.mp4

src/App.js Outdated Show resolved Hide resolved
@qdequele qdequele requested a review from bidoubiwa March 6, 2023 19:51
@bidoubiwa bidoubiwa force-pushed the get-token-from-url branch from a4698b6 to 477f5fb Compare March 13, 2023 15:53
@bidoubiwa bidoubiwa force-pushed the get-token-from-url branch 2 times, most recently from 2dc6c01 to 75a53d8 Compare March 13, 2023 16:45
@bidoubiwa bidoubiwa requested a review from mdubus March 13, 2023 16:45
@bidoubiwa bidoubiwa force-pushed the get-token-from-url branch from 75a53d8 to e7c3b59 Compare March 13, 2023 16:49
@bidoubiwa bidoubiwa force-pushed the get-token-from-url branch from e7c3b59 to 44914ff Compare March 13, 2023 16:57
@@ -83,7 +83,7 @@ jobs:
with:
start: yarn start:ci
wait-on: 'http://0.0.0.0:3000'
command: yarn cy:run
command: yarn cy:run:test-no-api-key
Copy link
Member

Choose a reason for hiding this comment

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

Can you double check that all the tests are being run? I recommend you check the cy:run command inside the package.json, which runs all the tests except some specific ones.

options: --user 1001
services:
meilisearch:
image: getmeili/meilisearch:v0.30.5
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to update this to v1?

@@ -137,3 +137,45 @@ jobs:
with:
name: cypress-videos
path: cypress/videos
cypress_meilisearch-api-key-query-param:
Copy link
Member

Choose a reason for hiding this comment

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

Why didn't you put all of this inside the cypress_meilisearch-api-key above which already makes tests with a running Meilisearch instance + API key?

cy.get('span').contains('Api Key').parent().click()
cy.get('div[aria-label=settings-api-key]').within(() => {
cy.get('input[name="apiKey"]').should('have.value', API_KEY)
cy.get('button').contains('Go').click()
Copy link
Member

@mdubus mdubus Mar 14, 2023

Choose a reason for hiding this comment

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

You don't really need this last line :)

package.json Outdated
Comment on lines 37 to 41
"cy:run:test-no-meilisearch": "cypress run --spec '**/*/test-no-meilisearch.cy.js'",
"cy:run:test-api-key-required": "cypress run --spec '**/*/test-api-key-required.cy.js'",
"cy:run:test-api-key-query-param": "cypress run --spec '**/*/test-api-key-query-param.cy.js'",
"cy:run:test-no-api-key": "cypress run --spec '**/*/test-no-api-key-required.cy.js'",
"cy:run": "cypress run --config excludeSpecPattern=['**/*/test-no-meilisearch.cy.js','**/*/test-api-key-required.cy.js']",
Copy link
Member

Choose a reason for hiding this comment

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

Initially I had those commands for those specific tests:

  • cy:run:test-no-meilisearch : tests when there is no Meilisearch instance running
  • cy:run:test-api-key-required : tests that require a Meilisearch instance running + an API key
  • cy:run : tests that require a Meilisearch instance running (without an API key here for simplicity)

I had those 3 because I needed to run 3 different instances in the CI.
I don't really get why you added more commands in the package.json nor more jobs in the CI, but I'm available to discuss it of you want :)

Copy link
Member

@Kerollmops Kerollmops left a comment

Choose a reason for hiding this comment

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

What do you think about making the mini-dashboard redirect to a clean URL (by removing the query parameter from it) and storing it in the local storage?

It is related to this message from @davelarkan (private link).

Is there a security concern here by reducing this friction? Will users understand that the master key in the URL can do damage if it's leaked?

@bidoubiwa
Copy link
Contributor

Removing the query parameters from an url is not common if I'm not mistaken. Either way, it presents a security risk as it's not because we remove the api_key from the URL that the user will suddenly not share the original URL.

if the user adds the api_key through the interface, we do not add it in the URL.

@bidoubiwa bidoubiwa requested a review from mdubus March 14, 2023 11:42
Copy link
Member

@mdubus mdubus left a comment

Choose a reason for hiding this comment

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

LGTM ✨🦕

@bidoubiwa
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Mar 20, 2023

Build succeeded:

@bors bors bot merged commit 224ff56 into main Mar 20, 2023
@bors bors bot deleted the get-token-from-url branch March 20, 2023 12:24
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.

4 participants