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

Helper party api key #37

Merged
merged 6 commits into from
Jun 13, 2024
Merged

Helper party api key #37

merged 6 commits into from
Jun 13, 2024

Conversation

eriktaubeneck
Copy link
Member

@eriktaubeneck eriktaubeneck commented Jun 9, 2024

Stacked diff: I'll update the base and rebase manually, but I put the base on here so that the diff is easy to review.

This creates a new table helper_party_api_keys, which will be used for helper parties to report their status back to the management plane (on the path to being able to manage the query queue, and start a new query when one finishes.)

Summary by CodeRabbit

  • Chores

    • Updated .gitignore to ignore .env*.local files for better handling of local environment configurations.
  • New Features

    • Introduced default API key values and Supabase variables for local development.
  • Database

    • Added helper_party_api_keys table with columns for UUID, references, hashed API keys, timestamps, and modification reasons.
    • Enabled row-level security for the new table to restrict access to authenticated users.
    • Seeded initial data for the helper_party_api_keys table.

Copy link

vercel bot commented Jun 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
draft ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 13, 2024 10:41pm

Copy link
Contributor

coderabbitai bot commented Jun 9, 2024

Walkthrough

The changes focus on enhancing local development environment configurations and managing API keys for helper parties. This includes updating the .gitignore to more specifically ignore local .env files, introducing default environment variables in server/.env.development, adding a new helper_party_api_keys entity to the Supabase schema, and updating seeding scripts to insert relevant data.

Changes

Files and Change Summaries
.gitignore
server/.env.development
server/data/supabaseTypes.ts
server/supabase/migrations/20240609010604_helper_party_api_keys.sql
server/supabase/seed.sql

Poem

In code we trust, a rabbit's cheer,
With keys and files for all to veer.
Environment local, secrets kept tight,
Supabase table, everything right.
🐇 In the data fields, we leap with might!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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.

@eriktaubeneck
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jun 9, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 82305e1 and 3b9474b.

Files selected for processing (5)
  • .gitignore (1 hunks)
  • server/.env.development (1 hunks)
  • server/data/supabaseTypes.ts (1 hunks)
  • server/supabase/migrations/20240609010604_helper_party_api_keys.sql (1 hunks)
  • server/supabase/seed.sql (1 hunks)
Files skipped from review due to trivial changes (3)
  • .gitignore
  • server/.env.development
  • server/supabase/seed.sql
Additional comments not posted (4)
server/supabase/migrations/20240609010604_helper_party_api_keys.sql (3)

1-9: The table structure and default values are well-defined and align with the requirements for API key management.


11-11: Enabling row-level security is a crucial step for protecting sensitive data in the table.


13-13: It's important to ensure that the application logic strictly adheres to the security guidelines mentioned in the comment to prevent unauthorized access to API keys.

server/data/supabaseTypes.ts (1)

55-89: The type definitions for helper_party_api_keys are comprehensive and correctly reflect the database schema. The relationships are well-defined, ensuring proper foreign key constraints.

@eriktaubeneck eriktaubeneck requested a review from akoshelev June 9, 2024 02:55
Base automatically changed from helper-party to main June 10, 2024 22:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3b9474b and 152dcd3.

