Page MenuHomeVyOS Platform

Unable to change configuration after changing it from script (vbash + script-template)
Closed, ResolvedPublicBUG

Description

Hi all!
If we change some configuration from script, then we can't do after this any changes manually until reboot system.
Example:

Startup configuration:

[edit]
vyos@vyos# show interfaces ethernet eth2 
 address 192.168.202.1/24
 disable
 duplex auto
 hw-id 08:00:27:2d:07:cb
 policy {
     route google
 }
 smp-affinity auto
 speed auto
[edit]
vyos@vyos# show system task-scheduler 
 task testtask01 {
     crontab-spec @reboot
     executable {
         path /config/scripts/testscript01.script
     }
 }
[edit]
vyos@vyos#

Script content:

root@vyos:/home/vyos# cat /config/scripts/testscript01.script 
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template

sleep 30s
configure
delete interfaces ethernet eth2 disable
commit
exit

Reboot, wait 30 seconds and check for configuration changes:

[edit]
vyos@vyos# show interfaces ethernet eth2 
 address 192.168.202.1/24
 duplex auto
 hw-id 08:00:27:2d:07:cb
 policy {
     route google
 }
 smp-affinity auto
 speed auto
[edit]
vyos@vyos# 
vyos@vyos# exit
exit
vyos@vyos:~$ show interfaces 
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             10.0.2.5/24                       u/u  
eth1             192.168.20.60/24                  u/u  
eth2             192.168.202.1/24                  u/u  
lo               127.0.0.1/8                       u/u  
                 ::1/128
vyos@vyos:~$

So, script is working. But, now if we try to change configuration:

[edit]
vyos@vyos# set system host-name test01

  Set failed

[edit]
vyos@vyos# set interfaces ethernet eth1 speed 100

  Set failed

[edit]
vyos@vyos# set firewall name test1 default-action drop 

  Set failed

[edit]
vyos@vyos#

... and so on. Configuration management become completely broken until we disable script and reboot.

Details

Difficulty level
Unknown (require assessment)
Version
VyOS 1.2.0-rolling+201810280337
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Perfectly compatible
Issue type
Bug (incorrect behavior)

Event Timeline

syncer triaged this task as Normal priority.Oct 28 2018, 7:28 PM
syncer added a subscriber: syncer.

the script must be run from vyatta group
sg vyattacfg /path/to/script

@dmbaturin should we run all our scripts with such wrapper? (e.g. add it to all places where scripts can be used)

@zsdc Which version are you using? It should be fixed in rc1 already. If you are using rc1 or newer, that means the fix is incomplete.

If you are using 1.1.8, please use sg as @syncer suggests.

@zsdc Ah, sorry, rolling-1028. I'll take a look.

@syncer, thanks for hint. Works with:

[edit]
vyos@vyos# show system task-scheduler 
 task testtask01 {
     crontab-spec @reboot
     executable {
         arguments "vyattacfg /config/scripts/testscript01.script"
         path /usr/bin/sg
     }
 }
[edit]
vyos@vyos#

But this workaround is ugly a little bit (if we want to use arguments for example).
Maybe, better will be if VyOS will do this under the hood, without end-user engagement?

@zsdc Yes, that's the idea. We even have a task about it: T462

The code looks right to me. Could you create a task without the workaround and post relevant crontab line?

@dmbaturin after some thinking about this problem I think that doing sg for all script is not a very good idea. There can be a situations, when we wan't to run it from other groups.
By now, I see two ways:

  • add additional parameter to executable option, that will define using script vbash with template or not;
  • move setting up right group to /opt/vyatta/etc/functions/script-template.

Second way seems more practical and easy for configuration migrations.

syncer raised the priority of this task from Normal to High.
syncer moved this task from Needs Triage to Backlog on the VyOS 1.2 Crux (VyOS 1.2.1) board.
Unknown Object (User) added a subscriber: Unknown Object (User).Sep 7 2019, 6:15 PM

As a workaround could this be added as the first lines of the bash script?
This will check the primary group the script executes via and respawn as the vyattacfg group if it's something else before continuing.

if [ $(id -gn) != vyattacfg ]; then
    exec sg vyattacfg "$0 $*"
fi

NB! the if is necessary because the script should not execute the exec when you respawn as correct group.
You will end in a exec loop if its not there .. :)
i've not tested this on vyos, but have helped me on other systems

syncer reassigned this task from dmbaturin to Unknown Object (User).Mar 16 2020, 12:47 AM
Unknown Object (User) added a comment.May 28 2020, 12:10 PM

@zsdc can you try to reproduce this issue on 1.3 rollings or on 1.2.5? I can't reach this behavior.

I don't see this behavior in VyOS 1.3-rolling-202007270117

set system task-scheduler task test crontab-spec '@reboot'
set system task-scheduler task test executable path '/config/scripts/test.sh'

vyos@r1-roll:~$ sudo cat /config/scripts/test.sh
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template

sleep 30s
configure
set interfaces ethernet eth1 description FOO
commit
exit

Reboot

vyos@r1-roll:~$ show int
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             192.168.122.11/24                 u/u  
eth1             192.168.100.189/24                u/u  FOO


vyos@r1-roll:~$ conf
se[edit]
vyos@r1-roll# set interfaces ethernet eth0 description BAR
[edit]
vyos@r1-roll# commit
[edit]
vyos@r1-roll# run show int
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface        IP Address                        S/L  Description
---------        ----------                        ---  -----------
eth0             192.168.122.11/24                 u/u  BAR
eth1             192.168.100.189/24                u/u  FOO
lo               127.0.0.1/8                       u/u  
                 ::1/128                                
[edit]
vyos@r1-roll#

@zsdc can we close it?

Unknown Object (User) closed this task as Resolved.Sep 18 2020, 8:48 AM

Marked as resolved

dmbaturin set Is it a breaking change? to Perfectly compatible.
dmbaturin set Issue type to Bug (incorrect behavior).