-
Notifications
You must be signed in to change notification settings - Fork 60
fix: source aware api-key flag + redact api key value from logging #1819
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
base: refactor
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "apiKeySecretArn": { | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-ceac1e1d-2BRhkE" | ||
| }, | ||
| "name": "agentcore-cli-identity-fixture", | ||
| "credentialProviderArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:token-vault/default/apikeycredentialprovider/agentcore-cli-identity-fixture", | ||
| "apiKeySecretSource": "MANAGED" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "apiKeySecretArn": { | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-2-56db9332-Jv9u5N" | ||
| }, | ||
| "name": "agentcore-cli-identity-fixture-2", | ||
| "credentialProviderArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:token-vault/default/apikeycredentialprovider/agentcore-cli-identity-fixture-2", | ||
| "apiKeySecretSource": "MANAGED" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| { | ||
| "apiKeySecretArn": { | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-34b3f8a9-cHh41n" | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-ceac1e1d-2BRhkE" | ||
| }, | ||
| "name": "agentcore-cli-identity-fixture", | ||
| "credentialProviderArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:token-vault/default/apikeycredentialprovider/agentcore-cli-identity-fixture", | ||
| "createdTime": { | ||
| "$date": "2026-07-23T16:31:54.009Z" | ||
| "$date": "2026-07-23T19:31:48.713Z" | ||
| }, | ||
| "lastUpdatedTime": { | ||
| "$date": "2026-07-23T16:31:54.009Z" | ||
| "$date": "2026-07-23T19:31:48.713Z" | ||
| }, | ||
| "apiKeySecretSource": "MANAGED" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "apiKeySecretArn": { | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-ceac1e1d-2BRhkE" | ||
| }, | ||
| "name": "agentcore-cli-identity-fixture", | ||
| "credentialProviderArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:token-vault/default/apikeycredentialprovider/agentcore-cli-identity-fixture", | ||
| "createdTime": { | ||
| "$date": "2026-07-23T19:31:48.713Z" | ||
| }, | ||
| "lastUpdatedTime": { | ||
| "$date": "2026-07-23T19:31:48.713Z" | ||
| }, | ||
| "apiKeySecretSource": "MANAGED" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| { | ||
| "apiKeySecretArn": { | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-34b3f8a9-cHh41n" | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-ceac1e1d-2BRhkE" | ||
| }, | ||
| "name": "agentcore-cli-identity-fixture", | ||
| "credentialProviderArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:token-vault/default/apikeycredentialprovider/agentcore-cli-identity-fixture", | ||
| "createdTime": "2026-07-23T16:31:54.009Z", | ||
| "lastUpdatedTime": "2026-07-23T16:31:54.009Z", | ||
| "createdTime": "2026-07-23T19:31:48.713Z", | ||
| "lastUpdatedTime": "2026-07-23T19:31:48.713Z", | ||
| "apiKeySecretSource": "MANAGED" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| { | ||
| "apiKeySecretArn": { | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-34b3f8a9-cHh41n" | ||
| "secretArn": "arn:aws:secretsmanager:us-west-2:685197708687:secret:bedrock-agentcore-identity!default/apikey/agentcore-cli-identity-fixture-ceac1e1d-2BRhkE" | ||
| }, | ||
| "name": "agentcore-cli-identity-fixture", | ||
| "credentialProviderArn": "arn:aws:bedrock-agentcore:us-west-2:685197708687:token-vault/default/apikeycredentialprovider/agentcore-cli-identity-fixture", | ||
| "createdTime": "2026-07-23T16:31:54.009Z", | ||
| "lastUpdatedTime": "2026-07-23T16:31:54.009Z", | ||
| "createdTime": "2026-07-23T19:31:48.713Z", | ||
| "lastUpdatedTime": "2026-07-23T19:31:48.713Z", | ||
| "apiKeySecretSource": "MANAGED" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,74 @@ | ||
| import z from "zod"; | ||
| import { createHandler, flag } from "../../../../router"; | ||
| import { JsonRendererKey } from "../../../../tui"; | ||
| import type { Core } from "../../../types"; | ||
| import type { AppIO, Core } from "../../../types"; | ||
| import { coreOptsFromCtx } from "../../../utils"; | ||
| import { readSourceText } from "../../../source"; | ||
| import { parseJsonFlag } from "../../../utils"; | ||
|
|
||
| export const createCreateApiKeyCredentialProviderHandler = (core: Core) => | ||
| export const createCreateApiKeyCredentialProviderHandler = (core: Core, io: AppIO) => | ||
| createHandler({ | ||
| name: "create", | ||
| description: "create an API key credential provider", | ||
| flags: [ | ||
| flag("name", "the name of the API key credential provider", z.string().optional()), | ||
| flag("api-key", "the API key value", z.string().optional()), | ||
| flag("api-key", "the API key value (inline, file://path, or -)", z.string().optional(), { | ||
| sensitive: true, | ||
| }), | ||
| flag("api-key-secret-arn", "existing Secrets Manager secret ARN", z.string().optional()), | ||
| flag( | ||
| "api-key-secret-json-key", | ||
| "JSON key containing the API key in the secret", | ||
| z.string().optional(), | ||
| ), | ||
| flag("tags", "tags as key=value (repeatable) or JSON object", z.string().optional()), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This advertises repeatable |
||
| ], | ||
| handle: async (ctx, flags) => { | ||
| if (!flags.name) { | ||
| throw new TypeError("required option '--name <name>' not specified"); | ||
| } | ||
| if (!flags["api-key"]) { | ||
| throw new TypeError("required option '--api-key <api-key>' not specified"); | ||
| } | ||
|
|
||
| ctx | ||
| .require(JsonRendererKey) | ||
| .renderJson( | ||
| await core.identity.createApiKeyCredentialProvider( | ||
| flags.name, | ||
| flags["api-key"], | ||
| coreOptsFromCtx(ctx), | ||
| ), | ||
| const hasApiKey = flags["api-key"] !== undefined; | ||
| const hasSecretArn = flags["api-key-secret-arn"] !== undefined; | ||
| const hasSecretJsonKey = flags["api-key-secret-json-key"] !== undefined; | ||
|
|
||
| if (hasApiKey && (hasSecretArn || hasSecretJsonKey)) { | ||
| throw new TypeError( | ||
| "--api-key and --api-key-secret-arn/--api-key-secret-json-key are mutually exclusive", | ||
| ); | ||
| } | ||
| if (!hasApiKey && !hasSecretArn) { | ||
| throw new TypeError( | ||
| "either --api-key or --api-key-secret-arn and --api-key-secret-json-key are required", | ||
| ); | ||
| } | ||
| if (hasSecretArn !== hasSecretJsonKey) { | ||
| throw new TypeError( | ||
| "--api-key-secret-arn and --api-key-secret-json-key must be specified together", | ||
| ); | ||
| } | ||
|
|
||
| const apiKey = hasApiKey ? await readSourceText(flags["api-key"]!, io.stdin) : undefined; | ||
|
|
||
| const apiKeySecretConfig = hasSecretArn | ||
| ? { secretId: flags["api-key-secret-arn"]!, jsonKey: flags["api-key-secret-json-key"]! } | ||
| : undefined; | ||
|
|
||
| const apiKeySecretSource = hasApiKey ? "MANAGED" : "EXTERNAL"; | ||
|
|
||
| const tags = parseJsonFlag<Record<string, string>>("tags", flags.tags); | ||
|
|
||
| ctx.require(JsonRendererKey).renderJson( | ||
| await core.identity.createApiKeyCredentialProvider( | ||
| { | ||
| name: flags.name, | ||
| apiKey, | ||
| apiKeySecretConfig, | ||
| apiKeySecretSource: apiKeySecretSource as any, | ||
| tags, | ||
| }, | ||
| coreOptsFromCtx(ctx), | ||
| ), | ||
| ); | ||
| }, | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the doc discussion, the preferred external-secret representation was one structured-reference flag rather than separate ARN and JSON-key flags. Could we use something like
--api-key-secret-reference '{"secretId":"...","jsonKey":"..."}'for create/update, mutually exclusive with--api-key? We should also have a successful external-reference request-mapping test, I think the current tests only cover invalid combinations.Update should first retrieve the provider and preserve its existing apiKeySecretSource. A MANAGED provider should accept only --api-key, while an EXTERNAL provider should accept only the structured secret reference. I think we should reject mismatched input locally and test both directions instead of deriving the source mode from the supplied flags.