diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 60283eb3b8db28d623a0209f1bd92b6266eecb52..a11f0f19a4a806c59524158c3c32aca95b03d7b5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ stages: include: - local: '/manifests/.gitlab-ci.yml' #- local: '/src/monitoring/.gitlab-ci.yml' - - local: '/src/centralizedcybersecurity/.gitlab-ci.yml' + - local: '/src/centralizedattackdetector/.gitlab-ci.yml' - local: '/src/context/.gitlab-ci.yml' - local: '/src/device/.gitlab-ci.yml' - local: '/src/service/.gitlab-ci.yml' diff --git a/install_development_dependencies.sh b/install_development_dependencies.sh index 4f395df2a27f5ef49b600688ae1563aa791b2178..cceee4e309be8f534ad7e74078d18cc1f4775603 100755 --- a/install_development_dependencies.sh +++ b/install_development_dependencies.sh @@ -7,7 +7,7 @@ pip install --upgrade pip setuptools wheel pip-tools pylint pytest pytest-benchm echo "" > requirements.in #TODO: include here your component -COMPONENTS="compute context device monitoring" +COMPONENTS="compute context device monitoring centralizedattackdetector" # compiling dependencies from all components for component in $COMPONENTS diff --git a/manifests/centralizedcybersecurityservice.yaml b/manifests/centralizedattackdetectorservice.yaml similarity index 78% rename from manifests/centralizedcybersecurityservice.yaml rename to manifests/centralizedattackdetectorservice.yaml index 96e8c300949b29d8112782332b2da9b76a98abc2..faf42a5550098c9e73d19e2587cc508dbd3cf7be 100644 --- a/manifests/centralizedcybersecurityservice.yaml +++ b/manifests/centralizedattackdetectorservice.yaml @@ -1,15 +1,15 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: centralizedcybersecurityservice + name: centralizedattackdetectorervice spec: selector: matchLabels: - app: centralizedcybersecurityservice + app: centralizedattackdetectorervice template: metadata: labels: - app: centralizedcybersecurityservice + app: centralizedattackdetectorervice spec: terminationGracePeriodSeconds: 5 containers: @@ -42,11 +42,11 @@ spec: apiVersion: v1 kind: Service metadata: - name: centralizedcybersecurityservice + name: centralizedattackdetectorervice spec: type: ClusterIP selector: - app: centralizedcybersecurityservice + app: centralizedattackdetectorervice ports: - name: grpc port: 10000 @@ -55,13 +55,13 @@ spec: apiVersion: v1 kind: Service metadata: - name: centralizedcybersecurityservice-public + name: centralizedattackdetectorervice-public labels: - app: centralizedcybersecurityservice + app: centralizedattackdetectorervice spec: type: NodePort selector: - app: centralizedcybersecurityservice + app: centralizedattackdetectorervice ports: - name: grpc protocol: TCP diff --git a/proto/centralized_cybersecurity.proto b/proto/centralized_attack_detector.proto similarity index 87% rename from proto/centralized_cybersecurity.proto rename to proto/centralized_attack_detector.proto index 53042be54641bfb203661a77183a95518a28fa8b..df4a58486390669656fa2939e3dc32ad519c5d29 100644 --- a/proto/centralized_cybersecurity.proto +++ b/proto/centralized_attack_detector.proto @@ -1,13 +1,13 @@ // protocol buffers documentation: https://developers.google.com/protocol-buffers/docs/proto3 syntax = "proto3"; -package centralized_cybersecurity; +package centralized_attack_detector; import "context.proto"; import "service.proto"; import "monitoring.proto"; -service CentralizedCyberSecurityService { +service CentralizedAttackDetectorService { rpc NotifyServiceUpdate (service.Service) returns (context.Empty) {} diff --git a/report_coverage_centralized_attack_detector.sh b/report_coverage_centralized_attack_detector.sh new file mode 100755 index 0000000000000000000000000000000000000000..ea34a11315cfdfbc8c05427c8d4f6e78dad4b42c --- /dev/null +++ b/report_coverage_centralized_attack_detector.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./report_coverage_all.sh | grep --color -E -i "^centralizedattackdetector/.*$|$" diff --git a/report_coverage_centralized_cybersecurity.sh b/report_coverage_centralized_cybersecurity.sh deleted file mode 100755 index 553315b7943730f3e6b5a1c66a0544df91c9d355..0000000000000000000000000000000000000000 --- a/report_coverage_centralized_cybersecurity.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -./report_coverage_all.sh | grep --color -E -i "^centralizedcybersecurity/.*$|$" diff --git a/run_local_tests.sh b/run_local_tests.sh index c1fb23861b43a29a82a51e30f9476076552fe631..3a02c1f6a6880849ce29bc62771c158b397ffd95 100755 --- a/run_local_tests.sh +++ b/run_local_tests.sh @@ -19,7 +19,7 @@ coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ common/database/tests/test_engine_inmemory.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ - centralizedcybersecurity/tests/test_unitary.py + centralizedattackdetector/tests/test_unitary.py coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ context/tests/test_unitary.py diff --git a/src/centralizedcybersecurity/.gitlab-ci.yml b/src/centralizedattackdetector/.gitlab-ci.yml similarity index 72% rename from src/centralizedcybersecurity/.gitlab-ci.yml rename to src/centralizedattackdetector/.gitlab-ci.yml index 5b7279441504dfd1846a2719ae40fc6423f2636c..c2e4d7a4d360b90fc7e8cedef83aae69c1d07d5d 100644 --- a/src/centralizedcybersecurity/.gitlab-ci.yml +++ b/src/centralizedattackdetector/.gitlab-ci.yml @@ -1,8 +1,8 @@ # Build, tag, and push the Docker images to the GitLab Docker registry -build centralizedcybersecurity: +build centralizedattackdetector: variables: - IMAGE_NAME: 'centralizedcybersecurity' # name of the microservice - IMAGE_NAME_TEST: 'centralizedcybersecurity-test' # name of the microservice + IMAGE_NAME: 'centralizedattackdetector' # name of the microservice + IMAGE_NAME_TEST: 'centralizedattackdetector-test' # name of the microservice IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) stage: build before_script: @@ -17,14 +17,14 @@ build centralizedcybersecurity: - .gitlab-ci.yml # Pull, execute, and run unitary tests for the Docker image from the GitLab registry -unit_test centralizedcybersecurity: +unit_test centralizedattackdetector: variables: - IMAGE_NAME: 'centralizedcybersecurity' # name of the microservice - IMAGE_NAME_TEST: 'centralizedcybersecurity-test' # name of the microservice + IMAGE_NAME: 'centralizedattackdetector' # name of the microservice + IMAGE_NAME_TEST: 'centralizedattackdetector-test' # name of the microservice IMAGE_TAG: 'latest' # tag of the container image (production, development, etc) stage: unit_test needs: - - build centralizedcybersecurity + - build centralizedattackdetector before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi @@ -45,16 +45,16 @@ unit_test centralizedcybersecurity: - .gitlab-ci.yml # Deployment of the service in Kubernetes Cluster -deploy centralizedcybersecurity: +deploy centralizedattackdetector: stage: deploy needs: - - build centralizedcybersecurity - - unit_test centralizedcybersecurity + - build centralizedattackdetector + - unit_test centralizedattackdetector - dependencies all - integ_test execute script: - kubectl version - kubectl get all - - kubectl apply -f "manifests/centralizedcybersecurityservice.yaml" - - kubectl delete pods --selector app=centralizedcybersecurityservice + - kubectl apply -f "manifests/centralizedattackdetectorservice.yaml" + - kubectl delete pods --selector app=centralizedattackdetectorservice - kubectl get all diff --git a/src/centralizedcybersecurity/Config.py b/src/centralizedattackdetector/Config.py similarity index 100% rename from src/centralizedcybersecurity/Config.py rename to src/centralizedattackdetector/Config.py diff --git a/src/centralizedcybersecurity/Dockerfile b/src/centralizedattackdetector/Dockerfile similarity index 65% rename from src/centralizedcybersecurity/Dockerfile rename to src/centralizedattackdetector/Dockerfile index 00c149aa6ca032055f9a70a2350c04f88e931db1..f683a8c853f1741ee3dbb1031a6df4aa00419d42 100644 --- a/src/centralizedcybersecurity/Dockerfile +++ b/src/centralizedattackdetector/Dockerfile @@ -23,13 +23,13 @@ WORKDIR /var/teraflow RUN mkdir -p /var/teraflow/centralizedcybersecurity # Get Python packages per module -COPY centralizedcybersecurity/requirements.in centralizedcybersecurity/requirements.in -RUN pip-compile --output-file=centralizedcybersecurity/requirements.txt centralizedcybersecurity/requirements.in -RUN python3 -m pip install -r centralizedcybersecurity/requirements.txt +COPY centralizedattackdetector/requirements.in centralizedattackdetector/requirements.in +RUN pip-compile --output-file=centralizedattackdetector/requirements.txt centralizedattackdetector/requirements.in +RUN python3 -m pip install -r centralizedattackdetector/requirements.txt # Add files into working directory COPY common/. common -COPY centralizedcybersecurity/. centralizedcybersecurity +COPY centralizedattackdetector/. centralizedattackdetector -# Start centralizedcybersecurity service -ENTRYPOINT ["python", "-m", "centralizedcybersecurity.service"] +# Start centralizedattackdetector service +ENTRYPOINT ["python", "-m", "centralizedattackdetector.service"] diff --git a/src/centralizedcybersecurity/__init__.py b/src/centralizedattackdetector/__init__.py similarity index 100% rename from src/centralizedcybersecurity/__init__.py rename to src/centralizedattackdetector/__init__.py diff --git a/src/centralizedcybersecurity/client/CentralizedCybersecurityClient.py b/src/centralizedattackdetector/client/CentralizedAttackDetectorClient.py similarity index 84% rename from src/centralizedcybersecurity/client/CentralizedCybersecurityClient.py rename to src/centralizedattackdetector/client/CentralizedAttackDetectorClient.py index c89cbc80fe1e4fcbc068555f2c5077c9081f1572..3cc76aba46a63f539a74c3e646900c75171f7446 100644 --- a/src/centralizedcybersecurity/client/CentralizedCybersecurityClient.py +++ b/src/centralizedattackdetector/client/CentralizedAttackDetectorClient.py @@ -1,15 +1,15 @@ import grpc, logging from common.tools.client.RetryDecorator import retry, delay_exponential -from centralizedcybersecurity.proto.context_pb2 import Empty -from centralizedcybersecurity.proto.service_pb2 import Service -from centralizedcybersecurity.proto.monitoring_pb2 import KpiList -from centralizedcybersecurity.proto.centralized_cybersecurity_pb2_grpc import CentralizedCyberSecurityServiceStub +from centralizedattackdetector.proto.context_pb2 import Empty +from centralizedattackdetector.proto.service_pb2 import Service +from centralizedattackdetector.proto.monitoring_pb2 import KpiList +from centralizedattackdetector.proto.centralized_attack_detector_pb2_grpc import CentralizedAttackDetectorServiceStub LOGGER = logging.getLogger(__name__) MAX_RETRIES = 15 DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0) -class CentralizedCybersecurityClient: +class CentralizedAttackDetectorClient: def __init__(self, address, port): self.endpoint = '{}:{}'.format(address, port) LOGGER.debug('Creating channel to {}...'.format(self.endpoint)) @@ -20,7 +20,7 @@ class CentralizedCybersecurityClient: def connect(self): self.channel = grpc.insecure_channel(self.endpoint) - self.stub = CentralizedCyberSecurityServiceStub(self.channel) + self.stub = CentralizedAttackDetectorServiceStub(self.channel) def close(self): if(self.channel is not None): self.channel.close() diff --git a/src/centralizedcybersecurity/client/__init__.py b/src/centralizedattackdetector/client/__init__.py similarity index 100% rename from src/centralizedcybersecurity/client/__init__.py rename to src/centralizedattackdetector/client/__init__.py diff --git a/src/centralizedcybersecurity/genproto.sh b/src/centralizedattackdetector/genproto.sh similarity index 93% rename from src/centralizedcybersecurity/genproto.sh rename to src/centralizedattackdetector/genproto.sh index 997801446af9c154e1c4feeabfddd8ceac63be53..548428f37721abde24d35780207343208aa8f4b9 100755 --- a/src/centralizedcybersecurity/genproto.sh +++ b/src/centralizedattackdetector/genproto.sh @@ -37,7 +37,7 @@ sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/service_pb2.py sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/monitoring_pb2.py # building current service protos -python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto centralized_cybersecurity.proto +python -m grpc_tools.protoc -I../../proto --python_out=proto --grpc_python_out=proto centralized_attack_detector.proto -sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/centralized_cybersecurity_pb2.py -sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/centralized_cybersecurity_pb2_grpc.py +sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/centralized_attack_detector_pb2.py +sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' proto/centralized_attack_detector_pb2_grpc.py diff --git a/src/centralizedcybersecurity/proto/__init__.py b/src/centralizedattackdetector/proto/__init__.py similarity index 100% rename from src/centralizedcybersecurity/proto/__init__.py rename to src/centralizedattackdetector/proto/__init__.py diff --git a/src/centralizedcybersecurity/proto/centralized_cybersecurity_pb2.py b/src/centralizedattackdetector/proto/centralized_attack_detector_pb2.py similarity index 58% rename from src/centralizedcybersecurity/proto/centralized_cybersecurity_pb2.py rename to src/centralizedattackdetector/proto/centralized_attack_detector_pb2.py index b300ace7466c1e3b1199f2db49dea482d6908413..2e4f1add6a52598640d3eb23717d61083d5b145f 100644 --- a/src/centralizedcybersecurity/proto/centralized_cybersecurity_pb2.py +++ b/src/centralizedattackdetector/proto/centralized_attack_detector_pb2.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! -# source: centralized_cybersecurity.proto +# source: centralized_attack_detector.proto """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message @@ -17,12 +17,12 @@ from . import monitoring_pb2 as monitoring__pb2 DESCRIPTOR = _descriptor.FileDescriptor( - name='centralized_cybersecurity.proto', - package='centralized_cybersecurity', + name='centralized_attack_detector.proto', + package='centralized_attack_detector', syntax='proto3', serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\x1f\x63\x65ntralized_cybersecurity.proto\x12\x19\x63\x65ntralized_cybersecurity\x1a\rcontext.proto\x1a\rservice.proto\x1a\x10monitoring.proto2\x80\x02\n\x1f\x43\x65ntralizedCyberSecurityService\x12\x39\n\x13NotifyServiceUpdate\x12\x10.service.Service\x1a\x0e.context.Empty\"\x00\x12\x30\n\x0c\x44\x65tectAttack\x12\x0e.context.Empty\x1a\x0e.context.Empty\"\x00\x12<\n\x13ReportSummarizedKpi\x12\x13.monitoring.KpiList\x1a\x0e.context.Empty\"\x00\x12\x32\n\tReportKpi\x12\x13.monitoring.KpiList\x1a\x0e.context.Empty\"\x00\x62\x06proto3' + serialized_pb=b'\n!centralized_attack_detector.proto\x12\x1b\x63\x65ntralized_attack_detector\x1a\rcontext.proto\x1a\rservice.proto\x1a\x10monitoring.proto2\x81\x02\n CentralizedAttackDetectorService\x12\x39\n\x13NotifyServiceUpdate\x12\x10.service.Service\x1a\x0e.context.Empty\"\x00\x12\x30\n\x0c\x44\x65tectAttack\x12\x0e.context.Empty\x1a\x0e.context.Empty\"\x00\x12<\n\x13ReportSummarizedKpi\x12\x13.monitoring.KpiList\x1a\x0e.context.Empty\"\x00\x12\x32\n\tReportKpi\x12\x13.monitoring.KpiList\x1a\x0e.context.Empty\"\x00\x62\x06proto3' , dependencies=[context__pb2.DESCRIPTOR,service__pb2.DESCRIPTOR,monitoring__pb2.DESCRIPTOR,]) @@ -32,19 +32,19 @@ _sym_db.RegisterFileDescriptor(DESCRIPTOR) -_CENTRALIZEDCYBERSECURITYSERVICE = _descriptor.ServiceDescriptor( - name='CentralizedCyberSecurityService', - full_name='centralized_cybersecurity.CentralizedCyberSecurityService', +_CENTRALIZEDATTACKDETECTORSERVICE = _descriptor.ServiceDescriptor( + name='CentralizedAttackDetectorService', + full_name='centralized_attack_detector.CentralizedAttackDetectorService', file=DESCRIPTOR, index=0, serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_start=111, - serialized_end=367, + serialized_start=115, + serialized_end=372, methods=[ _descriptor.MethodDescriptor( name='NotifyServiceUpdate', - full_name='centralized_cybersecurity.CentralizedCyberSecurityService.NotifyServiceUpdate', + full_name='centralized_attack_detector.CentralizedAttackDetectorService.NotifyServiceUpdate', index=0, containing_service=None, input_type=service__pb2._SERVICE, @@ -54,7 +54,7 @@ _CENTRALIZEDCYBERSECURITYSERVICE = _descriptor.ServiceDescriptor( ), _descriptor.MethodDescriptor( name='DetectAttack', - full_name='centralized_cybersecurity.CentralizedCyberSecurityService.DetectAttack', + full_name='centralized_attack_detector.CentralizedAttackDetectorService.DetectAttack', index=1, containing_service=None, input_type=context__pb2._EMPTY, @@ -64,7 +64,7 @@ _CENTRALIZEDCYBERSECURITYSERVICE = _descriptor.ServiceDescriptor( ), _descriptor.MethodDescriptor( name='ReportSummarizedKpi', - full_name='centralized_cybersecurity.CentralizedCyberSecurityService.ReportSummarizedKpi', + full_name='centralized_attack_detector.CentralizedAttackDetectorService.ReportSummarizedKpi', index=2, containing_service=None, input_type=monitoring__pb2._KPILIST, @@ -74,7 +74,7 @@ _CENTRALIZEDCYBERSECURITYSERVICE = _descriptor.ServiceDescriptor( ), _descriptor.MethodDescriptor( name='ReportKpi', - full_name='centralized_cybersecurity.CentralizedCyberSecurityService.ReportKpi', + full_name='centralized_attack_detector.CentralizedAttackDetectorService.ReportKpi', index=3, containing_service=None, input_type=monitoring__pb2._KPILIST, @@ -83,8 +83,8 @@ _CENTRALIZEDCYBERSECURITYSERVICE = _descriptor.ServiceDescriptor( create_key=_descriptor._internal_create_key, ), ]) -_sym_db.RegisterServiceDescriptor(_CENTRALIZEDCYBERSECURITYSERVICE) +_sym_db.RegisterServiceDescriptor(_CENTRALIZEDATTACKDETECTORSERVICE) -DESCRIPTOR.services_by_name['CentralizedCyberSecurityService'] = _CENTRALIZEDCYBERSECURITYSERVICE +DESCRIPTOR.services_by_name['CentralizedAttackDetectorService'] = _CENTRALIZEDATTACKDETECTORSERVICE # @@protoc_insertion_point(module_scope) diff --git a/src/centralizedcybersecurity/proto/centralized_cybersecurity_pb2_grpc.py b/src/centralizedattackdetector/proto/centralized_attack_detector_pb2_grpc.py similarity index 86% rename from src/centralizedcybersecurity/proto/centralized_cybersecurity_pb2_grpc.py rename to src/centralizedattackdetector/proto/centralized_attack_detector_pb2_grpc.py index fa693a586edeefc3d25ca1f7b76a1eac0c7b2c17..1dc1df6e7fd0fb55628314a90c23fadea591dd91 100644 --- a/src/centralizedcybersecurity/proto/centralized_cybersecurity_pb2_grpc.py +++ b/src/centralizedattackdetector/proto/centralized_attack_detector_pb2_grpc.py @@ -7,7 +7,7 @@ from . import monitoring_pb2 as monitoring__pb2 from . import service_pb2 as service__pb2 -class CentralizedCyberSecurityServiceStub(object): +class CentralizedAttackDetectorServiceStub(object): """Missing associated documentation comment in .proto file.""" def __init__(self, channel): @@ -17,28 +17,28 @@ class CentralizedCyberSecurityServiceStub(object): channel: A grpc.Channel. """ self.NotifyServiceUpdate = channel.unary_unary( - '/centralized_cybersecurity.CentralizedCyberSecurityService/NotifyServiceUpdate', + '/centralized_attack_detector.CentralizedAttackDetectorService/NotifyServiceUpdate', request_serializer=service__pb2.Service.SerializeToString, response_deserializer=context__pb2.Empty.FromString, ) self.DetectAttack = channel.unary_unary( - '/centralized_cybersecurity.CentralizedCyberSecurityService/DetectAttack', + '/centralized_attack_detector.CentralizedAttackDetectorService/DetectAttack', request_serializer=context__pb2.Empty.SerializeToString, response_deserializer=context__pb2.Empty.FromString, ) self.ReportSummarizedKpi = channel.unary_unary( - '/centralized_cybersecurity.CentralizedCyberSecurityService/ReportSummarizedKpi', + '/centralized_attack_detector.CentralizedAttackDetectorService/ReportSummarizedKpi', request_serializer=monitoring__pb2.KpiList.SerializeToString, response_deserializer=context__pb2.Empty.FromString, ) self.ReportKpi = channel.unary_unary( - '/centralized_cybersecurity.CentralizedCyberSecurityService/ReportKpi', + '/centralized_attack_detector.CentralizedAttackDetectorService/ReportKpi', request_serializer=monitoring__pb2.KpiList.SerializeToString, response_deserializer=context__pb2.Empty.FromString, ) -class CentralizedCyberSecurityServiceServicer(object): +class CentralizedAttackDetectorServiceServicer(object): """Missing associated documentation comment in .proto file.""" def NotifyServiceUpdate(self, request, context): @@ -68,7 +68,7 @@ class CentralizedCyberSecurityServiceServicer(object): raise NotImplementedError('Method not implemented!') -def add_CentralizedCyberSecurityServiceServicer_to_server(servicer, server): +def add_CentralizedAttackDetectorServiceServicer_to_server(servicer, server): rpc_method_handlers = { 'NotifyServiceUpdate': grpc.unary_unary_rpc_method_handler( servicer.NotifyServiceUpdate, @@ -92,12 +92,12 @@ def add_CentralizedCyberSecurityServiceServicer_to_server(servicer, server): ), } generic_handler = grpc.method_handlers_generic_handler( - 'centralized_cybersecurity.CentralizedCyberSecurityService', rpc_method_handlers) + 'centralized_attack_detector.CentralizedAttackDetectorService', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) # This class is part of an EXPERIMENTAL API. -class CentralizedCyberSecurityService(object): +class CentralizedAttackDetectorService(object): """Missing associated documentation comment in .proto file.""" @staticmethod @@ -111,7 +111,7 @@ class CentralizedCyberSecurityService(object): wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/centralized_cybersecurity.CentralizedCyberSecurityService/NotifyServiceUpdate', + return grpc.experimental.unary_unary(request, target, '/centralized_attack_detector.CentralizedAttackDetectorService/NotifyServiceUpdate', service__pb2.Service.SerializeToString, context__pb2.Empty.FromString, options, channel_credentials, @@ -128,7 +128,7 @@ class CentralizedCyberSecurityService(object): wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/centralized_cybersecurity.CentralizedCyberSecurityService/DetectAttack', + return grpc.experimental.unary_unary(request, target, '/centralized_attack_detector.CentralizedAttackDetectorService/DetectAttack', context__pb2.Empty.SerializeToString, context__pb2.Empty.FromString, options, channel_credentials, @@ -145,7 +145,7 @@ class CentralizedCyberSecurityService(object): wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/centralized_cybersecurity.CentralizedCyberSecurityService/ReportSummarizedKpi', + return grpc.experimental.unary_unary(request, target, '/centralized_attack_detector.CentralizedAttackDetectorService/ReportSummarizedKpi', monitoring__pb2.KpiList.SerializeToString, context__pb2.Empty.FromString, options, channel_credentials, @@ -162,7 +162,7 @@ class CentralizedCyberSecurityService(object): wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/centralized_cybersecurity.CentralizedCyberSecurityService/ReportKpi', + return grpc.experimental.unary_unary(request, target, '/centralized_attack_detector.CentralizedAttackDetectorService/ReportKpi', monitoring__pb2.KpiList.SerializeToString, context__pb2.Empty.FromString, options, channel_credentials, diff --git a/src/centralizedcybersecurity/proto/context_pb2.py b/src/centralizedattackdetector/proto/context_pb2.py similarity index 100% rename from src/centralizedcybersecurity/proto/context_pb2.py rename to src/centralizedattackdetector/proto/context_pb2.py diff --git a/src/centralizedcybersecurity/proto/monitoring_pb2.py b/src/centralizedattackdetector/proto/monitoring_pb2.py similarity index 97% rename from src/centralizedcybersecurity/proto/monitoring_pb2.py rename to src/centralizedattackdetector/proto/monitoring_pb2.py index 32394e232c196c4189a1e5c147980a66d6f8d34d..275fcc48a557d71eeedf2c5d6f6e062f5c47e731 100644 --- a/src/centralizedcybersecurity/proto/monitoring_pb2.py +++ b/src/centralizedattackdetector/proto/monitoring_pb2.py @@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( syntax='proto3', serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\x10monitoring.proto\x12\nmonitoring\x1a\rcontext.proto\"|\n\x03Kpi\x12!\n\x06kpi_id\x18\x01 \x01(\x0b\x32\x11.monitoring.KpiId\x12\x11\n\ttimestamp\x18\x02 \x01(\t\x12\x16\n\x0ekpiDescription\x18\x03 \x01(\t\x12\'\n\tkpi_value\x18\x04 \x01(\x0b\x32\x14.monitoring.KpiValue\"&\n\x05KpiId\x12\x1d\n\x06kpi_id\x18\x01 \x01(\x0b\x32\r.context.Uuid\"T\n\tKpiDevice\x12!\n\x06kpi_id\x18\x01 \x01(\x0b\x32\x11.monitoring.KpiId\x12$\n\tdevice_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\"+\n\x07KpiList\x12 \n\x07kpiList\x18\x01 \x03(\x0b\x32\x0f.monitoring.Kpi\"M\n\x08KpiValue\x12\x10\n\x06intVal\x18\x01 \x01(\rH\x00\x12\x13\n\tstringVal\x18\x02 \x01(\tH\x00\x12\x11\n\x07\x62oolVal\x18\x03 \x01(\x08H\x00\x42\x07\n\x05value2\xeb\x01\n\x11MonitoringService\x12/\n\nIncludeKpi\x12\x0f.monitoring.Kpi\x1a\x0e.context.Empty\"\x00\x12\x35\n\nMonitorKpi\x12\x15.monitoring.KpiDevice\x1a\x0e.context.Empty\"\x00\x12\x37\n\rGetStream_kpi\x12\x11.monitoring.KpiId\x1a\x0f.monitoring.Kpi\"\x00\x30\x01\x12\x35\n\rGetInstantKpi\x12\x11.monitoring.KpiId\x1a\x0f.monitoring.Kpi\"\x00\x62\x06proto3' + serialized_pb=b'\n\x10monitoring.proto\x12\nmonitoring\x1a\rcontext.proto\"|\n\x03Kpi\x12!\n\x06kpi_id\x18\x01 \x01(\x0b\x32\x11.monitoring.KpiId\x12\x11\n\ttimestamp\x18\x02 \x01(\t\x12\x16\n\x0ekpiDescription\x18\x03 \x01(\t\x12\'\n\tkpi_value\x18\x04 \x01(\x0b\x32\x14.monitoring.KpiValue\"&\n\x05KpiId\x12\x1d\n\x06kpi_id\x18\x01 \x01(\x0b\x32\r.context.Uuid\"T\n\tKpiDevice\x12!\n\x06kpi_id\x18\x01 \x01(\x0b\x32\x11.monitoring.KpiId\x12$\n\tdevice_id\x18\x02 \x01(\x0b\x32\x11.context.DeviceId\"+\n\x07KpiList\x12 \n\x07kpiList\x18\x01 \x03(\x0b\x32\x0f.monitoring.Kpi\"M\n\x08KpiValue\x12\x10\n\x06intVal\x18\x01 \x01(\rH\x00\x12\x13\n\tstringVal\x18\x02 \x01(\tH\x00\x12\x11\n\x07\x62oolVal\x18\x03 \x01(\x08H\x00\x42\x07\n\x05value2\xea\x01\n\x11MonitoringService\x12/\n\nIncludeKpi\x12\x0f.monitoring.Kpi\x1a\x0e.context.Empty\"\x00\x12\x35\n\nMonitorKpi\x12\x15.monitoring.KpiDevice\x1a\x0e.context.Empty\"\x00\x12\x36\n\x0cGetStreamKpi\x12\x11.monitoring.KpiId\x1a\x0f.monitoring.Kpi\"\x00\x30\x01\x12\x35\n\rGetInstantKpi\x12\x11.monitoring.KpiId\x1a\x0f.monitoring.Kpi\"\x00\x62\x06proto3' , dependencies=[context__pb2.DESCRIPTOR,]) @@ -300,7 +300,7 @@ _MONITORINGSERVICE = _descriptor.ServiceDescriptor( serialized_options=None, create_key=_descriptor._internal_create_key, serialized_start=424, - serialized_end=659, + serialized_end=658, methods=[ _descriptor.MethodDescriptor( name='IncludeKpi', @@ -323,8 +323,8 @@ _MONITORINGSERVICE = _descriptor.ServiceDescriptor( create_key=_descriptor._internal_create_key, ), _descriptor.MethodDescriptor( - name='GetStream_kpi', - full_name='monitoring.MonitoringService.GetStream_kpi', + name='GetStreamKpi', + full_name='monitoring.MonitoringService.GetStreamKpi', index=2, containing_service=None, input_type=_KPIID, diff --git a/src/centralizedcybersecurity/proto/service_pb2.py b/src/centralizedattackdetector/proto/service_pb2.py similarity index 100% rename from src/centralizedcybersecurity/proto/service_pb2.py rename to src/centralizedattackdetector/proto/service_pb2.py diff --git a/src/centralizedcybersecurity/requirements.in b/src/centralizedattackdetector/requirements.in similarity index 100% rename from src/centralizedcybersecurity/requirements.in rename to src/centralizedattackdetector/requirements.in diff --git a/src/centralizedcybersecurity/requirements.txt b/src/centralizedattackdetector/requirements.txt similarity index 100% rename from src/centralizedcybersecurity/requirements.txt rename to src/centralizedattackdetector/requirements.txt diff --git a/src/centralizedcybersecurity/service/CentralizedCybersecurityService.py b/src/centralizedattackdetector/service/CentralizedAttackDetectorService.py similarity index 76% rename from src/centralizedcybersecurity/service/CentralizedCybersecurityService.py rename to src/centralizedattackdetector/service/CentralizedAttackDetectorService.py index d209e8d0fd3822b82f098f72db089cef94950034..bbfb9eb5fdd82bc78afc98dbabce4dba8d4d4493 100644 --- a/src/centralizedcybersecurity/service/CentralizedCybersecurityService.py +++ b/src/centralizedattackdetector/service/CentralizedAttackDetectorService.py @@ -4,14 +4,14 @@ from concurrent import futures from grpc_health.v1.health import HealthServicer, OVERALL_HEALTH from grpc_health.v1.health_pb2 import HealthCheckResponse from grpc_health.v1.health_pb2_grpc import add_HealthServicer_to_server -from centralizedcybersecurity.proto.centralized_cybersecurity_pb2_grpc import add_CentralizedCyberSecurityServiceServicer_to_server -from centralizedcybersecurity.service.CentralizedCybersecurityServiceServicerImpl import CentralizedCybersecurityServiceServicerImpl -from centralizedcybersecurity.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD +from centralizedattackdetector.proto.centralized_attack_detector_pb2_grpc import add_CentralizedAttackDetectorServiceServicer_to_server +from centralizedattackdetector.service.CentralizedAttackDetectorServiceServicerImpl import CentralizedAttackDetectorServiceServicerImpl +from centralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD BIND_ADDRESS = '0.0.0.0' LOGGER = logging.getLogger(__name__) -class CentralizedCybersecurityService: +class CentralizedAttackDetectorService: def __init__(self, database, address=BIND_ADDRESS, port=GRPC_SERVICE_PORT, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD): self.database = database @@ -33,8 +33,8 @@ class CentralizedCybersecurityService: self.pool = futures.ThreadPoolExecutor(max_workers=self.max_workers) self.server = grpc.server(self.pool) # , interceptors=(tracer_interceptor,)) - self.centralized_cybersecurity_servicer = CentralizedCybersecurityServiceServicerImpl(self.database) - add_CentralizedCyberSecurityServiceServicer_to_server(self.centralized_cybersecurity_servicer, self.server) + self.centralized_attack_detector_servicer = CentralizedAttackDetectorServiceServicerImpl(self.database) + add_CentralizedAttackDetectorServiceServicer_to_server(self.centralized_attack_detector_servicer, self.server) self.health_servicer = HealthServicer( experimental_non_blocking=True, experimental_thread_pool=futures.ThreadPoolExecutor(max_workers=1)) diff --git a/src/centralizedcybersecurity/service/CentralizedCybersecurityServiceServicerImpl.py b/src/centralizedattackdetector/service/CentralizedAttackDetectorServiceServicerImpl.py similarity index 79% rename from src/centralizedcybersecurity/service/CentralizedCybersecurityServiceServicerImpl.py rename to src/centralizedattackdetector/service/CentralizedAttackDetectorServiceServicerImpl.py index b5d62e240a16be9399955ab07eb76b41fa1a2f03..ef9126c9cb2450de76e3c82f2d3f6de98866ba45 100644 --- a/src/centralizedcybersecurity/service/CentralizedCybersecurityServiceServicerImpl.py +++ b/src/centralizedattackdetector/service/CentralizedAttackDetectorServiceServicerImpl.py @@ -3,15 +3,15 @@ import grpc, logging from prometheus_client import Counter, Histogram from common.database.api.Database import Database from common.exceptions.ServiceException import ServiceException -from centralizedcybersecurity.proto.context_pb2 import Empty -from centralizedcybersecurity.proto.service_pb2 import Service -from centralizedcybersecurity.proto.monitoring_pb2 import KpiList -from centralizedcybersecurity.proto.centralized_cybersecurity_pb2_grpc import CentralizedCyberSecurityServiceServicer +from centralizedattackdetector.proto.context_pb2 import Empty +from centralizedattackdetector.proto.service_pb2 import Service +from centralizedattackdetector.proto.monitoring_pb2 import KpiList +from centralizedattackdetector.proto.centralized_attack_detector_pb2_grpc import CentralizedAttackDetectorServiceServicer LOGGER = logging.getLogger(__name__) -class CentralizedCybersecurityServiceServicerImpl(CentralizedCyberSecurityServiceServicer): +class CentralizedAttackDetectorServiceServicerImpl(CentralizedAttackDetectorServiceServicer): def __init__(self, database : Database): LOGGER.debug('Creating Servicer...') diff --git a/src/centralizedcybersecurity/service/__init__.py b/src/centralizedattackdetector/service/__init__.py similarity index 100% rename from src/centralizedcybersecurity/service/__init__.py rename to src/centralizedattackdetector/service/__init__.py diff --git a/src/centralizedcybersecurity/service/__main__.py b/src/centralizedattackdetector/service/__main__.py similarity index 75% rename from src/centralizedcybersecurity/service/__main__.py rename to src/centralizedattackdetector/service/__main__.py index 86f84c2a5aad2776162551ea22254ff84d25d6f0..da571acb4173fd376f0e5bdd716e587814caf525 100644 --- a/src/centralizedcybersecurity/service/__main__.py +++ b/src/centralizedattackdetector/service/__main__.py @@ -1,8 +1,8 @@ import logging, os, signal, sys, threading from prometheus_client import start_http_server from common.database.Factory import get_database -from centralizedcybersecurity.service.CentralizedCybersecurityService import CentralizedCybersecurityService -from centralizedcybersecurity.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT +from centralizedattackdetector.service.CentralizedAttackDetectorService import CentralizedAttackDetectorService +from centralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, METRICS_PORT terminate = threading.Event() logger = None @@ -15,7 +15,7 @@ def signal_handler(signal, frame): def main(): global terminate, logger - service_port = os.environ.get('CENTRALIZEDCYBERSECURITYSERVICE_SERVICE_PORT_GRPC', GRPC_SERVICE_PORT) + service_port = os.environ.get('CENTRALIZEDATTACKDETECTORSERVICE_SERVICE_PORT_GRPC', GRPC_SERVICE_PORT) max_workers = os.environ.get('MAX_WORKERS', GRPC_MAX_WORKERS ) grace_period = os.environ.get('GRACE_PERIOD', GRPC_GRACE_PERIOD) log_level = os.environ.get('LOG_LEVEL', LOG_LEVEL ) @@ -36,7 +36,7 @@ def main(): database = get_database() # Starting CentralizedCybersecurity service - grpc_service = CentralizedCybersecurityService(database, port=service_port, max_workers=max_workers, grace_period=grace_period) + grpc_service = CentralizedAttackDetectorService(database, port=service_port, max_workers=max_workers, grace_period=grace_period) grpc_service.start() # Wait for Ctrl+C or termination signal diff --git a/src/centralizedcybersecurity/tests/__init__.py b/src/centralizedattackdetector/tests/__init__.py similarity index 100% rename from src/centralizedcybersecurity/tests/__init__.py rename to src/centralizedattackdetector/tests/__init__.py diff --git a/src/centralizedattackdetector/tests/test_unitary.py b/src/centralizedattackdetector/tests/test_unitary.py new file mode 100644 index 0000000000000000000000000000000000000000..9368a0724145b03122493031a22077d250b29275 --- /dev/null +++ b/src/centralizedattackdetector/tests/test_unitary.py @@ -0,0 +1,54 @@ +import copy, grpc, logging, pytest +from google.protobuf.json_format import MessageToDict +from common.database.Factory import get_database, DatabaseEngineEnum +from common.database.api.Database import Database +from common.database.api.context.Constants import DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID +from common.database.tests.script import populate_example +from common.tests.Assertions import validate_empty, validate_service, validate_service_id, \ + validate_service_list_is_empty, validate_service_list_is_not_empty +from centralizedattackdetector.proto.monitoring_pb2 import Kpi, KpiList +from centralizedattackdetector.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD +from centralizedattackdetector.client.CentralizedAttackDetectorClient import CentralizedAttackDetectorClient +from centralizedattackdetector.proto.context_pb2 import Empty +from centralizedattackdetector.proto.service_pb2 import Service +from centralizedattackdetector.service.CentralizedAttackDetectorService import CentralizedAttackDetectorService + +port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports + +LOGGER = logging.getLogger(__name__) +LOGGER.setLevel(logging.DEBUG) + +@pytest.fixture(scope='session') +def database(): + _database = get_database(engine=DatabaseEngineEnum.INMEMORY) + return _database + +@pytest.fixture(scope='session') +def centralized_attack_detector_service(database): + _service = CentralizedAttackDetectorService( + database, port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD) + _service.start() + yield _service + _service.stop() + +@pytest.fixture(scope='session') +def centralized_attack_detector_client(centralized_attack_detector_service): + _client = CentralizedAttackDetectorClient(address='127.0.0.1', port=port) + yield _client + _client.close() + +def test_notify_service_update(centralized_attack_detector_client: CentralizedAttackDetectorClient): + service = Service() + centralized_attack_detector_client.NotifyServiceUpdate(service) + +def test_detect_attack(centralized_attack_detector_client: CentralizedAttackDetectorClient): + request = Empty() + centralized_attack_detector_client.DetectAttack(request) + +def test_report_summarized_kpi(centralized_attack_detector_client: CentralizedAttackDetectorClient): + kpi_list = KpiList() + centralized_attack_detector_client.ReportSummarizedKpi(kpi_list) + +def test_report_kpi(centralized_attack_detector_client: CentralizedAttackDetectorClient): + kpi_list = KpiList() + centralized_attack_detector_client.ReportKpi(kpi_list) diff --git a/src/centralizedcybersecurity/tests/test_unitary.py b/src/centralizedcybersecurity/tests/test_unitary.py deleted file mode 100644 index 5f22056ef48a96523b859ced4f9e33e200ca46b3..0000000000000000000000000000000000000000 --- a/src/centralizedcybersecurity/tests/test_unitary.py +++ /dev/null @@ -1,58 +0,0 @@ -import copy, grpc, logging, pytest -from src.centralizedcybersecurity.proto.monitoring_pb2 import Kpi, KpiList -from google.protobuf.json_format import MessageToDict -from common.database.Factory import get_database, DatabaseEngineEnum -from common.database.api.Database import Database -from common.database.api.context.Constants import DEFAULT_CONTEXT_ID, DEFAULT_TOPOLOGY_ID -from common.database.tests.script import populate_example -from common.tests.Assertions import validate_empty, validate_service, validate_service_id, \ - validate_service_list_is_empty, validate_service_list_is_not_empty -from centralizedcybersecurity.Config import GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD -from centralizedcybersecurity.client.CentralizedCybersecurityClient import CentralizedCybersecurityClient -from centralizedcybersecurity.proto.context_pb2 import Empty -from centralizedcybersecurity.proto.service_pb2 import Service -from centralizedcybersecurity.service.CentralizedCybersecurityService import CentralizedCybersecurityService - -port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports - -LOGGER = logging.getLogger(__name__) -LOGGER.setLevel(logging.DEBUG) - -@pytest.fixture(scope='session') -def database(): - _database = get_database(engine=DatabaseEngineEnum.INMEMORY) - return _database - -@pytest.fixture(scope='session') -def centralized_cybersecurity_service(database): - _service = CentralizedCybersecurityService( - database, port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD) - _service.start() - yield _service - _service.stop() - -@pytest.fixture(scope='session') -def centralized_cybersecurity_client(centralized_cybersecurity_service): - _client = CentralizedCybersecurityClient(address='127.0.0.1', port=port) - yield _client - _client.close() - -@pytest.fixture(scope='session') -def test_notify_service_update(centralized_cybersecurity_client: CentralizedCybersecurityClient): - service = Service() - centralized_cybersecurity_client.NotifyServiceUpdate(service) - -@pytest.fixture(scope='session') -def test_detect_attack(centralized_cybersecurity_client: CentralizedCybersecurityClient): - request = Empty() - centralized_cybersecurity_client.DetectAttack(request) - -@pytest.fixture(scope='session') -def test_report_summarized_kpi(centralized_cybersecurity_client: CentralizedCybersecurityClient): - kpi_list = KpiList() - centralized_cybersecurity_client.ReportSummarizedKpi(kpi_list) - -@pytest.fixture(scope='session') -def test_report_kpi(centralized_cybersecurity_client: CentralizedCybersecurityClient): - kpi_list = KpiList() - centralized_cybersecurity_client.ReportKpi(kpi_list)