Back to Infisical

infisical gateway

docs/cli/commands/gateway.mdx

0.162.2212.7 KB
Original Source
<Tabs> <Tab title="CLI"> ```bash infisical gateway start <gateway-name> --enroll-method=token --token=<enrollment-token> --domain=<domain> ``` </Tab> <Tab title="systemd"> ```bash sudo infisical gateway systemd install <gateway-name> --enroll-method=token --token=<enrollment-token> --domain=<domain> ``` </Tab> </Tabs>

Description

The Infisical gateway provides secure access to private resources using modern TCP-based SSH tunnel architecture with enhanced security and flexible deployment options.

The gateway system uses SSH reverse tunnels over TCP, eliminating firewall complexity and providing excellent performance for enterprise environments.

Subcommands & flags

<AccordionGroup> <Accordion title="infisical gateway start" defaultOpen="true"> Run the Infisical gateway component within your the network where your target resources are located. The gateway establishes an SSH reverse tunnel to a relay server and provides secure access to private resources within your network.
bash
infisical gateway start <gateway-name> --enroll-method=token --token=<enrollment-token> --domain=<domain>

The gateway name is provided as a positional argument.

<Info> By default, the gateway automatically connects to the relay with the lowest latency. To target a specific relay, use the `--target-relay-name=<relay-name>` flag. </Info>

Once started, the gateway component will:

  • Automatically connect to a healthy relay with the lowest latency (unless the --target-relay-name flag is specified)
  • Establish outbound SSH reverse tunnel to relay server (no inbound firewall rules needed)
  • Authenticate using SSH certificates issued by Infisical
  • Automatically reconnect if the connection is lost, and fail over to a different healthy relay if the current one becomes unreachable
  • Provide access to private resources within your network

Flags

<AccordionGroup> <Accordion title="--enroll-method"> How the gateway authenticates with Infisical. Must match the auth method configured on the gateway in the Infisical UI. One of `token`, `aws`, or `kubernetes`.
<Tabs>
  <Tab title="token">
    A one-time enrollment token from the Infisical UI bootstraps the gateway.

    <ParamField query="Flags">
    <Expandable title="properties">
        <ParamField query="token" type="string" required>
          The one-time enrollment token from the Infisical UI.
        </ParamField>
        <ParamField query="domain" type="string" required>
          The URL of your Infisical instance.
        </ParamField>
    </Expandable>
    </ParamField>

    ```bash
    infisical gateway start my-gateway --enroll-method=token --token=<enrollment-token> --domain=https://app.infisical.com
    ```

    After enrollment, the gateway saves its credentials locally. You can safely re-run the same command to restart the gateway. It will detect the token has already been used and skip enrollment automatically.
  </Tab>
  <Tab title="aws">
    The gateway signs an `sts:GetCallerIdentity` request with whatever AWS credentials it can resolve on the host (instance role, environment variables, shared profile), and re-authenticates on every start. No token is stored on disk.

    <ParamField query="Flags">
    <Expandable title="properties">
        <ParamField query="gateway-id" type="string" required>
          The gateway ID from the Infisical UI.
        </ParamField>
        <ParamField query="domain" type="string" required>
          The URL of your Infisical instance.
        </ParamField>
    </Expandable>
    </ParamField>

    ```bash
    infisical gateway start my-gateway --enroll-method=aws --gateway-id=<gateway-id> --domain=https://app.infisical.com
    ```
  </Tab>
  <Tab title="kubernetes">
    The gateway authenticates with the projected service account token of the pod it runs in, so no credential has to be distributed to the cluster. Infisical verifies the token against your cluster's TokenReview API and re-authenticates on every start. No token is stored on disk.

    This method requires the gateway to run inside a Kubernetes pod. Deploying with the [Helm chart](/self-hosting/helm-charts/gateway) is the recommended path.

    <ParamField query="Flags">
    <Expandable title="properties">
        <ParamField query="gateway-id" type="string" required>
          The gateway ID from the Infisical UI.
        </ParamField>
        <ParamField query="domain" type="string" required>
          The URL of your Infisical instance.
        </ParamField>
        <ParamField query="service-account-token-path" type="string">
          Path to the projected service account token. Defaults to `/var/run/secrets/kubernetes.io/serviceaccount/token`.
        </ParamField>
    </Expandable>
    </ParamField>

    ```bash
    infisical gateway start my-gateway --enroll-method=kubernetes --gateway-id=<gateway-id> --domain=https://app.infisical.com
    ```

    See [Gateway Deployment](/documentation/platform/gateways/gateway-deployment) for the cluster host and allowlist configuration this method needs.
  </Tab>
</Tabs>
</Accordion> <Accordion title="--target-relay-name"> The name of the relay that this gateway should connect to. The relay must be running and registered before starting the gateway.
If this flag is omitted, the gateway will automatically connect to a healthy relay with the lowest latency.

```bash
# Example
infisical gateway start my-gateway --target-relay-name=my-relay --enroll-method=token --token=<token> --domain=<domain>
```

**Note:** For Infisical Cloud users using instance relays, the relay infrastructure is already running and managed by Infisical. If using organization relays or self-hosted instance relays, you must first start a relay server. For more information on deploying relays, refer to the [Relay Deployment Guide](/documentation/platform/gateways/relay-deployment).
</Accordion> <Accordion title="--domain"> Domain of your self-hosted Infisical instance.
```bash
# Example
infisical gateway start <gateway-name> --domain=https://app.your-domain.com --enroll-method=token --token=<token>
```
</Accordion> <Accordion title="--pkcs11-module"> Absolute path to the PKCS#11 driver shipped by your HSM vendor. When set, the gateway loads the driver on startup and is reachable by HSM Connectors for signing operations.
```bash
# Example
infisical gateway start <gateway-name> --enroll-method=token --token=<token> --domain=<domain> --pkcs11-module=/opt/fortanix/pkcs11/fortanix_pkcs11.so
```

