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

Threat detection #1783

Draft
wants to merge 78 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
b4fc250
pushing malicious requests to kafka
ag060 Nov 6, 2024
ba42c14
added flush kafka messages task
ag060 Nov 9, 2024
302a0d1
added window based aggregation support for malicious requests
ag060 Nov 12, 2024
4f8fa2f
using separate mongo for storing suspect data
ag060 Nov 12, 2024
585a185
fixed kafka host
ag060 Nov 12, 2024
bd49fec
fixed source ip generation logic
ag060 Nov 12, 2024
dee4078
not syncing writes and read for RedisWriteBackCache at the same time
ag060 Nov 13, 2024
63620f7
using redis backed increment counter cache
ag060 Nov 13, 2024
c319b3c
added group id to aggregate notifier
ag060 Nov 14, 2024
a359662
added notification cooldown support
ag060 Nov 14, 2024
6344fef
added start and end bucket ids with each detected alerts
ag060 Nov 14, 2024
e80b9e2
added ttl for redis entries
ag060 Nov 14, 2024
1001bd7
added new collections for sample malicious requests and detected alerts
ag060 Nov 15, 2024
ff95829
addded cleanup sample malicious records task
ag060 Nov 16, 2024
db2b77c
refactor code
ag060 Nov 18, 2024
8667425
refactor code
ag060 Nov 18, 2024
4913668
refactor code
ag060 Nov 18, 2024
c6dc848
add aggregation parse layer
ayushaga14 Nov 21, 2024
ecc9765
grpc service for consuming malicious and smart events (#1748)
ag060 Nov 22, 2024
6e4655e
apply aggregations
ayushaga14 Nov 22, 2024
2ee9fe7
removed db service and using mongo client everywhere
ag060 Nov 22, 2024
c437d16
moved clean up task to threat protection service
ag060 Nov 22, 2024
babb05a
added authorization interceptor for grpc server
ag060 Nov 22, 2024
7408248
removed account_id field from consume event service requests (threat-…
ag060 Nov 22, 2024
1addc02
added client side authentication support while saving malicious and s…
ag060 Nov 23, 2024
5a9afa6
added new api threat detection
ag060 Nov 25, 2024
dd051b8
saving malicious sample data to postgres db
ag060 Nov 25, 2024
7e23fd3
abstracted out common kafka polling consumer task
ag060 Nov 26, 2024
c915686
added tasks for sending alerts to protection backend
ag060 Nov 28, 2024
d2a73b3
exposing single rpc method for recording alerts
ag060 Nov 28, 2024
6cbd95d
updated proto definition
ag060 Nov 29, 2024
8b1bfe9
removed cleanup task from threat protection backend module
ag060 Nov 29, 2024
536ff02
updated kafka topic names
ag060 Nov 29, 2024
a292b59
running flyway migrations programatically
ag060 Nov 29, 2024
02cfa89
refactored code
ag060 Nov 29, 2024
67d5ebd
added clean up for deleting all the malicious entries older than 7 days
ag060 Nov 29, 2024
74a90b2
added hibernate orm (#1786)
ag060 Dec 10, 2024
b4ad6ed
threat protection producer consumer db writes
ayushaga14 Dec 10, 2024
08e3af2
added proto generation to ci
ag060 Dec 10, 2024
c82cb6d
fix create mongo client params
ayushaga14 Dec 10, 2024
0cbcb93
deleted generated proto files
ag060 Dec 10, 2024
0ff337d
added dashboard rpc service (#1808)
ag060 Dec 10, 2024
d4f3fff
updated proto definition to include malicious event type (SINGLE or A…
ag060 Dec 10, 2024
23fb750
storing api_collection_id in postgres
ag060 Dec 10, 2024
b4ceae8
fixed paths in ci for threat-detection module
ag060 Dec 11, 2024
dba48ad
moved kafka config from threat detection to utils
ag060 Dec 11, 2024
f1787ca
moved consumer and producer on same machine for threat protection bac…
ag060 Dec 11, 2024
809c62a
refactored dashboard proto messages
ag060 Dec 11, 2024
31fe6f0
added check if buf is installed in proto-gen script
ag060 Dec 12, 2024
78dda75
fixed MaliciousEventModel not populating data from mongo
ag060 Dec 16, 2024
1f0b584
refactored code
ag060 Dec 17, 2024
78a464a
disabled debug logging for hibernate
ag060 Dec 17, 2024
e349f89
removed unused imports
ag060 Dec 17, 2024
c4c0433
disabled debug logging for hibernate
ag060 Dec 17, 2024
d1b1039
committing kafka offsets manually now
ag060 Dec 17, 2024
e3ead06
renamed threat detection backend service
ag060 Dec 17, 2024
2b02791
added health check server
ag060 Dec 17, 2024
d2532c5
building threat detection backend image in staging workflow
ag060 Dec 17, 2024
3b69b6c
refactored generated proto files
ag060 Dec 18, 2024
dd09c8b
added health check for rpc and enabled reflection
ag060 Dec 18, 2024
159cd8a
added health service for grpc
ag060 Dec 18, 2024
54c8b9b
using vertx http server as threat detection backend (#1842)
ag060 Dec 19, 2024
8929c38
reading akto threat detection backend url from env
ag060 Dec 20, 2024
5b67f3b
added try catch
ag060 Dec 21, 2024
9bbcd1f
fixed sample not being to backend
ag060 Dec 21, 2024
c846c77
clearing cache as soon the alert is raised
ag060 Dec 23, 2024
89216b4
sending sample malicious events to backend only once
ag060 Dec 23, 2024
edef904
use fastjson lib and increase template fetch interval
ayushaga14 Dec 29, 2024
57eb219
add log
ayushaga14 Dec 29, 2024
fe659be
avoid reevaluating params for each filter check
ayushaga14 Dec 30, 2024
0d86956
[temp commit] remove unneceesary build from stagiong workflow
ayushaga14 Dec 30, 2024
89e44b3
using proto message envelope for kafka transport in threat detection …
ag060 Jan 1, 2025
ac20f9e
setting redis ttl while sync to redis instead of increment op
ag060 Jan 2, 2025
eea86e7
fixed merge conflicts in staging and prod workflows
ag060 Jan 2, 2025
a74bf9a
proto changes
ayushaga14 Jan 1, 2025
fb3e1b6
remove logs and headers loop
ayushaga14 Jan 3, 2025
eb9f899
optimizations
notshivansh Jan 3, 2025
a12d198
move httpresponse param proto generated files
ayushaga14 Jan 4, 2025
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
68 changes: 34 additions & 34 deletions .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:
inputs:
release_version:
required: true
required: true
dashboard:
type: boolean
default: true
Expand All @@ -23,11 +23,16 @@ on:
type: boolean
default: true
description: Internal
protection:
threat_detection:
type: boolean
default: true
description: Protection

description: Threat Detection Client

threat_detection_backend:
type: boolean
default: true
description: Threat Deteection Backend

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
Expand All @@ -37,16 +42,21 @@ jobs:

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '8'
distribution: "adopt"
java-version: "8"
architecture: x64
- uses: actions/setup-node@v2
with:
node-version: '17'
node-version: "17"
- uses: bufbuild/buf-action@v1
with:
setup_only: true
- name: Generate Proto files
run: make proto-gen
- name: Download Akto templates zip and PII files
working-directory: ./apps/dashboard/src/main/resources
run: |
Expand Down Expand Up @@ -74,7 +84,7 @@ jobs:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
run: |
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD

- name: Build, tag, and push the image to DockerHub
id: build-image-dockerhub
Expand All @@ -92,36 +102,40 @@ jobs:
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY-dashboard:$IMAGE_TAG_1 -t $ECR_REGISTRY/$ECR_REPOSITORY-dashboard:$IMAGE_TAG_2 . --push
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY-dashboard:$IMAGE_TAG"
fi

if [[ "${{ github.event.inputs.testing }}" == "true" ]]; then
cd apps/testing
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-api-testing:$IMAGE_TAG_1 -t $ECR_REGISTRY/akto-api-testing:$IMAGE_TAG_2 . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-api-testing:$IMAGE_TAG"
fi

if [[ "${{ github.event.inputs.testing }}" == "true" ]]; then
cd apps/testing-cli
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-api-testing-cli:$IMAGE_TAG_1 -t $ECR_REGISTRY/akto-api-testing-cli:$IMAGE_TAG_2 . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-api-testing-cli:$IMAGE_TAG"
fi

if [[ "${{ github.event.inputs.billing }}" == "true" ]]; then
cd apps/billing
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-billing:$IMAGE_TAG_1 -t $ECR_REGISTRY/akto-billing:$IMAGE_TAG_2 . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-billing:$IMAGE_TAG"
fi

if [[ "${{ github.event.inputs.internal }}" == "true" ]]; then
cd apps/internal
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-internal:$IMAGE_TAG_1 -t $ECR_REGISTRY/akto-internal:$IMAGE_TAG_2 . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-internal:$IMAGE_TAG"
fi

if [[ "${{ github.event.inputs.protection }}" == "true" ]]; then
cd apps/api-threat-detection
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-api-protection:$IMAGE_TAG_1 -t $ECR_REGISTRY/akto-api-protection:$IMAGE_TAG_2 -t $ECR_REGISTRY/akto-api-protection:$IMAGE_TAG_3 . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-api-protection:$IMAGE_TAG"
fi

if [[ "${{ github.event.inputs.threat_detection}}" == "true" ]]; then
cd apps/threat-detection
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection:$IMAGE_TAG . --push
fi

if [[ "${{ github.event.inputs.threat_detection_backend}}" == "true" ]]; then
cd ../threat-detection-backend
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection-backend:$IMAGE_TAG . --push
fi
- name: Configure AWS Credentials for ECR
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -132,23 +146,9 @@ jobs:
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
mask-password: 'true'
mask-password: "true"
registry-type: public

- name: Build, tag, and push docker image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: akto-api-security
REGISTRY_ALIAS: p7q3h0z2
IMAGE_TAG: local
IMAGE_TAG2: latest
run: |
docker buildx create --use
# Build a docker container and push it to DockerHub
cd apps/api-threat-detection
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-protection:$IMAGE_TAG -t $ECR_REGISTRY/$REGISTRY_ALIAS/akto-api-protection:$IMAGE_TAG2 . --push
echo "::set-output name=image::$ECR_REGISTRY/akto-api-protection:$IMAGE_TAG"

- name: Push git tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: "17"
- uses: bufbuild/buf-action@v1
with:
setup_only: true
- name: Generate Proto files
run: make proto-gen
- name: Convert github branch name to be compatible with docker tag name convention and generate tag name
id: docker_tag
run: echo "IMAGE_TAG=a-$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')" >> $GITHUB_OUTPUT
Expand All @@ -36,20 +41,15 @@ jobs:
wget -O general.json https://raw.githubusercontent.com/akto-api-security/pii-types/master/general.json
wget -O fintech.json https://raw.githubusercontent.com/akto-api-security/akto/master/pii-types/fintech.json
wget -O filetypes.json https://raw.githubusercontent.com/akto-api-security/akto/master/pii-types/filetypes.json
- name: Prepare Dashboard polaris UI
working-directory: ./apps/dashboard/web/polaris_web
run: npm install && export RELEASE_VERSION=${{steps.docker_tag.outputs.IMAGE_TAG}} && npm run build

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws-region: ap-south-1

- name: Deploy polaris site to S3 bucket
run: aws s3 sync ./apps/dashboard/web/polaris_web/web/dist s3://dashboard-on-cdn/polaris_web/${{steps.docker_tag.outputs.IMAGE_TAG}}/dist --delete

- run: mvn package -Dakto-image-tag=${{ github.event.inputs.Tag }} -Dakto-build-time=$(eval "date +%s") -Dakto-release-version=${{steps.docker_tag.outputs.IMAGE_TAG}}
- run: mvn package -Dakto-image-tag=${{ github.event.inputs.Tag }} -Dakto-build-time=$(eval "date +%s") -Dakto-release-version=${{steps.docker_tag.outputs.IMAGE_TAG}} -DskipTests
- name: DockerHub login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
Expand Down Expand Up @@ -79,10 +79,12 @@ jobs:
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-billing:$IMAGE_TAG . --push
cd ../internal
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-internal:$IMAGE_TAG . --push
cd ../api-threat-detection
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-api-protection:$IMAGE_TAG . --push
cd ../source-code-analyser
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/source-code-analyser:$IMAGE_TAG . --push
cd ../threat-detection
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection:$IMAGE_TAG . --push
cd ../threat-detection-backend
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-threat-detection-backend:$IMAGE_TAG . --push

- name: Set up JDK 11
uses: actions/setup-java@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ https:
**/data-zoo-data
**/data-zoo-logs
**/bin
.factorypath
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
proto-gen:
sh ./scripts/proto-gen.sh

build: proto-gen
mvn install -DskipTests

build-clean: proto-gen
mvn clean install -DskipTests
Loading
Loading