Back to Infisical

Inject secrets during local development

docs/documentation/platform/secrets-mgmt/quick-starts/deliver-first-secret.mdx

0.162.175.5 KB
Original Source

This quickstart guide walks you through the recommended secrets management workflow for local development. You'll create a project, add secrets to one of its environments, and inject them into your local application using the Infisical CLI, all without needing a .env file.

<Info> Prerequisites:

Step 1: Configure in Infisical

Create a project

In Infisical, a project holds all secrets for one application or service. To create a project:

<Steps> <Step> Log in to [Infisical](https://app.infisical.com). </Step> <Step> Select **Secrets Management** > **+ Add New Project**. </Step> <Step> In the **Project Name** field, enter a name for the project (e.g., `orders-service`). </Step> <Step> Select **Create Project**. </Step> </Steps>

This opens your new project in the Development environment:

<Frame> ![New project](./assets/new-project.png) </Frame> <Note> Within a project, secrets are organized across [environments](/documentation/platform/secrets-mgmt/project#project-environments). Every new project starts with three environments: **Development**, **Staging**, and **Production**. </Note>

Add your secrets

You have two options for adding secrets to your project:

<Tabs> <Tab title="Create secrets manually"> To create a new secret from scratch:
<Steps>
  <Step>
    Select **+ Add a New Secret**.
  </Step>
  <Step>
    In the **Key** and **Value** fields, enter a key-value pair. For example:

    <Frame>
      ![Key and Value fields](./assets/key-value-fields.png)
    </Frame>
  </Step>
  <Step>
    Select **Create Secret**.
  </Step>
  <Step>
    Repeat these steps for each key-value pair you want to add.
  </Step>
</Steps>
</Tab> <Tab title="Import secrets from an existing file"> To import secrets from an existing file:
<Steps>
  <Step>
    Drag and drop the file containing your secrets (or enter the file's contents manually by selecting **Paste Secrets**).
  </Step>
  <Step>
    Review the discovered secrets. For example:

    <Frame>
      ![Review secrets](./assets/review-secrets.png)
    </Frame>
  </Step>
  <Step>
    Select **Upload Secrets**.
  </Step>
</Steps>
</Tab> </Tabs>

Step 2: Connect your app to Infisical

Now that you've set up a project that holds your secrets in Infisical, you can connect your application and give it access to those secrets at runtime.

Authenticate with the CLI

Authenticate with the Infisical CLI by running infisical login:

bash
infisical login

This prompts you to select your hosting option, then opens your browser to complete the login.

<Note> In a containerized environment such as WSL 2 or Codespaces, run `infisical login -i` to avoid browser-based login. </Note>

Connect your project

Next, connect your application to your Infisical project:

<Steps> <Step> In your application's directory, link it to the Infisical project you created by running [`infisical init`](/cli/commands/init):
```bash
infisical init
```
</Step> <Step> Follow the prompts to select the organization/project where you created your secrets earlier. This writes a `.infisical.json` file to your project with [local project settings](/cli/project-config):
```json .infisical.json
{
  "workspaceId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "defaultEnvironment": "",
  "gitBranchToEnvironmentMapping": null
}
```

<Note>
`.infisical.json` files contain no secrets and are safe to commit to version control systems like git.
</Note>
</Step> </Steps>

Step 3: Inject secrets into your app

Now that your Infisical project is configured within your application, Infisical can provide the secrets.

Start your application by wrapping its start command with infisical run:

<CodeGroup> ```bash Node.js infisical run --env=dev -- npm run dev ```
bash
infisical run --env=dev -- flask run
bash
infisical run --env=dev -- go run main.go
</CodeGroup>

Infisical fetches the secrets and injects them as environment variables. This lets your application read the secrets from its environment at runtime.

<Check> You can now manage your application's secrets through Infisical without needing a `.env` file. </Check>

Next Steps

<CardGroup cols={2}> <Card title="Core Concepts" icon="book" href="/documentation/platform/secrets-mgmt/concepts/secrets-mgmt"> Understand how projects, environments, folders, and secrets fit together. </Card> <Card title="Secrets Delivery" icon="truck-fast" href="/documentation/platform/secrets-mgmt/concepts/secrets-delivery"> Deliver secrets to production with SDKs, agents, Kubernetes, and CI/CD. </Card> <Card title="Local Development Guide" icon="laptop-code" href="/documentation/guides/local-development"> Set up a secure local development workflow for your whole team. </Card> <Card title="Access Control" icon="shield-halved" href="/documentation/platform/secrets-mgmt/concepts/access-control"> Scope who can access which environments and paths. </Card> </CardGroup>