Skip to content

feat: add bulk secret import upload to Add secret dialog (PLAT-240)#26725

Draft
dylanhuff-at-coder wants to merge 16 commits into
mainfrom
dylan/plat-240-secrets-import-frontend
Draft

feat: add bulk secret import upload to Add secret dialog (PLAT-240)#26725
dylanhuff-at-coder wants to merge 16 commits into
mainfrom
dylan/plat-240-secrets-import-frontend

Conversation

@dylanhuff-at-coder

@dylanhuff-at-coder dylanhuff-at-coder commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Adds a file dropzone to the create branch of the Add secret dialog (final PR in the PLAT-240 stack, after #26723 and #26724). The browser reads the file, derives the format from the extension (.env/.json/.yaml/.yml), and imports via POST /secrets/batch; per-entry backend errors surface in an alert and the success toast flags secrets imported without an env name. Storybook play stories and vitests cover the flow.

Also documents the upload flow in docs/user-guides/user-secrets.md.

Closes https://linear.app/codercom/issue/PLAT-240

Reviewed and updated by Coder Agents on behalf of @dylanhuff-at-coder.

@linear-code

linear-code Bot commented Jun 25, 2026

Copy link
Copy Markdown

PLAT-240

Copy link
Copy Markdown
Contributor Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Add POST /api/v2/users/{user}/secrets/batch to create many user secrets
from an uploaded env/json/yaml file. The batch is inserted in one
transaction, so any validation, uniqueness, or per-user-limit failure
rolls back everything and emits zero audit logs. Adds the codersdk
ImportUserSecrets client and the regenerated API docs.
Previously ParseSecretsFile set EnvName unconditionally to the file key
for every parsed entry. This caused keys that are not valid POSIX env
names (e.g. MY-TOKEN, my.key) or that are reserved (e.g. PATH) to fail
ValidateCreateUserSecretRequest on the env_name field, rolling back the
entire atomic batch import. Common real-world .env files typically
contain such keys.

Change EnvName assignment to best-effort: only set it when the key
passes UserSecretEnvNameValid; otherwise leave EnvName empty. The secret
is still imported, just without env injection. The env_name uniqueness
index is a partial index (WHERE env_name != ''), so multiple empty
env_names are fine.

Update tests:
- Add TestParseSecretsFileEnvBestEffortEnvName in codersdk with cases
  for hyphenated key (MY-TOKEN), reserved name (PATH), dot key (my.key),
  and a valid key (MY_TOKEN).
- Remove ReservedEnvName (PATH) from the rollback failure cases in
  coderd/usersecretsimport_test.go; add
  TestImportUserSecretsReservedEnvNameBestEffort to assert the new
  success behavior (secret created, env_name empty).
…240)

Add a file-upload dropzone to the create branch of the Add secret dialog
(edit is unchanged). The browser reads the file, derives the format from
the extension, and calls the import endpoint, surfacing per-entry backend
errors. Includes Storybook coverage for success, partial-failure, and
unsupported-file cases.
@dylanhuff-at-coder
dylanhuff-at-coder force-pushed the dylan/plat-240-secrets-import-frontend branch from cd114ba to 22ab3cd Compare July 23, 2026 16:33
@github-actions

Copy link
Copy Markdown

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@dylanhuff-at-coder dylanhuff-at-coder changed the title feat(site): add bulk secret import upload to Add secret dialog (PLAT-240) feat: add bulk secret import upload to Add secret dialog (PLAT-240) Jul 23, 2026
@dylanhuff-at-coder dylanhuff-at-coder removed the stale This issue is like stale bread. label Jul 23, 2026
Base automatically changed from dylan/plat-240-secrets-import-endpoint to main July 23, 2026 21:55
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.

1 participant