Skip to content

Commit e3f4b1a

Browse files
authored
Granular "feeling safe" control (#5045)
Instead of one big all-or-nothing switch, finer control over various dangerous action is needed. Users can still allow everything, with `--feeling-safe`, or allow individual dangerous functionalities.
1 parent 1cacdb1 commit e3f4b1a

33 files changed

Lines changed: 620 additions & 179 deletions

File tree

agents/AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ make build-deps
6969
pre-commit run --all-files
7070

7171
# Run the core test plan - runs on developer's workstation
72-
tmt --feeling-safe -vv run -a provision -h local plan -n '^/plans/features/core$'
72+
tmt --allow-unsafe-behavior=provision/local -vv run -a provision -h local plan -n '^/plans/features/core$'
7373
```
7474

7575
### Building and Packaging

docs/guide.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ directly on your localhost:
6262

6363
.. code-block:: shell
6464
65-
tmt --feeling-safe run --all provision --how local
65+
tmt --allow-unsafe-behavior=provision/local run --all provision --how local
6666
67-
Note that the extra ``--feeling-safe`` option is needed for the
67+
Note that the extra ``--allow-unsafe-behavior`` option is needed for the
6868
:ref:`/plugins/provision/local` provision plugin as it can be
6969
dangerous to execute unknown code directly on your system. If
7070
you're afraid that the test could break your machine or just want

docs/guide/execute-tests.inc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ directly on your ``local`` host:
377377

378378
.. code-block:: shell
379379
380-
tmt --feeling-safe run --all provision --how=local
380+
tmt --allow-unsafe-behavior=provision/local run --all provision --how=local
381381
382382
In order to reboot a provisioned guest use the ``reboot`` command.
383383
By default a soft reboot is performed which should prevent data

docs/overview.rst

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,27 @@ TMT_PLUGINS
397397
separated with the ``:`` character can be provided as well.
398398

399399
TMT_FEELING_SAFE
400-
Set this variable to ``1`` to enable potentially dangerous
401-
operations such as executing tests directly on the test runner
402-
using the ``local`` provision method. Use with caution, only
403-
when you can fully trust the ``tmt`` metadata or if you know
404-
what you are doing.
400+
Set this variable to enable potentially unsafe behavior such
401+
as executing tests directly on the test runner using the
402+
``local`` provision method. See ``tmt --help`` for the full
403+
documentation, and interaction between ``--feeling-safe`` and
404+
``--allow-unsafe-behavior`` which allows more granular control,
405+
and the corresponding ``TMT_ALLOW_UNSAFE_BEHAVIOR`` environment
406+
variable.
407+
408+
Use with caution, only when you can fully trust the ``tmt`` metadata
409+
or if you know what you are doing.
410+
411+
TMT_ALLOW_UNSAFE_BEHAVIOR
412+
Set this variable to enable potentially unsafe behavior such
413+
as executing tests directly on the test runner using the
414+
``local`` provision method. See ``tmt --help`` for the full
415+
documentation, and interaction between ``--allow-unsafe-behavior``
416+
and ``--feeling-safe`` and the corresponding ``TMT_FEELING_SAFE``
417+
environment variable.
418+
419+
Use with caution, only when you can fully trust the ``tmt`` metadata
420+
or if you know what you are doing.
405421

406422
TMT_EXPOSABLE_RUNNER_DEVICES
407423
Guests may require access to devices of the runner, and only devices
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
description: |
2+
The :tmt:story:`/stories/features/feeling-safe` is no longer working
3+
in the all-or-nothing mode, and new ``--allow-unsafe-behavior`` option
4+
now allows enabling unsafe behavior in a granular manner.
5+
6+
Users of :tmt:story:`/stories/features/feeling-safe` need to account
7+
for the following changes:
8+
9+
* ``--feeling-safe`` works as it used to.
10+
* ``--allow-unsafe-behavior`` option now offers the granularity,
11+
compared to ``--feeling-safe`` being the all-or-nothing switch.
12+
* step-level ``--feeling-safe`` option is no longer supported.

stories/features/feeling-safe.fmf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ description: |
2222
correct and safe. It would be beneficial to allow informed use
2323
of these scripts.
2424

25-
``tmt`` command gains a new option, ``--feeling-safe``. When
26-
specified, tmt will allow and obey possibly unsafe metadata keys
27-
and command line options. When not specified, keys and options
28-
deemed unsafe would lead to an error.
25+
``tmt`` command has two options, ``--feeling-safe`` and
26+
``--allow-unsafe-behavior``. When specified, tmt will allow and obey
27+
possibly unsafe metadata keys and command line options. When not
28+
specified, keys and options deemed unsafe would lead to an error.
29+
30+
It is possible to allow either all unsafe behavior, with
31+
``--feeling-safe`` or ``--allow-unsafe-behavior=all``, or allow just
32+
a subset. This may be very handy when the otherwise useful behavior
33+
could be constrained by other means user controls. For example, CI
34+
maintainer would like to allow custom reboot scripts the
35+
:py:ref:`/plugins/provision/connect` plugin supports while still
36+
preventing use of the :py:ref:`/plugins/provision/local` plugin.
2937

3038
.. versionadded:: 1.30
3139

tests/core/feeling-safe/test.sh

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rlJournalStart
88
rlRun "rundir=$(mktemp -d)" 0 "Creating tmp directory"
99
rlRun "options='run -i $rundir --scratch provision -h local plan -n /plans/features/core'"
1010
rlRun "unset TMT_FEELING_SAFE"
11+
rlRun "unset TMT_ALLOW_UNSAFE_BEHAVIOR"
1112
rlPhaseEnd
1213

1314
rlPhaseStartTest "Feeling Paranoid"
@@ -16,18 +17,93 @@ rlJournalStart
1617
rlAssertNotGrep "User is feeling safe" $rlRun_LOG
1718

1819
# Environment variable
19-
rlRun -s "TMT_FEELING_SAFE=0 tmt $options" 2
20+
rlRun -s "TMT_FEELING_SAFE= tmt $options" 2
21+
rlAssertNotGrep "User is feeling safe" $rlRun_LOG
22+
23+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR= tmt $options" 2
2024
rlAssertNotGrep "User is feeling safe" $rlRun_LOG
2125
rlPhaseEnd
2226

2327
rlPhaseStartTest "Feeling Safe"
2428
# Command line option
25-
rlRun -s "tmt --feeling-safe $options"
26-
rlAssertGrep "User is feeling safe" $rlRun_LOG
29+
rlRun -s "tmt --allow-unsafe-behavior=all $options"
30+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
31+
32+
rlRun -s "tmt --allow-unsafe-behavior=1 $options"
33+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
34+
35+
rlRun -s "tmt --allow-unsafe-behavior=provision/local $options"
36+
rlAssertGrep "User is feeling safe: 'local' provisioning plugin allowed" $rlRun_LOG
37+
38+
rlRun -s "tmt --allow-unsafe-behavior=provision/local --allow-unsafe-behavior=all $options"
39+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
40+
41+
rlRun -s "tmt --allow-unsafe-behavior=provision/local --allow-unsafe-behavior=1 $options"
42+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
43+
44+
rlRun -s "tmt --allow-unsafe-behavior=provision/local --feeling-safe $options"
45+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
46+
47+
rlRun -s "tmt --allow-unsafe-behavior=none $options" 2
48+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
49+
50+
rlRun -s "tmt --allow-unsafe-behavior=0 $options" 2
51+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
52+
53+
rlRun -s "tmt --allow-unsafe-behavior=provision/local --allow-unsafe-behavior=all --allow-unsafe-behavior=none $options" 2
54+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
55+
56+
rlRun -s "tmt --allow-unsafe-behavior=provision/local --allow-unsafe-behavior=all --allow-unsafe-behavior=0 $options" 2
57+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
58+
59+
rlRun -s "tmt --allow-unsafe-behavior=provision/local --feeling-safe --allow-unsafe-behavior=none $options" 2
60+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
61+
62+
rlRun -s "tmt --allow-unsafe-behavior=provision/local --feeling-safe --allow-unsafe-behavior=0 $options" 2
63+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
2764

2865
# Environment variable
29-
rlRun -s "TMT_FEELING_SAFE=1 tmt $options"
30-
rlAssertGrep "User is feeling safe" $rlRun_LOG
66+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR=all tmt $options"
67+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
68+
69+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR=1 tmt $options"
70+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
71+
72+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR=provision/local tmt $options"
73+
rlAssertGrep "User is feeling safe: 'local' provisioning plugin allowed" $rlRun_LOG
74+
75+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local all' tmt $options"
76+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
77+
78+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local 1' tmt $options"
79+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
80+
81+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local' TMT_FEELING_SAFE=1 tmt $options"
82+
rlAssertGrep "User is feeling safe: all unsafe behavior allowed" $rlRun_LOG
83+
84+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR=none tmt $options" 2
85+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
86+
87+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR=0 tmt $options" 2
88+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
89+
90+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local all none' tmt $options" 2
91+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
92+
93+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local all 0' tmt $options" 2
94+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
95+
96+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local none' TMT_FEELING_SAFE=1 tmt $options" 2
97+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
98+
99+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local 0' TMT_FEELING_SAFE=1 tmt $options" 2
100+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
101+
102+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local all' TMT_FEELING_SAFE=0 tmt $options" 2
103+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
104+
105+
rlRun -s "TMT_ALLOW_UNSAFE_BEHAVIOR='provision/local 1' TMT_FEELING_SAFE=0 tmt $options" 2
106+
rlAssertGrep "User is not feeling safe: no unsafe behavior allowed" $rlRun_LOG
31107
rlPhaseEnd
32108

33109
rlPhaseStartCleanup

tests/plan/select/test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ rlJournalStart
4545
done
4646

4747
rlPhaseStartTest "tmt plan ls --condition requires --feeling-safe"
48-
rlRun -s "TMT_FEELING_SAFE=0 tmt plan ls --condition 'True'" 2
49-
rlAssertGrep "requires the '--feeling-safe' option" $rlRun_LOG
48+
rlRun -s "unset TMT_FEELING_SAFE; tmt plan ls --condition 'True'" 2
49+
rlAssertGrep "'--condition' command-line option is allowed only with the '--allow-unsafe-behavior=cli.condition' or '--feeling-safe' option." $rlRun_LOG
5050
rlPhaseEnd
5151

52-
rlPhaseStartTest "tmt plan ls --condition with --feeling-safe"
53-
rlRun -s "tmt --feeling-safe plan ls --condition 'True'"
52+
rlPhaseStartTest "tmt plan ls --condition with --allow-unsafe-behavior=cli.condition"
53+
rlRun -s "tmt --allow-unsafe-behavior=cli.condition plan ls --condition 'True'"
5454
rlAssertGrep "/plans/features/core" $rlRun_LOG
5555
rlAssertGrep "/plans/features/basic" $rlRun_LOG
5656
rlPhaseEnd

tests/policy/test-test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ rlJournalStart
8383
local option="$1"
8484
local envvar="$2"
8585

86-
rlRun -s "$envvar tmt --feeling-safe -vv run --id $run --scratch $option discover provision -h local execute report -h display -vvv plan --default test --name /basic"
86+
rlRun -s "$envvar tmt --allow-unsafe-behavior=provision/local -vv run --id $run --scratch $option discover provision -h local execute report -h display -vvv plan --default test --name /basic"
8787

8888
rlAssertGrep "content: Spiked test." $rlRun_LOG
8989
rlAssertEquals \
@@ -131,10 +131,10 @@ rlJournalStart
131131
policy_name_envvar=""
132132
fi
133133

134-
rlRun -s "tmt --feeling-safe -vv run --id $run --scratch $policy_root_option $policy_file_option $policy_name_option discover provision -h local execute report -h display -vvv plan --default test --name /basic" "$expected_code"
134+
rlRun -s "tmt --allow-unsafe-behavior=provision/local -vv run --id $run --scratch $policy_root_option $policy_file_option $policy_name_option discover provision -h local execute report -h display -vvv plan --default test --name /basic" "$expected_code"
135135
rlAssertGrep "$expected_error" $rlRun_LOG
136136

137-
rlRun -s "$policy_root_envvar $policy_file_envvar $policy_name_envvar tmt --feeling-safe -vv run --id $run --scratch discover provision -h local execute report -h display -vvv plan --default test --name /basic" "$expected_code"
137+
rlRun -s "$policy_root_envvar $policy_file_envvar $policy_name_envvar tmt --allow-unsafe-behavior=provision/local -vv run --id $run --scratch discover provision -h local execute report -h display -vvv plan --default test --name /basic" "$expected_code"
138138
rlAssertGrep "$expected_error" $rlRun_LOG
139139
}
140140

tests/provision/local/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ rlJournalStart
2828

2929
rlPhaseStartTest "Test script installation"
3030
# Run tmt with local provision
31-
rlRun -s "tmt --feeling-safe run --id $run -vvv"
31+
rlRun -s "tmt --allow-unsafe-behavior=provision/local run --id $run -vvv"
3232
rlAssertNotGrep "No such file or directory" $rlRun_LOG
3333
rlAssertNotGrep "command not found" $rlRun_LOG
3434
rlAssertGrep "pass /test/beakerlib" $rlRun_LOG
@@ -43,7 +43,7 @@ rlJournalStart
4343
done
4444

4545
# Check that warning is raised when TMT_SCRIPTS_DIR is used
46-
rlRun -s "TMT_SCRIPTS_DIR=$tmp tmt --feeling-safe run --scratch --id $run -vvv"
46+
rlRun -s "TMT_SCRIPTS_DIR=$tmp tmt --allow-unsafe-behavior=provision/local run --scratch --id $run -vvv"
4747
rlAssertGrep "The 'TMT_SCRIPTS_DIR' variable is not supported" $rlRun_LOG
4848
rlPhaseEnd
4949

0 commit comments

Comments
 (0)