Skip to content

Commit

Permalink
auth web: make request/response timeout configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-sjorgedeaguiar committed May 21, 2024
1 parent 9246248 commit 244bfd9
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/actions/spell-check/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ conflictor
confx
connectionmanagement
connectionroom
connectiontimeout
connectlogstr
connectstr
connstr
Expand Down
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ configname
configsetting
configurability
confs
connectiontimeout
conntrack
Conntracking
Consolas
Expand Down
3 changes: 2 additions & 1 deletion docs/http-api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The following webserver related configuration items are available:
* :ref:`setting-webserver-port`: Port to bind the webserver to.
* :ref:`setting-webserver-allow-from`: Netmasks that are allowed to connect to the webserver
* :ref:`setting-webserver-max-bodysize`: Maximum request/response body size in megabytes
* :ref:`setting-webserver-connection-timeout`: Request/response timeout in seconds


Metrics Endpoint
Expand Down Expand Up @@ -290,7 +291,7 @@ Prometheus can then be configured to scrape metrics from this endpoint using a s
- job_name: 'pdns_auth'
scrape_interval: 1m
static_configs:
- targets: ['pdns_auth_host:pdns_auth_ws_port']
- targets: ['pdns_auth_host:pdns_auth_ws_port']
Further details can be gathered from the `prometheus docs <https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config>`_.

Expand Down
10 changes: 10 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,16 @@ The value between the hooks is a UUID that is generated for each request. This c

Maximum request/response body size in megabytes.

.. _setting-webserver-connection-timeout:

``webserver-connection-timeout``
--------------------------

- Integer
- Default: 5

Request/response timeout in seconds.

.. _setting-webserver-password:

``webserver-password``
Expand Down
1 change: 1 addition & 0 deletions pdns/auth-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ static void declareArguments()
::arg().set("webserver-allow-from", "Webserver/API access is only allowed from these subnets") = "127.0.0.1,::1";
::arg().set("webserver-loglevel", "Amount of logging in the webserver (none, normal, detailed)") = "normal";
::arg().set("webserver-max-bodysize", "Webserver/API maximum request/response body size in megabytes") = "2";
::arg().set("webserver-connection-timeout", "Webserver/API request/response timeout in seconds") = "5";
::arg().setSwitch("webserver-hash-plaintext-credentials", "Whether to hash passwords and api keys supplied in plaintext, to prevent keeping the plaintext version in memory at runtime") = "no";

::arg().setSwitch("query-logging", "Hint backends that queries should be logged") = "no";
Expand Down
5 changes: 3 additions & 2 deletions pdns/webserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ void WebServer::serveConnection(const std::shared_ptr<Socket>& client) const {
YaHTTP::AsyncRequestLoader yarl;
yarl.initialize(&req);
req.max_request_size=d_maxbodysize;
int timeout = 5;
int timeout = d_connectiontimeout;
client->setNonBlocking();

try {
Expand Down Expand Up @@ -598,7 +598,8 @@ WebServer::WebServer(string listenaddress, int port) :
d_listenaddress(std::move(listenaddress)),
d_port(port),
d_server(nullptr),
d_maxbodysize(2*1024*1024)
d_maxbodysize(2*1024*1024),
d_connectiontimeout(5)
{
}

Expand Down
5 changes: 5 additions & 0 deletions pdns/webserver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ public:
d_maxbodysize = s * 1024 * 1024;
}

void setConnectionTimeout(int t) { // in seconds
d_connectiontimeout = t;
}

void setACL(const NetmaskGroup &nmg) {
d_acl = nmg;
}
Expand Down Expand Up @@ -282,6 +286,7 @@ protected:
std::unique_ptr<CredentialsHolder> d_webserverPassword{nullptr};

ssize_t d_maxbodysize; // in bytes
int d_connectiontimeout; // in seconds

NetmaskGroup d_acl;

Expand Down
1 change: 1 addition & 0 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ AuthWebServer::AuthWebServer() :
d_ws->setACL(acl);

d_ws->setMaxBodySize(::arg().asNum("webserver-max-bodysize"));
d_ws->setConnectionTimeout(::arg().asNum("webserver-connection-timeout"));

d_ws->bind();
}
Expand Down

0 comments on commit 244bfd9

Please sign in to comment.