Skip to content

feat(xtest): add exp-go-sdk using experimental TDF writer#414

Open
pflynn-virtru wants to merge 4 commits intomainfrom
feat/exp-go-sdk
Open

feat(xtest): add exp-go-sdk using experimental TDF writer#414
pflynn-virtru wants to merge 4 commits intomainfrom
feat/exp-go-sdk

Conversation

@pflynn-virtru
Copy link
Member

@pflynn-virtru pflynn-virtru commented Feb 13, 2026

Summary

  • Adds exp-go-sdk, a new SDK target that wraps the platform's experimental streaming TDF writer (sdk/experimental/tdf) for encrypt and the standard SDK's LoadTDF for decrypt
  • Validates interoperability of TDFs produced by the experimental writer with all existing SDKs (go, java, js)
  • Uses autoconfigure flow: GetBaseKey / fetchKASPublicKey + GetAttributeValuesByFqns to resolve KAS keys and attribute grants from the platform

Changes

New files (xtest/sdk/exp-go-sdk/):

  • main.go — Go CLI with encrypt, decrypt, and supports subcommands
  • cli.sh — Shell wrapper translating XT_WITH_* env vars to CLI flags
  • Makefile — Build rules producing dist/main/exp-go-sdk + dist/main/cli.sh
  • go.mod / go.sum — Module with platform SDK dependencies

Modified files:

  • xtest/sdk/Makefile — Added exp-go-sdk build target
  • xtest/tdfs.py — Registered exp-go-sdk as sdk_type with autoconfigure and ns_grants feature flags
  • .github/workflows/xtest.yml — Added to CI matrix, build steps with go mod replace, focus-sdk validation

Supported features

assertions, assertion_verification, autoconfigure, ns_grants, ecwrap, hexless, connectrpc, kasallowlist, better-messages-2024

Not yet supported

hexaflexible (no target-mode selection), obligations, key_management, bulk_rewrap

Depends on platform SDK fixes

This PR found two bugs in the experimental TDF writer that need to be fixed in the platform repo before CI will fully pass:

  1. Segment hash mismatch (sdk/experimental/tdf/writer.go) — calculateSignature is called on segmentCipher only, but the standard SDK reader hashes nonce + segmentCipher. Every TDF produced by the experimental writer fails integrity verification on decrypt.

  2. Default KAS key not merged for attribute-based access (sdk/experimental/tdf/keysplit/xor_splitter.go) — When attributes are provided, collectAllPublicKeys only gathers keys from attribute grants. If grants reference the default KAS URL without including the public key PEM (legacy grants), the encrypt fails with "no valid key access objects generated". The default KAS public key should be merged into allKeys as a fallback.

Fixes for both are staged in a local platform branch.

Test plan

  • Platform SDK fixes merged (segment hash + default KAS key merge)
  • CI matrix runs exp-go-sdk alongside existing SDKs
  • Cross-SDK roundtrip: encrypt with exp-go-sdk, decrypt with go/java/js
  • Assertion encrypt/decrypt tests pass
  • ABAC autoconfigure / policy type tests pass
  • EC wrapping tests pass

🤖 Generated with Claude Code

Add a new SDK target that wraps the platform's experimental streaming
TDF writer for encrypt and the standard SDK for decrypt. This validates
interoperability of TDFs produced by the experimental writer with all
existing SDKs.

New files:
- xtest/sdk/exp-go-sdk/main.go: Go CLI with encrypt/decrypt/supports
- xtest/sdk/exp-go-sdk/cli.sh: shell wrapper for xtest integration
- xtest/sdk/exp-go-sdk/Makefile: build rules
- xtest/sdk/exp-go-sdk/go.mod: module with platform SDK dependencies

Modified files:
- xtest/sdk/Makefile: add exp-go-sdk build target
- xtest/tdfs.py: register exp-go-sdk as sdk_type with feature flags
- .github/workflows/xtest.yml: add to CI matrix with go.mod replace

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pflynn-virtru pflynn-virtru requested review from a team as code owners February 13, 2026 14:38
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @pflynn-virtru, 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 an experimental Go SDK (exp-go-sdk) to the xtest suite, designed to test a new streaming TDF writer. The primary goal is to ensure that TDFs created with this experimental writer are fully interoperable with existing SDKs across different languages. It leverages an automated configuration process for key and attribute resolution, streamlining its integration and testing within the platform's ecosystem.

