Skip to content

Commit 2023482

Browse files
authored
Merge pull request #7692 from freedomofpress/stg-7670-ossec-fail
ossec: ignore 'failed to find node for hop #1' error from tor
2 parents 8eaa9b9 + bb2b764 commit 2023482

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

molecule/testinfra/app/test_smoke.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@
1212
sdvars = testutils.securedrop_test_vars
1313
testinfra_hosts = [sdvars.app_hostname]
1414

15+
_TIMEOUT = 30.0
16+
_POLL_FREQUENCY = 5.0
1517

1618
JOURNALIST_PUB = "/var/lib/securedrop/journalist.pub"
1719
WEAK_KEY_CONTENTS = (
1820
Path(__file__).parent.parent.parent.parent / "redwood/res/weak_sample_key.asc"
1921
).read_text()
2022

2123

24+
def wait_for(necessary_condition, timeout=_TIMEOUT):
25+
"""Polling wait for an arbitrary true/false condition"""
26+
start_time = time.time()
27+
while time.time() - start_time < timeout:
28+
if necessary_condition():
29+
return True
30+
time.sleep(_POLL_FREQUENCY)
31+
# one last chance!
32+
return necessary_condition()
33+
34+
2235
@pytest.mark.parametrize(
2336
("name", "url", "curl_flags", "expected"),
2437
[
@@ -34,13 +47,13 @@ def test_interface_up(host, name, url, curl_flags, expected):
3447
best to grab the error log and print it via an intentionally failed
3548
assertion.
3649
"""
37-
response = host.run(f"curl -{curl_flags}i {url}").stdout
38-
if "200 OK" not in response:
50+
if not wait_for(lambda: "200 OK" in host.run(f"curl -{curl_flags}i {url}").stdout):
3951
# Try to grab the log and print it via a failed assertion
4052
with host.sudo():
4153
f = host.file(f"/var/log/apache2/{name}-error.log")
4254
if f.exists:
4355
assert "nopenopenope" in f.content_string
56+
response = host.run(f"curl -{curl_flags}i {url}").stdout
4457
assert "200 OK" in response
4558
assert expected in response
4659

@@ -76,12 +89,19 @@ def test_weak_submission_key(host):
7689
# give the interfaces a chance to come up - a TODO could be polling here
7790
time.sleep(10)
7891
# Now try to hit the JI
79-
response = host.run("curl -Li http://localhost:8080/").stdout
80-
assert "HTTP/1.1 500 Internal Server Error" in response
92+
assert wait_for(
93+
lambda: "HTTP/1.1 500 Internal Server Error"
94+
in host.run("curl -Li http://localhost:8080/").stdout
95+
)
8196
# Now hit the SI
82-
response = host.run("curl -i http://localhost:80/").stdout
83-
assert "HTTP/1.1 503 SERVICE UNAVAILABLE" in response # Flask shouts
84-
assert "We're sorry, our SecureDrop is currently offline." in response
97+
assert wait_for(
98+
lambda: "HTTP/1.1 503 SERVICE UNAVAILABLE"
99+
in host.run("curl -i http://localhost:80/").stdout
100+
)
101+
assert wait_for(
102+
lambda: "We're sorry, our SecureDrop is currently offline"
103+
in host.run("curl -i http://localhost:80/").stdout
104+
)
85105

86106
finally:
87107
set_public_key(host, old_public_key)

molecule/testinfra/vars/staging.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,33 @@ log_events_without_ossec_alerts:
126126
rule_id: "100114"
127127

128128
# #6866
129-
- name: NameError_hasattr_does_not_produce_alert
129+
- name: test_NameError_hasattr_does_not_produce_alert
130130
alert: >
131131
NameError: name 'hasattr' is not defined
132132
level: "0"
133133
rule_id: "199996"
134134

135135
# #7491
136-
- name: Update_notifier_download_failed_text_no_alert
136+
- name: test_Update_notifier_download_failed_text_no_alert
137137
alert: >
138138
Download data for packages that failed at package install time
139139
level: "0"
140140
rule_id: "199994"
141141

142142
# #7491
143-
- name: apt_news_warning_text_no_alert
143+
- name: test_apt_news_warning_text_no_alert
144144
alert: >
145145
Warning: W:Download is performed unsandboxed as root as file
146146
level: "0"
147147
rule_id: "199995"
148148

149+
# #7670
150+
- name: test_tor_hop_failure_no_alert
151+
alert: >
152+
Failed to find node for hop #1 of our path. Discarding this circuit.
153+
level: "0"
154+
rule_id: "199997"
155+
149156
# OSSEC should not alert when "manage.py check-disconnected-{db,fs}-
150157
# submissions" has logged that there are no disconnected submissions.
151158
- name: test_no_disconnected_db_submissions_produces_alert

securedrop/debian/ossec-server/var/ossec/rules/local_rules.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@
118118
</group>
119119

120120
<group name="do not alert">
121+
<rule id="199993" level="0">
122+
<match>Failed to find node for hop</match>
123+
<description>ignore non-fatal error generated by Tor</description>
124+
<options>no_email_alert</options>
125+
</rule>
126+
121127
<rule id="199994" level="0">
122128
<match>Download data for packages that failed at package install time</match>
123129
<description>ignore update_notifier_download.service text with "failed" string (https://github.com/freedomofpress/securedrop/issues/7491)</description>

0 commit comments

Comments
 (0)