# Static IP in GitLab CI/CD

Source: https://prontaro.com/docs/integrations/gitlab-ci/

Protect production firewalls from GitLab.com's shared pools by routing only the jobs that need a fixed IPv4 through Prontaro.

GitLab.com Shared Runners exit from rotating Google Cloud addresses that change between runs. You can keep dedicated CI variables separate from production credentials: HTTP calls use a proxy or Relay URL, while database migrations and SSH/SFTP deploys run through `prontaro forward` without affecting the rest of your pipeline.

## Which method to choose

| Pipeline task | Prontaro method | CLI install needed? |
| --- | --- | --- |
| **REST API calls, webhooks, smoke tests (`curl`, Node, Python, Go)** | `PRONTARO_PROXY_URL` on that step | No |
| **Database migrations (`psql`, Prisma, Flyway) and SSH/SFTP deploys** | `PRONTARO_KEY` + `prontaro forward` | Yes (single binary) |
| **Simple HTTPS call to one allowlisted host** | `PRONTARO_RELAY_URL` | No |

## Prerequisites

- A Prontaro account on Dedicated or Pro ([plans and pricing](https://prontaro.com/docs/billing/plans.md)) with a dedicated IPv4.
- Your dedicated IP (`/32`) added to the destination API, database, or firewall allowlist.
- Maintainer or Owner access in your GitLab project to manage **Settings → CI/CD → Variables**.

## Step 1. Create proxy credentials or a CLI token

Create separate credentials dedicated to GitLab CI so you can revoke pipeline access independently of production apps and developer laptops.

### Proxy credentials without CLI

1. Open **IP addresses** in [my.prontaro.com](https://my.prontaro.com/ips), pick your IP, and click **Create proxy credentials**.
2. Name them `gitlab-ci` and copy the `https://` connection string on port `:443`.

IP addresses Proxy credentials [Open in dashboard](https://my.prontaro.com/ips)

### CLI token for `prontaro forward`

Issue a dedicated CLI token named `gitlab-ci` in the dashboard:

CLI [Open in dashboard](https://my.prontaro.com/cli)

The `prontaro` CLI reads `PRONTARO_KEY` directly from the environment, so you do not need to run `prontaro login` or write credentials to the runner disk.

## Step 2. Add CI/CD Variables in GitLab

Open **Settings → CI/CD → Variables** and create the variable for your path. Enable both **Masked** (redacts the value in job logs) and **Protected** (exposes the variable only on protected branches and tags such as `main` or `v*`).

**Project → Settings → CI/CD → Variables**

- `PRONTARO_PROXY_URL`: `https://u_ci:s3cr3t@<entry>.prontaro.io:443 (Masked, Protected)`
- `PRONTARO_KEY`: `prontaro.<cli-token> (Masked, Protected)`

> **Disable variable expansion and isolate fork merge requests**
>
> 1. Uncheck **Expand variable reference** in GitLab so `$` characters in secrets are passed literally instead of expanded.
> 2. Keep **Protected** enabled to block fork merge requests from reading secrets. For `staging` and `production`, use **Environment scope** with separate Prontaro credentials.

## Step 3. Verify the outbound IP

Before restricting allowed proxy targets, confirm that your runner exits through your dedicated IPv4. Add a temporary manual job to `.gitlab-ci.yml`:

```yaml
verify_egress_ip:
  stage: test
  image: curlimages/curl:8.11.1
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      when: manual
  script:
    - curl -fsS --proxy "$PRONTARO_PROXY_URL" https://api.ipify.org
```

Run `verify_egress_ip` manually on a protected branch. The job log should print your dedicated address:

```
 curl -fsS --proxy "$PRONTARO_PROXY_URL"
203.0.113.10
```

## Step 4. Restrict allowed targets

Once `api.ipify.org` confirms the address, lock the `gitlab-ci` credentials down to the exact hosts and ports your pipeline calls. Because Shared Runners use dynamic IPs, keep the source allowlist open and tighten the destination list.

1. Open the `gitlab-ci` credentials under **IP addresses** in [my.prontaro.com](https://my.prontaro.com/ips) and switch to the **Access** tab.
2. Under **To**, add the required `host:port` entries (for example `api.example.com:443`) and save.

IP addresses Proxy credentials Access [Open in dashboard](https://my.prontaro.com/ips)

## Path A. API calls without installing the CLI

Pass `PRONTARO_PROXY_URL` only to the commands that need your static IP:

```yaml
partner_sync:
  stage: deploy
  image: curlimages/curl:8.11.1
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
  script:
    - |
      curl -fsS --proxy "$PRONTARO_PROXY_URL" \
        -H "Authorization: Bearer $PARTNER_API_TOKEN" \
        https://api.example.com/v1/sync
```

> **Never set HTTPS_PROXY globally for the whole pipeline**
>
> Exporting `HTTPS_PROXY` in the top-level `variables:` block routes `git fetch`, Docker pulls, `npm ci`, and artifact uploads through Prontaro, slowing down builds and consuming your monthly traffic allowance (100 GB on Dedicated). Scope the proxy to the exact command or job that needs it.

## Path B. Database migrations and SSH/SFTP deploys with `prontaro forward`

For PostgreSQL, MySQL, MongoDB, or SSH/SFTP deploys, install the `prontaro` binary inside the job. The CLI picks up `PRONTARO_KEY` automatically from the GitLab CI environment.

```yaml
migrate_prod_db:
  stage: deploy
  image: postgres:16-alpine
  environment:
    name: production
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
      when: manual
  before_script:
    - apk add --no-cache curl netcat-openbsd
    - curl -fsSL https://prontaro.com/install.sh | sh
    - export PATH="$HOME/.local/bin:$PATH"
  script:
    - |
      set -euo pipefail
      prontaro forward 15432 db.example.com:5432 --ip 203.0.113.10 &
      FWD_PID=$!
      trap 'kill "$FWD_PID" 2>/dev/null || true' EXIT

      for i in $(seq 1 30); do
        if nc -z 127.0.0.1 15432; then break; fi
        sleep 0.5
      done
      if ! nc -z 127.0.0.1 15432; then
        echo "prontaro forward did not open 127.0.0.1:15432" >&2
        exit 1
      fi

      PGPASSWORD="$DATABASE_PASSWORD" psql \
        "postgresql://${DATABASE_USER}@127.0.0.1:15432/app?sslmode=require" \
        -f migrations/001_schema.sql
```

For SSH or SFTP deploys, point `prontaro forward` at `deploy.example.com:22` on local port `2222` and pass `-o HostKeyAlias=deploy.example.com` so OpenSSH verifies the real host key in `known_hosts`:

```bash
prontaro forward 2222 deploy.example.com:22 --ip 203.0.113.10 &
FWD_PID=$!
trap 'kill "$FWD_PID" 2>/dev/null || true' EXIT

for i in $(seq 1 30); do
  if nc -z 127.0.0.1 2222; then break; fi
  sleep 0.5
done

ssh -p 2222 -o HostKeyAlias=deploy.example.com -o StrictHostKeyChecking=yes \
  deploy@127.0.0.1 "cd /srv/app && ./deploy.sh"
```

> **Always stop background prontaro forward with trap**
>
> Without `trap 'kill "$FWD_PID" 2>/dev/null || true' EXIT`, the background process keeps stdout/stderr open and the GitLab job hangs until its timeout expires.
>
> On Pro accounts with multiple IPv4 addresses, `prontaro forward` exits with an error in non-interactive CI unless `--ip <your-IP>` is passed explicitly.

## Common errors

| Symptom | Cause | Fix |
| --- | --- | --- |
| Empty `PRONTARO_PROXY_URL` or `PRONTARO_KEY` | Variable is marked **Protected** and the job ran on an unprotected branch. | Run on a protected branch or update **Protected branches / tags**. |
| `407 Proxy Authentication Required` | Wrong password, a `$` character in the secret mangled by **Expand variable reference**, or new credentials are still propagating. | Uncheck **Expand variable reference**, re-copy the URL, and retry after a few seconds. |
| `403 target_denied` | Destination host or port is missing from the **To** list. | Add `host:port` under **To** in the credentials’ **Access** tab in [IP addresses](https://my.prontaro.com/ips). |
| `You have 2 addresses — choose which one to go out from` | Account has multiple IPs on Pro and `--ip` was omitted in CI. | Pass `--ip <your-IP>` to `prontaro forward`. |
| Job hangs after migration succeeds | Background `prontaro forward` was not terminated on exit. | Add `trap ’kill “$FWD_PID” 2>/dev/null |

## Next steps

- [Security, TLS, and production checklist](https://prontaro.com/docs/outbound/security.md) — target allowlists, secret rotation, and production hardening for outbound traffic.
- [Local port forwarding (`prontaro forward`)](https://prontaro.com/docs/outbound/forward.md) — outbound TCP connections to databases and SSH servers without SOCKS5.
- [HTTP & SOCKS5 proxy](https://prontaro.com/docs/outbound/proxy.md) — proxy credentials, destination rules, and password rotation.
- [Static IP in GitHub Actions](https://prontaro.com/docs/integrations/github-actions.md) — setting up proxy credentials, Relay URLs, and `prontaro forward` in GitHub workflows.
