The Simplest Way to Make GitLab CI and Tcp Proxies Work Like They Should
Using gitlab ci and tcp proxies lets build jobs reach private network ports safely. This setup routes runner traffic to internal databases and services during automated deploys. Teams use this pairing to run database migrations and integration tests from cloud runners. The runner starts a job, opens a tunnel, and sends traffic to the private host. When the job ends, the runner closes the port right away. This flow keeps private databases off the public internet during every release. How gitla
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Using gitlab ci and tcp proxies lets build jobs reach private network ports safely. This setup routes runner traffic to internal databases and services during automated deploys.
Teams use this pairing to run database migrations and integration tests from cloud runners. The runner starts a job, opens a tunnel, and sends traffic to the private host. When the job ends, the runner closes the port right away. This flow keeps private databases off the public internet during every release.
How gitlab ci and tcp proxies handle traffic and keys
A GitLab runner starts a fresh job container for every pipeline step. That container needs a clear network path to reach private ports inside your cloud. The runner reads job variables or tokens to verify its identity first. Then the job opens a local socket that forwards packets to the remote host.
Data flows through this encrypted path as raw TCP packets. The build script speaks native database or service protocols over the local port. The remote host checks the source IP and the service role before accepting traffic. Once verified, the job runs its schema changes or test queries and exits.
Teams should map each GitLab project to a distinct service identity. When a job runs on a protected branch, it gets production role rights. Jobs on feature branches only receive staging role rights and staging network routes. This separation stops test code from touching live production tables by mistake.
Common failure modes and how to scope network paths
Many teams store one shared static key in group variables for all pipelines. If any job leaks that key in build logs, attackers gain broad network reach. Shared service accounts also make it hard to trace which pipeline ran a query. In database logs, every pipeline action looks like the same generic user.
Broad network rules create another major risk for build systems. If a runner can reach every port in a subnet, a bad script can scan hosts. Open ports also stay active if a build job hangs or crashes mid-run. Stale sockets can exhaust connection pools on your target database over time.
GitLab CI Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix this, scope each runner to the exact IP and port it needs. Set strict timeouts on both the job step and the network socket. Use dynamic job tokens instead of static secrets stored in shared group settings. Rotate service roles often and log every socket open event with the job ID.
Best practices for reliable pipeline network sessions
Network drops often break long deployment jobs during peak hours. Build scripts should check that the local port is listening before sending queries. Adding a brief health check step saves time when a remote host is down. It fails the pipeline fast and gives the team a clear error message.
Keep test data safe when pipelines read from staging databases. Data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in results. This keeps sensitive strings out of runner build logs and test artifacts. Always scrub job logs and close background processes before the runner finishes the step.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Why do my pipeline jobs hang when opening a TCP tunnel?
Jobs usually hang when a background tunnel process keeps standard output open. Run the background process quietly and set a strict timeout on the job step.
How can I stop feature branch jobs from reaching production ports?
Scope your network credentials and host variables to protected branches only. Use separate runners and role rules for staging and production jobs.
What should I log when a build job talks to a private database?
Record the GitLab job ID, commit hash, target host, and timestamp for every session. This helps your team trace every schema change back to a specific code commit.
Related guides
In this post