-
Notifications
You must be signed in to change notification settings - Fork 3
Add context namespace to requests #411
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
base: feature/isolated-namespace
Are you sure you want to change the base?
Add context namespace to requests #411
Conversation
Summary of ChangesHello @jnmt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a fundamental enhancement by integrating a 'context namespace' into the client-side request architecture. This change enables operations to be logically grouped and isolated within distinct namespaces, improving the system's multi-tenancy capabilities and organizational structure. It touches upon core request models, client-side configuration, and the request signing mechanism to ensure consistent and secure handling of namespace-aware operations. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a context_namespace to various requests, which is a significant feature impacting many parts of the codebase. While the core implementation is present, there are several critical issues that need to be addressed before this can be merged.
Specifically, the signature validation logic for contracts is incomplete and marked with a TODO, which is a critical bug. The context_namespace is also lost when registering secrets. Furthermore, some requests are missing the context_namespace field, leading to inconsistencies. There is also a noticeable lack of tests for the new namespace functionality; existing tests are updated to use the default namespace, but no new tests cover non-default scenarios. I've added specific comments with details on these issues.
| entry.getBinaryName(), | ||
| entry.getByteCode(), | ||
| entry.getProperties().orElse(null), | ||
| null, // TODO: use context namespace |
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.
Passing null for contextNamespace with a TODO comment is a critical issue. This will cause signature validation to fail for any contract registered with a non-default namespace. The ContractEntry class should be updated to store the contextNamespace from the ContractRegistrationRequest, and that value should be used here for correct signature validation. A similar issue exists in ContractValidator.java.
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.
This will be fixed in another PR.
| public static SecretEntry from(SecretRegistrationRequest request) { | ||
| return new SecretEntry( | ||
| request.getEntityId(), | ||
| request.getKeyVersion(), | ||
| request.getSecretKey(), | ||
| Time.getCurrentUtcTimeInMillis()); | ||
| } |
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.
The from(SecretRegistrationRequest request) method creates a SecretEntry but discards the contextNamespace from the request. The SecretEntry class itself has not been updated to store the namespace. This is a data loss issue that will likely cause problems, for example, if secrets need to be scoped by namespace. The SecretEntry class should be updated to include the contextNamespace.
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.
SecretEntry will not include the context namespace. Anyway, registering secrets with context namespace will be supported in another PR.
| ContractExecutionRequest.serialize( | ||
| ContractEntry.Key.deserialize(record.contractId()).getId(), | ||
| record.argument(), | ||
| null, // TODO: use context namespace |
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.
Passing null for contextNamespace with a TODO comment is a critical issue. This will cause signature validation to fail for any contract execution with a non-default namespace. The ContractEntry (from which the ContractMachine is created) should be updated to store the contextNamespace, and that value should be used here for correct signature validation. A similar issue exists in ContractManager.java.
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.
This will be fixed in another PR.
| int keyVersion, | ||
| byte[] signature) { | ||
| super(entityId, keyVersion); | ||
| super(null, entityId, keyVersion); |
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.
The contextNamespace is hardcoded to null for AssetProofRetrievalRequest. This is inconsistent with other requests in this PR. The .proto definition for AssetProofRetrievalRequest is also missing the context_namespace field. Was this intentional? If not, it should be added for consistency. A similar issue exists for ExecutionAbortRequest.
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.
This is intended. AssetProofRetrievalRequest and ExecutionAbortRequest will always be coming from the Auditor with the Auditor's signature in the default context.
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.
@jnmt Even without context_namespace, can Ledger handle those requests from Auditor in a namespace-aware way? For example, can Auditor get an asset proof from the correct namespace?
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.
@KodaiD Thank you for the question! Yes, as the next line shows, the request can have the "target" namespace information.
| @SuppressFBWarnings("EI_EXPOSE_REP2") | ||
| public ExecutionAbortRequest(String nonce, String entityId, int keyVersion, byte[] signature) { | ||
| super(entityId, keyVersion); | ||
| super(null, entityId, keyVersion); |
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.
The contextNamespace is hardcoded to null for ExecutionAbortRequest. This is inconsistent with other requests in this PR. The .proto definition for ExecutionAbortRequest is also missing the context_namespace field. Was this intentional? If not, it should be added for consistency. A similar issue exists for AssetProofRetrievalRequest.
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.
This is intended. AssetProofRetrievalRequest and ExecutionAbortRequest will always be coming from the Auditor with the Auditor's signature in the default context.
...er/src/integration-test/java/com/scalar/dl/ledger/service/LedgerServiceEndToEndTestBase.java
Outdated
Show resolved
Hide resolved
| /** Constants related to namespaces. */ | ||
| public final class Namespaces { | ||
| /** The default namespace name. */ | ||
| public static final String DEFAULT = "default"; |
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.
Previously, we have NamespaceManager.DEFAULT_NAMESPACE for the default namespace name. However, both clients and servers want to refer to it, so I will newly introduce this. The places that use the old one will be refactored later.
|
|
||
| public void register(SecretEntry entry) { | ||
| base.register(entry); | ||
| public void register(SecretRegistrationRequest request) { |
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.
For consistency, I added SecretRegistrationRequest, the same as register(CertificateRegistrationRequest request).
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
| if (!config.getContextNamespace().equals(Namespaces.DEFAULT)) { | ||
| builder.setContextNamespace(config.getContextNamespace()); | ||
| } |
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 contracts registered by old clients have a signature without context, the contract validation fails if the context namespace is included when executing the contract. To exclude the context namespace (i.e., as null) if it is default when validating the contract, new clients also need to sign without the context if it is default. It's complicated, so to avoid confusion, I think it's better to do the same for all the requests in both the client and servers (i.e., treat as null if it's the default namespace). cf. assertion in AbstractRequest
Description
This PR adds the context namespace to each request.
This is the first step for supporting the isolated namespace feature. The isolated namespace feature enables users to register/execute contracts on an isolated namespace without considering which namespace should be used to read/write assets when executing contracts.
For example, assume a Payment contract that can send money from one account (asset) to another account (asset) using the
get(String assetId) and put(String assetId, T data)methods. The developer does not have to care about the namespace to get/put. With thenamespace1as a context, users of thenamespace1can register/execute this contract and get/put assets in their own namespace. Of course, the same contract can be run on a different namespace (e.g.,namespace2) in an isolated manner, preventing access from other namespaces. So, users can easily build a multi-tenant service with the isolated namespace feature. See also the rough design doc for additional information.Since the isolated namespace feature will introduce a lot of changes, this PR only introduces the changes for the protocol. I will create separate PRs for each small functionality after this PR. The current plan is as follows:
Related issues and/or PRs
Changes made
Checklist
Additional notes (optional)
Release notes