Skip to content

feat(core): improve resource and entity metadata within kas and authz decision audit logs#3109

Draft
jakedoublev wants to merge 12 commits intomainfrom
feat/audit-metadata-DSPX-2113
Draft

feat(core): improve resource and entity metadata within kas and authz decision audit logs#3109
jakedoublev wants to merge 12 commits intomainfrom
feat/audit-metadata-DSPX-2113

Conversation

@jakedoublev
Copy link
Contributor

  • Adds resource/entity metadata fields to APIs and docs.
  • Threads decrypted/structured metadata through SDK and KAS requests.
  • Expands audit logging for metadata in authz/rewrap flows.
  • Updates example configs to include the new metadata settings.

@github-actions github-actions bot added comp:sdk A software development kit, including library, for client applications and inter-service communicati comp:kas Key Access Server comp:authorization docs Documentation comp:middleware:auth size/l labels Mar 4, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 enhances the OpenTDF platform by adding support for resource and entity metadata within KAS and authorization decision audit logs. These changes provide a richer context for access control decisions and improve the granularity of audit logging. The updates include modifications to proto definitions, SDK enhancements, and example configurations.

Highlights

  • Resource/Entity Metadata: Adds metadata fields to resource and entity definitions in the authorization and entity proto definitions.
  • Audit Logging: Expands audit logging to include metadata in authorization and rewrap flows, providing more context for security analysis.
  • Configuration Updates: Updates example configurations to include new metadata settings, demonstrating how to configure the system to utilize the new metadata features.
  • SDK Enhancements: Threads decrypted/structured metadata through SDK and KAS requests, ensuring metadata is available throughout the system.

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

Ignored Files
  • Ignored by pattern: docs/openapi/**/* (3)
    • docs/openapi/authorization/v2/authorization.openapi.yaml
    • docs/openapi/entity/entity.openapi.yaml
    • docs/openapi/entityresolution/v2/entity_resolution.openapi.yaml
  • Ignored by pattern: protocol/**/* (2)
    • protocol/go/authorization/v2/authorization.pb.go
    • protocol/go/entity/entity.pb.go
Activity
  • Added resource/entity metadata fields to APIs and docs.
  • Threaded decrypted/structured metadata through SDK and KAS requests.
  • Expanded audit logging for metadata in authz/rewrap flows.
  • Updated example configs to include the new metadata settings.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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.


A claim's journey, Through KAS and logs it flies, Context now so rich.

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.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

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 a significant feature to improve resource and entity metadata within KAS and authorization decision audit logs. The changes are comprehensive, touching upon API definitions, SDK logic, KAS request handling, and audit logging. The implementation appears solid and well-tested. I have one suggestion regarding code duplication in the SDK to improve long-term maintainability.

Comment on lines +1 to +65
package sdk

import (
"encoding/json"
"maps"
)

func buildResourceMetadata(cfg *TDFConfig, totalPlaintextSize int64) map[string]any {
resourceMetadata := make(map[string]any)

if cfg.resourceMetadata != nil {
maps.Copy(resourceMetadata, cfg.resourceMetadata)
}

if _, ok := resourceMetadata[encMetadataKeyByteSize]; !ok {
resourceMetadata[encMetadataKeyByteSize] = totalPlaintextSize
}

if len(resourceMetadata) == 0 {
return nil
}
return resourceMetadata
}

func mergeEncryptedMetadata(base string, resourceMetadata map[string]any) (string, error) {
if len(resourceMetadata) == 0 {
return base, nil
}

if base != "" {
var baseObject map[string]any
if err := json.Unmarshal([]byte(base), &baseObject); err == nil {
baseObject["resourceMetadata"] = mergeResourceMetadata(baseObject["resourceMetadata"], resourceMetadata)
merged, err := json.Marshal(baseObject)
if err != nil {
return "", err
}
return string(merged), nil
}
}

envelope := map[string]any{
"resourceMetadata": resourceMetadata,
}
if base != "" {
envelope["metadata"] = base
}

merged, err := json.Marshal(envelope)
if err != nil {
return "", err
}
return string(merged), nil
}

func mergeResourceMetadata(existing any, additions map[string]any) map[string]any {
existingMap, ok := existing.(map[string]any)
if !ok {
existingMap = make(map[string]any)
}
for k, v := range additions {
existingMap[k] = v
}
return existingMap
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This file is nearly identical to sdk/experimental/tdf/resource_metadata.go. This code duplication can lead to maintenance issues, as changes would need to be synchronized across both files. To improve maintainability, consider refactoring this logic into a shared internal package.

For example, you could define an interface that both TDFConfig and experimental/tdf.WriterFinalizeConfig implement to provide the resource metadata. This would allow a single implementation of these utility functions to operate on that interface, eliminating the duplicated code.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

X-Test Failure Report

opentdfplatformV44VLB.dockerbuild

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 199.953985ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 102.237039ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 363.668734ms
Throughput 274.98 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 39.675340573s
Average Latency 395.589517ms
Throughput 126.02 requests/second

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 183.065176ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 96.986214ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 375.324813ms
Throughput 266.44 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.891304748s
Average Latency 407.266882ms
Throughput 122.28 requests/second

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:authorization comp:kas Key Access Server comp:middleware:auth comp:sdk A software development kit, including library, for client applications and inter-service communicati docs Documentation size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant