-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(secret-manager): dynamic secret support for proxied services #7288
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
Open
saifsmailbox98
wants to merge
14
commits into
main
Choose a base branch
from
saif/age2-42-dynamic-secret-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f448445
feat(secret-manager): dynamic secret support for proxied services
saifsmailbox98 751cdf7
fix(secret-manager): address review for dynamic secret proxied services
saifsmailbox98 8a62091
fix(secret-manager): collect dynamic secret lease inputs once per secret
saifsmailbox98 1a78315
chore(secret-manager): keep dynamic secret field choice generic
saifsmailbox98 6546fde
chore(secret-manager): trim explanatory comments to match codebase style
saifsmailbox98 d2908cd
chore(secret-manager): drop unused schema + unexport in-file-only hel…
saifsmailbox98 742daaf
docs(agent-proxy): fix stale dynamic-secret notes (generic fields, co…
saifsmailbox98 f21aa43
chore(secret-manager): use a real timestamp for the dynamic-secret mi…
saifsmailbox98 d5ca9f3
docs(agent-proxy): document Lease permission for dynamic-secret broke…
saifsmailbox98 d0b1be4
Merge remote-tracking branch 'origin/main' into saif/age2-42-dynamic-…
saifsmailbox98 e30f1b5
chore(secret-manager): cap dynamic secret credential columns with var…
saifsmailbox98 d6a6dc7
fix(secret-manager): don't disclose full principal allowlist in valid…
saifsmailbox98 dc60d35
improvement(secret-manager): submenu-based credential source picker f…
saifsmailbox98 4d267c5
improvement(secret-manager): restrict proxied-service credentials to …
saifsmailbox98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
backend/src/db/migrations/20260714100000_proxied-service-dynamic-secret-credentials.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { Knex } from "knex"; | ||
|
|
||
| import { TableName } from "../schemas"; | ||
|
|
||
| export async function up(knex: Knex): Promise<void> { | ||
| const hasDynamicSecretName = await knex.schema.hasColumn(TableName.ProxiedServiceCredential, "dynamicSecretName"); | ||
|
|
||
| await knex.schema.alterTable(TableName.ProxiedServiceCredential, (t) => { | ||
| if (!hasDynamicSecretName) { | ||
| // Name-based reference to a dynamic secret in the credential's own folder. | ||
| // Intentionally NO FK to dynamic_secrets: matches secretKey's self-heal semantics | ||
| // (a deleted-then-recreated dynamic secret with the same name re-links automatically). | ||
| t.text("dynamicSecretName"); | ||
| t.text("dynamicSecretField"); | ||
| t.jsonb("dynamicSecretConfig"); | ||
| } | ||
|
|
||
| // A credential now references either a static secret (secretKey) or a dynamic secret | ||
| // (dynamicSecretName), so secretKey can no longer be NOT NULL. The "exactly one of" rule | ||
| // is enforced at the Zod/application layer. | ||
| t.string("secretKey").nullable().alter(); | ||
| }); | ||
| } | ||
|
|
||
| export async function down(knex: Knex): Promise<void> { | ||
| // Dynamic-only rows have a null secretKey and would violate the restored NOT NULL constraint. | ||
| await knex(TableName.ProxiedServiceCredential).whereNull("secretKey").delete(); | ||
|
|
||
| const hasDynamicSecretName = await knex.schema.hasColumn(TableName.ProxiedServiceCredential, "dynamicSecretName"); | ||
|
|
||
| await knex.schema.alterTable(TableName.ProxiedServiceCredential, (t) => { | ||
| if (hasDynamicSecretName) { | ||
| t.dropColumn("dynamicSecretName"); | ||
| t.dropColumn("dynamicSecretField"); | ||
| t.dropColumn("dynamicSecretConfig"); | ||
| } | ||
| t.string("secretKey").notNullable().alter(); | ||
| }); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
backend/src/ee/services/dynamic-secret/providers/dynamic-secret-provider-outputs.test.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { DYNAMIC_SECRET_PROVIDER_OUTPUTS } from "./dynamic-secret-provider-outputs"; | ||
| import { DynamicSecretProviders } from "./models"; | ||
|
|
||
| describe("DYNAMIC_SECRET_PROVIDER_OUTPUTS", () => { | ||
| it("has an entry for every provider", () => { | ||
| Object.values(DynamicSecretProviders).forEach((provider) => { | ||
| expect(DYNAMIC_SECRET_PROVIDER_OUTPUTS[provider]).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| it("lists at least one output field for every provider (nothing is force-hidden)", () => { | ||
| Object.values(DynamicSecretProviders).forEach((provider) => { | ||
| expect(DYNAMIC_SECRET_PROVIDER_OUTPUTS[provider].outputFields.length).toBeGreaterThan(0); | ||
| }); | ||
| }); | ||
|
|
||
| it("exposes ssh key/cert fields for injection (e.g. into a request body)", () => { | ||
| expect(DYNAMIC_SECRET_PROVIDER_OUTPUTS[DynamicSecretProviders.Ssh].outputFields).toEqual([ | ||
| "PRIVATE_KEY", | ||
| "SIGNED_KEY" | ||
| ]); | ||
| }); | ||
|
|
||
| it("keeps the lowercase output-field oddballs verbatim", () => { | ||
| expect(DYNAMIC_SECRET_PROVIDER_OUTPUTS[DynamicSecretProviders.AzureEntraID].outputFields).toEqual([ | ||
| "email", | ||
| "password" | ||
| ]); | ||
| expect(DYNAMIC_SECRET_PROVIDER_OUTPUTS[DynamicSecretProviders.Couchbase].outputFields).toEqual([ | ||
| "username", | ||
| "password" | ||
| ]); | ||
| }); | ||
|
|
||
| it("only attaches a lease config schema to kubernetes and ssh", () => { | ||
| Object.values(DynamicSecretProviders).forEach((provider) => { | ||
| const { leaseConfigSchema } = DYNAMIC_SECRET_PROVIDER_OUTPUTS[provider]; | ||
| if (provider === DynamicSecretProviders.Kubernetes || provider === DynamicSecretProviders.Ssh) { | ||
| expect(leaseConfigSchema).toBeDefined(); | ||
| } else { | ||
| expect(leaseConfigSchema).toBeUndefined(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| it("validates the kubernetes namespace lease config", () => { | ||
| const schema = DYNAMIC_SECRET_PROVIDER_OUTPUTS[DynamicSecretProviders.Kubernetes].leaseConfigSchema!; | ||
| expect(schema.safeParse({ namespace: "prod" }).success).toBe(true); | ||
| expect(schema.safeParse({}).success).toBe(true); | ||
| expect(schema.safeParse({ unknown: "x" }).success).toBe(false); | ||
| }); | ||
| }); |
70 changes: 70 additions & 0 deletions
70
backend/src/ee/services/dynamic-secret/providers/dynamic-secret-provider-outputs.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| import { DynamicSecretProviders } from "./models"; | ||
|
|
||
| // Canonical map of dynamic secret provider -> every field its lease output can contain, plus the | ||
| // per-lease config a proxied service may set. This drives proxied-service field validation: any listed | ||
| // field may be injected. The frontend mirror additionally marks which fields are "recommended" (the | ||
| // credential-bearing ones) versus lease metadata, but the backend accepts any listed field. | ||
| // | ||
| // KEEP IN SYNC with the frontend mirror at | ||
| // frontend/src/hooks/api/dynamicSecret/providerOutputs.ts | ||
| // (same convention as the host-pattern grammar shared with the CLI's match.go). | ||
| // | ||
| // Field names match each provider's create() return verbatim, including the lowercase oddballs | ||
| // (azure-entra-id -> email/password, couchbase -> username/password). | ||
|
|
||
| export type TDynamicSecretProviderOutputEntry = { | ||
| outputFields: string[]; | ||
| // undefined = the provider accepts no per-lease config; a non-empty config is then rejected. | ||
| leaseConfigSchema?: z.ZodTypeAny; | ||
| }; | ||
|
|
||
| export const DynamicSecretKubernetesLeaseConfigSchema = z | ||
| .object({ namespace: z.string().trim().min(1).optional() }) | ||
| .strict(); | ||
|
|
||
| export const DynamicSecretSshLeaseConfigSchema = z | ||
| .object({ principals: z.array(z.string().trim().min(1)).optional() }) | ||
| .strict(); | ||
|
|
||
| const DB_USER_PASS = ["DB_USERNAME", "DB_PASSWORD"]; | ||
|
|
||
| export const DYNAMIC_SECRET_PROVIDER_OUTPUTS: Record<DynamicSecretProviders, TDynamicSecretProviderOutputEntry> = { | ||
| [DynamicSecretProviders.SqlDatabase]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.Clickhouse]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.Cassandra]: { outputFields: DB_USER_PASS }, | ||
| // aws-iam returns SESSION_TOKEN for the STS-based methods (assume-role / access-key / IRSA) and | ||
| // USERNAME for the IAM-user method; the shape depends on encrypted provider config, so both are listed. | ||
| [DynamicSecretProviders.AwsIam]: { outputFields: ["ACCESS_KEY", "SECRET_ACCESS_KEY", "SESSION_TOKEN", "USERNAME"] }, | ||
| [DynamicSecretProviders.Redis]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.AwsElastiCache]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.AwsMemoryDb]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.MongoAtlas]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.ElasticSearch]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.MongoDB]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.RabbitMq]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.AzureEntraID]: { outputFields: ["email", "password"] }, | ||
| [DynamicSecretProviders.AzureSqlDatabase]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.Ldap]: { outputFields: ["USERNAME", "PASSWORD", "DN_ARRAY"] }, | ||
| [DynamicSecretProviders.SapHana]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.Snowflake]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.Totp]: { outputFields: ["TOTP", "TIME_REMAINING"] }, | ||
| [DynamicSecretProviders.SapAse]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.Kubernetes]: { | ||
| outputFields: ["TOKEN"], | ||
| leaseConfigSchema: DynamicSecretKubernetesLeaseConfigSchema | ||
| }, | ||
| [DynamicSecretProviders.Vertica]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.GcpIam]: { outputFields: ["SERVICE_ACCOUNT_EMAIL", "TOKEN"] }, | ||
| [DynamicSecretProviders.Github]: { | ||
|
saifsmailbox98 marked this conversation as resolved.
|
||
| outputFields: ["TOKEN", "EXPIRES_AT", "PERMISSIONS", "REPOSITORY_SELECTION"] | ||
| }, | ||
| [DynamicSecretProviders.Couchbase]: { outputFields: ["username", "password"] }, | ||
| [DynamicSecretProviders.Milvus]: { outputFields: DB_USER_PASS }, | ||
| [DynamicSecretProviders.Ssh]: { | ||
| outputFields: ["PRIVATE_KEY", "SIGNED_KEY"], | ||
| leaseConfigSchema: DynamicSecretSshLeaseConfigSchema | ||
| }, | ||
| [DynamicSecretProviders.IbmApiConnect]: { outputFields: ["CLIENT_ID", "CLIENT_SECRET"] } | ||
| }; | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.