Filebin2 is a web application that facilitates convenient file sharing over the web. It is the software that powers https://filebin.net/. It is still in development status and will see breaking changes.
Table of contents
* With Docker Compose * With the container image * From the binary * ConfigurationWhy filebin2?
A couple of (in hindsight) bad architectural decisions in the previous version of filebin paved the road for filebin2. Filebin2 is using a PostgreSQL database to handle meta data and S3 to store files. I decided to move to a new repository because of breaking changes from the previous verson of filebin.
Getting started
Filebin2 requires read write access to an S3 bucket for file storage and a PostgreSQL database that it will use for meta data. The Filebin application itself is written in Go and builds to a single binary that is configured using command line arguments and/or environment variables.
Using Docker Compose
The quickest way to get a fully working setup is to use the included docker-compose.yml, which builds Filebin from source and starts it together with PostgreSQL and Stupid Simple S3):
docker compose up --build
This makes Filebin available at http://localhost:8080/ with an admin interface at http://admin:changeme@localhost:8080/admin.
Review and adjust the environment variables in docker-compose.yml to suit your needs. See the Configuration section for all available options.
Using the container image
Multi-arch container images (linux/amd64 and linux/arm64) are published to GitHub Container Registry for each release. The container images are distroless and contain only the filebin binary:
ghcr.io/espebra/filebin2:latest
Run the container with the required environment variables pointing to your PostgreSQL database and S3 bucket:
docker run -p 8080:8080 \
-e FILEBIN_DATABASE_HOST=db.example.com \
-e FILEBIN_DATABASE_NAME=filebin \
-e FILEBIN_DATABASE_USERNAME=filebin \
-e FILEBIN_DATABASE_PASSWORD=secret \
-e FILEBIN_S3_ENDPOINT=s3.example.com \
-e FILEBIN_S3_REGION=us-east-1 \
-e FILEBIN_S3_BUCKET=filebin \
-e FILEBIN_S3_ACCESS_KEY=accesskey \
-e FILEBIN_S3_SECRET_KEY=secretkey \
-e FILEBIN_LISTEN_HOST=0.0.0.0 \
-e [email protected] \
ghcr.io/espebra/filebin2:latest
Using the binary
Pre-built binaries for Linux and macOS (amd64 and arm64) are attached to each release. Download the appropriate binary for your platform:
| Binary | Platform |
| ------ | -------- |
| filebin2-linux-amd64 | Linux x86_64 |
| filebin2-linux-arm64 | Linux ARM64 |
| filebin2-darwin-amd64 | macOS x86_64 |
| filebin2-darwin-arm64 | macOS ARM64 (Apple Silicon) |
Make the binary executable and run it with the required flags:
chmod +x filebin2-linux-amd64
./filebin2-linux-amd64 \
--db-host db.example.com \
--db-name filebin \
--db-username filebin \
--db-password secret \
--s3-endpoint s3.example.com \
--s3-region us-east-1 \
--s3-bucket filebin \
--s3-access-key accesskey \
--s3-secret-key secretkey \
--listen-host 0.0.0.0 \
--contact [email protected]
Configuration
Filebin can be configured using command line arguments or environment variables. Environment variables use the FILEBIN_ prefix with uppercase letters and underscores instead of hyphens. Command line flags take precedence over environment variables.
General
Base URL
- Environment Variable:
FILEBIN_BASEURL - Command Line Argument:
--baseurl - Default:
https://filebin.net
Contact
- Environment Variable:
FILEBIN_CONTACT - Command Line Argument:
--contact - Default: (required)
Expiration
- Environment Variable:
FILEBIN_EXPIRATION - Command Line Argument:
--expiration - Default:
604800
Temporary Directory
- Environment Variable:
FILEBIN_TMPDIR - Command Line Argument:
--tmpdir - Default:
/tmp
Temporary Directory Capacity Threshold
- Environment Variable:
FILEBIN_TMPDIR_CAPACITY_THRESHOLD - Command Line Argument:
--tmpdir-capacity-threshold - Default:
4.0
Manual Approval
- Environment Variable:
FILEBIN_MANUAL_APPROVAL - Command Line Argument:
--manual-approval - Default:
false
PUT /admin/approve/{bin}.
Require Verification Cookie
- Environment Variable:
FILEBIN_REQUIRE_VERIFICATION_COOKIE - Command Line Argument:
--require-verification-cookie - Default:
false
Verification Cookie Lifetime
- Environment Variable:
FILEBIN_VERIFICATION_COOKIE_LIFETIME - Command Line Argument:
--verification-cookie-lifetime - Default:
365
--require-verification-cookie.
Expected Cookie Value
- Environment Variable:
FILEBIN_EXPECTED_COOKIE_VALUE - Command Line Argument:
--expected-cookie-value - Default:
2024-05-24
--require-verification-cookie.
GeoIP City Database
- Environment Variable:
FILEBIN_MMDB_CITY - Command Line Argument:
--mmdb-city - Default: (not set)
GeoIP ASN Database
- Environment Variable:
FILEBIN_MMDB_ASN - Command Line Argument:
--mmdb-asn - Default: (not set)
Allow Robots
- Environment Variable:
FILEBIN_ALLOW_ROBOTS - Command Line Argument:
--allow-robots - Default:
false
X-Robots-Tag response header will allow search engines to index and show Filebin in search results. Otherwise, robots will be instructed to not show files and bins in search results.
Pre-Upload Hook
- Environment Variable:
FILEBIN_PRE_UPLOAD_HOOK - Command Line Argument:
--pre-upload-hook - Default: (not set)
--bin-id, --filename, --content-type, --size, --md5, --sha1, and --sha256. The checksums are hex encoded.
The exit code determines the outcome:
1— Reject the upload with HTTP 403 (Forbidden). The last line of stdout from the command is returned to the client as the response message.0— Accept the upload.- Any other exit code — Accept the upload. The exit code and output are logged.
misc/pre-upload-hook-example.
Pre-Upload Hook Timeout
- Environment Variable:
FILEBIN_PRE_UPLOAD_HOOK_TIMEOUT - Command Line Argument:
--pre-upload-hook-timeout - Default:
5s
5s, 30s, 1m.
Post-Upload Hook
- Environment Variable:
FILEBIN_POST_UPLOAD_HOOK - Command Line Argument:
--post-upload-hook - Default: (not set)
--bin-id, --filename, --content-type, --size, --md5, --sha1, and --sha256. The checksums are hex encoded.
The hook does not affect the response to the client: any non-zero exit code or stdout/stderr is logged but the upload is always reported as successful. An example hook script is provided in misc/post-upload-hook-example.
Post-Upload Hook Timeout
- Environment Variable:
FILEBIN_POST_UPLOAD_HOOK_TIMEOUT - Command Line Argument:
--post-upload-hook-timeout - Default:
10s
5s, 30s, 1m.
Limits
Limit File Downloads
- Environment Variable:
FILEBIN_LIMIT_FILE_DOWNLOADS - Command Line Argument:
--limit-file-downloads - Default:
0
Limit Storage
- Environment Variable:
FILEBIN_LIMIT_STORAGE - Command Line Argument:
--limit-storage - Default:
0
Reject File Extensions
- Environment Variable:
FILEBIN_REJECT_FILE_EXTENSIONS - Command Line Argument:
--reject-file-extensions - Default: (not set)
HTTP Server
Listen Host
- Environment Variable:
FILEBIN_LISTEN_HOST - Command Line Argument:
--listen-host - Default:
127.0.0.1
Listen Port
- Environment Variable:
FILEBIN_LISTEN_PORT - Command Line Argument:
--listen-port - Default:
8080
Access Log
- Environment Variable:
FILEBIN_ACCESS_LOG - Command Line Argument:
--access-log - Default:
/var/log/filebin/access.log
Proxy Headers
- Environment Variable:
FILEBIN_PROXY_HEADERS - Command Line Argument:
--proxy-headers - Default:
false
Timeouts
Read Timeout
- Environment Variable:
FILEBIN_READ_TIMEOUT - Command Line Argument:
--read-timeout - Default:
1h
Read Header Timeout
- Environment Variable:
FILEBIN_READ_HEADER_TIMEOUT - Command Line Argument:
--read-header-timeout - Default:
2s
Write Timeout
- Environment Variable:
FILEBIN_WRITE_TIMEOUT - Command Line Argument:
--write-timeout - Default:
1h
Idle Timeout
- Environment Variable:
FILEBIN_IDLE_TIMEOUT - Command Line Argument:
--idle-timeout - Default:
30s
Database
Database Host
- Environment Variable:
FILEBIN_DATABASE_HOST - Command Line Argument:
--db-host - Default: (required)
Database Port
- Environment Variable:
FILEBIN_DATABASE_PORT - Command Line Argument:
--db-port - Default:
5432
Database Name
- Environment Variable:
FILEBIN_DATABASE_NAME - Command Line Argument:
--db-name - Default: (required)
Database Username
- Environment Variable:
FILEBIN_DATABASE_USERNAME - Command Line Argument:
--db-username - Default: (required)
Database Password
- Environment Variable:
FILEBIN_DATABASE_PASSWORD - Command Line Argument:
--db-password - Default: (required)
Max Open Connections
- Environment Variable:
FILEBIN_DATABASE_MAX_OPEN_CONNS - Command Line Argument:
--db-max-open-conns - Default:
25
Max Idle Connections
- Environment Variable:
FILEBIN_DATABASE_MAX_IDLE_CONNS - Command Line Argument:
--db-max-idle-conns - Default:
25
Connection Max Lifetime
- Environment Variable:
FILEBIN_DATABASE_CONN_MAX_LIFETIME - Command Line Argument:
--db-conn-max-lifetime - Default:
5m
5m, 10m, 1h.
Connection Max Idle Time
- Environment Variable:
FILEBIN_DATABASE_CONN_MAX_IDLE_TIME - Command Line Argument:
--db-conn-max-idle-time - Default:
1m
1m, 5m, 10m.
S3 Storage
S3 Endpoint
- Environment Variable:
FILEBIN_S3_ENDPOINT - Command Line Argument:
--s3-endpoint - Default: (required)
hostname:port.
S3 Bucket
- Environment Variable:
FILEBIN_S3_BUCKET - Command Line Argument:
--s3-bucket - Default: (required)
S3 Region
- Environment Variable:
FILEBIN_S3_REGION - Command Line Argument:
--s3-region - Default: (required)
S3 Access Key
- Environment Variable:
FILEBIN_S3_ACCESS_KEY - Command Line Argument:
--s3-access-key - Default: (required)
S3 Secret Key
- Environment Variable:
FILEBIN_S3_SECRET_KEY - Command Line Argument:
--s3-secret-key - Default: (required)
S3 Secure
- Environment Variable:
FILEBIN_S3_SECURE - Command Line Argument:
--s3-secure - Default:
true
S3 URL TTL
- Environment Variable:
FILEBIN_S3_URL_TTL - Command Line Argument:
--s3-url-ttl - Default:
1m
30s, 5m, 2h.
S3 Timeout
- Environment Variable:
FILEBIN_S3_TIMEOUT - Command Line Argument:
--s3-timeout - Default:
30s
S3 Transfer Timeout
- Environment Variable:
FILEBIN_S3_TRANSFER_TIMEOUT - Command Line Argument:
--s3-transfer-timeout - Default:
10m
Lurker (Background Jobs)
Lurker Interval
- Environment Variable:
FILEBIN_LURKER_INTERVAL - Command Line Argument:
--lurker-interval - Default:
300
Lurker Throttle
- Environment Variable:
FILEBIN_LURKER_THROTTLE - Command Line Argument:
--lurker-throttle - Default:
250
Log Retention
- Environment Variable:
FILEBIN_LOG_RETENTION - Command Line Argument:
--log-retention - Default:
7
Admin Authentication
Admin Username
- Environment Variable:
FILEBIN_ADMIN_USERNAME - Command Line Argument:
--admin-username - Default: (not set)
Admin Password
- Environment Variable:
FILEBIN_ADMIN_PASSWORD - Command Line Argument:
--admin-password - Default: (not set)
Metrics
Enable Metrics
- Environment Variable:
FILEBIN_METRICS - Command Line Argument:
--metrics - Default:
false
/metrics endpoint. If this is not set, the endpoint will not return any metrics.
Metrics Username
- Environment Variable:
FILEBIN_METRICS_USERNAME - Command Line Argument:
--metrics-username - Default: (not set)
/metrics endpoint for Prometheus metrics.
Metrics Password
- Environment Variable:
FILEBIN_METRICS_PASSWORD - Command Line Argument:
--metrics-password - Default: (not set)
/metrics endpoint for Prometheus metrics.
Metrics Auth
- Environment Variable:
FILEBIN_METRICS_AUTH - Command Line Argument:
--metrics-auth - Default: (not set)
basic, basic auth will be required. If not set, the endpoint is open to the world.
Metrics ID
- Environment Variable:
FILEBIN_METRICS_ID - Command Line Argument:
--metrics-id - Default:
$HOSTNAME
$HOSTNAME environment variable.
Metrics Proxy URL
- Environment Variable:
FILEBIN_METRICS_PROXY_URL - Command Line Argument:
--metrics-proxy-url - Default: (not set)
/metrics endpoint. This can be useful when running another Prometheus exporter in the same operating system instance, for example to capture system metrics.
Slack Integration
Slack Secret
- Environment Variable:
FILEBIN_SLACK_SECRET - Command Line Argument:
--slack-secret - Default: (not set)
Slack Domain
- Environment Variable:
FILEBIN_SLACK_DOMAIN - Command Line Argument:
--slack-domain - Default: (not set)
Slack Channel
- Environment Variable:
FILEBIN_SLACK_CHANNEL - Command Line Argument:
--slack-channel - Default: (not set)
/integration/slack can be accessed using a webhook from Slack. This parameter limits which Slack channel is allowed to access the http api. Requests from other channels will be rejected.
Development
Local development environment
The development environment consists of one PostgreSQL instance, one Stupid Simple S3 object storage instance and an instance of filebin2 built from source. The easiest way to set up this environment is to clone this repository and do:
# With Docker
docker compose up --build
With Podman
podman compose up --build
This will make:
- Filebin2 available on http://localhost:8080/.
- Filebin2 admin available on http://admin:changeme@localhost:8080/admin.
- Stupid Simple S3 available on http://localhost:5553/.
- PostgreSQL available on
localhost:5432.
Testing
The easiest way to run the test suite is to run it in docker compose. Docker will exit successfully (return code 0) if the tests succeed, and exit with an error code other than 0 if the tests fail.
# Docker
docker compose -f integration-tests.yml up --abort-on-container-exit
Podman
podman compose -f integration-tests.yml up --abort-on-container-exit
Building
The program can be built using:
# Build for Linux amd64 only
make linux
Build for all platforms:
make build-all
The output will be the Filebin program as binaries in the artifacts/ folder called filebin2-linux-amd64 (depending on the platform). The filebin binary take the following environment variables and command line parameters.
Integrations
Grafana and Prometheus
Filebin2 comes with a /metrics endpoint that is compatible with Prometheus. There is an example dashboard that visualizes this data.
Slack
This integration may be useful if manual approval is required (see --manual-approval). The integration allows members of a Slack channel to list the recently updated bins and approve specific bins directly in the Slack channel using slash commands. The slash commands available are:
| Slash command | Description |
| ------------- | ----------- |
| /filebin approve bin_id | Approve the bin bin_id |
| /filebin lastupdated | List the 10 last updated bins |
| /filebin lastupdated n | List the n last updated bins |
The documention on how to configure Slack to work with this integration does not exist currently.