Skip to content

worldline-go/forward

Repository files navigation

forward

License Coverage GitHub Workflow Status Go PKG

Export socket connection to HTTP service with filter options.

Usage

Use LOG_LEVEL and LOG_PRETTY env values to control the log level and format.

Flags:
  -h, --help                 help for forward
  -H, --host stringArray     Host to listen on (default [0.0.0.0:8080])
  -s, --socket stringArray   Socket to export: /var/run/docker.sock:/:*,-POST,-PUT,-DELETE
  -v, --version              version for forward

Show the lists of sockets to export with show http methods.

HTTP methods could be any string(case insensitive), and starting with - will not allowed.

# allow all methods to / path
/var/run/docker.sock

# allow all except POST, PUT, DELETE with basepath /docker/
/var/run/docker.sock:/docker/:-POST,-PUT,-DELETE

# Only allow GET requests
/var/run/docker.sock:/docker/:GET

# Disable all methods of requests
/var/run/docker.sock:/docker/:-*
sudo ./forward -s '/var/run/docker.sock:/:-POST,-PUT,-DELETE'

If you need multiple ports with multiple sockets than give name before prefix of @.

forward -H [email protected]:8082 -s 'localhost@/var/run/docker.sock'

Use -H and -s more than once to make connections.

forward -H [email protected]:8082 -s 'localhost@/var/run/docker.sock' -H [email protected]:8080 -s 'share@/var/run/docker.sock:/:-POST,-PUT,-DELETE'

# 2024-09-07 21:01:45 CEST INF forward version: v0.0.0 commit: - buildDate:-
# 2024-09-07 21:01:45 CEST INF localhost - route [/] to [/var/run/docker.sock]; allow: *; deny:
# 2024-09-07 21:01:45 CEST INF share - route [/] to [/var/run/docker.sock]; allow: *; deny: DELETE,POST,PUT
# 2024-09-07 21:01:45 CEST INF server share on [0.0.0.0:8080]
# 2024-09-07 21:01:45 CEST INF server localhost on [127.0.0.1:8082]

If program cannot access the socket, you will get 502 Bad Gateway on every request.

Docker

There are scratch and alpine version of container image.

docker run --rm -it -p 8080:8080 -v /var/run/docker.sock:/docker.sock ghcr.io/worldline-go/forward -s /docker.sock:/:-POST,-PUT,-DELETE,-PATCH

Development

Local generate binary

make build