Repository navigation
feat(box): Send box telemetry to Langfuse, LangSmith, and OTLP endpoints on AgentCore Runtime - #2917
SaiAbhishek98 wants to merge 9 commits into
Conversation
… the Runtime This commit holds five commits of box-integration-development, resolved against box-integration: 7ad00c3, 212d17f, 96cc734, 3ad5f5c, and 71801df. Deploy writes the key of each third-party telemetry target (otlp, langfuse, langsmith) into one AWS Secrets Manager secret for each runtime, agentcore/<project>/<runtime>/box, outside the stack. The Runtime profile gets plugins = ["@box/aws-secrets-manager"] and an aws-secretsmanager:// reference for each target. The execution role gets secretsmanager:GetSecretValue on that secret only. The container image installs the AWS CLI after a signature check, because the plugin runs aws.
…er, and remove the AGENTCORE_BOX_SECRETS_MANAGER switch
…arn that its VPC has no path to the host, and ask the L3 for an AWS Secrets Manager endpoint
… box under agentcore dev
…n OTLP endpoint on AgentCore Runtime
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## box-integration #2917 +/- ##
=================================================
Coverage 96.89% 96.90%
=================================================
Files 776 778 +2
Lines 69346 69941 +595
=================================================
+ Hits 67194 67775 +581
- Misses 2152 2166 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…emetry build test The step message names ENV_LOCAL_RELATIVE_PATH, which has a backslash on Windows. The test now expects that constant, as the other tests in this file do.
leo237
left a comment
There was a problem hiding this comment.
Adversarial security review of the third-party telemetry key flow, at 00168c4. Decision: COMMENT. I found no leaks and no over-broad grants. I have one merge-order dependency and two medium items. None of them blocks.
Secret lifecycle, as I traced it
- Where the key comes from. The key comes from
env://VARin the shell. Build copies it intoagentcore/.env.localasAGENTCORE_CREDENTIAL_<RT>_TELEMETRY_<T>, and.env.localis gitignored. Deploy reads that variable from the env or.env.local. - How it gets to Secrets Manager. Deploy calls
CreateSecret/PutSecretValuedirectly with the deploy credentials, in the target region, before synth. The secret is not a stack resource. - Name and encryption. The name is
agentcore/<project>/<runtime>/box. The secret uses the AWS-managed KMS key. It has no tags and no resource policy. - Runtime read and IAM. The execution role gets only
secretsmanager:GetSecretValueonarn:<partition>:secretsmanager:<region>:*:secret:agentcore/<project>/<runtime>/box-??????, one policy file per runtime. - Box side. Box 0.3.0 reads the key through
@box/aws-secrets-manager(resources/plugins/aws-secrets-manager/plugin.tomlat v0.3.0), outside the sandbox.split_referenceincrates/credentials/src/sources/command.rsacceptsname#telemetry.<target>. - Profile keys. The copied keys are destination, project, include, accepts, headers, and secret.header/prefix/placement. Every one is a field of the
deny_unknown_fieldsTelemetryEntry/TelemetrySecretin box v0.3.0, andpluginsis a top-level profile key there. Box should therefore accept the generated profile. - Removal and teardown. On removal, deploy deletes orphans after the stack update, with a 7-day recovery window, and keeps any secret another target records. Teardown deletes the secrets after the stack. If a write fails, deploy deletes the secrets it created in that run. A later deploy restores a secret that is scheduled for deletion.
- No leaks found. The value is not in agentcore.json, the CDK context or template, deployed-state (ARN only), the Runtime profile (ref only),
box-release.env(CLI URL, SHA, keyring), DockerfileARG/ENV, step messages or error text. The Docker build context is the agent folder, soagentcore/.env.localis not in it. - Egress. No agent egress route is added. Box sends telemetry from outside the sandbox, and box itself enforces https when a secret is set.
Findings (inline)
- Merge order (must land after aws/agentcore-l3-cdk-constructs#491). On L3
box-integration(fa72f21),ContainedNetworkSchemais az.strictObjectwith nosecretsManagerEndpoint. A PRIVATE_VPC runtime with a keyed target would fail synth with an unrecognized key until #491 merges. The PR body already says this; I am repeating it so that nobody merges in the wrong order. - Medium: deploy adopts any existing secret with this name and, later, deletes it. It does not check ownership, and the CLI does not tag what it creates.
- Medium: build copies the key only from the shell, not from
.env.local.agentcore devreads both, so a setup that works in dev fails at deploy, and the error message is wrong for that case. - Nits: the account is
*in the IAM ARN; a failed delete is reported only as a step line; targets that share an account and region also share one secret (the last deploy wins), and the docs don't say so; the provenance of the fixture.
Tests.
bun run typecheck: pass.bun test: 6558 pass, 9 skip, 0 fail.- CI: Linux, CodeQL and Analyze pass. macOS and Windows were pending when I checked. e2e is skipped.
Mutation checks (all reverted). Each mutant below failed the targeted tests, so each was caught:
Resourcewidened to*: 5 fail.name*in place ofname-??????: 5 fail.- The keep-other-target guard removed: 2 fail.
- Force delete with no recovery window: 2 fail.
- The rollback of created secrets removed: 1 fail.
- The plugin not added: 4 fail.
- The missing-key error removed: 2 fail.
- The gpgv/VALIDSIG lines removed from the Dockerfile: 1 fail.
- CodeZip carrying a keyed target: 1 fail.
Coverage gaps.
- A pre-existing secret that this CLI did not create (finding 2).
- A key that is only in
.env.local(finding 3). - An otlp target with a key on the Runtime. The PR body says the live tests did not cover it.
Dependency. @aws-sdk/client-secrets-manager@^3.1121.0 is the same SDK v3 line as client-s3 (^3.1121.0) and the other SDK clients. It adds one small client package. Its transitive deps are the shared @aws-sdk/core and @smithy/*, so the bundle grows very little.
In the squash plan (https://pippin.amazon.dev/docs/XFRmP1pP9L90nl/box-integration-squash-and-pr-plan-v2), this PR is SA-6, and no later phase changes this code.
| * Gives the VPC an AWS Secrets Manager endpoint, so the box of the runtime can read the keys of | ||
| * its third-party telemetry targets. Build sets it and removes it. | ||
| */ | ||
| secretsManagerEndpoint: z.boolean().optional(), |
There was a problem hiding this comment.
Merge order: build writes this key into agentcore.json for a PRIVATE_VPC runtime with a keyed third-party target. On L3 box-integration (fa72f21), ContainedNetworkSchema in src/schema/schemas/agent-env.ts is a z.strictObject with no secretsManagerEndpoint, so synth would fail with an unrecognized key. Please merge this only after aws/agentcore-l3-cdk-constructs#491, or keep that ordering explicit in the squash plan.
| ...field, | ||
| value: env[field.variable] || undefined, | ||
| })); | ||
| const existing = await calls.describe(secret.name); |
There was a problem hiding this comment.
Medium: deploy finds the secret by name and then adopts it. It reads it, PutSecretValues it, and records its ARN. Later, an orphan removal or a teardown schedules its deletion. Nothing checks that this CLI created the secret.
Two projects with the same name in one account and region (two developers on a shared dev account is enough) would overwrite each other's keys. One project's teardown would also delete the other's secret, and the other runtime would fail to start, because box cannot resolve its ref. A secret that a user created with that name gets the same treatment.
Suggestion: tag the secrets on CreateSecret (for example agentcore:project, agentcore:runtime, and possibly the deployed-state target). Then refuse to adopt or delete a secret that lacks the tag, with a clear error. The tags also help with cost tracking and with finding these secrets later.
| const entries: EnvLocalEntry[] = []; | ||
| for (const { runtime, fields } of secrets) { | ||
| for (const { target, variable, source } of fields) { | ||
| const value = env[source]; |
There was a problem hiding this comment.
Medium: this reads env[source] only, and env is this.processEnv (manager.tsx, around line 1884). boxKeyReads selects only route variables from .env.local, so a telemetry source variable is never read from there.
agentcore dev does read the source from .env.local (boxDevSecrets). So a user who keeps LANGFUSE_AUTH in agentcore/.env.local sees dev work, but build copies nothing. Deploy then fails, and the missingKeys text says "Build copies LANGFUSE_AUTH there when it is set", although it is set.
Suggestion: also read the source variables through boxKeyReads, as for an env:// route. Otherwise, make the docs and the error say "exported in the shell that runs build".
| return new ProjectStateError( | ||
| `Runtime '${secret.runtime}' has no key for ${targets} to store in AWS Secrets Manager ` + | ||
| `secret '${secret.name}'. Set ${variables} in ${join(rootPath, ENV_LOCAL_RELATIVE_PATH)} ` + | ||
| `or in the environment you deploy from. Build copies ${sources} there when it is set.`, |
There was a problem hiding this comment.
nit: this hint is wrong when the source variable is only in .env.local (see the comment on boxTelemetrySecretEnvEntries). Say "when it is set in the shell that runs build", or fix the read.
| ): Record<string, unknown> | undefined { | ||
| if (secrets.length === 0) return undefined; | ||
| const arn = (name: string) => | ||
| `arn:${partition(region).name}:secretsmanager:${region}:*:secret:${name}-??????`; |
There was a problem hiding this comment.
nit: the account is *. Each name is exact (the -?????? suffix) and a cross-account read would also need a resource policy on the other side, so I don't see a real exposure. Still, a reader expects the account here. If the policy file can take the account at deploy, or the L3 can fill in ${AWS::AccountId}, that would be tighter. If neither can, a comment that says why the account is * is enough.
| failed[name] = { secretArn }; | ||
| yield { | ||
| type: "step", | ||
| message: `Could not delete secret '${name}' (${secretArn}): ${(error as Error).message}.`, |
There was a problem hiding this comment.
nit: a failed delete shows only as a step line in the deploy stream, and a user can miss it. The record stays, so the next deploy retries, which is good. Consider a warning event, so that a secret that stays in the account (and is billed) is visible.
|
|
||
| /** | ||
| * The name of the secret that holds the telemetry keys of runtime `runtime`. Each deployment target | ||
| * of the project in one account and region shares it, because the AgentCore Runtime profile is the |
There was a problem hiding this comment.
nit: when two deployment targets are in one account and region, they share this secret, so the last deploy's keys win for both. That is fine, but docs/box-local-testing.md should say it. If someone deploys a staging target with a different key, prod gets that key too.
| "mcp": {} | ||
| } | ||
| }, | ||
| "secretsManager": { |
There was a problem hiding this comment.
nit: I checked these entries. They contain only env:// refs and the box-stand-in dummies, so nothing sensitive. The test compares only telemetry and plugins, so most of the +1053 lines are whole profiles that nothing asserts on. Consider trimming them, or say in the OLD_RENDERER comment which commit or renderer these secretsManager cases were recorded from, as the comment does for the other sets.
…me kind have different secret fields and Runtime profile refs
…third-party telemetry target that it does not carry
|
Two new commits are on this branch:
Problem. The stop told the operator to read "the warning for [telemetry.]". Build stops before it shows warnings, so the operator did not see the cause. Change. The Box network model now gives the refusal rule each target that it does not carry, with the cause and the step that corrects it. The stop now shows both. For example, on a CodeZip runtime: The other four causes use the same shape: a value that build cannot copy, a Tests. |
leo237
left a comment
There was a problem hiding this comment.
Re-reviewed 71572e9...52e61a1. The stop now carries the cause and the fix, and it no longer points at a warning that build never shows. buildBoxNetwork is the only producer of the context, and it always passes leftOut. Every third-party target is either carried or left out with a reason, so I found no path where the stop loses its cause. The fixes for the CodeZip, ref, name, and collision causes are correct.
The six touched test files pass (599 tests), and so do typecheck and oxlint. Mutation checks: replacing the leftOutTelemetry lookup in refusals.ts with undefined fails 4 tests, passing leftOutTelemetry: [] in network.ts fails 3, and changing the CodeZip fix text fails 2.
Two nits are inline. My earlier comments (secret adoption by name, .env.local not read at build, and the nits) are not touched by these commits. They stay open and non-blocking.
| if (uncopied.length > 0) { | ||
| leftOut.push({ | ||
| name, | ||
| reason: `Box resolves its \`${uncopied[0]}\` to a value build cannot copy`, |
There was a problem hiding this comment.
nit: this is the only cause with no fix, but there is a step: give the key a string, a list of strings, or a table of strings (what copiedValue accepts). Something like fix: `Give \`${uncopied[0]}\` a string, a list of strings, or a table of strings` would do. Then the test title at network.test.ts:1718 ("has no step but to remove it") and the fix doc comment ("absent means no such step") should change too.
| ]); | ||
| }); | ||
|
|
||
| test("a target with a value build cannot copy, which has no step but to remove it", () => { |
There was a problem hiding this comment.
nit: the PR comment says each case goes through buildBoxNetwork, but this block covers 3 of the 5 causes. The bad target name (telemetry.ts) and the variable collision (network.ts) are checked only through their warnings. Two more stopOf cases would also pin their "Rename the target, remove ..." text.
|
The fix to the CodeZip stop message moves to its own pull request, aws/agentcore-cli#2919. ed28c3aa removes it from this pull request. The code of this pull request is now the same as at 009fbee8, which adds only the tests for two targets of the same kind. |
Description
Problem. Today,
agentcore buildstops withRUNTIME_TELEMETRY_NOT_CLOUDWATCHwhen a box profile has alangfuse,langsmith, orotlptelemetry target. Each of these targets needs an API key. Withagentcore dev, box reads the key from an environment variable (secret.ref = "env://VAR"). On AgentCore Runtime, that variable is not there.Solution.
agentcore/.env.localasAGENTCORE_CREDENTIAL_<RUNTIME>_TELEMETRY_<TARGET>.agentcore/<project>/<runtime>/box, with one field for each target. Deploy uses the Secrets Manager API. Thus, the secret is not a stack resource, and no key goes into a template. A new deploy without the key keeps the value in the secret. When no runtime uses a secret, deploy schedules its deletion.plugins = ["@box/aws-secrets-manager"]. Each target getssecret.ref = "aws-secretsmanager://agentcore/<project>/<runtime>/box#telemetry.<target>". Box 0.3.0 has this plugin. The box trusted process reads the key before the agent starts, and the agent does not see the key.secretsmanager:GetSecretValueon that secret and on no other secret, inagentcore/box-telemetry-policy-<runtime>.json.aws.network.secretsManagerEndpointon the runtime. The L3 then adds an AWS Secrets Manager endpoint to the secure VPC. Without the endpoint, box cannot read the key and does not start the agent. This part needs aws/agentcore-l3-cdk-constructs#491.agentcore devgives theenv://key of each third-party telemetry target to box, for a container runtime and for a CodeZip runtime.AGENTCORE_BOX_SECRETS_MANAGERswitch ofbox-integration-development.The first commit holds five commits of
box-integration-development, resolved againstbox-integration: 7ad00c39, 212d17f1, 96cc7341, 3ad5f5c3, and 71801dfd. The tree of this branch is the same as the tree ofbox-integration-developmentat 42a8975e.Tests on AgentCore Runtime (a test account, container template):
GetSecretValueby the execution role, with no error. Box sends to Langfuse (401) and LangSmith (403), which shows that box read the keys and sent them. No key is in the logs or in the environment of the agent.GetSecretValuegoes through the VPC endpoint, with no error. Each send fails with a DNS error for the host. This is correct, because the VPC has no path to the internet. The lock of the runtime role does not stop the endpoint call.GetSecretValueby the execution role, with no error. Box shows notelemetry export failedline, withSTRANDS_BOX_TELEMETRY_DEBUG=1.Not in the tests: LangSmith with a key that works, an
otlptarget on AgentCore Runtime, and CodeZip (refused by design).Related Issue
No issue. This change is part of the Box on AgentCore integration.
Documentation PR
Documentation is in this PR:
docs/box-local-testing.md.Type of Change
Testing
bun test(6558 pass, 9 skip, 0 fail)bun run test:e2e, or explained why they are not applicable: the live tests above replace them for this changebun run typecheckbun run lint:checkbun run format:checkbun run auditbun run secrets:checkbun run buildsrc/assets/, I updated affected snapshots withbun test <test-file> --update-snapshotsand committed themcommand.md(the release workflow regenerates it)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.