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 Jun 3, 2024
1 parent 71e1bc7 commit f1a968d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions 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
11 changes: 11 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2038,6 +2038,17 @@ 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``
--------------------------------
.. versionadded:: 4.8.5

- 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 @@ -244,6 +244,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 @@ -520,7 +520,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 @@ -588,7 +588,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)
{
YaHTTP::Router::Map("OPTIONS", "/<*url>", [](YaHTTP::Request *req, YaHTTP::Response *resp) {
// look for url in routes
Expand Down
5 changes: 5 additions & 0 deletions pdns/webserver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,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 @@ -285,6 +289,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 @@ -117,6 +117,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 f1a968d

Please sign in to comment.