dnspython icon indicating copy to clipboard operation
dnspython copied to clipboard

Allow disabling `$GENERATE`

Open peterthomassen opened this issue 2 years ago • 1 comments

Motivation When reading a zone file, records can be dynamically generated using the $GENERATE directive. This is a BIND-specific feature, not a DNS feature. It should not necessarily be supported whenever presentation format is read.

We use dnspython to allow users at desec.io to paste their zone data when creating a domain at deSEC, for easy migration. We do not think that it is a good idea to allow creating server-side load via $GENERATE in that context. We would therefore like to be able to disable this directive, just like it is possible to disable $INCLUDE.

Describe the solution you'd like. Two options come to mind:

  • Add a allow_generate argument to dns.zone.from_text(), which can be set to False to disable the functionality (like allow_include=False).
  • More generically, turn the allow_directives argument of the Reader constructor from Boolean into a list, which has the names of the allowed directives. One could then very easily allow $TTL and/or $ORIGIN, while disabling others. -- Interaction with allow_include would have to be specified.

Not sure what's best.

@nils-wisiol

peterthomassen avatar Aug 09 '22 01:08 peterthomassen

At the moment I like the idea of allowing allow_directives in the Reader to be either a boolean or an iterable. (The boolean is for backwards compatibility). We then expose allow_directives in dns.zone.from_text() too, keeping allow_include for backwards compatibility, and saying that if both specified then allow_directives wins. This way we get fine grained control over all directives without adding an allow_ to the API every time.

rthalley avatar Aug 09 '22 16:08 rthalley

Limiting $GENERATE is certainly a good idea... as opposed to generating 2^31 RRs from a single-line snippet.

pspacek avatar Aug 15 '22 07:08 pspacek

complete by merge of #833 (thanks!)

peterthomassen avatar Aug 17 '22 03:08 peterthomassen