class LittleGhost::Network::Facade
A plaintext listener that forwards every request to one HTTPS host.
A facade gives a client that honors a base URL, such as a command-line tool pointed at http://127.0.0.1:3130, a way to reach exactly one upstream without trusting a proxy certificate. The gateway originates TLS to upstream and asks the policy’s authorizer about every request before forwarding it, so the authorizer can restrict methods and paths and replace a placeholder credential with a real one. Responses stream back without buffering.
LittleGhost::Network::Facade.new( name: :help_center, upstream: "api.example.com", port: 3130, timeout: 0 )
Exactly one of port or socket is required. port listens on 127.0.0.1; socket is an absolute Unix socket path that the application makes reachable from the sandbox. timeout bounds each request in seconds; 0 disables the bound for streaming responses, and nil uses the policy’s timeout for the upstream host or no bound.
Any process that can connect to the facade receives the credentials its authorizer injects. Place a socket in a directory that only the intended sandbox can reach, and use a port only when the sandbox has its own network namespace.
Public Class Methods
Source
# File lib/little_ghost/network.rb, line 107 def self.coerce(value) return value if value.is_a?(self) raise PolicyError, "network facades must be Hashes or LittleGhost::Network::Facade values" unless value.is_a?(Hash) new(**value.transform_keys(&:to_sym)) end
Returns value unchanged or builds a facade from a Hash.
# File lib/little_ghost/network.rb, line 115 def initialize(name:, upstream:, port: nil, socket: nil, timeout: nil) name = String(name) raise PolicyError, "network facade names must be lowercase identifiers" unless NAME.match?(name) raise PolicyError, "network facades require exactly one of port or socket" if port.nil? == socket.nil? upstream = String(upstream) upstream = "#{upstream}:443" unless upstream.match?(/:\d+\z/) host, upstream_port = EnvoyConfig.parse_endpoint(upstream) if !port.nil? && !(port.is_a?(Integer) && port.between?(1, 65_535)) raise PolicyError, "network facade ports must be integers between 1 and 65535" end unless socket.nil? socket = String(socket) raise PolicyError, "network facade sockets must be absolute paths" unless socket.start_with?("/") end super( name: name.freeze, upstream: "#{host}:#{upstream_port}".freeze, port:, socket: socket&.freeze, timeout: timeout.nil? ? nil : Network.timeout_seconds(timeout) ) end
Builds a normalized facade declaration.
Public Instance Methods
Source
# File lib/little_ghost/network.rb, line 140 def host = upstream.rpartition(":").first
The upstream DNS name without its port.
Source
# File lib/little_ghost/network.rb, line 143 def upstream_port = Integer(upstream.rpartition(":").last)
The upstream TLS port.