summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2026-11-08 15:13:02 +0100
committerChristian Breunig <christian@breunig.cc>2026-11-08 17:48:31 +0100
commitd495ea4ff90118908e1fbeadbf9fc419b542ff9e (patch)
tree06cfeb92136f20b0ae3931df744a65e8f2fa5f23
parent8f5305b60ed2efede08f8de2a981a812f23bbbb1 (diff)
downloadvyos-1x-d495ea4ff90118908e1fbeadbf9fc419b542ff9e.tar.gz
vyos-1x-d495ea4ff90118908e1fbeadbf9fc419b542ff9e.zip
smoketest: T9587: verify operator users can run op-mode commands
No smoketest logged in as an operator-level user, so losing the SUID bit on the op-mode runner went unnoticed. Add a test which checks the SUID bit, then logs in via SSH as an operator and verifies that commands in the command-policy return the same output as for an admin, while commands outside of it are rejected.
-rwxr-xr-xsmoketest/scripts/cli/test_op-mode_show.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/smoketest/scripts/cli/test_op-mode_show.py b/smoketest/scripts/cli/test_op-mode_show.py
index ed7c3e8de..2af176b3e 100755
--- a/smoketest/scripts/cli/test_op-mode_show.py
+++ b/smoketest/scripts/cli/test_op-mode_show.py
@@ -14,10 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
+import stat
import unittest
from base_vyostest_shim import VyOSUnitTestSHIM
+from vyos.configquery import ConfigTreeQuery
from vyos.utils.process import cmdl
from vyos.version import get_version
@@ -42,5 +45,64 @@ class TestOPModeShow(VyOSUnitTestSHIM.TestCase):
# Validate
self.assertIn('VRF is not configured', tmp)
+ def test_op_mode_operator_user(self):
+ login_path = ['system', 'login']
+ op_wrapper = '/opt/vyatta/bin/vyatta-op-cmd-wrapper'
+ op_runner = '/usr/bin/vyos-op-run'
+ op_group = 'smoketest'
+ op_user = 'smoketest-operator'
+ op_password = 'vyos-operator-123'
+
+ # T9587: operators do not use sudo, they rely on the SUID bit of the
+ # op-mode runner to gain privileges after the permission check
+ self.assertTrue(os.stat(op_runner).st_mode & stat.S_ISUID)
+
+ # The SSH helper uses password login on localhost:22, an existing SSH
+ # configuration must permit that
+ config = ConfigTreeQuery()
+ ssh_path = ['service', 'ssh']
+ ssh_pre_test = config.exists(ssh_path)
+ if ssh_pre_test:
+ listen = config.values(ssh_path + ['listen-address'])
+ if ('22' not in (config.values(ssh_path + ['port']) or ['22']) or
+ (listen and not {'0.0.0.0', '::', '127.0.0.1', '::1'} & set(listen)) or
+ config.exists(ssh_path + ['disable-password-authentication']) or
+ config.exists(ssh_path + ['vrf'])):
+ self.skipTest('SSH configuration does not permit password login on localhost:22')
+ else:
+ self.cli_set(ssh_path)
+
+ # A policy entry implicitly allows all of its sub-commands, while a
+ # more specific entry rejects the shorter command
+ allowed = ['show version kernel', 'show interfaces']
+ denied = ['show version', 'show version frr']
+
+ for command in allowed:
+ self.cli_set(login_path + ['operator-group', op_group,
+ 'command-policy', 'allow', command])
+ self.cli_set(login_path + ['user', op_user, 'authentication',
+ 'plaintext-password', op_password])
+ self.cli_set(login_path + ['user', op_user, 'operator', 'group', op_group])
+ self.cli_commit()
+
+ try:
+ for command in allowed:
+ out, err = self.ssh_send_cmd(f'{op_wrapper} {command}',
+ op_user, op_password)
+ self.assertFalse(err)
+ self.assertEqual(out, self.op_mode([command]))
+
+ for command in denied:
+ out, err = self.ssh_send_cmd(f'{op_wrapper} {command}',
+ op_user, op_password)
+ self.assertFalse(out)
+ self.assertIn('You do not have a permission to execute VyOS command', err)
+ finally:
+ self.cli_delete(login_path + ['user', op_user])
+ self.cli_delete(login_path + ['operator-group', op_group])
+ if not ssh_pre_test:
+ self.cli_delete(ssh_path)
+ self.cli_commit()
+
if __name__ == '__main__':
unittest.main(verbosity=2, failfast=VyOSUnitTestSHIM.TestCase.debug_on())