Highlights

  • New Experimental Go SDK Target: Introduced exp-go-sdk, a new SDK target within the xtest framework. This SDK specifically utilizes an experimental streaming TDF writer for encryption operations and the standard Go SDK's LoadTDF for decryption.
  • Interoperability Validation: The new exp-go-sdk is designed to validate the interoperability of TDFs produced by the experimental writer with existing Go, Java, and JavaScript SDKs, ensuring compatibility across the platform.
  • Automated Configuration Flow: The exp-go-sdk implements an autoconfigure flow, leveraging GetBaseKey and GetAttributeValuesByFqns to dynamically resolve KAS keys and attribute grants from the platform.
  • CI Integration and Feature Support: The new SDK has been integrated into the CI matrix, including build steps and focus-sdk validation. It supports features such as assertions, assertion verification, autoconfigure, namespace grants, EC wrapping, hexless, connectrpc, KAS allowlist, and better-messages-2024.

🧠 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
  • xtest/sdk/Makefile
    • Added exp-go-sdk to the .PHONY target list.
    • Included exp-go-sdk in the all build target.
    • Added a new build rule for exp-go-sdk to navigate into its directory and execute its Makefile.
  • xtest/sdk/exp-go-sdk/Makefile
    • Created a new Makefile to define build targets for the exp-go-sdk CLI and its shell wrapper.
    • Included all and clean as phony targets.
    • Defined rules to build the exp-go-sdk Go binary and copy/chmod the cli.sh script into the dist/main directory.
  • xtest/sdk/exp-go-sdk/cli.sh
    • Added a new shell script to act as a common wrapper for the exp-go-sdk CLI.
    • Implemented logic to parse environment variables (XT_WITH_*) and translate them into command-line arguments for the Go binary.
    • Provided encrypt, decrypt, and supports subcommands, handling various configuration options like platform endpoint, client credentials, attributes, assertions, and KAS allowlist.
  • xtest/sdk/exp-go-sdk/go.mod
    • Added a new Go module file defining the module path and required dependencies for the exp-go-sdk.
    • Specified github.com/opentdf/platform/protocol/go and github.com/opentdf/platform/sdk as direct requirements.
  • xtest/sdk/exp-go-sdk/go.sum
    • Added a new Go sum file containing cryptographic checksums for the module's dependencies, ensuring build integrity.
  • xtest/sdk/exp-go-sdk/main.go
    • Implemented the core Go CLI application for exp-go-sdk, supporting encrypt, decrypt, and supports commands.
    • Integrated the experimental TDF writer for encryption, handling segment writing and TDF finalization with KAS keys, attributes, and assertions.
    • Utilized the standard SDK's LoadTDF for decryption, supporting assertion verification keys and KAS allowlist configurations.
    • Included helper functions for SDK client creation, attribute resolution, and parsing assertion and verification key JSON structures.
  • xtest/tdfs.py
    • Updated the sdk_type literal to include the new exp-go-sdk.
    • Modified the _uncached_supports method to explicitly mark exp-go-sdk as supporting autoconfigure and ns_grants features within the test framework.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/xtest.yml
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.

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

This pull request introduces a new experimental Go SDK (exp-go-sdk) that utilizes an experimental streaming TDF writer, incorporating Go source code, a shell wrapper for the CLI, a Makefile, and updates to the Python test framework. A medium-severity security issue was identified in the cli.sh script, where sensitive information (the client secret) is logged to standard output, potentially leading to credential leakage. Furthermore, the Go implementation has a potential panic due to fragile command-line argument parsing and uses a non-standard Go version in go.mod. An improvement to make the encryption process fully streaming has also been suggested.

Comment on lines +95 to +97
case "--output", "-o":
i++
f.output = args[i]
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The manual command-line argument parsing is fragile and can lead to a panic if a flag that expects a value (like --output) is provided at the end of the arguments without its value. This will cause an index out of range error. This affects all flags that take a value in both parseEncryptFlags and parseDecryptFlags.

It would be more robust to use the standard flag package for parsing. If you prefer to keep the manual parsing, you should add checks to prevent reading past the end of the args slice. Here is an example for the --output flag:

Suggested change
case "--output", "-o":
i++
f.output = args[i]
case "--output", "-o":
if i+1 >= len(args) {
return nil, fmt.Errorf("missing value for flag: %s", args[i])
}
i++
f.output = args[i]

args+=(--assertions "$XT_WITH_ASSERTIONS")
fi

echo "$cmd" encrypt "${args[@]}" "$2"
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The script echoes the full command line before execution, which includes the --client-secret argument. This causes the client secret to be printed to standard output, potentially leaking sensitive credentials into build logs, console output, or other logging systems. It is recommended to mask sensitive arguments or avoid echoing the command line entirely.

