Skip to content

feat(sdk)!: add base key and support for key grants in ZTDF #271

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

Open
wants to merge 40 commits into
base: main
Choose a base branch
from

Conversation

mkleene
Copy link
Contributor

@mkleene mkleene commented Jun 18, 2025

Introduces the Planner class, which encapsulates the policy about how to create a split plan, basing its
decision on TDFConfig.autoconfigure, whether KASes were provided in config, and whether a split plan
was manually provided in config.

Modifies the Autoconfigure.Granter class to consume key grants. When a key is specified using a KID
the KID is used during key assignment. When there are no grants or mapped keys present Autoconfigure.Granter
reaches out to the wellknown endpoint to download a base key and constructs a single element split plan.

  • update visibility of some internal classes
  • get rid of a bit of duplication
  • include a WellknownServiceClientInterface in the SDK.Services interface. Not sure if this is a good idea
    or not but it doesn't seem dangerous.
  • update some test classes

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @mkleene, 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 undertakes a minor refactor to enhance the modularity, encapsulation, and overall clarity of the codebase, primarily focusing on the Autoconfigure and TDF classes. The changes aim to improve internal structure and maintainability without altering external behavior, by centralizing key logic and refining class/method access.

Highlights

  • Encapsulation Improvements: Restricted the visibility of several internal classes and methods within Autoconfigure.java from public to package-private or private, promoting better encapsulation and clearer API boundaries.
  • Code Modularity and Reusability: Extracted the logic for generating default key split plans from TDF.java into a new, dedicated static helper method, generatePlanFromDefaultKases, within Autoconfigure.Granter. This centralizes the logic and reduces duplication across the codebase.
  • Code Cleanup and Simplification: Removed the AttributeMapping inner class from Autoconfigure.java, streamlining the codebase. Additionally, simplified the defaultKases method in TDF.java and refined map population logic.
  • Type Safety and Immutability: Introduced @Nonnull annotations for better nullability guarantees and made several fields final to enforce immutability where appropriate, enhancing code robustness.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and 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 to provide feedback.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the Autoconfigure and TDF classes, focusing on code structure and encapsulation. Key changes include reducing member visibility, making inner classes static, using final for fields, and extracting logic into new methods. These changes improve the maintainability and clarity of the codebase.

@mkleene mkleene changed the title minor refactor chore(sdk)!: refactor Jun 18, 2025
@mkleene
Copy link
Contributor Author

mkleene commented Jul 2, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 significant refactoring by centralizing key split plan generation into a new Planner class, improving modularity and reducing duplication. It also integrates Key IDs (kid) into the key management and caching logic, enhancing key specificity. The changes include appropriate visibility updates for internal classes and services, aligning with good software engineering practices. However, a critical issue was identified in the KASKeyCache's key equality logic, which needs immediate attention.

@mkleene
Copy link
Contributor Author

mkleene commented Jul 3, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

An excellent refactoring effort that significantly improves the structure and clarity of the SDK. The introduction of the Planner class is a great step towards better separation of concerns, and the reduced visibility of internal classes enhances encapsulation. I've identified a critical compilation issue and a medium-severity issue related to an unused parameter. Addressing these will further solidify the quality of this refactoring.

@mkleene
Copy link
Contributor Author

mkleene commented Jul 3, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 the Planner class, which encapsulates the policy about how to create a split plan. It also adds support for key grants and a base key from a .well-known endpoint. The changes include updates to visibility for better encapsulation and general code cleanup. The review focuses on exception handling and code clarity.

@mkleene
Copy link
Contributor Author

mkleene commented Jul 3, 2025

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 significant and valuable features, including the Planner class for orchestrating key split plans, support for key grants, and the ability to fetch a base key from a well-known endpoint. The refactoring to centralize planning logic and improve encapsulation of internal classes is a great step towards better maintainability. I've found one critical issue in the grant resolution logic that needs to be addressed. Otherwise, the changes are well-implemented and the addition of new tests is commendable.

@mkleene mkleene marked this pull request as ready for review July 3, 2025 14:54
@mkleene mkleene requested review from a team as code owners July 3, 2025 14:54
@mkleene mkleene changed the title feat(sdk)!: add base key and support for key grants feat(sdk)!: add base key and support for key grants in ZTDF Jul 3, 2025
Copy link
Contributor

@c-r33d c-r33d left a comment

Choose a reason for hiding this comment

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

One thing I see that is different from the golang SDK is when we go to create the key access object. Currently it looks like this is still relying on the algorithm passed in from the seeded options, which it should instead use the algorithm passed back from the grant/key mappings.

opentdf/platform#2475

@mkleene mkleene requested a review from c-r33d July 21, 2025 20:30
@mkleene mkleene requested a review from c-r33d July 21, 2025 20:51
Copy link

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