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

feat(admin-api): enable auth headers for admin api routes #354

Merged
merged 27 commits into from
Jun 21, 2024

Conversation

frdomovic
Copy link
Member

@frdomovic frdomovic commented Jun 6, 2024

feat(admin-api): enable auth headers for admin api routes

Summary

In this PR admin API routes were split into two different routers.
One router is protected routes which should be always protected, and unprotected routes which should not be protected when there are no root keys saved in the DID.

Unprotected routes:

  • "/health" - to ping node when setting up the node URL
  • "/fetch-challenge" - to be able to sign challenge in process of adding the root key
  • "/root-key"- to be able to add the first root key

Once the DID has saved root_key, auth layer is also applied to unprotected routes.

Requires adding auth headers to calimero sdk and admin dashboard

Summary by CodeRabbit

  • New Features

    • Added a constant APP_URL and functions for managing application endpoints in storage.ts.
    • Introduced functionality for creating authentication headers in auth/headers.ts.
    • Updated version from "0.0.22" to "0.0.23" in package.json.
  • Refactor

    • Reorganized routing logic in admin/service.rs with new routers and function imports.
    • Updated interfaces in nodeApi.ts to include a contextId field.
    • Renamed and added variables in routing logic within admin/service.rs.
  • Documentation

    • No alterations to exported or public entities in package.json and other files.

Copy link

coderabbitai bot commented Jun 6, 2024

Walkthrough

The changes encompass restructuring route logic in the crates/server/src/admin/service.rs file, updating interfaces in calimero-sdk, and enhancing functionalities related to authentication headers and storage management.

Changes

File Change Summary
crates/server/src/admin/service.rs Reorganized routing logic, introduced new routers, and imported a function from storage.
packages/calimero-sdk/package.json Updated version from "0.0.20" to "0.0.23".
packages/calimero-sdk/src/api/nodeApi.ts Added a new contextId field to LoginRequest and RootKeyRequest interfaces.
packages/calimero-sdk/src/auth/headers.ts Added functionality for creating authentication headers and managing private keys.
packages/calimero-sdk/src/auth/index.ts Exported functionality related to headers and Ed25519.
packages/calimero-sdk/src/index.ts Added export for the new auth module.
packages/calimero-sdk/src/storage/storage.ts Introduced new constants, functions, and operations for managing application endpoints and storage.

Poem

In code's dance, changes unfold,
Routes reimagined, stories retold.
Interfaces adorned with context anew,
Headers crafted, security ensue.
Storage whispers of keys and URLs,
A symphony of tech, a rabbit's cues. 🐇✨


Note

Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://coderabbit.ai

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@frdomovic frdomovic requested review from miraclx and fbozic June 6, 2024 13:50
@frdomovic frdomovic force-pushed the C20-87_add_admin_ui_auth branch from a3df7c1 to 8a63ec3 Compare June 17, 2024 11:20
@frdomovic frdomovic changed the title feat(admin-api): initial update for node ui auth feat(admin-api): enable auth headers for admin api routes Jun 17, 2024
@frdomovic frdomovic force-pushed the C20-87_add_admin_ui_auth branch from 948cceb to 22a9d53 Compare June 17, 2024 16:03
@frdomovic frdomovic force-pushed the C20-87_add_admin_ui_auth branch from 813c7fe to 76330b9 Compare June 18, 2024 14:01
@frdomovic frdomovic marked this pull request as ready for review June 18, 2024 15:04
@frdomovic frdomovic requested a review from MatejVukosav June 19, 2024 12:10
@xilosada
Copy link
Member

@MatejVukosav are we ok with this?

@@ -118,6 +118,7 @@ export function LoginWithMetamask({
walletSignature: signData,
payload: walletSignatureData?.payload,
walletMetadata: walletMetadata,
contextId: applicationId,
Copy link
Member

Choose a reason for hiding this comment

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

This is not part of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Screenshot 2024-06-19 at 17 52 33 Auth wrapper already has this context_id header check thats why adding this is needed.

Copy link
Member

@MatejVukosav MatejVukosav Jun 20, 2024

Choose a reason for hiding this comment

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

Now, when I think more about it, I think it will not work. We don't know the context id during login. We only know the application id... and multiple contexts can use the same application

Copy link
Member Author

Choose a reason for hiding this comment

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

It will work when context id replaces application id. When this happens we can just put context id in envs of application e.g. only peers client.
Right now this works when you pass application id as context id and apart from checking if the header exists there are no other tests with context_id. This new field is only used in context details > client keys so it does not break anything else.

Copy link
Member

Choose a reason for hiding this comment

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

But you don't know context upfront

Copy link
Member Author

Choose a reason for hiding this comment

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

So what do you propose should be done?

Copy link
Member

Choose a reason for hiding this comment

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

Lets wait for Mira to deploy context and then we can check it. I think we will need to remove client keys from context and bring them to level of root keys, independent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Tested the admin ui and it works

@MatejVukosav
Copy link
Member

MatejVukosav commented Jun 19, 2024

@MatejVukosav are we ok with this?

@xilosada not yet

@frdomovic frdomovic requested a review from MatejVukosav June 20, 2024 08:57
@frdomovic frdomovic requested a review from MatejVukosav June 20, 2024 14:31
@@ -47,27 +49,18 @@ pub(crate) fn setup(
let session_layer = SessionManagerLayer::new(session_store).with_secure(false);

let shared_state = Arc::new(AdminState {
store,
store: store.clone(),
Copy link
Member

Choose a reason for hiding this comment

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

Check if this will work across multiple calls. We had some issues with cloning store before but can't recall exactly what was it

Copy link
Member

@MatejVukosav MatejVukosav left a comment

Choose a reason for hiding this comment

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

Just test it all together

@xilosada
Copy link
Member

🚀

@frdomovic frdomovic merged commit 03dc2e8 into master Jun 21, 2024
@frdomovic frdomovic deleted the C20-87_add_admin_ui_auth branch June 21, 2024 12:22
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