Secure Production Deployment: Cloudflare and Sentry | Intway
Tecnologías / Secure Production Deployment and Monitoring: Cloudflare, Sentry and Tunnels
Technology Cloud & DevOps

Secure production deployment: nothing left open and errors in sight

· upd.

What is exposed, how to reach servers without opening them and how to learn about an error before your customer.

Cloudflare · WAF · tunnelsSentry · monitors · alertsFirewalls · Session ManagerNext.js · NestJS · AWS

We put systems into production securely and keep them monitored. Between finished code and a system in use there are three questions worth answering before day one: what is exposed to the Internet, how you get into the servers without leaving them open and how you find out about an error before your customer does. For that we propose Cloudflare in front of the system, tunnels and firewalls to lock the servers down, and Sentry for errors; what goes into each system is decided project by project. The security of the application itself (permissions, sessions, other customers' data) is checked separately, with an OWASP audit and penetration tests.

What is exposed to the Internet

The rule is simple: only the web and the API are reachable from the Internet, and only through a proxy that filters. Everything else stays closed: the database, Redis (the fast in-memory store the system uses), the admin panel and the server console. This is how a typical system looks:

Part of the systemOpen to the Internet?How it's reached
Web and APIYes, behind the proxyCloudflare, with a web application firewall and rate limiting
Admin panelOnly its entry address, which requires identity; the server takes no direct connectionsWith the company account and a second factor; from there to the panel, through the tunnel
Server consoleNoThrough a tunnel or AWS Session Manager, with port 22 closed
DatabaseNoOnly from the API, inside the private network
RedisNoFrom the API and authorized processes, inside the private network

What gets forgotten most: a DNS record pointing straight at the server, bypassing the proxy. That record exposes the server's IP to anyone who looks it up and, if the server accepts direct requests, the IP lets it be attacked around the protections.

Cloudflare in front of the system

Cloudflare sits between users and your servers: it receives every request, filters it and only then passes it on. We set it up like this:

  • Encryption on each leg. Cloudflare opens the request to filter it and encrypts it again, so there are two legs. The first, between the user and Cloudflare, is HTTPS: Cloudflare redirects every HTTP request to HTTPS. The second depends on how it reaches the server. If it goes direct, we use Full (strict) mode: Cloudflare validates the origin certificate it issues for free for up to 15 years. Flexible mode leaves that leg unencrypted: we don't use it. If it goes through a tunnel, it's encrypted up to the tunnel program; from there to the service it stays on the same machine or, if the service is on another one, goes over HTTPS with a validated certificate.
  • Cloudflare WAF (web application firewall). Managed rules stop known attacks, such as SQL injection or a request for /.env. The free plan includes the basic rules; paid plans add the full set and the OWASP set. On top go our own rules, for example blocking /admin on the website's public address, because the panel has its own protected address. Traffic that reaches the server directly doesn't go through this firewall: the network and the server close that off.
  • Rate limiting to cut off anyone trying passwords one after another: the free plan allows a single rule, which we put on sign-in. Public forms get Turnstile, the free CAPTCHA alternative, and the server validates every response before processing the form.
  • Denial-of-service protection, included in every plan.
  • The server only talks to Cloudflare. If the server accepts requests from any IP, the proxy can be bypassed. Cloudflare's addresses belong to its whole network, not just your account, so allowing them isn't enough: with a direct server, we add origin authentication with our own certificate; better still, we use a tunnel and leave no port open. We also change the server's IP when it goes behind Cloudflare, because the old one is still in earlier DNS records and in the mail records.
Secure production deployment: an exposure inventory with the web and the API behind the proxy and through a tunnel, and a record that exposes the server's IP
What is exposed, at a glanceExample: the web, the API and the admin panel go through the proxy and a tunnel; the database record exposes the server's IP and has to go.

Cloudflare Tunnel and server firewalls: no open ports

A Cloudflare tunnel turns the connection around: a small program on your server (cloudflared) connects out to Cloudflare and brings the requests in that way. The server needs no public IP and no open port, so the firewall can reject everything coming in. Each instance opens four connections to at least two data centers. With a second instance, if one goes down the other keeps serving, as long as it reaches a service that's working: that's tested route by route.

The admin panel stays on a private server. It's reached through a protected entry address: first the access rule is created, requiring the company account with a second factor, and the tunnel rejects any request that doesn't carry the token that rule issues. Every sign-in is logged. When someone leaves the company, their account is deactivated and their open sessions are revoked: deactivation alone leaves an existing session valid until it expires. The server console goes the same way or, on AWS, through Session Manager, which needs no open ports, bastion host or SSH keys. With its logging turned on, it records what was done in each of its own console sessions (not those that go through SSH or port forwarding).

Each server's firewall starts by closing everything and opens only what's needed: the database accepts connections only from the API, and Redis from the API and authorized processes. On AWS we do this with security groups, which allow nothing that isn't in a rule; accounts and networking are covered in AWS development and architecture.

Sentry monitoring: finding out about an error before your customer does

An error in production that nobody reports keeps happening every day. Sentry collects the errors it captures in the web, the API or the app, and each one arrives with the context available: the file and line, the user's previous steps, the released version and how many people that issue affected. It doesn't see everything: what the code doesn't capture, what gets filtered or what goes over the plan's limit stays out. We set it up like this:

  • Readable lines. The code that reaches the browser is minified; we upload the source maps of every build that's released so the error shows the original file and line.
  • Every error with its release and environment, to know which change brought it and to keep production apart from staging. After each release we check crash-free sessions and that release's new issues.
  • Nothing sensitive in errors. We configure what data the SDK collects in the version in use, filter cookies, authorization headers and the body of sign-in forms in every part that sends data (browser and server), for errors and performance data alike, and check it with a test that generates an error and a trace with fake data and reviews what goes out before it reaches Sentry. Sentry also masks passwords, tokens and card numbers on its side. If the user's session is recorded, all text and inputs are masked by default.
  • Monitors and alerts. That the web and the API respond, that scheduled jobs (the daily close, the backup, the invoice delivery) run on time, and that errors don't rise after a release. Each monitor has a rule that alerts whoever is on call by Slack or email.
  • Where the data lives. Errors go to the region you choose, the United States or the European Union; some data, such as scheduled-job and uptime data, may stay in the United States. If nothing can leave, Sentry is installed on your own servers.
Production error monitoring with Sentry: a phone alert and the error with the exact line, previous steps and sensitive data filtered
The alert arrives before the complaintExample: the error reaches the phone within minutes, with the line of code, the release and the request data filtered.

Best practices for putting a system into production

These are the rules we work by. What gets published, who gets in and whom each alert notifies are agreed with you and tested before go-live.

Network and access

  • No open port that isn't needed: not 22, not the database's, not Redis's.
  • Access with the company account and a second factor for everything internal, with every sign-in logged; when someone leaves, their account is deactivated and their open sessions revoked.
  • Separate environments: staging and production with different domains, credentials and tunnels.

Cloudflare

  • Every leg encrypted: Full (strict) mode if the server receives traffic directly; never Flexible.
  • No DNS record that exposes the server's IP, checked on every change.
  • Firewall rules and rate limits written as code and reviewed like any change, not edited by hand in the dashboard.

Errors and logs

  • JSON logs with one ID per request, the same one that goes into the Sentry error, to follow a problem from the screen to the database.
  • Never passwords, tokens, session IDs or connection strings in logs or errors, as the OWASP logging guide says, with a test that checks it.
  • Every alert with an owner and a way to resolve it; an alert nobody looks at gets switched off or fixed.

Releases

  • Security headers from day one (HSTS, Content-Security-Policy, nosniff, Referrer-Policy), as we explain in Next.js and NestJS development.
  • Secrets out of the code and different per environment.
  • Backups tested by restoring them, and a monitor that alerts if one didn't run.

Case studies

The cases don't detail which tools were used for this: this is what operations had to guarantee in each one.

Starting pointWhat operations had to guaranteeCase
A regional Visual Basic and ASP Classic payroll engine that required Internet ExplorerFollowing a payroll run from the screen to the API, the queue and the engine, with alerts on errors, retries and timings; encryption, managed secrets, backups and audit logsSee the case
More than 300 companies clocking in with face recognitionEach clock-in image travels and is stored encrypted, and only users with permission at that company can see itSee the case

How much does a secure production setup cost?

It depends on how many systems and environments there are, whether they already run in the cloud or on your own servers, what has to be closed and who gets the alerts. The tools aren't usually the expensive part. Cloudflare has a free plan with denial-of-service protection and basic firewall rules. Sentry's free plan covers one person, one scheduled-job monitor and one uptime monitor, with email alerts; more than one scheduled-job or uptime monitor, or Slack alerts, already need a paid plan, even if one person runs it. The work is reviewing what's exposed today, closing it without interrupting the service and getting the alerts running. How we put the number together is in how to estimate a software project, and for your system, get in touch.

Common mistakes

  • Cloudflare in Flexible mode. The padlock shows in the browser, but between Cloudflare and the server the data travels unencrypted.
  • The server still accepts anyone. With the IP in plain sight, the attack bypasses the proxy.
  • Port 22 open to the whole Internet “because it has a password”.
  • The admin panel published like any other page, protected only by its own sign-in.
  • Deactivating someone without revoking their sessions. They keep getting in until the session expires.
  • Errors carrying personal data or tokens, stored in an external service.
  • Alerts that go off all day. By day three nobody looks at them, and the important one slips by.
Secure production deployment with Cloudflare, tunnels and Sentry: a panel of what is exposed and error alerts

How we put a system into production

What sits in front, what stays closed and what alerts you when something fails.

Firewall dashboard with flagged requests: blocked by managed rules, SQL injection and rate limiting

Cloudflare in front of the system

Every request is filtered before it arrives.

Ver más →
Terminal with a firewall denying all inbound traffic and a panel of tunnels with their production routes

Tunnels: no open ports

The server connects out; nobody connects in.

Ver más →
Tablet with the access log after signing in with a second factor, including a deactivated user with revoked sessions

Internal tools, identity only

Company account and a second factor.

Ver más →
Error-tracking tool with an issue from the released version: file, line, previous steps and filtered data

Errors with their line and release

Sentry, with no sensitive data.

Ver más →
Support TV with the monitoring console: uptime, scheduled jobs, alerts and owners

Monitors and on-call

If something doesn't respond or run, someone knows.

Ver más →
What we solve

What we solve when putting a system into production

What goes wrong when a system goes online without closing what's extra or watching what fails.

Servers left too open

The database, Redis or port 22 answer anyone on the Internet.

A proxy that can be bypassed

The server's IP is in plain sight and attacks arrive directly, unfiltered.

Errors reported by customers

You learn about a failure when someone calls to complain, days later.

Jobs that stop running

The backup or the invoice delivery didn't run and nobody noticed.

How we work

How we work

1

Review

What's exposed today, how the servers are reached and what's being watched.

2

Plan

What gets published, what gets closed, who gets in and whom each alert notifies.

3

Lockdown without downtime

Proxy, tunnels, firewalls and Sentry, environment by environment, staging first.

4

On call

Monitors, alerts with an owner and a review after every release.

25+
Years building software
500+
Projects
300+
Companies on the time-and-attendance platform
10,000+
Users on the time-and-attendance platform
FAQ
What is Cloudflare for in a business system?

It sits in front of the system: it encrypts traffic, stops known attacks with its web application firewall, rate-limits sign-in and the API, and absorbs denial-of-service attacks. Set up well, your server only serves requests that came through Cloudflare.

Which Cloudflare encryption mode should I use?

If the server receives traffic directly, Full (strict), with an origin certificate on your server. Flexible mode only encrypts between the user and Cloudflare: between Cloudflare and your server the data travels unencrypted. With a tunnel, it's encrypted up to the tunnel program on your server; from there to the service, on the same machine or over HTTPS with a validated certificate.

What is Cloudflare Tunnel?

A small program (cloudflared) that runs on your server and connects out to Cloudflare to bring requests in. Because the connection starts from the inside, the server needs no public IP or open ports, and the firewall can reject everything coming in.

Does Sentry store users' personal data?

It can store whatever it's sent. So we configure what data it collects, filter cookies, authorization headers and sign-in forms before sending, and check it with a test using fake data; Sentry also masks fields such as passwords, tokens and card numbers on its side. Errors go to the chosen region (the United States or the European Union), though some monitor data may stay in the United States; if nothing can leave, it's installed on your own servers.

Do I need to close port 22?

Yes. The server console is reached through a tunnel with the company account or, on AWS, through Session Manager, which needs no open ports or SSH keys and, with its logging on, records what was done in its own console sessions, not in those that go through SSH or port forwarding.

How much does it cost?

It depends on how many systems and environments there are and what's exposed today. Cloudflare has a free plan; Sentry's covers one person, one scheduled-job monitor and one uptime monitor; the work is reviewing, closing without interrupting the service and getting the alerts running. We quote it after a first conversation.

Let's talk about your system

Tell us how it's published today and we'll tell you what to close first and what to watch.

Contact us