#[non_exhaustive]pub struct ServeOptions {Show 15 fields
pub listen: Vec<SocketAddr>,
pub tls: Option<ServerTls>,
pub client_ca_pem: Option<Vec<u8>>,
pub trusted_proxies: Vec<IpNet>,
pub trusted_proxy_header: Option<ForwardedHeader>,
pub trusted_proxy_client_cert: Option<String>,
pub proxy_protocol: bool,
pub body_timeout: Duration,
pub receive: Option<Arc<ReceivePolicies>>,
pub allow_cleartext_credentials: bool,
pub parallel_uploads: u32,
pub session_idle_timeout: Duration,
pub max_sessions: usize,
pub on_report: Option<Arc<dyn Fn(ReceiveReport) + Send + Sync>>,
pub on_event: Option<Arc<dyn Fn(&ServerEvent) + Send + Sync>>,
}Expand description
The options of bind.
The struct is #[non_exhaustive], so a caller starts from
ServeOptions::default and sets the fields.
bind checks the fields that go together. Its
errors list the refusals.
The fields parallel_uploads, session_idle_timeout, max_sessions, and
on_report go to the EndpointOptions of the receive endpoint. Their
defaults are the defaults of EndpointOptions::default. If
receive is None, bind does
not read these four fields or allow_cleartext_credentials. It then
refuses no value of them.
§Authentication
The server identifies the client of each request by the auth items of the
client groups of receive: the requests of the
receive endpoint, and the reads of the archive view and of the ref
listing. Identification gives one auth item. The server takes the first
step that applies:
- A request with more than one
Authorizationheader gets 401. - If the connection has no TLS, a bearer or Basic credential gets 403,
unless
allow_cleartext_credentialsis set, or a trusted proxy states the schemehttps(see Client address). - A request with an
Authorizationheader gets the item of its credential. A bearer token,Authorization: Bearer TOKEN, gets thetoken-sha256:HEXitem of the SHA-256 digest of the token. A Basic credential,Authorization: Basicwith the base64 ofUSER:PASSWORD, gets thebasic-sha256:USER:HEXitem of the user name and of the digest of the password. The user name runs to the first:, so the password can hold:. A credential that matches no item gets 401, also when the request has a client certificate. An empty token, a Basic credential with no:, a user name that is not UTF-8, an empty password, and another scheme match no item. - A request with a client certificate gets the first item that matches,
in this order:
tls-sha256:HEXby the SHA-256 digest of the DER bytes,tls:NAMEby the subject CN,tls:*. A certificate that matches no item gets 403. A subject matchestls:NAMEonly if it holds exactly one CN, of type UTF8String or PrintableString. From a trusted proxy with a header of a forwarded certificate, the certificate comes from that header alone, and never from the TLS handshake (see Forwarded certificate). With noclient_ca_pem, a request has no client certificate, so thetls-sha256:HEX,tls:NAME, andtls:*items match no request. The other items of their groups still match. - A request whose client address is in the network of a
net:item gets that item. When two items match, the item with the longer prefix wins. - A request gets the
anonymousitem, if one exists. - Else the request gets 401 when a
token-sha256or abasic-sha256item exists, and 403 when none exists.
The server compares the digest of a credential with every token-sha256
or basic-sha256 item in constant time. It does not stop at a match. The
TLS handshake verifies a client certificate against
client_ca_pem. The server reads the
certificate of the handshake one time for each connection.
Each 401 carries two headers: WWW-Authenticate: Bearer realm="ostrya"
and WWW-Authenticate: Basic realm="ostrya".
A read gets the ReadAccess of the item,
with the claims of its certificate. A refused read gets the status of the
refusal and an empty body. Server states the rules of
a read.
The owner key of a request is the text of its item, as
AuthItem writes it. All clients with one
item share one owner key, for example all anonymous clients. A client
certificate that gives a tls:*, tls:NAME, or tls-sha256:HEX item of
a group with tls-accept-claim=true has the key tls-sha256:HEX, the
SHA-256 digest of its DER bytes. So two certificates with different
claims never share a session. This key is the key of no other client:
the certificate sets the item that it matches, and only the certificate
of that digest matches the item tls-sha256:HEX.
A session request selects the client group that carries the item in the
namespace of its Hello, with
ReceivePolicies::select. The
collection id of Hello names the namespace, and no collection or the
collection id of the repository names the local refs. The session gets
the policy of that group and no hooks. With no such group, and with a
group that opens no push session, the request gets 403.
§Claims
A client group with tls-accept-claim=true reads the claims of the client
certificate that gives the item of a session request or of a read: the
URI SANs with the scheme ostrya, as Claims
reads them.
The claims of the certificate of the TLS handshake are read one time for
each connection. The claims of a forwarded certificate are read one time
for each cache entry.
- When the certificate holds one or more claims for the namespace of the
session or of the ref that a read names, as
ClientAccess::claim_rulesgives them, they replace the allow items and the deny items of the group. The other values of the policy come from the group. - When it holds no claim for the namespace, the rules of the group apply.
- When the claims do not parse, the request gets 403, and the server
reports a
ServerEvent::BadClaimstoon_event. The claims do not parse when a URI with the schemeostrya, in any case, is no claim form, when the certificate holds more thanMAX_CLAIMSsuch URIs, when the certificate does not decode, when it holds more than one subjectAltName extension, and when its subjectAltName extension does not decode. Each case has its own reason. - When the rules of the claims open no push session, the
sessionrequest gets 403. - A read gets 403 when the claims do not parse and a group with
tls-accept-claim=truecarries the item of the certificate, also a read of an object or ofconfig. The server reports aServerEvent::BadClaimsfor each such read.
A group with tls-accept-claim=false, a credential, a net: item, and the
anonymous item read no claim.
§Client address
The client address is the TCP peer address of the connection, with these changes:
- With
proxy_protocol, the source address of the PROXY header replaces the peer address. A header with no address keeps the peer address. - When the peer address is in
trusted_proxies, the server reads the client address from the one header oftrusted_proxy_header. It walks the hops of the header from the right, and skips each hop whose address is in a trusted network. The first other hop is the client. When all hops are trusted, the client is the leftmost hop. A hop with no address, for exampleunknown, gives a client with no address, which matches nonet:item. A header that is absent, or that has one line of white space alone, keeps the peer address. A header that is not UTF-8, that does not parse, or that has text and no hop, for exampleX-Forwarded-For: , ,, gives no address. - From a trusted peer, the request counts as TLS for step 2 when the
proxy states the scheme
https, in any case. WithForwardedHeader::Forwarded, the scheme is theprotoof the selected hop. With the other headers, it is the rightmost value ofX-Forwarded-Proto. - From a peer that is not trusted, the server reads no forwarding header,
no
X-Forwarded-Proto, and no forwarded certificate.
An IPv4-mapped IPv6 address counts as its IPv4 address.
With proxy_protocol, the server compares
the source address of the PROXY header with
trusted_proxies, so it does not read
the forwarding headers and the forwarded certificate of a proxy that
states the address of its client in the PROXY header.
A trusted proxy must set or remove the forwarding header, the
X-Forwarded-Proto header, and the header of a forwarded certificate of
each request. Else a client can send these headers through the proxy and
take another address or another certificate.
§Forwarded certificate
trusted_proxy_client_cert
names the request header that carries the client certificate from a
trusted proxy. The server reads the header for each request, and never
keeps the result for a connection, because a proxy sends the requests of
many clients over one connection. The value is one of these forms, after
the server percent-decodes it, with + kept as +:
- a PEM certificate that starts with
-----BEGIN, as nginx$ssl_client_escaped_certgives it URL-escaped; - the base64 of the DER bytes, as HAProxy
ssl_c_der,base64gives it, or URL-escaped, as TraefikpassTLSClientCertgives it.
From a trusted proxy, this header alone gives the certificate. The server
does not use the certificate of the TLS handshake, which is the
certificate of the proxy. A request with no such header gives no
certificate. From a peer that is not trusted, or with no
trusted_proxy_client_cert, the certificate of the TLS handshake applies.
An empty value, or white space alone, is no certificate. These cases get
403: a value with a comma, as the chain of Traefik holds; more than one
line of the header; PEM with more than one CERTIFICATE section; a value
that does not decode; and a certificate that
client_ca_pem does not verify. The
server uses no intermediate certificate from the proxy, so the client CA
must hold each intermediate CA. The verification checks the validity
period and the clientAuth extended key usage.
The server keeps each verified certificate in a cache of 1024 entries, keyed by the SHA-256 digest of its DER bytes, until the end of its validity period. A full cache removes its oldest entry. The cache keeps no refusal.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.listen: Vec<SocketAddr>The addresses to listen on.
Port 0 lets the kernel choose a port, which
Server::local_addrs reports.
bind refuses an empty list. The default is
127.0.0.1:8080.
tls: Option<ServerTls>The TLS files, or None for plain HTTP. The default is None.
client_ca_pem: Option<Vec<u8>>The PEM CA certificates that verify the client certificate of the TLS
handshake and a forwarded certificate, or None.
bind builds one verifier from the certificates, and
the handshake and each forwarded certificate use it. A client that
presents no certificate also completes the handshake. A client that
presents a certificate that the CA did not sign fails the handshake.
The field needs tls or
trusted_proxy_client_cert.
The default is None.
trusted_proxies: Vec<IpNet>The networks of the peers whose forwarding data the server reads.
Client address states the rules. A
non-empty list needs
trusted_proxy_header. The
default is an empty list, which trusts no peer.
trusted_proxy_header: Option<ForwardedHeader>The request header from which the server reads the client address of
a request from a trusted proxy, or None.
The server reads this one header, and no other header of a client
address. The field needs a non-empty
trusted_proxies. The default is
None.
trusted_proxy_client_cert: Option<String>The name of the request header that carries the client certificate
from a trusted proxy, or None.
Forwarded certificate states the
rules. The name passes ostrya::access::is_header_name. The field
needs client_ca_pem and a non-empty
trusted_proxies. The default is
None.
proxy_protocol: boolThe switch that reads a PROXY protocol header, version 1 or 2, at the start of each connection.
With the switch, each listener reads the header before the TLS
handshake and before the first request. Its source address replaces
the peer address. A header with no address, for example UNKNOWN or
LOCAL, keeps the peer address. The server closes a connection with
no valid header, or with no header within 30 seconds, and writes no
byte to it. The default is false.
Each peer that can connect states its own client address in the header. Only the proxy must be able to reach the listener.
body_timeout: DurationThe longest time that a response body waits for the client to take its next bytes.
If a body waits longer, its connection ends. The bodies of the connection then drop and release the files and the compressors that they hold. An HTTP/2 connection sends a ping after half this time with no frame from the peer. It ends if the peer does not answer within this time.
A body that waits for its own reader, for example for a compressor of the archive view, does not wait for the client. The time does not count for such a body until it gives its next frame.
The default is 60 seconds. bind refuses zero.
receive: Option<Arc<ReceivePolicies>>The client groups of the server and their policies, or None for a
read-only server.
With None, the server has no receive endpoint and identifies no
client. Each read gets the rights of the anonymous item under the
implicit group of a config with no client group. The default is
None.
ReceivePolicies::from_config
builds the value from the repository config.
Authentication states how a request
gets its group. The server does not read the groups or a repository
setting of the endpoint again while it runs. A change takes effect at
the next start.
allow_cleartext_credentials: boolThe switch that takes a bearer or Basic credential on a connection without TLS.
The default is false. If the switch is false, the server refuses
such a credential with 403, unless a trusted proxy states the scheme
https. A server on a loopback address, or behind a proxy that
terminates TLS and is not in
trusted_proxies, can set it. A
read-only server does not read the field.
parallel_uploads: u32The number of object streams of one session, as in
EndpointOptions::parallel_uploads.
The default is 4.
session_idle_timeout: DurationThe idle timeout of a session, as in
EndpointOptions::session_idle_timeout.
The default is 300 seconds.
max_sessions: usizeThe most sessions open at the same time, as in
EndpointOptions::max_sessions.
The default is 16.
on_report: Option<Arc<dyn Fn(ReceiveReport) + Send + Sync>>The callback for the report of a committed session, as in
EndpointOptions::on_report.
on_event: Option<Arc<dyn Fn(&ServerEvent) + Send + Sync>>The callback for each ServerEvent of the
server, or None.
The server calls it in the task of the request, so the callback must
return soon. A host writes the event to its log, for example the
Display text of the event on standard error.
ServerEvent::is_warning tells a
warning from an error. The server calls it also with no receive
policies. The default is None, which drops each event.
Trait Implementations§
Source§impl Clone for ServeOptions
impl Clone for ServeOptions
Source§impl Debug for ServeOptions
The debug text shows a callback that is set as <callback>, a
client CA that is set as <N bytes>, the trusted proxies as networks,
and the receive policies as the
names of their client groups. It holds no auth item, so no digest and no
user name.
impl Debug for ServeOptions
The debug text shows a callback that is set as <callback>, a
client CA that is set as <N bytes>, the trusted proxies as networks,
and the receive policies as the
names of their client groups. It holds no auth item, so no digest and no
user name.