Available commands
The SecretStash CLI provides a series of commands to securely create and manage environment variables across multiple applications.
Introduction
The SecretStash CLI lets you securely create and manage environment variables across multiple applications. It syncs your application's .env with SecretStash, and most commands are interactive but also provide flags for automation.
Managing Variables
Listing variables
To see a summary of the variables currently stored in SecretStash for your environment:
Options
--environmentdefaults toAPP_ENVif omitted
Pulling variables
The pull command retrieves variables from SecretStash, decrypts them using your local environment key, and updates your local .env file.
Options
--environmentdefaults toAPP_ENVif omitted--filedefaults to.env
Pushing variables
The push command reads your local .env file, encrypts the values, and sends them to the SecretStash API.
Notes:
- Variables starting with
SECRET_STASH_are ignored automatically. - You can also ignore specific variables in
config/secret-stash.php.
Managing Environments
List environments
Shows all environments in SecretStash, including each environment's:
- ID
- name
- environment type
- slug
- created date
Create an environment
Creates a new environment in the SecretStash service.
Options
--namethe name of the environment (e.g.,Staging).--sluga shortened, url-friendly version of the environment name (e.g.,staging). This will need to match theAPP_ENVenvironment variable.--typethe type of environment, allowing to easily identify which environments are which within the SecretStash service. Available options are:localdevelopmentproduction
Managing Encryption Keys
SecretStash CLI uses client-side encryption. This means your raw values never touch SecretStash's servers; only the encrypted payloads do. Keys are stored locally in ~/.secret-stash.
This portion of the package is something that you will likely not need. Please be sure to perform the installation command php artisan secret-stash:install. This will generate the necessary encryption keys for you.
Generate a Key
Generate a new 32-byte encryption key for an environment:
Set an Existing Key
If you are setting up a new machine and already have a key:
Options
--environment: Specify the environment slug (e.g.,production).--key: The Base64-encoded encryption key.
List Keys
View which environments have keys configured on your local machine:
Device Status
View the status of your local private key and server registration:
Initialize Device
Generate and register a new RSA-4096 key pair for this device:
Options
--force: Force device key regeneration.--label: Provide a custom label for this device (e.g., "Work MacBook").
Sync Device
Sync your local device metadata from the SecretStash server:
Key Recovery
Generate a recovery key and export it to a file or QR code:
Options
--copies: Number of recovery share copies to print.--output-dir: Directory to save recovery share files.
Managing Envelopes
Managing envelopes is critical to SecretStash's client-side encryption model. Your raw environment variables are never stored on our servers; instead, they are encrypted using an environment-specific Data Encryption Key (DEK).
To share this DEK securely, SecretStash uses "envelopes"—the DEK encrypted with a user's unique RSA public key. Only the intended recipient, using their local private key, can "open" the envelope to retrieve the DEK and decrypt the variables.
Rewrap Envelope
When to use: Use this when moving to a new machine or generating a new device key pair while still having access to your old private key.
Why it's important: It migrates access to your new device. It uses your old private key to decrypt the DEK and immediately re-encrypts it with your new public key, creating a new envelope for your current session.
Options
--application: The unique application ID that identifies your application within SecretStash--environment: Specify the environment slug (e.g.,production).--old-key-file: Path to your old private key PEM file.--old-device-key-id: The ID of your old device key.
Repair Envelope
When to use: Use this if you encounter decryption errors or "envelope not found" messages after a device change or key sync issue.
Why it's important: It simplifies recovery by first attempting a rewrap with your old credentials. If that fails, it provides a fallback option to reset the environment envelopes entirely.
Options
--application: The unique application ID that identifies your application within SecretStash--environment: Specify the environment slug (e.g.,production).--old-key-file: Path to your old private key PEM file.--old-device-key-id: The ID of your old device key.
Reset Envelope
When to use: Use this "break glass" operation if keys are lost, a device is compromised, or during a scheduled security rotation.
Why it's important: It generates a brand-new DEK and creates new envelopes for all registered devices.
!WARNING This is a destructive action. Once reset, all team members must pull the latest variables and re-push them to ensure they are encrypted with the new key. Any variables not re-pushed will be inaccessible.
Options
--application: The unique application ID that identifies your application within SecretStash--environment: Specify the environment slug (e.g.,production).
Tips
- Run
php artisan --help | grep secret-stashto discover all commands. - In CI, provide
SECRET_STASH_API_KEYandSECRET_STASH_APPLICATION_IDvia secrets.