-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate publishing to eventbridge (#23)
- Loading branch information
Showing
20 changed files
with
1,259 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Adapted from https://edu.chainguard.dev/chainguard/chainguard-images/reference/python/overview/#usage | ||
|
||
# Python 3.11.4, dev base image. See https://www.chainguard.dev/unchained/a-guide-on-how-to-use-chainguard-images-for-public-catalog-tier-users for more details on how to update this | ||
FROM cgr.dev/chainguard/python@sha256:ed93b11743a002aa79f7f084d2f23b7040a8c35ce26a34b7918f15db16fbc8f2 as builder | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.txt . | ||
|
||
RUN pip install -r requirements.txt --user | ||
|
||
# Python 3.11.4, production base image. See https://www.chainguard.dev/unchained/a-guide-on-how-to-use-chainguard-images-for-public-catalog-tier-users for more details on how to update this | ||
FROM cgr.dev/chainguard/python@sha256:bbaba40f4dfff902af5ec49793a8d42478cae07ad9fcd6eace93a55c348a2aa6 | ||
|
||
# Make sure you update Python version in path | ||
COPY --from=builder /home/nonroot/.local/lib/python3.11/site-packages /home/nonroot/.local/lib/python3.11/site-packages | ||
|
||
COPY ./src/ . | ||
|
||
# Arbitrary non-root id, something just below the 65535 limit https://unix.stackexchange.com/questions/191663/any-concerns-with-using-high-uid-numbers-3000-on-rhel5 | ||
USER 65532 | ||
ENTRYPOINT [ "python", "main.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
TODO | ||
# Honeypot | ||
|
||
## Contributing | ||
|
||
### Dependency Management | ||
|
||
When adding a new pypi dependency, first add it to Poetry like | ||
|
||
``` | ||
poetry add (--dev) <name-of-dependency> | ||
``` | ||
|
||
Then regenerate `requirements.txt` from the Poetry lockfile like | ||
|
||
``` | ||
poetry export -f requirements.txt --output requirements.txt | ||
``` | ||
|
||
This will make sure it's included in the Docker image build (requirements.txt) as well as the local dev environment (Poetry). |
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
boto3==1.28.5 ; python_version >= "3.11" and python_version < "4.0" \ | ||
--hash=sha256:2c76db4a1208b8d09814261fc5e530fc36b3b952ef807312495e6869fa6eaad5 \ | ||
--hash=sha256:a5c815ab81219a606f20362c9d9c190f5c224bf33c5dc4c20501036cc4a9034f | ||
botocore==1.31.5 ; python_version >= "3.11" and python_version < "4.0" \ | ||
--hash=sha256:8aec97512587a5475036a982785e406c52efd260457b809846985f849c3d7cf3 \ | ||
--hash=sha256:b35114dae9c451895a11fef13d76881e2bb5428e5de8a702cc8589a28fb34c7a | ||
jmespath==1.0.1 ; python_version >= "3.11" and python_version < "4.0" \ | ||
--hash=sha256:02e2e4cc71b5bcab88332eebf907519190dd9e6e82107fa7f83b1003a6252980 \ | ||
--hash=sha256:90261b206d6defd58fdd5e85f478bf633a2901798906be2ad389150c5c60edbe | ||
python-dateutil==2.8.2 ; python_version >= "3.11" and python_version < "4.0" \ | ||
--hash=sha256:0123cacc1627ae19ddf3c27a5de5bd67ee4586fbdd6440d9748f8abb483d3e86 \ | ||
--hash=sha256:961d03dc3453ebbc59dbdea9e4e11c5651520a876d0f4db161e8674aae935da9 | ||
s3transfer==0.6.1 ; python_version >= "3.11" and python_version < "4.0" \ | ||
--hash=sha256:3c0da2d074bf35d6870ef157158641178a4204a6e689e82546083e31e0311346 \ | ||
--hash=sha256:640bb492711f4c0c0905e1f62b6aaeb771881935ad27884852411f8e9cacbca9 | ||
six==1.16.0 ; python_version >= "3.11" and python_version < "4.0" \ | ||
--hash=sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926 \ | ||
--hash=sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254 | ||
urllib3==1.26.16 ; python_version >= "3.11" and python_version < "4.0" \ | ||
--hash=sha256:8d36afa7616d8ab714608411b4a3b13e58f463aee519024578e062e141dce20f \ | ||
--hash=sha256:8f135f6502756bde6b2a9b28989df5fbe87c9970cecaa69041edcce7f0589b14 |
This file was deleted.
Oops, something went wrong.
Empty file.
8 changes: 8 additions & 0 deletions
8
packages/honeypot/src/eventClients/event_client_adapter_protocol.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from typing import Protocol | ||
from abc import abstractmethod | ||
|
||
|
||
class EventClientAdapterProtocol(Protocol): | ||
@abstractmethod | ||
def sendEvent(self, eventDetails: object) -> None: | ||
raise NotImplementedError |
48 changes: 48 additions & 0 deletions
48
packages/honeypot/src/eventClients/eventbridge_client_adapter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from .event_client_adapter_protocol import EventClientAdapterProtocol | ||
|
||
import boto3 | ||
|
||
from dataclasses import dataclass | ||
import json | ||
|
||
|
||
class EventbridgeClientAdapter(EventClientAdapterProtocol): | ||
def __init__(self, eventBusNameOrArn: str) -> None: | ||
self.__eventBusNameOrArn: str = eventBusNameOrArn | ||
|
||
self.__eventbridgeClient = boto3.client("events") | ||
|
||
def sendEvent(self, eventDetails: object) -> None: | ||
response = self.__eventbridgeClient.put_events( | ||
Entries=[ | ||
{ | ||
"Source": "cloud-native-honeypot", | ||
"DetailType": "cloudNativeHoneypotTriggered", | ||
"Detail": json.dumps(eventDetails), | ||
"EventBusName": self.__eventBusNameOrArn, | ||
} | ||
] | ||
) | ||
|
||
if response["FailedEntryCount"] == 0: | ||
print("Eventbridge event published successfully.") | ||
else: | ||
print( | ||
f"""Failed to publish {response['FailedEntryCount']} event(s) to | ||
Eventbridge.""" | ||
) | ||
|
||
|
||
@dataclass | ||
class EventbridgeClientAdapterInputs: | ||
eventBusNameOrArn: str | ||
|
||
|
||
def createEventClientAdapter( | ||
inputs: EventbridgeClientAdapterInputs, | ||
) -> EventClientAdapterProtocol: | ||
eventBusNameOrArn = inputs.eventBusNameOrArn | ||
if not eventBusNameOrArn: | ||
raise ValueError("eventBusNameOrArn must be a non-empty string") | ||
|
||
return EventbridgeClientAdapter(eventBusNameOrArn=eventBusNameOrArn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.