berghain

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

README

Berghain

🕺 Welcome to Berghain: Where Only Valid Browsers Get the Backend Party Started! 🎉

Berghain is your trusty SPOE-Agent, guarding the entrance to the backend like a seasoned bouncer. This Go and HAProxy-powered tool ensures that only the coolest and most valid browsers can access the exclusive party happening on the other side.

With Berghain in charge, you can be confident that your backend is reserved for the true VIPs of the internet, keeping out any uninvited guests. It's like the bouncer of the web world, ensuring that your resources are reserved for the browsers that really know how to dance!

Supported CAPTCHAs

  • None (Simple JS execute)
  • POW

Planned support

Example setup with HAProxy

To start berghain locally you can follow these easy steps:

For Debian / Ubuntu: apt install npm

  1. Run npm install inside web/
  2. Run npm run build inside web/
  3. Run haproxy -f examples/haproxy/haproxy.cfg
  4. Run go run ./cmd/spop/. -config cmd/spop/config.yaml

For production use, generate a random secret to place in the Berghain configuration file using openssl rand -base64 32.

Running with Docker

To run the project using Docker, follow these steps:

  1. Build the Docker images:

    docker-compose build
    
  2. Start the services:

    docker-compose up
    
  3. Access the application:

Make sure to have Docker and Docker Compose installed on your system before running these commands.

Attributions

Thanks to @NullDev and @arellak, as they did most of the frontend work.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmpty         = fmt.Errorf("empty")
	ErrInvalidLength = fmt.Errorf("invalid length")
	ErrLevelTooLow   = fmt.Errorf("cookie level too low")
	ErrExpired       = fmt.Errorf("expired")
	ErrInvalidHMAC   = fmt.Errorf("invalid hmac")
)

Functions

func AcquireCookieBuffer

func AcquireCookieBuffer() *buffer.SliceBuffer

func NewZeroHasher

func NewZeroHasher(h hash.Hash) hash.Hash

func ReleaseCookieBuffer

func ReleaseCookieBuffer(b *buffer.SliceBuffer)

func ReleaseValidatorRequest

func ReleaseValidatorRequest(v *ValidatorRequest)

func ReleaseValidatorResponse

func ReleaseValidatorResponse(v *ValidatorResponse)

Types

type Berghain

type Berghain struct {
	Levels         []*LevelConfig
	TrustedDomains []string
	// contains filtered or unexported fields
}

func NewBerghain

func NewBerghain(secret []byte) *Berghain

func (*Berghain) IsValidCookie

func (b *Berghain) IsValidCookie(ri RequestIdentifier, cookie []byte) error

func (*Berghain) LevelConfig

func (b *Berghain) LevelConfig(level uint8) *LevelConfig

type LevelConfig

type LevelConfig struct {
	Countdown int
	Duration  time.Duration
	Type      ValidationType
}

type RequestIdentifier

type RequestIdentifier struct {
	SrcAddr netip.Addr
	Host    []byte
	Level   uint8
}

func (RequestIdentifier) ToCookie

func (ri RequestIdentifier) ToCookie(b *Berghain, enc *buffer.SliceBuffer) error

func (RequestIdentifier) WriteTo

func (ri RequestIdentifier) WriteTo(h io.Writer) (int64, error)

type ValidationType

type ValidationType int
const (
	ValidationTypeNone ValidationType
	ValidationTypePOW
)

func (ValidationType) RunValidator

func (v ValidationType) RunValidator(b *Berghain, req *ValidatorRequest, resp *ValidatorResponse) error

type ValidatorRequest

type ValidatorRequest struct {
	Method     string
	Body       []byte
	Identifier *RequestIdentifier
}

func AcquireValidatorRequest

func AcquireValidatorRequest() *ValidatorRequest

type ValidatorResponse

type ValidatorResponse struct {
	Body  *buffer.SliceBuffer
	Token *buffer.SliceBuffer
}

func AcquireValidatorResponse

func AcquireValidatorResponse() *ValidatorResponse

Directories

Path Synopsis
cmd
spop command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL