Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fly io bugfixes and improvements #109

Merged
merged 4 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions aikido_firewall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
# Import background process
from aikido_firewall.background_process import start_background_process

# Load environment variables
# Load environment variables and constants
# Load environment variables and constants
from aikido_firewall.config import PKG_VERSION

load_dotenv()


Expand Down Expand Up @@ -51,4 +54,4 @@ def protect(module="any", server=True):
import aikido_firewall.sinks.os_system
import aikido_firewall.sinks.subprocess

logger.info("Aikido python firewall started")
logger.info("Aikido python firewall v%s starting.", PKG_VERSION)
2 changes: 2 additions & 0 deletions aikido_firewall/background_process/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

# Remove the socket file if it already exists
if os.path.exists(IPC_ADDRESS):
logger.debug("Unix Domain Socket file already exists, deleting.")

Check warning on line 29 in aikido_firewall/background_process/__init__.py

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/background_process/__init__.py#L29

Added line #L29 was not covered by tests
os.remove(IPC_ADDRESS)

logger.debug("Communication starting on UDS File : %s", IPC_ADDRESS)
comms = AikidoIPCCommunications(IPC_ADDRESS, secret_key_bytes)
comms.start_aikido_listener()
10 changes: 9 additions & 1 deletion aikido_firewall/background_process/comms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# pylint: disable=global-statement # This needs to be global
global comms
if comms:
comms.send_data_to_bg_process("KILL", {})
logger.debug("Resetting communications. (comms = None)")
comms = None


Expand Down Expand Up @@ -68,6 +68,14 @@
self.background_process.start()

def send_data_to_bg_process(self, action, obj, receive=False):
"""Try-catched send_data_to_bg_process"""
try:
return self._send_data_to_bg_process(action, obj, receive=False)
except Exception as e:
logger.debug("Exception happened in send_data_to_bg_process : %s", e)
return {"success": False, "error": "unknown"}

Check warning on line 76 in aikido_firewall/background_process/comms.py

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/background_process/comms.py#L74-L76

Added lines #L74 - L76 were not covered by tests

def _send_data_to_bg_process(self, action, obj, receive=False):
"""
This creates a new client for comms to the background process
"""
Expand Down
2 changes: 1 addition & 1 deletion aikido_firewall/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_protect_with_django(monkeypatch, caplog):

protect(module="django")

assert "Aikido python firewall started" in caplog.text
assert "starting" in caplog.text
assert get_comms() != None
reset_comms()
assert get_comms() == None
4 changes: 2 additions & 2 deletions aikido_firewall/sinks/psycopg2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __getattr__(self, name):
def execute(*args, **kwargs):
run_vulnerability_scan(
kind="sql_injection",
op="pymysql.connection.cursor.execute",
op="psycopg2.Connection.Cursor.execute",
args=(args[0], Postgres()), # args[0] : sql
)
return self._execute_func_copy(*args, **kwargs)
Expand All @@ -53,7 +53,7 @@ def executemany(*args, **kwargs):
for sql in args[0]:
run_vulnerability_scan(
kind="sql_injection",
op="pymysql.connection.cursor.executemany",
op="psycopg2.Connection.Cursor.executemany",
args=(sql, Postgres()),
)
return self._executemany_func_copy(*args, **kwargs)
Expand Down
Loading