Skip to content

Commit

Permalink
docs: add rate limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
haveachin committed Jan 31, 2024
1 parent 01fb149 commit 199d59d
Show file tree
Hide file tree
Showing 27 changed files with 420 additions and 356 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ dist/
.dev/
cmd/infrared/config.yml

# VSCode
# VSCode Dev Files
.vscode/

# IntelliJ
# IntelliJ Dev Files
.idea/

# Docs
Expand Down
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dockers:
- "ghcr.io/{{ .Env.DOCKER_IMAGE_NAME }}:{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.DOCKER_IMAGE_NAME }}:latest-amd64"
use: buildx
dockerfile: Dockerfile.goreleaser
dockerfile: build/packages/Dockerfile.goreleaser
build_flag_templates:
- "--pull"
- "--platform=linux/amd64"
Expand All @@ -58,7 +58,7 @@ dockers:
- "ghcr.io/{{ .Env.DOCKER_IMAGE_NAME }}:latest-arm64v8"
use: buildx
goarch: arm64
dockerfile: Dockerfile.goreleaser
dockerfile: build/packages/Dockerfile.goreleaser
build_flag_templates:
- "--pull"
- "--platform=linux/arm64/v8"
Expand Down
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ You can also contribute indirectly by donation.
## Tools

- Coding
- [Go](https://go.dev/) 1.20+
- [Go](https://go.dev/)
- [GNUMake](https://www.gnu.org/software/make/) (Optional)
- [Docker](https://www.docker.com/get-started/) (Optional)
- [golangci-lint](https://golangci-lint.run/) (Optional)
- Docs
- [Node.js]()
- [Node.js](https://nodejs.org/)


## Contributing
Expand Down
4 changes: 0 additions & 4 deletions Dockerfile.goreleaser

This file was deleted.

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ dos:
./out/dos

docs:
cd ./docs && npm run docs:dev
cd ./docs && npm i && npm run docs:dev

lint:
golangci-lint run
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
<img alt="CI" src="https://github.com/haveachin/infrared/actions/workflows/ci.yml/badge.svg" />
</p>

> [!WARNING]
> Infrared is currently under active development: breaking changes can happen.
> Feedback and contributions are welcome.
An ultra lightweight Minecraft reverse proxy and status placeholder:
Ever wanted to have only one exposed port on your server for multiple Minecraft servers?
Then Infrared is the tool you need!
Infrared works as a reverse proxy using a sub-/domains to connect clients to a specific Minecraft server.



## Features

- [X] Reverse Proxy
Expand All @@ -29,17 +35,18 @@ Infrared works as a reverse proxy using a sub-/domains to connect clients to a s
- [X] Proxy Protocol Support
- [X] Ratelimiter

## Links
## Useful Links

- [Docs](https://infrared.dev)
- **[Docs](https://infrared.dev)**
- **[Ask Questions](https://github.com/haveachin/infrared/discussions)**
- [Latest Release](https://github.com/haveachin/infrared/releases/latest)
- [Discord Invite](https://discord.gg/r98YPRsZAx)
- [Contributing](CONTRIBUTING.md)

## Build

Requirements:
- [Go](https://go.dev/) 1.20+
- [Go](https://go.dev/) 1.21+

```
CGO_ENABLED=0 go build -ldflags "-s -w" -o ./out/infrared ./cmd/infrared
Expand All @@ -60,6 +67,7 @@ or `make all` (requires GNU Make). The binary is in the `out/` directory.
- [pires/go-proxyproto](https://github.com/pires/go-proxyproto), Apache-2.0
- [spf13/pflag](https://github.com/spf13/pflag), BSD-3-Clause
- [go-yaml/yaml](https://github.com/go-yaml/yaml), Apache-2.0, MIT
- [vitepress](https://github.com/vuejs/vitepress), MIT

<br />
<p align="center">
Expand Down
12 changes: 12 additions & 0 deletions build/packages/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
ARG TARGETARCH
WORKDIR /tmp/build
COPY . /tmp/build
ENV GO111MODULE=on
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$TARGETARCH go build -ldflags "-s -w" -o ./out/infrared ./cmd/infrared
RUN chmod +x ./out/infrared

FROM alpine:latest
COPY --from=builder /tmp/build/out/infrared /usr/bin/
WORKDIR /etc/infrared
ENTRYPOINT [ "/usr/bin/infrared" ]
4 changes: 4 additions & 0 deletions build/packages/Dockerfile.goreleaser
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine:latest
COPY infrared /usr/bin/infrared
WORKDIR /etc/infrared
ENTRYPOINT [ "/usr/bin/infrared" ]
17 changes: 11 additions & 6 deletions configs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ proxyProtocol:
#
#receive: true

# TODO
#
#trustedProxies:
# - "127.0.0.1"

# Maximum duration between packets before the client gets timed out.
#
keepAliveTimeout: 30s

# Filter
# Filter are hooks that trigger befor a connection is processed.
# They are used as preconditions to validate a connection.
#
filters:
# Rate Limiter will only allow an IP address to connect a specified
# amount of times in a given time frame.
#
rateLimiter:
# Request Limit is the amount of times an IP address can create
# a new connection before it gets blocked.
#
requestLimit: 10

# Windows Length is the time frame for the Request Limit.
#
windowLength: 1s
2 changes: 1 addition & 1 deletion configs/proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ domains:
- "*"

addresses:
- example.com:25565
- 127.0.0.1:25565

# Send a Proxy Protocol v2 Header to the server to
# forward the players IP address
Expand Down
8 changes: 4 additions & 4 deletions deployments/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ services:
haproxy:
image: haproxy
container_name: infrared-dev-haproxy
networks:
- infrared
volumes:
- ../.dev/haproxy:/usr/local/etc/haproxy:ro
sysctls:
- net.ipv4.ip_unprivileged_port_start=0
volumes:
- ../.dev/haproxy:/usr/local/etc/haproxy:ro
ports:
- 25567:25565/tcp
networks:
- infrared

redis:
image: redis
Expand Down
11 changes: 11 additions & 0 deletions deployments/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.8"

services:
infrared:
image: haveachin/infrared:latest
container_name: infrared
restart: always
ports:
- 25565:25565/tcp
volumes:
- ./data/infrared:/etc/infrared
20 changes: 13 additions & 7 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineConfig} from 'vitepress'

// https://vitepress.dev/reference/site-config
export default defineConfig({
lang: 'en-US',
title: 'Infrared',
Expand All @@ -18,21 +17,21 @@ export default defineConfig({
],
],
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
logo: '/assets/logo.svg',

nav: [
{
text: 'Guides',
text: 'Features',
items: [
{ text: 'Forward Player IPs', link: '/guide/forward-player-ips' },
{ text: 'PROXY Protocol', link: '/features/forward-player-ips' },
{ text: 'Rate Limiter', link: '/features/rate-limit-ips' },
]
},
{
text: 'Config',
items: [
{ text: 'Global', link: '/config/' },
{ text: 'Proxy', link: '/config/proxy' },
{ text: 'Proxies', link: '/config/proxies' },
{ text: 'CLI & Env Vars', link: '/config/cli-and-env-vars' },
]
},
Expand All @@ -56,9 +55,16 @@ export default defineConfig({
],
},
{
text: 'Guides',
text: 'Features',
items: [
{ text: 'Forward Player IPs', link: '/guide/forward-player-ips' },
{ text: 'Forward Player IPs', link: '/features/forward-player-ips' },
{
text: 'Filters',
link: '/features/filters',
items: [
{ text: 'Rate Limit IPs', link: '/features/rate-limit-ips' },
]
}
]
},
{ text: 'Report an Issue', link: 'https://github.com/haveachin/infrared/issues' },
Expand Down
16 changes: 3 additions & 13 deletions docs/config/index.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# Config

On fist start Infrared should generate a `config.yml` file and a `proxies` directory.
The default config file should look something like this:
A minmal

```yml [config.yml]
# Infrared Config
```yml
# Minimal Infrared Config

# Address that Infrared bind and listens to
#
bind: 0.0.0.0:25565

proxyProtocol:
# Receive proxy protocol
#
#receive: true

# TODO
#
#trustedProxies:
# - "127.0.0.1"

# Maximum duration between packets before the client gets timed out.
#
keepAliveTimeout: 30s
Expand Down
9 changes: 2 additions & 7 deletions docs/config/proxies.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ Proxy config example:
# Supports '*' and '?' wildcards in the pattern string.
#
domains:
- "*"
- "example.com"

addresses:
- example.com:25565

# Send a Proxy Protocol v2 Header to the server to
# forward the players IP address
#
#sendProxyProtocol: true
- 127.0.0.1:25565
```
1 change: 0 additions & 1 deletion docs/contribute.md

This file was deleted.

20 changes: 20 additions & 0 deletions docs/features/filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Filters

Filter are hooks that trigger befor a connection is processed.
They are used as preconditions to validate a connection.

## Use Filters

To use filters you just need to a this to your [**global config**](../config/index.md):

```yml
# Filter are hooks that trigger befor a connection is processed.
# They are used as preconditions to validate a connection.
#
filters:
```
Now you actually need to add filters to your config.
This is a list of all the filters that currently exist:
- [Rate Limiter](rate-limit-ips)
16 changes: 16 additions & 0 deletions docs/features/forward-player-ips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Forward Player IPs

You can forward the player IPs via proxy protocol.
To enable it in Infrared you just have to change this in you [**proxy config**](../config/proxies.md):
```yml
# Send a Proxy Protocol v2 Header to the server to
# forward the players IP address.
#
#sendProxyProtocol: true // [!code --]
sendProxyProtocol: true // [!code ++]
```
## Paper
In Paper you have to enable it also to work.
See [the Paper documentation on Proxy Protocol](https://docs.papermc.io/paper/reference/global-configuration#proxies_proxy_protocol) for more.
20 changes: 20 additions & 0 deletions docs/features/rate-limit-ips.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Rate Limit IPs

You can rate limit by IP address using the `rateLimit` filter.
This can be easily activated in your [**global config**](../config/index.md) by adding this:

```yml{2-16}
filters:
# Rate Limiter will only allow an IP address to connect a specified
# amount of times in a given time frame.
#
rateLimiter:
# Request Limit is the amount of times an IP address can create
# a new connection before it gets blocked.
#
requestLimit: 10
# Windows Length is the time frame for the Request Limit.
#
windowLength: 1s
```
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ services:
ports:
- 25565:25565/tcp
volumes:
- ./data/infrared:/infrared
- ./data/infrared:/etc/infrared
```
15 changes: 0 additions & 15 deletions docs/guide/forward-player-ips.md

This file was deleted.

Loading

0 comments on commit 199d59d

Please sign in to comment.