Skip to content

Commit 8eb562f

Browse files
authored
docs(self-hosted): handle reverse proxy cors issues for ingest endpoints (#12513)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Someone on Discord pointed out that they had CORS issues from the browser when submitting events to Sentry. This patch is to make sure that would never happen. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 997f8cd commit 8eb562f

File tree

2 files changed

+93
-32
lines changed

2 files changed

+93
-32
lines changed

develop-docs/self-hosted/experimental/external-storage.mdx

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ sidebar_title: External Storage
44
sidebar_order: 90
55
---
66

7-
In some cases, storing Sentry data on-disk is not really something people can do. Sometimes, it's better to offload it into some bucket storage (like AWS S3 or Google Cloud Storage).
8-
97
<Alert title="Important" level="warning">
108
These are community-contributed docs. Sentry does not officially provide support for self-hosted configurations beyond the default install.
119
</Alert>
10+
11+
In some cases, storing Sentry data on-disk is not really something people can do. Sometimes, it's better to offload it into some bucket storage (like AWS S3 or Google Cloud Storage).
12+
1213
<Alert title="Note">
1314
After changing configuration files, re-run the <code>./install.sh</code> script, to rebuild and restart the containers. See the <Link to="/self-hosted/#configuration">configuration section</Link> for more information.
1415
</Alert>

develop-docs/self-hosted/experimental/reverse-proxy.mdx

+90-30
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ sidebar_order: 80
88
These are community-contributed docs. Sentry does not officially provide support for self-hosted configurations beyond the default install.
99
</Alert>
1010

11-
Adding a reverse proxy in front of your Sentry deployment is strongly recommended for one big reason: you can fine tune every configuration to fit your current setup. A dedicated reverse proxy that does SSL/TLS termination that also forwards the client IP address as Docker Compose internal network (as this is [close to impossible to get otherwise](https://github.com/getsentry/self-hosted/issues/554)) would give you the best Sentry experience.
11+
Adding a reverse proxy in front of your Sentry deployment is strongly recommended for one big reason: you can fine tune every configuration to fit your current setup. A dedicated reverse proxy that does SSL/TLS termination that also forwards the client IP address as Docker Compose internal network (as this is [close to impossible to get otherwise](https://github.com/getsentry/self-hosted/issues/554)) would give you the best Sentry experience.
1212

1313
Once you have setup a reverse proxy to your Sentry instance, you should modify the `system.url-prefix` in the `config.yml` file to match your new URL and protocol. You should also update the SSL/TLS section in the `sentry/sentry.conf.py` script, otherwise you may get CSRF-related errors when performing certain actions such as configuring integrations.
1414

15-
Keep in mind that all this setup uses single-nodes for all services, including Kafka. For larger loads, you'd need a beefy machine with lots of RAM and disk storage. To scale up even further, you are very likely to use clusters with a more complex tool, such as Kubernetes. Due to self-hosted installations' very custom nature, we do not offer any recommendations or guidance around scaling up. We do what works for us for our thousands of customers over at [sentry.io](https://sentry.io/) and would love to have you over when you feel your local install's maintenance becomes a burden instead of a joy.
15+
Keep in mind that all this setup uses single-nodes for all services, including Kafka. For larger loads, you'd need a beefy machine with lots of RAM and disk storage. To scale up even further, you are very likely to use clusters with a more complex tool, such as Kubernetes. Due to self-hosted installations' very custom nature, we do not offer any recommendations or guidance around scaling up. We do what works for us for our thousands of customers over at [sentry.io](https://sentry.io/) and would love to have you over when you feel your local install's maintenance becomes a burden instead of a joy.
1616

1717
## Enabling HTTPS
1818

19-
We recommend TLS termination to be done on your own dedicated load balancer or proxy. Although you can set it on the `nginx.conf` file, it is not recommended as newer self-hosted releases might alter some configurations on the file. Some examples are available on [Reverse Proxy Examples](#reverse-proxy-examples) section.
19+
We recommend TLS termination to be done on your own dedicated load balancer or proxy. Although you can set it on the `nginx.conf` file provided by the self-hosted installation, it is not recommended as newer self-hosted releases might alter some configurations on the file. Some examples are available on [Reverse Proxy Examples](#reverse-proxy-examples) section.
2020

2121
## Expose Only Ingest Endpoint Publicly
2222

2323
Certain self-hosted deployments requires the dashboard to be accessed only via internal network. But, they also need to provide public Sentry ingestion endpoint for client devices such as mobile and desktop apps. You can expose some of these endpoints publicly:
2424

25-
- `/api/[1-9]\d*/envelope/` - Main endpoint for submitting event from SDK
26-
- `/api/[1-9]\d*/minidump/` - Endpoint for submitting minidump from native SDKs
27-
- `/api/[1-9]\d*/security/` - Endpoint for submitting security-related such as CSP errors
28-
- `/api/[1-9]\d*/store/` - Old endpoint for submitting event from SDK, it is deprecated.
29-
- `/api/[1-9]\d*/unreal/` - Endpoint for submitting crash report from Unreal Engine SDK
25+
- `/api/[1-9]\d+/envelope/` - Main endpoint for submitting event from SDK
26+
- `/api/[1-9]\d+/minidump/` - Endpoint for submitting minidump from native SDKs
27+
- `/api/[1-9]\d+/security/` - Endpoint for submitting security-related such as CSP errors
28+
- `/api/[1-9]\d+/store/` - Old endpoint for submitting event from SDK, it is deprecated.
29+
- `/api/[1-9]\d+/unreal/` - Endpoint for submitting crash report from Unreal Engine SDK
3030

3131
The `[1-9]\d+` is a regular expression string that is acquired from the project DSN.
3232

@@ -71,6 +71,21 @@ server {
7171
proxy_buffer_size 128k;
7272
proxy_buffers 4 256k;
7373
74+
# Handle CORS-related headers for ingest endpoints.
75+
# You can also only expose the ingest endpoints only,
76+
# by removing the other `location` directive.
77+
#
78+
# It is recomended to put a rate limiter on the ingest endpoints.
79+
location ~ ^/api/[1-9]\d*/(envelope|minidump|security|store|unreal)/ {
80+
add_header Access-Control-Allow-Origin * always;
81+
add_header Access-Control-Allow-Credentials false always;
82+
add_header Access-Control-Allow-Methods GET,POST,PUT always;
83+
add_header Access-Control-Allow-Headers sentry-trace,baggage always;
84+
add_header Access-Control-Expose-Headers sentry-trace,headers always;
85+
include proxy_params;
86+
proxy_pass http://your-sentry-ip:9000;
87+
}
88+
7489
location / {
7590
include proxy_params;
7691
proxy_pass http://your-sentry-ip:9000;
@@ -107,10 +122,35 @@ It is also recommended to fine tune your NGINX for some performance benefits. Yo
107122

108123
```caddyfile
109124
sentry.yourcompany.com {
110-
reverse_proxy your-sentry-ip:9000 {
111-
health_uri /_health/
112-
health_status 2xx
113-
header_up Host {upstream_hostport}
125+
# Handle CORS-related headers for ingest endpoints.
126+
# You can also only expose the ingest endpoints only,
127+
# by removing the other `handle` directive.
128+
#
129+
# It is recomended to put a rate limiter on the ingest endpoints.
130+
@ingest_endpoint path_regexp ^/api/[1-9]\d+/(envelope|minidump|security|store|unreal)/
131+
132+
handle @ingest_endpoint {
133+
header {
134+
Access-Control-Allow-Origin *
135+
Access-Control-Allow-Credentials false
136+
Access-Control-Allow-Methods GET,POST,PUT
137+
Access-Control-Allow-Headers sentry-trace,baggage
138+
Access-Control-Expose-Headers sentry-trace,headers
139+
}
140+
141+
reverse_proxy your-sentry-ip:9000 {
142+
health_uri /_health/
143+
health_status 2xx
144+
header_up Host {upstream_hostport}
145+
}
146+
}
147+
148+
handle {
149+
reverse_proxy your-sentry-ip:9000 {
150+
health_uri /_health/
151+
health_status 2xx
152+
header_up Host {upstream_hostport}
153+
}
114154
}
115155
116156
# By default, the TLS is acquired from Let's Encrypt
@@ -133,11 +173,6 @@ sentry.yourcompany.com {
133173
# events 100
134174
# }
135175
# }
136-
137-
# To expose only ingest endpoint publicly, add the named matcher below before `reverse_proxy` directive
138-
# @ingest_endpoint {
139-
# path_regexp /api/[1-9]\d+/(envelope|minidump|security|store|unreal)/
140-
# }
141176
}
142177
```
143178

@@ -147,24 +182,39 @@ For detailed documentation on Caddyfile configuration, see [Caddy documentation]
147182

148183
[Traefik](https://doc.traefik.io/traefik/) is another reverse proxy that provides a lot of plugin and integrations out of the box. It automatically handles TLS certificate management via ACME, too. After you [install Traefik](https://doc.traefik.io/traefik/getting-started/install-traefik/), add a configuration to Traefik as follows (this example is using the YAML file provider, convert to your prefered configuration provider as needed).
149184

185+
The configuration below is intended for Traefik v3 with a File Provider.
186+
150187
```yaml
151188
http:
152189
routers:
190+
# Handle CORS-related headers for ingest endpoints.
191+
# You can also only expose the ingest endpoints only,
192+
# by removing the other `handle` directive.
193+
#
194+
# It is recomended to put a rate limiter on the ingest endpoints.
195+
sentry-ingest:
196+
entryPoints:
197+
- web # Assuming this your HTTP entrypoint
198+
- websecure # Assuming this is your HTTPS entrypoint
199+
service: sentry@file
200+
rule: "Host(`sentry.yourcompany.com`) && PathRegexp(`^/api/[1-9]\\d+/(envelope|minidump|security|store|unreal)`)"
201+
tls:
202+
certResolver: letsencrypt # Assuming you have a TLS certificate resolver named "letsencrypt"
203+
middlewares:
204+
- https_redirect@file
205+
- cors_headers@file # For handling browser clients
206+
- rate_limiter@file
153207
sentry:
154208
entryPoints:
155209
- web # Assuming this your HTTP entrypoint
156210
- websecure # Assuming this is your HTTPS entrypoint
157211
service: sentry@file
158212
rule: "Host(`sentry.yourcompany.com`)"
159-
# If you want to expose only ingest endpoint publicly
160-
# rule: "Host(`sentry.yourcompany.com`) && PathPrefix(`/api/{id:[1-9]\d*}/envelope`, `/api/{id:[1-9]\d*}/minidump`, `/api/{id:[1-9]\d*}/security`, `/api/{id:[1-9]\d*}/store`, `/api/{id:[1-9]\d*}/unreal`)"
161213
tls:
162214
certResolver: letsencrypt # Assuming you have a TLS certificate resolver named "letsencrypt"
163215
# Enable middleware as needed
164216
middlewares:
165217
- https_redirect@file
166-
- cors_headers@file # For handling browser clients
167-
- rate_limiter@file
168218

169219
services:
170220
sentry:
@@ -187,8 +237,6 @@ http:
187237
cors_headers:
188238
headers:
189239
customResponseHeaders:
190-
# We can't remove header on Traefik, but we can put it to some other values
191-
server: "Your Company Name"
192240
addVaryHeader: true
193241
# If you want to set this to true, adjust "accessControlAllowOriginList" to a valid domain and remove the asterisk wildcard
194242
accessControlAllowCredentials: false
@@ -201,12 +249,9 @@ http:
201249
- GET
202250
- POST
203251
- PUT
204-
- PATCH
205-
- DELETE
206252
accessControlExposeHeaders:
207253
- "sentry-trace"
208254
- "baggage"
209-
sslRedirect: true
210255
rate_limiter:
211256
rateLimit:
212257
average: 100
@@ -254,12 +299,27 @@ frontend https_bind
254299
bind *:443 ssl crt /etc/haproxy/certs/ name https_port
255300
mode http
256301
257-
acl sentry_domain hdr(host) -i sentry.yourcompany.com
302+
acl sentry_domain hdr(host) -i sentry.yourcompany.com
303+
acl ingest_endpoint path_reg -i /api/[1-9]\d+/(envelope|minidump|security|store|unreal)/
304+
305+
# Handle CORS-related headers for ingest endpoints.
306+
# You can also only expose the ingest endpoints only,
307+
# by removing the other `handle` directive.
308+
#
309+
# It is recomended to put a rate limiter on the ingest endpoints.
310+
use_backend sentry_ingest if sentry_domain ingest_endpoint
311+
258312
use_backend sentry if sentry_domain
259313

260-
# To expose only ingest endpoints publicly, add the acl below on `use_backend` directive
261-
# acl ingest_endpoint path_reg -i /api/[1-9]\d+(envelope|minidump|security|store|unreal)/
262-
# use_backend sentry if sentry_domain ingest_endpoint
314+
backend sentry_ingest
315+
mode http
316+
option httpchk
317+
server server1 your-sentry-ip:9000 check
318+
http-response set-header Access-Control-Allow-Origin *
319+
http-response set-header Access-Control-Allow-Credentials false
320+
http-response set-header Access-Control-Allow-Methods GET,POST,PUT
321+
http-response set-header Access-Control-Allow-Headers sentry-trace,baggage
322+
http-response set-header Access-Control-Expose-Headers sentry-trace,headers
263323

264324
backend sentry
265325
mode http

0 commit comments

Comments
 (0)