Files
windmill/cli/test/variable_ciphertext_shape_unit.test.ts
T
6f4124e9a0 feat: reference existing HashiCorp Vault secrets from secret variables (#12078)
* feat: reference existing HashiCorp Vault secrets from secret variables

A secret variable can hold `$external:vault://<path>#<key>` instead of a
value. The reference is resolved from Vault each time the variable is
read, so the value is never stored in Windmill. An instance-level
allow-list of path prefixes, optionally per workspace, is checked when a
reference is saved and again when it is resolved. Other schemes are
parsed and refused as unsupported backends.

Adds AppRole as a Vault auth method, an "External reference" toggle in
the variable editor and an instance settings section for the connection
and the allow-list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: point ee-repo-ref at the external secret references branch

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep external secret references intact on delete, deploy and export

- Deleting a reference no longer runs the managed backend cleanup, which
  could delete the secret it points at.
- Deploying a variable to another workspace copies the reference, which
  the target's allow-list then checks, instead of its resolved value.
- A plain-secrets workspace export writes references verbatim.
- Reference paths reject backslashes, `#` and control characters, which
  the URL parser would otherwise normalize past the allow-list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: skip external secret references in key rotation and the read cache

- Workspace key rotation no longer tries to decrypt references.
- `get_value?allow_cache=true` does not cache a resolved reference, so
  Vault rotation and allow-list changes apply on the next read.
- `VaultSettings.mount_path` is optional in the OpenAPI spec, matching
  its serde default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: keep the OSS Vault reader stub public and regenerate workspace tool schemas

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: restrict external secret references to workspace admins and keep them out of the managed Vault storage

Creating, repointing or removing a reference now takes a workspace admin, on
create and update including already-encrypted pushes and cross-workspace
deploys; the variable form disables the toggle and fields for anyone else.

A reference into the storage of Windmill's own Vault secret backend (same
address, namespace folded into the path) is refused on save and on resolve,
whatever the allow-list says.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: compare external secret references as written in workspace comparison

Two references that currently resolve to the same value still point at
different secrets, so comparing their resolved values hid a repoint from the
diff and from deployment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: let external secret references reuse the Vault backend connection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: hide the external reference toggle from non-admins unless already set

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: read whole Vault secrets, show allowed paths, and pick the variable type in one control

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: mask JSON fields only for whole Vault secrets, and skip PEM armor and JSON lines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: align the reference editor and settings warning with the form and alert guidelines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: let a saved reference become non-secret directly, and warn when no prefix is allowed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: save an empty value when a reference is switched to another type

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a saved reference's baseline through type round trips

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: drop an unused binding in the reference parser

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: offer vault reference only when a vault path is allowed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* chore: update ee-repo-ref to c0fd22ba77e6618cea7611d72fe2e75c8855c595

This commit updates the EE repository reference after PR #932 was merged in windmill-ee-private.

Previous ee-repo-ref: 56cba4e7771e7a87e56a67eb115549a31dd12b1a

New ee-repo-ref: c0fd22ba77e6618cea7611d72fe2e75c8855c595

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
2026-10-30 20:23:27 +01:00

44 lines
1.8 KiB
TypeScript

import { expect, test } from "bun:test";
import { looksLikeWorkspaceCiphertext } from "../src/commands/variable/variable.ts";
// =============================================================================
// looksLikeWorkspaceCiphertext drives whether single-file `variable push` treats
// a secret's value as already-encrypted (store verbatim) or as plaintext to be
// encrypted server-side. It must agree with the server guard
// (validate_already_encrypted_secret in windmill-store/src/variables.rs): a value
// is "ciphertext shaped" iff it is an external-backend marker, or standard base64
// decoding to a non-zero multiple of the AES block size (16 bytes).
// =============================================================================
test("treats workspace-ciphertext-shaped values as already-encrypted", () => {
const ciphertextShaped = [
"MpYeXnSBBF7dzI6K8J89xQ==", // real magic_crypt output: 16 bytes
Buffer.alloc(16, 7).toString("base64"), // 16 bytes
Buffer.alloc(32, 7).toString("base64"), // 32 bytes
"$vault:f/x/cfg",
"$aws_sm:f/x/cfg",
"$azure_kv:f/x/cfg",
"$external:vault://secret/team/app#token",
];
for (const value of ciphertextShaped) {
expect(looksLikeWorkspaceCiphertext(value)).toBe(true);
}
});
test("treats hand-authored plaintext as NOT already-encrypted", () => {
const plaintext = [
"some: plaintext\n", // space, colon, newline
"original-secret", // hyphen, not length % 4
"hunter2",
'{"a": 1}',
"", // empty
"dGVzdA==", // valid base64 but decodes to 4 bytes (not % 16)
Buffer.alloc(17, 7).toString("base64"), // 17 bytes (not % 16)
"$omething-plain", // starts with $ but is not a real backend marker
];
for (const value of plaintext) {
expect(looksLikeWorkspaceCiphertext(value)).toBe(false);
}
});