Files selected for processing (4)
  • server/.env.development (1 hunks)
  • server/data/supabaseTypes.ts (2 hunks)
  • server/supabase/migrations/20240609010604_helper_party_api_keys.sql (1 hunks)
  • server/supabase/seed.sql (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • server/.env.development
  • server/data/supabaseTypes.ts
  • server/supabase/migrations/20240609010604_helper_party_api_keys.sql
  • server/supabase/seed.sql

@eriktaubeneck eriktaubeneck changed the title Helper party api key [STACKED DIFF] Helper party api key Jun 11, 2024
hashed_api_key varchar(255) not null,
created_at timestamp default current_timestamp not null,
expires_at timestamp default current_timestamp + interval '1 year' not null,
revoked boolean default false not null
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you elaborate why we need an extra flag here? One may think that to revoke a key, you can set expires_at in the past and wait until this change is propagated

Copy link
Member Author

Choose a reason for hiding this comment

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

Main reason is so that we retain more information, e.g., revoking a key is different than it expiring, and we'd want to provide different error messages based on those different facts.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My main concern is the validity check - you must not forget to check both and if expires_at is still in the future and revoked is set, that looks weird. Maybe, as an alternative, you could use status or modify_reason/modified_at? Validity check can only look at expires_at and that is simpler

Copy link
Member Author

Choose a reason for hiding this comment

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

If we have a status column, then it becomes a bit less clear to a future developer that they need to do a validity check on expires_at and not status, and similarly with modify_reason/modify_at you need to assure that it also changes expiry.

Here's another idea. It would require slightly more work, but would be easier to worry about. Create two tables:

helper_party_api_key_creation_events and helper_party_api_key_revocation_events. The first table would have everything in this PR except the revoked column, and the second table would have: uuid, helper_party_api_key_creation_event_uuid (join column), helper_party_uuid, created_at.

Then, we'd create a view (possibly materialized), which would be used for the validity checks

select 
    c.helper_party_uuid, 
  , c.hashed_api_key
  , c.expires_at < current_timestamp() and r.uuid is null as valid
  , case 
      when r.uuid is not null as 'revoked'
      when c.expires_at >= current_timestamp() as 'expired'
      else null
from 
  helper_party_api_key_creation_events c
left outer join
  helper_party_api_key_revocation_events r
on c.uuid = r.helper_party_api_key_creation_event_uuid

This does a few nice things:

  1. Maintains all information (e.g., nothing is overwritten or modified, just computed as a result of events.)
  2. Minimizes the risk of incorrect validation, as stored directly on the table.
  3. Minimized the risk of incorrectly invalidating, as a future developer just needs to create that event, rather than make sure to properly modify the helper_party_api_key table.

The only potential downside is that it moves some of business logic into the database. For this, it seems like there are essentially 3 places where logic can live (and things can go wrong):

  1. When events are created or modified (revoked). In your example, this would require making sure that when a revoke action happens, the developer needs to correctly update the expiration.
  2. When api keys are validated. This requires potentially checking expires_at and revoked.
  3. In the database, as a view computed over actions.

After writing this all out, I think I like 3/ the best. Also, this type of event driven architecture is a possible solution to the problem you mention about state management across between the management plane and multiple control planes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

With the event sourcing, you typically have only one timestamp which is the timestamp of the event. Then you can build a snapshot and/or the latest status by applying these events according to their timestamp and looking at the resulting object. So you technically can have only one table that records two event types - create/revoke and if revoke is the last event, then key is no longer valid.

This could be more powerful than what we want here - I was thinking that expiry_at + modify_reason = "REVOKE" is enough information for an engineer to see what is going on, even if reason is unstructured. I don't want to overcompicate things here, so if you are not inclined with this, I think the current proposal is better than even sourcing because it is less complex

@@ -0,0 +1,13 @@
create table
helper_party_api_keys (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Most of the time I see API keys bound to clients that use them. Helper party has the power to revoke them. but they also want to know who requested them and why, so they can validate both at the request time. If you allow more than one key per party, that may be worth exploring, because otherwise it gets hard to manage

Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't super clear from the PR, but it will be more clear in the next one: the point of these keys for the report collector (draft/server) to provide a key to the helper party (draft/sidecar), that allows that helper party to POST a status update about a query to the server. This is issued from the report collector to the helper party, so that the helper party can validate that POSTs coming in from helper parties are valid.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. So, generally systems that are allowed to talk to each other using bi-directional channels, that is: sending actions/mutating the state on both sides are much harder to reason about. Both sides need to have "write" permission on the other side which leads to security complications and maintainability issues.

For the short term, it can work but I'd love us to reconsider this approach after the test

Copy link
Member Author

Choose a reason for hiding this comment

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

yea, a more detailed design review here would be great. at a very high level, I'm not sure we can avoid bi-directional all together, but I certainly want to (and think we can) avoid managing state in both places. As I see it:

  1. Management Plane --> Control Plane: Start query signal, Stop Query signal, etc
  2. Control Plane --> Management Plane: Current state, logs, observability

So different signals, but in both directions, we need authentication from between these two planes (as they are operated by different parties.)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 152dcd3 and 5de1101.

Files selected for processing (2)
  • server/data/supabaseTypes.ts (1 hunks)
  • server/supabase/migrations/20240609010604_helper_party_api_keys.sql (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • server/data/supabaseTypes.ts
  • server/supabase/migrations/20240609010604_helper_party_api_keys.sql

@eriktaubeneck eriktaubeneck merged commit 46142c8 into main Jun 13, 2024
3 checks passed
@eriktaubeneck eriktaubeneck deleted the helper-party-api-key branch June 13, 2024 22:45
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.

2 participants