args+=(--ignore-kas-allowlist)
fi

echo "$cmd" decrypt "${args[@]}" "$2"
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

Similar to the encrypt command, the decrypt command line is echoed to standard output, which includes the --client-secret argument. This leads to the exposure of sensitive credentials in logs.

Comment on lines 196 to 217
data, err := os.ReadFile(f.inputFile)
if err != nil {
return fmt.Errorf("reading input file: %w", err)
}

segIdx := 0
for offset := 0; offset < len(data); offset += segmentSize {
end := offset + segmentSize
if end > len(data) {
end = len(data)
}
if _, err := writer.WriteSegment(ctx, segIdx, data[offset:end]); err != nil {
return fmt.Errorf("writing segment %d: %w", segIdx, err)
}
segIdx++
}
// Handle empty file: write one empty segment
if len(data) == 0 {
if _, err := writer.WriteSegment(ctx, 0, []byte{}); err != nil {
return fmt.Errorf("writing empty segment: %w", err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The doEncrypt function reads the entire input file into memory using os.ReadFile. While the experimental writer supports streaming writes via WriteSegment, reading the whole file at once can lead to high memory consumption for large files and defeats the purpose of a streaming writer. To fully leverage the streaming capabilities, you should read the input file in chunks.

	inFile, err := os.Open(f.inputFile)
	if err != nil {
		return fmt.Errorf("opening input file: %w", err)
	}
	defer inFile.Close()

	segIdx := 0
	buf := make([]byte, segmentSize)
	for {
		n, readErr := inFile.Read(buf)
		if n > 0 {
			if _, writeErr := writer.WriteSegment(ctx, segIdx, buf[:n]); writeErr != nil {
				return fmt.Errorf("writing segment %d: %w", segIdx, writeErr)
			}
			segIdx++
		}
		if readErr == io.EOF {
			break
		}
		if readErr != nil {
			return fmt.Errorf("reading input file: %w", readErr)
		}
	}
	// Handle empty file: write one empty segment
	if segIdx == 0 {
		if _, err := writer.WriteSegment(ctx, 0, []byte{}); err != nil {
			return fmt.Errorf("writing empty segment: %w", err)
		}
	}

- Remove `if: heads` condition from CI replace step so exp-go-sdk
  always gets go.mod replacements (it always builds from platform checkout)
- Regenerate go.sum against published module versions so builds work
  without replace directives
- Add fallback to direct KAS public key fetch when GetBaseKey returns
  "base key is empty" (older platforms without well-known base_key)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

X-Test Failure Report

❌ exp-go-sdk-main
❌ js-main
❌ go-main

…bute defs

Two fixes for test failures:

1. TDF assembly: The experimental writer's Finalize().Data only contains
   the manifest + central directory trailer. The payload segments are
   returned by each WriteSegment().TDFData call. The complete TDF zip
   is: concat(segment data...) + finalize data. Without this, Python's
   zipfile saw a corrupt zip64 end-of-central-directory locator.

2. Attribute definitions: The experimental writer's boolean expression
   builder requires Value.Attribute (parent definition) to be set.
   Ensure we copy it from the GetAttributeValuesByFqns response's
   Attribute field when the Value doesn't already have it populated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

X-Test Failure Report

❌ exp-go-sdk-main
❌ exp-go-sdk-v0.12.0

@github-actions
Copy link

…ist env var

- Add --ecwrap flag to fetch EC public key from KAS for ec-wrapped TDFs
- Support PEM public keys (PKIX/PKCS1) in assertion verification, not just
  private keys — test fixtures use -----BEGIN PUBLIC KEY----- for RS256
- Fix XT_WITH_KAS_ALLOWLIST env var name to match tdfs.py (was KAS_ALLOW_LIST)
- Make fetchKASPublicKey accept algorithm parameter (rsa:2048 or ec:secp256r1)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@github-actions
Copy link

Copy link
Member

@dmihalcik-virtru dmihalcik-virtru left a comment

Choose a reason for hiding this comment

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

Does resolve-versions.py not have any problem with this? Do you have sample runs using workflow_call?

matrix:
platform-tag: ${{ fromJSON(needs.resolve-versions.outputs.platform-tag-list) }}
sdk: ["go", "java", "js"]
sdk: ["go", "java", "js", "exp-go-sdk"]
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we should skip exp-go-sdk for workflow calls from other repos until it is stable?

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