Page MenuHomeVyOS Platform

unescape backslashes for config save, compare commands
Closed, ResolvedPublicBUG

Description

Having moved to using the configtree data structure for the config 'save' command (T4292), respectively, 'compare' command (T4942), single backslashes escaped before parsing need to be restored. This becomes evident in leaf node values with a single backslash, for example, T5939.

Details

Difficulty level
Hard (possibly days)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Perfectly compatible
Issue type
Bug (incorrect behavior)

Event Timeline

This turns out to be non-trivial, due to the interaction between legacy and modern behavior; nonetheless, a simple preliminary fix is in testing, and the task will be updated with the details when the PR is complete.

jestabro changed Difficulty level from Normal (likely a few hours) to Hard (possibly days).Feb 12 2024, 9:05 PM

The examples in T5939 reveal a general issue that, although uncommon, needs to be rationalized. The modern parser requires single backslashes to be escaped, if in quoted strings, however (1) the legacy parser (unlike the modern parser) is inconsistent in quoting values (2) the existing solution escapes all single backslashes not a part of control sequences and makes no attempt to restore single backslashes when possible --- this is safe, but leads to redundant escaping of backslashes as revealed in the examples in T5939.

We still rely on the legacy representation of the config as the base record which is then passed to modern tools for all subsequent modifications: migration, save, config_dict, etc. Normalizing the output before passing to configtree is necessary.

As this affects migration and config only in corner cases, and any solution is potentially dangerous, the solution below will be recommended for 1.5 but NOT for backport until some time is spent in the rolling release. The latter recommendation assumes that a workaround is available for the issue of T5939 and any similar examples.

Proposed fix in preparation:
https://github.com/vyos/vyos-1x/compare/current...jestabro:replace-backslash

The above will normalize behavior for 1.4/1.5, such that output of save and compare will correctly reflect set values containing single backslashes. What is cannot do is avoid a single escape of '\' --> '\\' when migrating a config value containing a single backslash and no white space (idiosyncrasy of legacy output); consequently, although controlling behavior, a full solution there would be ugly and fragile; a simple workaround however could be provided.

PR:
https://github.com/vyos/vyos-1x/pull/3035

After normalization of PR (compare with examples from T5939)

vyos@vyos# set interfaces ethernet eth0 description 'fo\o'
[edit]
vyos@vyos# compare
[interfaces ethernet eth0]
+ description "fo\o"

[edit]
vyos@vyos# commit
[edit]
vyos@vyos# run show configuration commands |match desc
set interfaces ethernet eth0 description 'fo\o'
[edit]
vyos@vyos# set interfaces ethernet eth0 description 'fo\\o'
[edit]
vyos@vyos# compare
[interfaces ethernet eth0]
- description "fo\o"
+ description "fo\\o"

[edit]
vyos@vyos# commit
[edit]
vyos@vyos# run show configuration commands |match desc
set interfaces ethernet eth0 description 'fo\\o'
jestabro changed the task status from Open to Needs testing.Feb 20 2024, 5:35 PM
jestabro removed a project: VyOS 1.4 Sagitta.
jestabro changed the task status from Needs testing to Backport candidate.Mar 19 2024, 1:58 PM
jestabro moved this task from Need Triage to Finished on the VyOS 1.5 Circinus board.

As discussed, this will wait before being backported to 1.4.