Skip to content

Commit

Permalink
auth LUA: (optionally) drop whitespace on join
Browse files Browse the repository at this point in the history
fixes #14002
  • Loading branch information
Habbie committed Apr 8, 2024
1 parent bc68688 commit 26dbeed
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
14 changes: 13 additions & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1084,14 +1084,26 @@ guaranteed to be stable, and is in fact likely to change.
.. _setting-lua-records-exec-limit:

``lua-records-exec-limit``
-----------------------------
--------------------------

- Integer
- Default: 1000

Limit LUA records scripts to ``lua-records-exec-limit`` instructions.
Setting this to any value less than or equal to 0 will set no limit.

.. _setting-lua-records-insert-whitespace:

``lua-records-insert-whitespace``
---------------------------------

- Boolean
- Default: no in 5.0, yes before that

.. versionadded:: 4.9.1

When combining the ``"`` delimited chunks of a LUA record, whether to insert whitespace between each chunk.

.. _setting-master:

``master``
Expand Down
5 changes: 5 additions & 0 deletions docs/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ upgrade notes if your version is older than 3.4.2.
4.9.0 to 5.0.0/master
--------------

LUA records whitespace insertion
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:ref:`setting-lua-records-insert-whitespace`, introduced in 4.9.1 with the default value (``yes``) set to maintain the old behaviour of inserting whitespace, is set to ``no`` in 5.0.

ixfrdist IPv6 support
^^^^^^^^^^^^^^^^^^^^^

Expand Down
2 changes: 2 additions & 0 deletions pdns/auth-main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ static void declareArguments()
::arg().setSwitch("8bit-dns", "Allow 8bit dns queries") = "no";
#ifdef HAVE_LUA_RECORDS
::arg().setSwitch("enable-lua-records", "Process LUA records for all zones (metadata overrides this)") = "no";
::arg().setSwitch("lua-records-insert-whitespace", "Insert whitespace when combining LUA chunks") = "no";
::arg().set("lua-records-exec-limit", "LUA records scripts execution limit (instructions count). Values <= 0 mean no limit") = "1000";
::arg().set("lua-health-checks-expire-delay", "Stops doing health checks after the record hasn't been used for that delay (in seconds)") = "3600";
::arg().set("lua-health-checks-interval", "LUA records health checks monitoring interval in seconds") = "5";
Expand Down Expand Up @@ -704,6 +705,7 @@ static void mainthread()
g_doLuaRecord = ::arg().mustDo("enable-lua-records");
g_LuaRecordSharedState = (::arg()["enable-lua-records"] == "shared");
g_luaRecordExecLimit = ::arg().asNum("lua-records-exec-limit");
g_luaRecordInsertWhitespace = ::arg().mustDo("lua-records-insert-whitespace");
g_luaHealthChecksInterval = ::arg().asNum("lua-health-checks-interval");
g_luaConsistentHashesExpireDelay = ::arg().asNum("lua-consistent-hashes-expire-delay");
g_luaConsistentHashesCleanupInterval = ::arg().asNum("lua-consistent-hashes-cleanup-interval");
Expand Down
1 change: 1 addition & 0 deletions pdns/auth-main.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ extern size_t g_proxyProtocolMaximumSize;
#ifdef HAVE_LUA_RECORDS
extern bool g_doLuaRecord;
extern bool g_LuaRecordSharedState;
extern bool g_luaRecordInsertWhitespace;
extern time_t g_luaHealthChecksInterval;
extern time_t g_luaHealthChecksExpireDelay;
extern time_t g_luaConsistentHashesExpireDelay;
Expand Down
18 changes: 15 additions & 3 deletions pdns/dnsrecords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,27 @@ boilerplate_conv(OPT,
);

#ifdef HAVE_LUA_RECORDS

bool g_luaRecordInsertWhitespace;

string LUARecordContent::getCode() const
{
// in d_code, series of "part1" "part2"
vector<string> parts;
stringtok(parts, d_code, "\"");
string ret;
for(const auto& p : parts) {
ret += p;
ret.append(1, ' ');
if (g_luaRecordInsertWhitespace) { // default before 5.0
for(const auto& part : parts) {
ret += part;
ret.append(1, ' ');
}
}
else { // default since 5.0
for(const auto& part : parts) {
if (part != " ") {
ret += part;
}
}
}
return ret;
}
Expand Down
34 changes: 34 additions & 0 deletions regression-tests.auth-py/test_LuaRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class TestLuaRecords(AuthTest):
launch=bind geoip
any-to-tcp=no
enable-lua-records
lua-records-insert-whitespace=yes
lua-health-checks-interval=1
"""

Expand Down Expand Up @@ -157,6 +158,8 @@ class TestLuaRecords(AuthTest):
lookmeup IN A 192.0.2.5
dblookup IN LUA A "dblookup('lookmeup.example.org', pdns.A)[1]"
whitespace IN LUA TXT "'foo" "bar'"
""",
'createforward6.example.org': """
createforward6.example.org. 3600 IN SOA {soa}
Expand Down Expand Up @@ -1090,6 +1093,22 @@ def testDblookup(self):
self.assertRcodeEqual(res, dns.rcode.NOERROR)
self.assertEqual(self.sortRRsets(res.answer), self.sortRRsets(response.answer))

def testWhitespace(self, expectws=True):
"""
Test TXT query for whitespace
"""
name = 'whitespace.example.org.'

query = dns.message.make_query(name, 'TXT')

response = dns.message.make_response(query)

response.answer.append(dns.rrset.from_text(name, 0, dns.rdataclass.IN, dns.rdatatype.TXT, '"foo bar"' if expectws else '"foobar"'))

res = self.sendUDPQuery(query)
self.assertRcodeEqual(res, dns.rcode.NOERROR)
self.assertEqual(res.answer, response.answer)


class TestLuaRecordsShared(TestLuaRecords):
_config_template = """
Expand All @@ -1098,6 +1117,7 @@ class TestLuaRecordsShared(TestLuaRecords):
launch=bind geoip
any-to-tcp=no
enable-lua-records=shared
lua-records-insert-whitespace=yes
lua-health-checks-interval=1
"""

Expand All @@ -1112,6 +1132,20 @@ def testCounter(self):
self.assertEqual(len(resUDP), 50)
self.assertEqual(len(resTCP), 50)

class TestLuaRecordsNoWhiteSpace(TestLuaRecords):
_config_template = """
geoip-database-files=../modules/geoipbackend/regression-tests/GeoLiteCity.mmdb
edns-subnet-processing=yes
launch=bind geoip
any-to-tcp=no
enable-lua-records
lua-records-insert-whitespace=no
lua-health-checks-interval=1
"""

def testWhitespace(self):
return TestLuaRecords.testWhitespace(self, False)

if __name__ == '__main__':
unittest.main()
exit(0)

0 comments on commit 26dbeed

Please sign in to comment.