Skip to content

Commit 17081fd

Browse files
committed
update docs
1 parent 77aa8f7 commit 17081fd

5 files changed

Lines changed: 226 additions & 15 deletions

File tree

packages/varlock-website/src/content/docs/getting-started/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Varlock aims to be the most comprehensive environment variable management tool.
1212
- **[AI-Safe Config](/guides/ai-tools/)** - Your `.env.schema` gives AI agents full context on your config without ever exposing secret values. Prevent leaks to AI servers by design, and scan for leaked secrets with `varlock scan`
1313
- **[Security](/guides/secrets/)** - Automatic log redaction for sensitive values, leak detection in bundled code and server responses, and proactive scanning via `varlock scan`
1414
- **[Validation & Type Safety](/reference/data-types/)** - Powerful validation capabilities with clear error messages, plus automatic type generation for IntelliSense support
15-
- **[Secure Secrets](/guides/secrets/)** - Load secrets from provider [plugins](/plugins/overview/) (e.g., [1Password](/plugins/1password/), [AWS](/plugins/aws-secrets/), [HashiCorp Vault](/plugins/hashicorp-vault/)) or any CLI tool using [exec()](/reference/functions/#exec)
15+
- **[Secure Secrets](/guides/secrets/)** - Built-in [device-local encryption](/guides/secrets/#local-encryption) with hardware-backed security (Secure Enclave, TPM), plus provider [plugins](/plugins/overview/) (e.g., [1Password](/plugins/1password/), [AWS](/plugins/aws-secrets/), [HashiCorp Vault](/plugins/hashicorp-vault/)) or any CLI tool using [exec()](/reference/functions/#exec)
1616
- **[Multi-Environment Management](/guides/environments/)** - Flexible environment handling with support for environment-specific files, local overrides, and value composition
1717
- **[Value Composition](/reference/functions/)** - Compose values together using functions, references, and external data sources
1818
- **[Framework Integrations](/integrations/overview/)** - Official integrations for Next.js, Vite, Astro, and more, plus support for any language via `varlock run`

packages/varlock-website/src/content/docs/getting-started/usage.mdx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,22 @@ See the [`varlock load` CLI Reference](/reference/cli-commands/#load) for more i
4141
Executes a command in a child process, injecting your resolved and validated environment variables. This is useful when a code-level integration is not possible. For example, if you're using a database migration tool, you can use `varlock run` to run the migration tool with the correct environment variables. Or if you're using a non-js/ts language, you can use `varlock run` to run a command and inject validated environment variables.
4242

4343

44-
See the [`varlock run` CLI Reference](/reference/cli-commands/#run) for more information.
44+
See the [`varlock run` CLI Reference](/reference/cli-commands/#run) for more information.
45+
46+
### `varlock encrypt`
47+
48+
<ExecCommandWidget command="varlock encrypt --file .env.local" />
49+
50+
Encrypts sensitive values using device-local encryption. Use `--file` to encrypt all `@sensitive` plaintext values in a `.env` file in-place, or run without arguments for interactive single-value encryption.
51+
52+
Encrypted values are stored as `varlock("local:<encrypted>")` and are automatically decrypted during `varlock load` or `varlock run`.
53+
54+
See the [`varlock encrypt` CLI Reference](/reference/cli-commands/#encrypt) and the [secrets guide](/guides/secrets/#local-encryption) for more information.
55+
56+
### `varlock reveal`
57+
58+
<ExecCommandWidget command="varlock reveal" />
59+
60+
Securely view or copy decrypted values of `@sensitive` environment variables. Values are shown in an alternate screen buffer to prevent scrollback capture.
61+
62+
See the [`varlock reveal` CLI Reference](/reference/cli-commands/#reveal) for more information.

packages/varlock-website/src/content/docs/guides/secrets.mdx

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,97 @@ description: Best practices for managing secrets and sensitive environment varia
55

66
`varlock` uses the term _sensitive_ to describe any value that should not be exposed to the outside world. This includes secret api keys, passwords, and other generally sensitive information. Instead of relying on prefixes (e.g., `NEXT_PUBLIC_`) to know which items may be "public", varlock relies on `@decorators` to mark sensitive items explicitly.
77

8-
{/* For local development, `varlock` allows you to encrypt sensitive values in your `.env.*` files using `varlock encrypt` and then decrypt them using `varlock load` or `varlock run`.
8+
## Local encryption via `varlock()` {#local-encryption}
99

10-
This (currently) works exclusively for local development since it relies on encryption keys stored on your system. */}
10+
Varlock includes built-in device-local encryption that lets you store encrypted secrets directly in your `.env` files. Encrypted values are safe to commit to version control — they can only be decrypted on machines that have the corresponding encryption key.
1111

12-
:::tip[Coming soon]
13-
We'll be adding support for our own trustless, cloud-based secret storage in the very near future.
14-
:::
12+
This is ideal for:
13+
- **Solo developers** who want encrypted secrets in their repo without relying on an external service
14+
- **Small teams** where each developer encrypts their own local secrets
15+
- **Avoiding plaintext** `.env.local` files on disk
16+
17+
### How it works
18+
19+
Secrets are encrypted using [ECIES](https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme) (Elliptic Curve Integrated Encryption Scheme) with a device-local key. The best available encryption backend is selected automatically:
20+
21+
| Platform | Backend | Key Storage | Biometric |
22+
|----------|---------|-------------|-----------|
23+
| macOS | Secure Enclave | Hardware Secure Enclave | Touch ID / Face ID |
24+
| Windows | DPAPI | Windows credential store | Planned (Windows Hello) |
25+
| Linux | Kernel keyring | Kernel keyring | Planned (TPM2) |
26+
| All platforms | File-based fallback | `~/.varlock/` directory | No |
27+
28+
On macOS, the Secure Enclave provides hardware-backed encryption — keys cannot be extracted from the device, and decryption can require biometric authentication via Touch ID.
1529

16-
{/* ## Encryption via `varlock`
30+
### Quick start
31+
32+
1. Add your secrets as plaintext in `.env.local` (which should be gitignored)
33+
2. Run `varlock encrypt --file .env.local` to encrypt them in-place
34+
3. The values are replaced with `varlock("local:<encrypted>")` calls
35+
4. These encrypted values are automatically decrypted when you run `varlock load` or `varlock run`
36+
37+
```env-spec title=".env.local"
38+
# Before encryption
39+
# @sensitive
40+
API_KEY=sk-secret-key-12345
41+
42+
# After running `varlock encrypt --file .env.local`
43+
# @sensitive
44+
API_KEY=varlock("local:BGJ2a3...")
45+
```
1746

18-
1. [Install](/getting-started/installation) `varlock` including the desktop app
19-
2. Add sensitive values to your `.env.*` file(s)
20-
3. Encrypt them using `varlock encrypt`
21-
4. Decrypt them using `varlock load` or `varlock run` */}
47+
### Using prompt mode
48+
49+
Instead of encrypting existing values, you can use `varlock(prompt)` as a placeholder that will prompt you to enter a secret on first load:
50+
51+
```env-spec title=".env.local"
52+
# @sensitive
53+
API_KEY=varlock(prompt)
54+
```
55+
56+
When varlock encounters this during `varlock load` or `varlock run`, it will:
57+
1. Prompt you to enter the secret value (via a native dialog on macOS, or a terminal prompt otherwise)
58+
2. Encrypt the value
59+
3. Automatically replace `varlock(prompt)` with `varlock("local:<encrypted>")` in the file
60+
61+
### Encrypting values
62+
63+
Use [`varlock encrypt`](/reference/cli-commands/#encrypt) to encrypt values:
64+
65+
```bash
66+
# Interactive: encrypt a single value
67+
varlock encrypt
68+
69+
# Batch: encrypt all sensitive plaintext values in a file
70+
varlock encrypt --file .env.local
71+
```
72+
73+
In batch mode, only items marked as `@sensitive` in your schema are considered for encryption.
74+
75+
### Revealing encrypted values
76+
77+
Use [`varlock reveal`](/reference/cli-commands/#reveal) to securely view decrypted values:
78+
79+
```bash
80+
# Interactive picker
81+
varlock reveal
82+
83+
# Reveal a specific variable
84+
varlock reveal API_KEY
85+
86+
# Copy to clipboard (auto-clears after 10s)
87+
varlock reveal API_KEY --copy
88+
```
89+
90+
Values are shown in an alternate terminal screen buffer so they don't appear in your scrollback history.
91+
92+
### Locking the session
93+
94+
On platforms with biometric authentication (macOS Secure Enclave), decryption sessions are cached to avoid repeated Touch ID prompts. Use [`varlock lock`](/reference/cli-commands/#lock) to invalidate the session when stepping away:
95+
96+
```bash
97+
varlock lock
98+
```
2299

23100
## Marking `@sensitive` items
24101
Whether each item is sensitive or not is controlled by the [`@defaultSensitive`](/reference/root-decorators/#defaultsensitive) root decorator and the [`@sensitive`](/reference/item-decorators/#sensitive) item decorator. Whether you want to default to sensitive or not, or infer based on key names is up to you. For example:

packages/varlock-website/src/content/docs/reference/cli-commands.mdx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,96 @@ You can also set it up manually -- see the [Secrets guide](/guides/secrets/#scan
238238

239239
</div>
240240

241+
<div>
242+
### `varlock encrypt` ||encrypt||
243+
244+
Encrypts sensitive values using device-local encryption. Encrypted values are stored in `.env` files using the `varlock()` resolver function and are automatically decrypted at load time.
245+
246+
On macOS, encryption is hardware-backed via the Secure Enclave (with Touch ID / biometric authentication). On Windows and Linux, platform-specific secure storage is used. A pure-JavaScript file-based fallback is available on all platforms.
247+
248+
```bash
249+
varlock encrypt [options]
250+
```
251+
252+
**Options:**
253+
- `--key-id`: Encryption key ID (default: `varlock-default`)
254+
- `--file`: Path to a `.env` file — encrypts all sensitive plaintext values in-place
255+
256+
**Examples:**
257+
```bash
258+
# Interactive mode: encrypt a single value
259+
varlock encrypt
260+
261+
# Encrypt all sensitive plaintext values in a .env file
262+
varlock encrypt --file .env.local
263+
```
264+
265+
In interactive mode, you'll be prompted to enter a value, and the encrypted output will be printed for you to copy into your `.env.local` file:
266+
```
267+
SOME_SENSITIVE_KEY=varlock("local:<encrypted>")
268+
```
269+
270+
In file mode, varlock loads the env graph, identifies `@sensitive` items with plaintext values, and lets you select which to encrypt in-place.
271+
272+
:::tip
273+
Use `varlock encrypt --file .env.local` after adding new secrets to quickly encrypt them all at once.
274+
:::
275+
276+
:::note[Alternative: prompt mode]
277+
Instead of encrypting values ahead of time, you can use `varlock(prompt)` as a placeholder in your `.env` files. On first load, varlock will prompt you to enter the secret and automatically replace the placeholder with the encrypted value. See the [`varlock()` function reference](/reference/functions/#varlock) for details.
278+
:::
279+
280+
</div>
281+
282+
<div>
283+
### `varlock reveal` ||reveal||
284+
285+
Securely view or copy the decrypted values of `@sensitive` environment variables. Values are displayed in an alternate terminal screen buffer so they don't persist in your scrollback history.
286+
287+
```bash
288+
varlock reveal [VAR_NAME] [options]
289+
```
290+
291+
**Options:**
292+
- `--copy`: Copy the value to clipboard instead of displaying (auto-clears after 10s)
293+
- `--path` / `-p`: Path to a specific `.env` file or directory to use as the entry point
294+
- `--env`: Set the environment (e.g., production, development, etc)
295+
296+
**Examples:**
297+
```bash
298+
# Interactive picker to browse and reveal sensitive values
299+
varlock reveal
300+
301+
# Reveal a specific variable
302+
varlock reveal MY_SECRET
303+
304+
# Copy a value to clipboard (auto-clears after 10s)
305+
varlock reveal MY_SECRET --copy
306+
```
307+
308+
:::note
309+
Non-sensitive values are not shown by `varlock reveal`. Use [`varlock printenv`](#printenv) for non-sensitive values.
310+
:::
311+
312+
</div>
313+
314+
<div>
315+
### `varlock lock` ||lock||
316+
317+
Locks the encryption daemon, requiring biometric authentication (e.g., Touch ID) for the next decrypt operation. This invalidates the current biometric session cache.
318+
319+
```bash
320+
varlock lock
321+
```
322+
323+
This command only has an effect when using a biometric-enabled encryption backend (macOS Secure Enclave or Windows Hello). On other backends, it will display a message and exit.
324+
325+
:::tip
326+
Use `varlock lock` when stepping away from your machine to ensure the next person to decrypt a secret must authenticate biometrically.
327+
:::
328+
329+
</div>
330+
241331
<div>
242332
### `varlock typegen` ||typegen||
243333

packages/varlock-website/src/content/docs/reference/functions.mdx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,38 @@ CONFIG=exec(`aws ssm get-parameter --name "/config/${APP_ENV}" --with-decryption
2222
```
2323

2424

25-
Currently, there are built-in utility functions, and soon there will be functions to handle values encrypted using varlock provided tools.
25+
There are built-in utility functions, a built-in `varlock()` function for device-local encryption, and plugin-provided resolver functions that can fetch data from external providers.
2626

27-
Plugins may also register additional resolvers - which can be used to generate and transform values, or fetch data from external providers.
27+
<div class="reference-docs">
28+
29+
<div>
30+
### `varlock()`
2831

32+
Decrypts a locally encrypted value, or prompts for a new secret to encrypt. This is the built-in resolver for varlock's [device-local encryption](/guides/secrets/#local-encryption) feature.
33+
34+
**Decrypt mode** — pass an encrypted payload to decrypt at load time:
35+
```env-spec "varlock"
36+
# @sensitive
37+
API_KEY=varlock("local:<encrypted-payload>")
38+
```
39+
40+
**Prompt mode** — prompts the user to enter a secret, encrypts it, and writes the encrypted value back to the source file:
41+
```env-spec "varlock"
42+
# @sensitive
43+
API_KEY=varlock(prompt)
44+
# also valid as a key=value param:
45+
API_KEY=varlock(prompt=1)
46+
```
47+
48+
On first run with `prompt` mode, you'll be asked to enter the secret value. Once entered, the file is automatically updated with the encrypted payload. On macOS with Secure Enclave, a native dialog with biometric authentication is used.
49+
50+
Values are encrypted using the best available backend on your platform — see the [secrets guide](/guides/secrets/#local-encryption) for details.
51+
52+
:::tip
53+
You don't need to write `varlock()` calls by hand. Use [`varlock encrypt`](/reference/cli-commands/#encrypt) to encrypt values interactively or in bulk.
54+
:::
55+
</div>
2956

30-
<div class="reference-docs">
3157
<div>
3258
### `ref()`
3359

0 commit comments

Comments
 (0)