-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Secrets Masking This feature adds secrets masking to enable users to replace sensitive values in the checkpoint with a `[secret]` mask. ![image](https://github.com/user-attachments/assets/390c06af-b401-4772-baa1-917490661950) Fixes #156 ## Summary - Add new `ComponentOpts` type - Add support for selective or broad masking of props via property paths. - Support broad masking of outputs via the "output" property path. - Support Components and StreamComponent - Support transitive secrets masking across children - Extensive tests (16 cases, 700 lines) across all the edge cases I could think of ## Implementation Secrets can be masked by adding props property paths, or the "output" key to a new `ComponentOpts.secrets` array. Masked secrets are tracked by value, masking is transitive across children, and we search props and outputs to mask any value even if it just contains the masked value ( either `contains` or `===` will result in masking, but we are more selective with masking for contains). For instance if the secret is `secretsecretsecret` and a child component uses that value in a template string to output `this is a secretsecretsecret` the child output will be masked as `this is a [secret]`. We enforce this transitive relationship via context. We extended the parentId context that was added for checkpointing to include the entire node. This gives us access to the hierarchy of previously masked values. For every node that gets added to the graph, we walk it's ancestors looking for secret values that need to be masked in it's inputs and outputs. Value-based masking plus transitive child masking gives as much safety as possible, and minimizes the amount that a user needs to think about masking secrets when writing and composing component. ## Using Secret Outputs We've added a new `ComponentOpts` type. Components accept `defaultOpts` at declaration time, and users can specify a `componentOpts` prop at the time of instantiation to mark additional props and outputs as secrets. ```tsx // specify defaults at declaration time export const OpenAIProvider = gsx.Component<ClientOptions, never>( "OpenAIProvider", (args) => { const client = new OpenAI(args); return <OpenAIContext.Provider value={{ client }} />; }, { secrets: ["apiKey"], }, ); // specify additive secret props at the time you use a component. `apiKey` will still be secret in this case. <OpenAIProvider apiKey={key} foo={...} componentOpts={secrets: ["foo"]} ``` To make a prop, a secret refer to it by property path in the array: ```tsx interface Inputs { foo: string; bar: { buzz: number }; baz: number; } const secrets = ["bar.buzz", "baz"] ``` All outputs can be masked by adding the `output` path to the array. Selective output masking is not currently supported: ```tsx <Component componentOpts={secrets: ["output"]} ``` If the property path refers to a property that is an object or array, all nested values within that object or array will be masked as `[secret]`, but the keys and structure of the object/array will stay intact, primarily to help with debugging and visualization of outputs.
- Loading branch information
Showing
7 changed files
with
911 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.