See [HSM Connectors](/documentation/platform/pki/settings/hsm-connectors) for the full setup.
</Accordion> </AccordionGroup> </Accordion> <Accordion title="infisical gateway systemd install"> Install and enable the gateway as a systemd service. This command must be run with sudo on Linux.
bash
sudo infisical gateway systemd install my-gateway --enroll-method=token --token=<enrollment-token> --domain=<domain>

Requirements

  • Must be run on Linux
  • Must be run with root/sudo privileges
  • Requires systemd

Flags

<AccordionGroup> <Accordion title="--enroll-method"> How the gateway authenticates with Infisical. One of `token` or `aws`.
```bash
# Enrollment token
sudo infisical gateway systemd install my-gateway --enroll-method=token --token=<enrollment-token> --domain=<domain>

# AWS auth, re-authenticated on every service start
sudo infisical gateway systemd install my-gateway --enroll-method=aws --gateway-id=<gateway-id> --domain=<domain>
```

`kubernetes` is not available here. In-cluster gateways are not managed by systemd, so run `infisical gateway start --enroll-method=kubernetes` as the container command instead.
</Accordion> <Accordion title="--token"> The one-time enrollment token from the Infisical UI.
```bash
# Example
sudo infisical gateway systemd install my-gateway --enroll-method=token --token=<token> --domain=<domain>
```
</Accordion> <Accordion title="--domain"> Domain of your self-hosted Infisical instance.
```bash
# Example
sudo infisical gateway systemd install my-gateway --enroll-method=token --token=<token> --domain=https://app.your-domain.com
```
</Accordion> <Accordion title="--target-relay-name"> The name of the relay that this gateway should connect to. The relay must be running and registered before starting the gateway.
If this flag is omitted, the gateway will automatically connect to a healthy relay with the lowest latency.

```bash
# Example
sudo infisical gateway systemd install my-gateway --target-relay-name=my-relay --enroll-method=token --token=<token> --domain=<domain>
```

**Note:** For Infisical Cloud users using instance relays, the relay infrastructure is already running and managed by Infisical. If using organization relays or self-hosted instance relays, you must first start a relay server. For more information on deploying relays, refer to the [Relay Deployment Guide](/documentation/platform/gateways/relay-deployment).
</Accordion> <Accordion title="--pkcs11-module"> Absolute path to the PKCS#11 driver shipped by your HSM vendor. When set, the systemd unit captures the flag so every restart loads the same driver and the gateway is reachable by HSM Connectors.
```bash
# Example
sudo infisical gateway systemd install my-gateway --enroll-method=token --token=<token> --domain=<domain> --pkcs11-module=/opt/fortanix/pkcs11/fortanix_pkcs11.so
```

See [HSM Connectors](/documentation/platform/pki/settings/hsm-connectors) for the full setup.
</Accordion> </AccordionGroup>

Service details

The systemd service is installed with secure defaults:

  • Service file: /etc/systemd/system/<gateway-name>.service
  • Config file: /etc/infisical/gateways/<gateway-name>.conf
  • Runs with restricted privileges:
    • InaccessibleDirectories=/home
    • PrivateTmp=yes
    • Resource limits configured for stability
  • Automatically restarts on failure
  • Enabled to start on boot
  • Maintains persistent SSH reverse tunnel connections to the specified relay
  • Handles certificate rotation and connection recovery automatically

After installation, manage the service with standard systemd commands (replace my-gateway with your gateway name):

bash
sudo systemctl start my-gateway    # Start the service
sudo systemctl stop my-gateway     # Stop the service
sudo systemctl status my-gateway   # Check service status
sudo systemctl disable my-gateway  # Disable auto-start on boot
</Accordion> <Accordion title="infisical gateway systemd uninstall"> Uninstall and remove the gateway systemd service. This command must be run with sudo on Linux.
bash
sudo infisical gateway systemd uninstall my-gateway

The gateway name is provided as a positional argument.

</Accordion> </AccordionGroup>

Frequently asked questions

<AccordionGroup> <Accordion title="Can I re-run the same enrollment command after a restart?"> Yes. The CLI stores the enrollment token locally after the first successful enrollment. If you run the same command again with the same `--token` value, it detects the token has already been used and skips enrollment, proceeding directly to start the gateway. This means you can safely use the same command (e.g., via up-arrow in your shell) without getting "token already used" or "token expired" errors. </Accordion> <Accordion title="How are relays auto-selected?"> If the `--target-relay-name` flag is omitted, the gateway automatically selects the optimal relay. It first checks for healthy organization relays and connects to the one with the lowest latency. If no organization relays are available, it then performs the same latency-based selection among the available managed relays.
  If the selected relay becomes unreachable while the gateway is running, the gateway will automatically switch to a different healthy one. Gateways started with an explicit `--target-relay-name` do not switch and will keep retrying the specified relay.
</Accordion> <Accordion title="When restarting the gateway without a relay flag, does it select a new relay every time?"> No. The first time the gateway starts, it selects the optimal relay (based on latency) and caches that selection. On subsequent restarts, it will prioritize connecting to the cached relay. If it's unable to connect, it will then re-evaluate and connect to the next most optimal relay available. </Accordion> <Accordion title="Will additional authentication methods be supported?"> Yes. Additional gateway authentication methods are planned for future releases. </Accordion> </AccordionGroup>