feat(xtest): add exp-go-sdk using experimental TDF writer#414
feat(xtest): add exp-go-sdk using experimental TDF writer#414pflynn-virtru wants to merge 4 commits intomainfrom
Conversation
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>
Summary of ChangesHello @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 ( 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
Ignored Files
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.
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.
| case "--output", "-o": | ||
| i++ | ||
| f.output = args[i] |
There was a problem hiding this comment.
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:
| 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" |
There was a problem hiding this comment.
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" |
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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>
X-Test Failure Report |
…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>
X-Test Failure Report |
X-Test Failure Report❌ exp-go-sdk-v0.12.0 |
…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>
|
X-Test Failure Report❌ exp-go-sdk-main |
dmihalcik-virtru
left a comment
There was a problem hiding this comment.
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"] |
There was a problem hiding this comment.
Perhaps we should skip exp-go-sdk for workflow calls from other repos until it is stable?



Summary
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'sLoadTDFfor decryptGetBaseKey/fetchKASPublicKey+GetAttributeValuesByFqnsto resolve KAS keys and attribute grants from the platformChanges
New files (
xtest/sdk/exp-go-sdk/):main.go— Go CLI withencrypt,decrypt, andsupportssubcommandscli.sh— Shell wrapper translatingXT_WITH_*env vars to CLI flagsMakefile— Build rules producingdist/main/exp-go-sdk+dist/main/cli.shgo.mod/go.sum— Module with platform SDK dependenciesModified files:
xtest/sdk/Makefile— Addedexp-go-sdkbuild targetxtest/tdfs.py— Registeredexp-go-sdkassdk_typewithautoconfigureandns_grantsfeature flags.github/workflows/xtest.yml— Added to CI matrix, build steps withgo mod replace, focus-sdk validationSupported features
assertions,assertion_verification,autoconfigure,ns_grants,ecwrap,hexless,connectrpc,kasallowlist,better-messages-2024Not yet supported
hexaflexible(no target-mode selection),obligations,key_management,bulk_rewrapDepends 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:
Segment hash mismatch (
sdk/experimental/tdf/writer.go) —calculateSignatureis called onsegmentCipheronly, but the standard SDK reader hashesnonce + segmentCipher. Every TDF produced by the experimental writer fails integrity verification on decrypt.Default KAS key not merged for attribute-based access (
sdk/experimental/tdf/keysplit/xor_splitter.go) — When attributes are provided,collectAllPublicKeysonly 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 intoallKeysas a fallback.Fixes for both are staged in a local platform branch.
Test plan
exp-go-sdkalongside existing SDKs🤖 Generated with Claude Code