tbin
tbin is a simple pastebin application that allows you to store and share text snippets from your terminal.
Prerequisites
Before building and starting tbin, ensure that you have the following software installed on your system:
- Docker
- Go 1.27+ (if you want to build the application from source)
Building from source
To build tbin from source, follow these steps:
- Clone the tbin repository:
git clone https://git.rznet.fr/tchivert/tbin - Change into the project directory:
cd tbin - Build the application using Go:
go build -o tbin - The
tbinbinary will be generated in the project directory.
Starting tbin with Docker
tbin can also be started using Docker. To do this, follow these steps:
- Make sure you have Docker installed and running on your machine.
- Clone the tbin repository:
git clone https://git.rznet.fr/tchivert/tbin - Change into the project directory:
cd tbin - Start the application using Docker Compose:
docker-compose up -d - tbin will be started as a Docker container and will be accessible via telnet and HTTP.
The Docker container runs as a non-root user (UID 1000) and uses a named volume (tbin-data) for data persistence.
Usage
To submit a text snippet using the telnet interface, follow these steps:
- Open a terminal session.
- Use the
nccommand to connect to the tbin server:echo "Your text snippet" | nc localhost 4242 - The server will generate a unique URL for your text snippet, which will be displayed in the terminal.
Purges can be trigged with the /purge endpoint (localhost only).
It will remove all snippets olders than the configuered TTL (default: 48 hours).
Configuration
tbin can be configured using command-line flags when starting the application.
--host: Host address to listen on (default: 0.0.0.0).--port: Port number to listen on for telnet connections (default: 4242).--http-port: Port number to listen on for HTTP connections (default: 8080).--http-url: Base URL to send back to the client (default: http://localhost:8080/).--dir: Directory to store snippets (default: ./data).--ttl: Time-to-live in hours for the snippets (default: 48).--buff: Buffer size in MB for handling incoming data (default: 8).--chunk: Chunk size in bytes for reading data (default: 8192).--conn-time: Connection timeout in seconds (default: 10).--read-time: Read timeout in seconds (default: 2).--verbose: Enable verbose (debug-level) logging (default: false).--plaintext: Only allow plaintext snippets (default: false).--max-conns: Maximum concurrent TCP connections (default: 100).--rate-limit: Max requests per second per IP, 0 to disable (default: 10).--metrics-addr: Prometheus metrics listen address, empty to disable (default: "").
Monitoring
tbin exposes Prometheus metrics when --metrics-addr is set. The metrics server runs on a separate port and is not exposed on the main HTTP port. Available metrics:
tbin_pastes_total: Total pastes createdtbin_pastes_bytes_total: Total bytes of pastes createdtbin_http_requests_total: HTTP requests by method, endpoint, and statustbin_tcp_connections_total: Total TCP connections acceptedtbin_tcp_active_connections: Current active TCP connectionstbin_purge_runs_total: Total purge operations executedtbin_purge_files_total: Files processed during purge by resulttbin_removes_total: Total manual remove requests
A /health endpoint is also available on the HTTP port for health checks.
Security
- HTTP server has read/write/idle timeouts to prevent slowloris attacks
- Request body size is limited via
http.MaxBytesReader - TCP connections are rate-limited per-IP and capped with
--max-conns - HTTP requests are rate-limited per-IP
- Paste files are created with 0600 permissions and O_EXCL to prevent races
- The
/purgeendpoint is restricted to localhost - Security headers (CSP, X-Frame-Options, etc.) are set on all responses
- Graceful shutdown on SIGTERM/SIGINT with WaitGroup tracking of in-flight requests
- Docker container runs as non-root user (UID 1000)
- Docker base images are pinned (golang:1.27-alpine, alpine:3.24)
License
tbin is licensed under the MIT License. See the LICENSE file for more information.