class Amber::Configuration::ServerConfig

Included Modules

Defined in:

amber/configuration/server_config.cr

Constant Summary

DEFAULT_TRUSTED_PROXIES = ["127.0.0.0/8", "::1"]

Loopback only: a reverse proxy on the same host (Caddy, nginx) is trusted out of the box, and nothing else is.

LIST_OF_TRUSTED_PROXY_HEADERS = [TRUSTED_PROXY_HEADERS_X_FORWARDED, TRUSTED_PROXY_HEADERS_FORWARDED]
TRUSTED_PROXY_HEADERS_FORWARDED = "forwarded"

#trusted_proxy_headers value for proxies that write the RFC 7239 Forwarded header instead.

TRUSTED_PROXY_HEADERS_X_FORWARDED = "x-forwarded"

#trusted_proxy_headers value for proxies that write X-Forwarded-For and X-Forwarded-Proto (Caddy, nginx, HAProxy, cloud load balancers).

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new #

[View source]

Class Method Detail

def self.check_unix_socket!(terminates_tls : Bool, process_count : Int32) : Nil #

Raises Amber::Exceptions::ConfigurationError when a server listening on #unix_socket would also terminate TLS or run more than one process. Amber::Server#run calls it with the effective settings before it forks or binds.


[View source]

Instance Method Detail

def after_initialize #

Validates the forwarding settings read from YAML, so a bad entry fails while the settings load rather than on a request.


[View source]
def host : String #

[View source]
def host=(host : String) #

[View source]
def listens_on_unix_socket? : Bool #

Returns true when the server listens on #unix_socket rather than TCP.


[View source]
def port : Int32 #

[View source]
def port=(port : Int32) #

[View source]
def port_reuse : Bool #

[View source]
def port_reuse=(port_reuse : Bool) #

[View source]
def process_count : Int32 #

[View source]
def process_count=(process_count : Int32) #

[View source]
def reads_forwarded_header? : Bool #

Returns true when the trusted proxies write the RFC 7239 Forwarded header rather than the X-Forwarded-* headers.


[View source]
def secret_key_base : String #

[View source]
def secret_key_base=(secret_key_base : String) #

[View source]
def ssl : SSLConfig #

[View source]
def ssl=(ssl : SSLConfig) #

[View source]
def trusted_proxies : Array(String) #

Returns a copy of the IP addresses and CIDR blocks of the reverse proxies allowed to report the client's scheme and address. Assign a new list to change it; editing the returned array changes nothing.

server:
  trusted_proxies:
    - "127.0.0.1"
    - "10.0.0.0/8"

[View source]
def trusted_proxies=(list_of_notations : Array(String)) : Array(String) #

Replaces the trusted proxy list. Raises Amber::Exceptions::ConfigurationError when an entry is not an IP address or CIDR block, or is a /0 block that trusts every address.


[View source]
def trusted_proxy_headers : String #

Returns which forwarding headers the trusted proxies write: "x-forwarded" (X-Forwarded-For and X-Forwarded-Proto, the default) or "forwarded" (RFC 7239 Forwarded). Amber reads only that family, because a proxy passes the other family through from the client unchanged, so believing it would let the client choose its own address and scheme.


[View source]
def trusted_proxy_headers=(header_family : String) : String #

Sets which forwarding headers the trusted proxies write. Raises Amber::Exceptions::ConfigurationError for a value other than "x-forwarded" or "forwarded".


[View source]
def trusted_proxy_networks : Slice(Amber::Support::TrustedProxyNetwork) #

Returns the trusted proxies parsed into networks, as a read-only slice of the current snapshot: writing to it raises.


[View source]
def unix_socket : String | Nil #

Path of a UNIX socket to listen on instead of #host and #port, for a reverse proxy on the same machine (reverse_proxy unix//run/app.sock in Caddy). While it is set, every UNIX socket peer counts as a trusted proxy: such a connection is local by construction, and the socket file's permissions decide who may open it.


[View source]
def unix_socket=(unix_socket : String | Nil) #

Path of a UNIX socket to listen on instead of #host and #port, for a reverse proxy on the same machine (reverse_proxy unix//run/app.sock in Caddy). While it is set, every UNIX socket peer counts as a trusted proxy: such a connection is local by construction, and the socket file's permissions decide who may open it.


[View source]
def validate!(environment : Amber::Environment::Env | Nil = nil) : Nil #

[View source]