Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: add support for options.profile on aws clients #1493

Open
wants to merge 7 commits into
base: canary
Choose a base branch
from

Conversation

sxlijin
Copy link
Collaborator

@sxlijin sxlijin commented Feb 19, 2025

Fixes three issues:

  • AWS_PROFILE is only supported through aws_config::default_provider right now, aka when the user provides no cues about aws creds in the baml client options
  • options.profile is not respected by baml-runtime in python/ts
  • options.profile is not respected by the vscode extension (aka wasm)

Implementation notes:

  • vscode extensions are somewhat limited in what files they're allowed to access through the vscode API
    • technically, they're only allowed to open files available in the repository/workspace
      • although apparently the roo-code extension doesn't have this issue? seems some experimentation is required here to determine what is/isn't allowed (but i definitely remember testing this when i implemented file ref support for images)
    • the baml playground (since it's a webview) currently has to request files from vscode by RPCing through the extension
    • the language server does have filesystem access, so we could go through that (i don't love the idea of pushing the aws config files and cached credentials through the LSP stdin/stdio channel)
    • better approach is to probably re-purpose the request proxy for this (vbv's work around enabling/disabling the proxy will conflict with this, unfortunately), and use that to bypass vscode filesystem limitations
  • we need this filesystem access for the playground (this is complicated b/c the rust->wasm code doesn't have filesystem access (since WASI is not yet a standard): AWS_PROFILE can be backed by either IAM role profiles or SSO exchanges
    • IAM role profile creds are cached in ~/.aws/credentials
    • SSO profiles are stored in ~/.aws/sso/ (I'm unclear on how exactly the Rust SDK hooks into this yet, nor if an override point exists here)
    • so there's a number of files that we need to support; at a minimum we should support aws sso, and we should also look into what other files are needed to implement a reasonable level of support for
  • alternatively: if instead of providing a shim for std::fs::read in wasm, we instead just implement ProvideCredentials in wasm and force it to delegate to npm:@aws-sdk/credential-providers in the proxy, that feels a lot more doable. however, protocol will also need to support forwarding env vars over (and shimming them on the node side). we may also need some shenanigans to make sure bedrock works on promptfiddle if we do this.

fixes #1488

(currently WIP)


Important

Enhances AWS profile support across the system, including VSCode extension and runtime, with updated tests and dependencies.

  • AWS Profile Support:
    • Adds support for options.profile in aws_client.rs and aws_bedrock.rs.
    • Implements LoadAwsCredsRequest and LoadAwsCredsResponse in vscode-rpc.ts.
    • Updates WebviewPanelHost to handle AWS credentials loading.
  • VSCode Extension:
    • Adds baml.envVarFile and baml.envVarCommand settings in package.json.
    • Implements environment variable loading in WebviewPanelHost.ts.
    • Updates extension.ts to handle new AWS profile configurations.
  • Testing:
    • Modifies aws.test.ts to include tests for AWS profile and credential handling.
    • Updates build script to run AWS tests.
  • Dependencies:
    • Updates @aws-sdk/credential-providers and @smithy/types in package.json files.
    • Updates Cargo.lock for Rust dependencies.

This description was created by Ellipsis for 7a4ecce. It will automatically update as commits are pushed.

Copy link

vercel bot commented Feb 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
baml ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 24, 2025 8:46am

@sxlijin sxlijin changed the title fix: add support for options.profile on aws clients feat: add support for options.profile on aws clients Feb 19, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to a6422c0 in 1 minute and 48 seconds

More details
  • Looked at 183 lines of code in 8 files
  • Skipped 0 files when reviewing.
  • Skipped posting 12 drafted comments based on config settings.
1. integ-tests/typescript/tests/providers/aws.test.ts:334
  • Draft comment:
    Remove 'it.only' in invalid profile test to avoid limiting test run.
  • Reason this comment was not posted:
    Marked as duplicate.
2. tools/build:222
  • Draft comment:
    Ensure switching test target from vertex to aws is intentional.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50%
    This comment violates our rules. It starts with "Ensure..." which is explicitly called out as likely not useful. It's asking the author to verify their intention, which is against our guidelines. The author deliberately made this change, and we should assume they know what they're doing unless there's strong evidence of a problem.
    Maybe the test target change could break some important test coverage? Maybe there's a specific reason vertex.test.ts needs to run?
    Without strong evidence that running vertex.test.ts is required or that this change causes problems, we should trust the author's judgment. The change appears deliberate and straightforward.
    Delete this comment. It's asking for verification of intention which violates our rules, and we don't have evidence that the change is problematic.
3. tools/uv.lock:3
  • Draft comment:
    Raising 'requires-python' to '>=3.12' may break compatibility with older python versions; confirm intention.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50%
    This is a dependency/version management change. The comment asks for confirmation of intention, which violates our rules. Lock files are typically generated files that reflect deliberate version choices. The author likely intentionally updated the Python version requirement.
    The Python version change could have significant implications for the project's compatibility. Maybe this deserves special attention?
    While Python version changes are important, our rules explicitly state not to comment on dependency changes or ask for confirmation of intentions. Lock files especially are deliberately generated.
    Delete the comment as it violates our rules about commenting on dependency changes and asking for confirmation of intentions.
4. integ-tests/typescript/tests/providers/aws.test.ts:191
  • Draft comment:
    Remove 'it.only' here to avoid skipping other tests. 'it.only' should not be committed.
  • Reason this comment was not posted:
    Marked as duplicate.
5. integ-tests/typescript/tests/providers/aws.test.ts:334
  • Draft comment:
    Remove 'it.only' in the invalid profile test; leaving .only will limit test execution.
  • Reason this comment was not posted:
    Marked as duplicate.
6. tools/build:221
  • Draft comment:
    Verify that switching the test command from 'vertex.test.ts' to 'aws.test.ts' is deliberate and doesn’t inadvertently skip vertex provider tests.
  • Reason this comment was not posted:
    Marked as duplicate.
7. tools/uv.lock:1
  • Draft comment:
    Ensure the upgrade to Python >=3.12 and removal of conditional markers (e.g., for termcolor) aligns with all target environments.
  • Reason this comment was not posted:
    Marked as duplicate.
8. integ-tests/baml_src/clients.baml:246
  • Draft comment:
    Typographical issue: The client definition 'client Invalid{' is missing a space before the opening brace. For consistency and readability, please change it to 'client Invalid {'.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
9. integ-tests/python/baml_client/inlinedbaml.py:350
  • Draft comment:
    Typo: In the declaration for 'client Invalid{', it would be more readable to add a space between 'Invalid' and '{'. Please change it to 'client Invalid {' to maintain consistency with the other client declarations.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
10. fiddle-examples/chat-roles.baml:10
  • Draft comment:
    Typographical error: The return type of function 'ClassifyMessage2' is declared as 'Category' while the defined enum is named 'Category2'. Please update the function's return type to 'Category2' (or adjust the enum name) to align them.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
11. fiddle-examples/chat-roles.baml:4
  • Draft comment:
    Typographical error: The function 'ClassifyMessage2' is declared to return 'Category', but the defined enum is 'Category2'. Please update the return type to 'Category2' for consistency.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
12. tools/build:273
  • Draft comment:
    Typographical error: In the comment on line 273, 'schanges' should be corrected to 'changes' (and consider using 'consumes' if that fits the intent).
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_FNYMgQzWeZ6HBj6B


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -188,12 +188,12 @@ describe('AWS Provider', () => {
})
})

it('should support AWS profile configuration', async () => {
it.only('should support AWS profile configuration', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove 'it.only' in profile tests to ensure full test suite runs.

Suggested change
it.only('should support AWS profile configuration', async () => {
it('should support AWS profile configuration', async () => {

@sxlijin sxlijin changed the title feat: add support for options.profile on aws clients WIP: feat: add support for options.profile on aws clients Feb 20, 2025
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Incremental review on a199d09 in 1 minute and 54 seconds

More details
  • Looked at 79 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. engine/baml-lib/llm-client/src/clients/aws_bedrock.rs:230
  • Draft comment:
    Removing the cfg attributes for wasm and always resolving profile is intentional? Ensure that enabling profile resolution in wasm does not break limitations (e.g., file system access) in the playground.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.
2. engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:155
  • Draft comment:
    The WASM branch now uses the provided profile (if any) by setting it on the credentials chain builder. Confirm that the builder.profile_name(profile) call produces the intended effect in the playground. Also, consider removing/commenting out leftover debug code.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 50% <= threshold 50%
    The comment asks the PR author to confirm the effect of a specific call, which violates the rule against asking for confirmation of intention or behavior. However, it also suggests considering the removal of leftover debug code, which is a valid suggestion. The comment is partially useful, but the part asking for confirmation should be removed.
3. engine/baml-runtime/src/internal/llm_client/primitive/aws/wasm.rs:44
  • Draft comment:
    Profile file support is now enabled by uncommenting the .profile_files() call. Verify that the hard-coded config content and the file access in WASM work as intended in the playground, given the filesystem limitations.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50%
    The comment is asking the PR author to verify the behavior of the code, which violates the rule against asking for confirmation or verification of behavior. It does not provide a specific code suggestion or ask for a specific test to be written. Therefore, it should be removed.
4. engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:155
  • Draft comment:
    The updated block now logs debug information and uses WasmAwsCreds with a profile name when no explicit credentials are provided. Consider cleaning up by removing commented-out alternative calls and clarifying the note about the 'static lifetime' requirement.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_NiyMOqKtTezU7itt


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -231,16 +231,16 @@ impl UnresolvedAwsBedrock {
}
};

#[cfg(not(target_arch = "wasm32"))]
// #[cfg(not(target_arch = "wasm32"))]
Copy link
Contributor

Choose a reason for hiding this comment

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

The cfg attributes for wasm are now commented out so that the profile is always resolved. Consider removing the commented-out cfg checks entirely once the feature is stable to reduce confusion.

Suggested change
// #[cfg(not(target_arch = "wasm32"))]

fix profile loading, we were previously respecting the wrong one

omg it works

ok commented out change is fine

vscode ext works again, but not triggering WasmAwsCreds

more stuff

finally stop freaking out about json files

rename to load_env

one more rename

one more atom
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Incremental review on 7a4ecce in 2 minutes and 34 seconds

More details
  • Looked at 270 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 7 drafted comments based on config settings.
1. engine/baml-runtime/src/internal/llm_client/primitive/aws/wasm.rs:194
  • Draft comment:
    The ProvideCredentials implementation currently returns hardcoded fake credentials. Ensure this is intended as a temporary placeholder and that production use is properly secured.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50%
    The comment points out a real security concern - hardcoded fake credentials in production could be dangerous. However, the comment is phrased as a verification request ("Ensure this is intended...") which violates our rules. Additionally, the code is in a WASM-specific implementation which suggests this may be intentional for browser environments where real AWS credentials wouldn't be used.
    I might be wrong about the WASM context - perhaps real AWS credentials are needed even in browser environments. Also, even if this is intentional, having fake credentials could still be a security risk worth flagging.
    While security is important, the comment's phrasing as a verification request makes it not actionable. If there was a real security issue, it should be stated directly rather than asking for confirmation.
    Delete the comment. While it identifies a potential security concern, it's phrased as a verification request rather than an actionable issue, and the WASM context suggests this may be intentional behavior.
2. engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:151
  • Draft comment:
    Replace the unprofessional debug message with a more appropriate log (avoid profanity).
  • Reason this comment was not posted:
    Marked as duplicate.
3. engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:159
  • Draft comment:
    The call to aws_config::defaults(BehaviorVersion::latest()) is made without capturing its result. Consider removing it or assigning it, if needed.
  • Reason this comment was not posted:
    Marked as duplicate.
4. typescript/playground-common/src/shared/baml-project-panel/atoms.ts:88
  • Draft comment:
    The awsCreds are loaded and logged but not integrated into the runtime/environment configuration. Confirm if additional handling is needed for profile support in the playground.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50%
    The comment is asking the author to confirm if additional handling is needed for profile support, which violates the rule against asking for confirmation or ensuring behavior. It does not provide a specific suggestion or point out a clear issue.
5. engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:207
  • Draft comment:
    Typo: In the comment explaining the secret key check, 'remainer' should be corrected to 'remainder'.
  • Reason this comment was not posted:
    Comment was on unchanged code.
6. engine/baml-runtime/src/types/runtime_context.rs:48
  • Draft comment:
    There appears to be a typographical error in the non-wasm branch definition of AwsCredProvider. The type declaration ends with an extra '>' (i.e., ...Result<HashMap<String, String>>>> should likely be corrected to ...Result<HashMap<String, String>>>). Please fix this extra bracket.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50%
    The comment suggests removing a bracket, but looking at the parallel wasm implementation and counting the brackets carefully, 5 brackets are actually correct: 1 for HashMap, 1 for Result, 1 for BoxFuture, 1 for Box, and 1 for Option. The comment is suggesting a change that would make the code incorrect.
    Could I be miscounting the brackets? Should I be considering other factors beyond just matching the wasm version?
    I've triple-checked the bracket count and mapped each closing bracket to its opening construct. The 5 brackets are definitely correct and necessary for this type definition.
    The comment is incorrect - it suggests removing a bracket that is actually needed. The PR change adding the bracket was correct.
7. typescript/playground-common/src/shared/baml-project-panel/atoms.ts:319
  • Draft comment:
    Typo found in the comment. The word 'somehting' should be corrected to 'something' for clarity.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_yovLItWpTCWkruPV


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

if let Some(profile) = self.properties.profile.as_ref() {
builder = builder.profile_name(profile);
}
log::debug!("Building wasm aws credentials chain - UNCONDITIONALLY BECAUSE BULLSHIT $ENV_VAR UNCONDITIONAL SUBSTITUTION");
Copy link
Contributor

Choose a reason for hiding this comment

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

The debug log message here contains profanity, which is unprofessional. Consider rephrasing it to a more neutral message.

Suggested change
log::debug!("Building wasm aws credentials chain - UNCONDITIONALLY BECAUSE BULLSHIT $ENV_VAR UNCONDITIONAL SUBSTITUTION");
log::debug!("Building wasm aws credentials chain - due to unconditional $ENV_VAR substitution");


// Set region if specified
let loader = {
aws_config::defaults(BehaviorVersion::latest());
Copy link
Contributor

Choose a reason for hiding this comment

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

The non-WASM branch calls aws_config::defaults(...) without assigning its result. Likely, you meant to capture the returned loader before proceeding with credentials configuration.

Suggested change
aws_config::defaults(BehaviorVersion::latest());
let loader = aws_config::defaults(BehaviorVersion::latest());

&aws_secret_access_key.api_key.expose_secret()[1..]
));
_ => {
log::debug!(
Copy link
Contributor

Choose a reason for hiding this comment

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

The log message in the non-WASM branch uses wording referring to a WASM credentials chain. This may be confusing; ensure the log clearly indicates which branch is executing.

const vscodeEnv = (await vscode.loadEnv())?.envVars ?? {}

const awsCreds = await vscode.loadAwsCreds()
console.log('awsCreds', awsCreds)
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid leaving console.log statements (e.g. logging awsCreds) in production code. Consider using a proper logger or removing it.

Suggested change
console.log('awsCreds', awsCreds)

// let datetime: DateTime<Utc> = datetime_str.parse().expect("Invalid datetime format");
// let expires_after =
// web_time::UNIX_EPOCH + web_time::Duration::from_secs(datetime.timestamp() as u64);
ProvideCredentials::ready(Ok(Credentials::new(
Copy link
Contributor

Choose a reason for hiding this comment

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

WasmAwsCreds currently returns hardcoded fake credentials. Please add a TODO or implement proper profile-based credentials support.

} else {
use futures::future::BoxFuture;
pub type BamlSrcReader = Option<Box<fn(&str) -> BoxFuture<'static, Result<Vec<u8>>>>>;
pub type AwsCredProvider = Option<Box<fn(Option<&str>) -> BoxFuture<'static, Result<HashMap<String, String>>>>>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

The type definition for AwsCredProvider appears to have an extra '>' in the closing brackets. Please verify and correct the type signature.

Suggested change
pub type AwsCredProvider = Option<Box<fn(Option<&str>) -> BoxFuture<'static, Result<HashMap<String, String>>>>>>;
pub type AwsCredProvider = Option<Box<fn(Option<&str>) -> BoxFuture<'static, Result<HashMap<String, String>>>>>;

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.

Amazon Bedrock Profile Feature in Playground
1 participant