-
-
Notifications
You must be signed in to change notification settings - Fork 145
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
Use random generated key #1010
Use random generated key #1010
Conversation
WalkthroughThe changes enhance error handling and functionality in several database-related functions. The Changes
Sequence Diagram(s)sequenceDiagram
participant DB
participant Client
participant ProjectInfo
DB->>ProjectInfo: NewProjectInfo(name, owner, threshold)
alt Error Occurs
ProjectInfo-->>DB: return error
else Success
ProjectInfo-->>DB: return ProjectInfo instance
end
DB->>Client: ensureDefaultProjectInfo()
Client->>DB: CreateProjectInfo()
alt Error Occurs
DB-->>Client: return error
else Success
DB-->>Client: return ProjectInfo instance
end
Poem
Recent review detailsConfiguration used: CodeRabbit UI Files ignored due to path filters (1)
Files selected for processing (2)
Files skipped from review as they are similar to previous changes (1)
Additional comments not posted (1)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
Outside diff range and nitpick comments (2)
server/backend/database/project_info.go (2)
72-88
: Consider migrating existing time-based keys.The PR introduces a new method for generating keys but does not address the migration of existing time-based keys. Consider adding a migration plan to ensure all keys are using the new secure method.
72-88
: Create a separate issue for implementing the API gateway.The PR objectives mention creating an issue to implement an API gateway for key refreshment. Please create a separate issue to track this work.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- server/backend/database/memory/database.go (2 hunks)
- server/backend/database/mongo/client.go (2 hunks)
- server/backend/database/project_info.go (3 hunks)
- server/backend/database/project_info_test.go (1 hunks)
Additional context used
golangci-lint
server/backend/database/project_info.go
158-158: error returned from external package is unwrapped: sig: func crypto/rand.Read(b []byte) (n int, err error)
(wrapcheck)
GitHub Check: build
server/backend/database/project_info.go
[failure] 158-158:
error returned from external package is unwrapped: sig: func crypto/rand.Read(b []byte) (n int, err error) (wrapcheck)
Additional comments not posted (7)
server/backend/database/project_info_test.go (1)
32-33
: LGTM!The change to include error handling when creating the
project
object is a good improvement. It ensures that any issues during the instantiation ofproject
are caught and reported, enhancing the robustness and reliability of the test.server/backend/database/project_info.go (2)
72-88
: LGTM!The changes to
NewProjectInfo
look good. Generating random keys forPublicKey
andSecretKey
fields enhances security by replacing the time-based approach. The error handling ensures that the caller is notified if key generation fails.
154-161
: LGTM!The new
GenerateRandomKey
function looks good. It generates a secure random base64-encoded string of the specified length using thecrypto/rand
package. The error handling ensures that the caller is notified if random byte generation fails.Tools
golangci-lint
158-158: error returned from external package is unwrapped: sig: func crypto/rand.Read(b []byte) (n int, err error)
(wrapcheck)
GitHub Check: build
[failure] 158-158:
error returned from external package is unwrapped: sig: func crypto/rand.Read(b []byte) (n int, err error) (wrapcheck)server/backend/database/memory/database.go (2)
203-206
: LGTM!The added error handling improves the robustness of the function by ensuring that any errors during project creation are properly propagated. This change aligns with best practices for error handling in Go.
239-242
: LGTM!The added error handling improves the robustness of the function by ensuring that any errors during project creation are properly propagated. This change aligns with best practices for error handling in Go.
server/backend/database/mongo/client.go (2)
168-171
: LGTM!The added error handling for
database.NewProjectInfo
improves the robustness of the code. It ensures that if an error occurs during the creation of the default project info, it is properly propagated with additional context. This prevents the use of potentially uninitialized or invalidProjectInfo
objects.
212-215
: LGTM!Similar to the changes in
ensureDefaultProjectInfo
, the added error handling fordatabase.NewProjectInfo
enhances the robustness of theCreateProjectInfo
function. It ensures that if an error occurs during the creation of a new project info, it is properly propagated with additional context. This prevents the use of potentially uninitialized or invalidProjectInfo
objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution.
Below are some comments regarding this change.
Reason for this change?
// TODO(hackerwins): Use random generated Key.
Are we changing because current key generation xid
uses the Mongo Object ID algorithm and we don't want to be predictable, just like @window9u explained? Knowing the exact reason will help us determine if this approach is suitable. @hackerwins
API Key rolling
API Gateway: Consider creating an issue to implement an API gateway for key refreshment.
I agree with your opinion of having API for rolling (refreshing) API key by various cases like key exposure. But what does it mean by implementing API Gateway
?
|
@sejongk Is there any constraints when we use UUID as project key considering our MongoDB environment especially for indexing and sharding? |
Regarding the uniqueness of UUID, the
|
@krapie In the current MongoDB sharding settings, combinations of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we do not put any information in our API key, I think (shorten) UUID is good approach for generating API key in terms of its randomness, uniqueness.
I was little worried about indexing of this API key in terms of retrieving Single query (not range) that we use will not affect performance.Project
, since we retrieve Project
every time the API call is made. But since we are using cache while retrieving this, it will have little impact on the performance. Reference: https://github.com/icamys/mongo-ULID-UUID-ObjectID
@window9u Could you create subsequence issue or PR for providing API for rolling these API keys?
Thank you for reviewing my PR. I've created the issue!! |
What this PR does / why we need it
This PR introduces a new method for generating API keys using short UUID instead of the current time-based approach. This change aims to enhance security and reduce the predictability of our API keys.
Which issue(s) this PR fixes:
Fixes #
Key Generation Options
1. Custom Charset [0-9a-v]
xid
([0-9a-v]).2. Base64 Encoding
3. ShortUUID(selected option)
4. Standard UUID
Notes for Reviewers
This approach does not ensure absolute uniqueness, but the probability of collision is extremely low. See UUID comment for details.MongoDB uniqueness constraint ensure this uniqueness comment