Skip to content

Commit b81b5e7

Browse files
authored
Add missing dependency (#43)
* Add missing dependency pyyaml now used for secure example files * Add one-line install including virtualenv * Update tests The error for set_secure_system_falco_rules.py has changed. Now that the system rules file is not per-customer, it can't be tied to this test account. So just verify it can be fetched without inspecting its contents. This also changes the result of creating default policies/modifying policies a bit.
1 parent 1fd3a9a commit b81b5e7

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Installation
1818
cd python-sdc-client
1919
python setup.py install
2020

21+
#### One-step cmdline to create virtualenv, install client, and gain access to sample programs
22+
23+
```
24+
$ virtualenv python-sdc-env && source python-sdc-env/bin/activate && pip install sdcclient && git clone https://github.com/draios/python-sdc-client && python python-sdc-client/examples/set_secure_system_falco_rules.py --help
25+
```
26+
2127
Quick start
2228
-----------
2329
- If you are interested in exporting metrics data from Sysdig Monitor, take a look at [examples/get_data_simple.py](examples/get_data_simple.py) and [examples/get_data_advanced.py](examples/get_data_advanced.py).

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests
2+
pyyaml

test/test_secure_apis.sh

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ if [[ $? != 1 ]]; then
1515
exit 1
1616
fi
1717

18-
if [[ "$OUT" != "status code 405" ]]; then
18+
if [[ "$OUT" != "Access is denied Not enough privileges to complete the action" ]]; then
1919
echo "Unexpected output from set_secure_system_falco_rules.py: $OUT"
2020
exit 1
2121
fi
2222
set -e
2323

24-
# There's a known system falco rules file. Get it and compare it to the expected file
24+
# Get the system falco rules file. Don't validate it, just verify that it can be fetched.
2525
$SCRIPTDIR/../examples/get_secure_system_falco_rules.py $PYTHON_SDC_TEST_API_TOKEN > /tmp/falco_rules.yaml
26-
diff /tmp/falco_rules.yaml $SCRIPTDIR/sample-falco-rules.yaml
2726

2827
NOW=$(date)
2928
cat <<EOF > /tmp/test_apis_user_rules.yaml
@@ -50,66 +49,66 @@ fi
5049
# be 1, corresponding to the system falco rule.
5150
$SCRIPTDIR/../examples/create_default_policies.py $PYTHON_SDC_TEST_API_TOKEN
5251
OUT=`$SCRIPTDIR/../examples/list_policies.py $PYTHON_SDC_TEST_API_TOKEN`
53-
if [[ $OUT != *"\"name\": \"My Rule\""* ]]; then
52+
if [[ $OUT != *"\"name\": \"Write below binary dir\""* ]]; then
5453
echo "Unexpected output after creating default policies"
5554
exit 1
5655
fi
5756

5857
# Get that policy, change the name, and create a new duplicate policy.
59-
OUT=`$SCRIPTDIR/../examples/get_policy.py $PYTHON_SDC_TEST_API_TOKEN "My Rule"`
58+
OUT=`$SCRIPTDIR/../examples/get_policy.py $PYTHON_SDC_TEST_API_TOKEN "Write below binary dir"`
6059
MY_POLICY=$OUT
61-
if [[ $OUT != *"\"name\": \"My Rule\""* ]]; then
62-
echo "Could not fetch policy with name \"My Rule\""
60+
if [[ $OUT != *"\"name\": \"Write below binary dir\""* ]]; then
61+
echo "Could not fetch policy with name \"Write below binary dir\""
6362
exit 1
6463
fi
6564

66-
NEW_POLICY=`echo $MY_POLICY | sed -e "s/My Rule/Copy Of My Rule/g" | sed -e 's/"id": [0-9]*,//' | sed -e 's/"version": [0-9]*/"version": null/'`
65+
NEW_POLICY=`echo $MY_POLICY | sed -e "s/Write below binary dir/Copy Of Write below binary dir/g" | sed -e 's/"id": [0-9]*,//' | sed -e 's/"version": [0-9]*/"version": null/'`
6766
OUT=`echo $NEW_POLICY | $SCRIPTDIR/../examples/add_policy.py $PYTHON_SDC_TEST_API_TOKEN`
68-
if [[ $OUT != *"\"name\": \"Copy Of My Rule\""* ]]; then
67+
if [[ $OUT != *"\"name\": \"Copy Of Write below binary dir\""* ]]; then
6968
echo "Could not create new policy"
7069
exit 1
7170
fi
7271

7372
# Change the description of the new policy and update it.
74-
MODIFIED_POLICY=`echo $MY_POLICY | sed -e "s/My Description/My New Description/g"`
73+
MODIFIED_POLICY=`echo $MY_POLICY | sed -e "s/an attempt to write to any file below a set of binary directories/My New Description/g"`
7574
OUT=`echo $MODIFIED_POLICY | $SCRIPTDIR/../examples/update_policy.py $PYTHON_SDC_TEST_API_TOKEN`
7675
if [[ $OUT != *"\"description\": \"My New Description\""* ]]; then
77-
echo "Could not update policy \"Copy Of My Rule\""
76+
echo "Could not update policy \"Copy Of Write below binary dir\""
7877
exit 1
7978
fi
8079

8180
# Delete the new policy.
82-
OUT=`$SCRIPTDIR/../examples/delete_policy.py --name "Copy Of My Rule" $PYTHON_SDC_TEST_API_TOKEN`
83-
if [[ $OUT != *"\"name\": \"Copy Of My Rule\""* ]]; then
84-
echo "Could not delete policy \"Copy Of My Rule\""
81+
OUT=`$SCRIPTDIR/../examples/delete_policy.py --name "Copy Of Write below binary dir" $PYTHON_SDC_TEST_API_TOKEN`
82+
if [[ $OUT != *"\"name\": \"Copy Of Write below binary dir\""* ]]; then
83+
echo "Could not delete policy \"Copy Of Write below binary dir\""
8584
exit 1
8685
fi
8786

8887
OUT=`$SCRIPTDIR/../examples/list_policies.py $PYTHON_SDC_TEST_API_TOKEN`
89-
if [[ $OUT = *"\"name\": \"Copy Of My Rule\""* ]]; then
90-
echo "After deleting policy Copy Of My Rule, policy was still present?"
88+
if [[ $OUT = *"\"name\": \"Copy Of Write below binary dir\""* ]]; then
89+
echo "After deleting policy Copy Of Write below binary dir, policy was still present?"
9190
exit 1
9291
fi
9392

9493
# Make a copy again, but this time delete by id
95-
NEW_POLICY=`echo $MY_POLICY | sed -e "s/My Rule/Another Copy Of My Rule/g" | sed -e 's/"id": [0-9]*,//' | sed -e 's/"version": [0-9]*/"version": null/'`
94+
NEW_POLICY=`echo $MY_POLICY | sed -e "s/Write below binary dir/Another Copy Of Write below binary dir/g" | sed -e 's/"id": [0-9]*,//' | sed -e 's/"version": [0-9]*/"version": null/'`
9695
OUT=`echo $NEW_POLICY | $SCRIPTDIR/../examples/add_policy.py $PYTHON_SDC_TEST_API_TOKEN`
97-
if [[ $OUT != *"\"name\": \"Another Copy Of My Rule\""* ]]; then
96+
if [[ $OUT != *"\"name\": \"Another Copy Of Write below binary dir\""* ]]; then
9897
echo "Could not create new policy"
9998
exit 1
10099
fi
101100

102101
ID=`echo $OUT | grep -E -o '"id": [^,]+,' | awk '{print $2}' | awk -F, '{print $1}'`
103102

104103
OUT=`$SCRIPTDIR/../examples/delete_policy.py --id $ID $PYTHON_SDC_TEST_API_TOKEN`
105-
if [[ $OUT != *"\"name\": \"Another Copy Of My Rule\""* ]]; then
106-
echo "Could not delete policy \"Copy Of My Rule\""
104+
if [[ $OUT != *"\"name\": \"Another Copy Of Write below binary dir\""* ]]; then
105+
echo "Could not delete policy \"Copy Of Write below binary dir\""
107106
exit 1
108107
fi
109108

110109
OUT=`$SCRIPTDIR/../examples/list_policies.py $PYTHON_SDC_TEST_API_TOKEN`
111-
if [[ $OUT = *"\"name\": \"Another Copy Of My Rule\""* ]]; then
112-
echo "After deleting policy Another Copy Of My Rule, policy was still present?"
110+
if [[ $OUT = *"\"name\": \"Another Copy Of Write below binary dir\""* ]]; then
111+
echo "After deleting policy Another Copy Of Write below binary dir, policy was still present?"
113112
exit 1
114113
fi
115114

@@ -120,7 +119,7 @@ FOUND=0
120119

121120
for i in $(seq 10); do
122121
sleep 10
123-
touch /tmp/some-file.txt
122+
sudo touch /bin/some-file.txt
124123

125124
EVTS=`$SCRIPTDIR/../examples/get_secure_policy_events.py $PYTHON_SDC_TEST_API_TOKEN 60`
126125

0 commit comments

Comments
 (0)