Skip to content

SK-2679: Add JSON object context support for Conditional Data Access#293

Closed
samsternberg wants to merge 3 commits intomainfrom
feature/SK-2679-conditional-data-access-ctx-map-support
Closed

SK-2679: Add JSON object context support for Conditional Data Access#293
samsternberg wants to merge 3 commits intomainfrom
feature/SK-2679-conditional-data-access-ctx-map-support

Conversation

@samsternberg
Copy link
Copy Markdown
Collaborator

@samsternberg samsternberg commented Apr 7, 2026

Summary

  • Add setCtx(Map<String, Object>) overloads to BearerToken and SignedDataTokens builders so the JWT ctx claim can be a nested JSON object (required for Conditional Data Access CEL expressions like request.context.role == 'admin')
  • Add setContext(Map<String, Object>) and getContextAsObject() to Credentials for high-level Skyflow client usage
  • Fully backwards compatible — existing setCtx(String) and setContext(String) APIs unchanged

Changes

  • Core: BearerToken.java, SignedDataTokens.java — widen internal ctx field to Object, add Map overloads to builders
  • Config: Credentials.java — add setContext(Map) setter and getContextAsObject() getter (preserves getContext() returning String)
  • Utils: Utils.java — dispatch context to correct setCtx overload based on type
  • Validation: Validations.java — validate empty Map context same as empty String
  • Tests: 8 new unit tests across BearerTokenTests, SignedDataTokensTests, CredentialsTests
  • Samples: Updated BearerTokenGenerationWithContextExample and SignedTokenGenerationExample with Map context examples
  • README: Documented Conditional Data Access with CEL expressions, string vs. JSON object context usage

Replaces #291 (which was created from a fork and couldn't run CI).

Test plan

  • mvn compile — clean
  • mvn test -Dtest=BearerTokenTests,SignedDataTokensTests,CredentialsTests — 51 tests, 0 failures
  • Samples compile against locally installed SDK
  • End-to-end test with a Skyflow vault using a Conditional Data Access policy

Refs SK-2679, DOCU-1438

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

The ctx claim in bearer tokens and signed data tokens previously only
accepted a String, which meant structured CEL expressions like
request.context.role == 'admin' could not be satisfied. Add
setCtx(Map<String, Object>) overloads to BearerToken and
SignedDataTokens builders so the JWT ctx claim is serialized as a
nested JSON object. Also add setContext(Map) and getContextAsObject()
to Credentials for use with the high-level Skyflow client.

All changes are backwards compatible — existing setCtx(String) and
setContext(String) APIs are unchanged.

Refs SK-2679
Co-Authored-By: Claude <noreply@anthropic.com>
@samsternberg samsternberg force-pushed the feature/SK-2679-conditional-data-access-ctx-map-support branch from 67c6762 to c683024 Compare April 7, 2026 13:30
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Gitleaks Findings: No secrets detected. Safe to proceed!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Semgrep Findings: Issues with Error level severity are found (Error is Highest severity in Semgrep), Please resolve the issues before merging.

return sb.toString();
}

@SuppressWarnings("unchecked")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is @SuppressWarnings("unchecked") needed here? Can you add a comment explaining this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch — rather than just adding a comment, I refactored to address the root cause. Added a typed getContextAsMap() getter to Credentials (which owns the invariant via its typed setters), so call sites in Utils.generateBearerToken no longer need a cast at all. The @SuppressWarnings now lives in Credentials directly next to the field and setters that guarantee the type is safe. See commit 4f83032.

import com.skyflow.vault.tokens.TokenizeRequest;

public class Validations {
private static final Pattern CTX_MAP_KEY_PATTERN = Pattern.compile("^[a-zA-Z0-9_]+$");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Use constants instead hard-coded strings

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed — moved the regex to Constants.CTX_MAP_KEY_REGEX (same pattern as API_KEY_REGEX) and updated Validations to reference it. See commit 364b8bb.

samsternberg and others added 2 commits April 28, 2026 08:12
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…d cast in Utils

The suppression now lives in Credentials next to the typed setters that
guarantee the invariant, keeping call sites in Utils cast-free.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@saileshwar-skyflow saileshwar-skyflow self-requested a review April 28, 2026 12:26
@samsternberg
Copy link
Copy Markdown
Collaborator Author

Closing in favour of #302, which re-applies these changes cleanly on top of main after SK-2777 landed and caused conflicts.

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