diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | clover/logging/conftest.py | 15 | ||||
-rw-r--r-- | clover/logging/es_test.py | 30 | ||||
-rw-r--r-- | clover/logging/validate.py | 3 | ||||
-rw-r--r-- | docker/Dockerfile | 4 | ||||
-rw-r--r-- | docs/development/design/logging.rst | 136 | ||||
-rw-r--r-- | docs/release/release-notes/index.rst | 2 | ||||
-rw-r--r-- | docs/release/release-notes/release-notes.rst (renamed from docs/release/release-notes/Fraser-release-notes.rst) | 201 | ||||
-rw-r--r-- | docs/release/userguide/Fraser-userguide.rst | 81 | ||||
-rw-r--r-- | docs/release/userguide/index.rst | 2 | ||||
-rw-r--r-- | docs/release/userguide/userguide.rst | 64 | ||||
-rw-r--r-- | samples/services/snort_ids/docker/grpc/snort.proto | 5 | ||||
-rw-r--r-- | samples/services/snort_ids/docker/grpc/snort_alerts.py | 18 | ||||
-rw-r--r-- | samples/services/snort_ids/docker/grpc/snort_client.py | 16 | ||||
-rw-r--r-- | samples/services/snort_ids/docker/grpc/snort_pb2.py | 23 | ||||
-rw-r--r-- | samples/services/snort_ids/docker/grpc/snort_server.py | 13 |
16 files changed, 408 insertions, 206 deletions
@@ -35,3 +35,4 @@ cover/ .tox/ # work env work/ +.pytest_cache diff --git a/clover/logging/conftest.py b/clover/logging/conftest.py new file mode 100644 index 0000000..d464fab --- /dev/null +++ b/clover/logging/conftest.py @@ -0,0 +1,15 @@ +# Copyright (c) Authors of Clover +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +from elasticsearch import Elasticsearch +import pytest + +ES_HOST="localhost:9200" + +@pytest.fixture +def es(): + return Elasticsearch([ES_HOST]) diff --git a/clover/logging/es_test.py b/clover/logging/es_test.py new file mode 100644 index 0000000..bd0e359 --- /dev/null +++ b/clover/logging/es_test.py @@ -0,0 +1,30 @@ +# Copyright (c) Authors of Clover +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 + +INDEX_PATTERN='logstash-*' +TAG='newlog.logentry.istio-system' + +def test_health(es): + assert es.cat.health(h='status') != 'red\n' + +def test_indices(es): + assert len(es.cat.indices(INDEX_PATTERN)) > 0 + +def test_logentry(es): + assert es.count( + index=INDEX_PATTERN, + body={"query":{"match":{"tag":TAG}}})['count'] > 0 + +def test_lb(es): + """requests in and out load balance should match""" + from_lb = es.count( + index=INDEX_PATTERN, + body={"query":{"match":{"source": "http-lb"}}}) + to_lb = es.count( + index=INDEX_PATTERN, + body={"query":{"match":{"destination": "http-lb"}}}) + assert from_lb['count'] == to_lb['count'] diff --git a/clover/logging/validate.py b/clover/logging/validate.py index 821f912..aca0394 100644 --- a/clover/logging/validate.py +++ b/clover/logging/validate.py @@ -9,6 +9,8 @@ from kubernetes import client, config from kubernetes.stream import stream import sh import re +import os +import pytest FLUENTD_NAMESPACE = 'logging' FLUENTD_PATTERN = 'fluentd-.*' @@ -54,3 +56,4 @@ def main(): if __name__ == '__main__': main() + pytest.main([os.path.dirname(os.path.realpath(__file__))]) diff --git a/docker/Dockerfile b/docker/Dockerfile index daed730..2cd6340 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -7,7 +7,6 @@ FROM ubuntu:16.04 LABEL image=opnfv/clover -ARG BRANCH=master ARG ISTIO_VERSION=0.6.0 # GIT repo directory @@ -20,7 +19,8 @@ ENV CLOVER_REPO_DIR="${REPOS_DIR}/clover" RUN apt-get update \ && apt-get install -y git python-setuptools python-pip curl apt-transport-https \ && apt-get -y autoremove && apt-get clean \ - && pip install --upgrade pip + && pip install --upgrade pip \ + && python -m pip install grpcio argparse # Fetch source code RUN mkdir -p ${REPOS_DIR} diff --git a/docs/development/design/logging.rst b/docs/development/design/logging.rst index 196ba40..05f3f5b 100644 --- a/docs/development/design/logging.rst +++ b/docs/development/design/logging.rst @@ -26,3 +26,139 @@ It validates the installation with the following criterias #. existence of fluented pod #. fluentd input is configured correctly #. TBD + +************************** +Understanding how it works +************************** + +In clover stack, Istio is configured to automatically gather logs for services +in a mesh. More specificly, it is configured in `Mixer`_:: + +- when to log +- what to log +- where to log + +.. _Mixer: https://istio.io/docs/concepts/policy-and-control/mixer.html + +When to log +=========== + +Istio defines when to log by creating a custom resource ``rule``. For example: + +.. code-block:: yaml + + apiVersion: "config.istio.io/v1alpha2" + kind: rule + metadata: + name: newlogtofluentd + namespace: istio-system + spec: + match: "true" # match for all requests + actions: + - handler: handler.fluentd + instances: + - newlog.logentry + +This rule specifies that all instances of ``newlog.logentry`` that matches the +expression will be handled by the specified handler ``handler.fluentd``. We +shall explain ``instances`` and ``handler`` later. The expression ``true`` means +whenever a request arrive at Mixer, it will trigger the actions defined belows. + +``rule`` is a custom resource definition from `Istio installation`_. + +.. code-block:: yaml + + # Rule to send logentry instances to the fluentd handler + kind: CustomResourceDefinition + apiVersion: apiextensions.k8s.io/v1beta1 + metadata: + name: rules.config.istio.io + labels: + package: istio.io.mixer + istio: core + spec: + group: config.istio.io + names: + kind: rule + plural: rules + singular: rule + scope: Namespaced + version: v1alpha2 + +.. _Istio installation: https://github.com/istio/istio/blob/master/install/kubernetes/templates/istio-mixer.yaml.tmpl + +What to log +=========== + +The instance defines what content to be logged. + +> A (request) instance is the result of applying request attributes to the +> template mapping. The mapping is specified as an instance configuration. + +For example: + +.. code-block:: yaml + + # Configuration for logentry instances + apiVersion: "config.istio.io/v1alpha2" + kind: logentry + metadata: + name: newlog + namespace: istio-system + spec: + severity: '"info"' + timestamp: request.time + variables: + source: source.labels["app"] | source.service | "unknown" + user: source.user | "unknown" + destination: destination.labels["app"] | destination.service | "unknown" + responseCode: response.code | 0 + responseSize: response.size | 0 + latency: response.duration | "0ms" + monitored_resource_type: '"UNSPECIFIED"' + +The keys under ``spec`` should conform to the template. To learn what fields +are available and valid type, you may need to reference the corresponding +template, in this case, `Log Entry template`_. + +The values of each field could be either `Istio attributes`_ or an expression. + +> A given Istio deployment has a fixed vocabulary of attributes that it +> understands. The specific vocabulary is determined by the set of attribute +> producers being used in the deployment. The primary attribute producer in +> Istio is Envoy, although Mixer and services can also introduce attributes. + +Refer to the `Attribute Vocabulary`_ to learn the full set. + +By the way, ``logentry`` is also a custom resource definition created by Istio. + +.. _Istio attributes: https://istio.io/docs/concepts/policy-and-control/attributes.html +.. _Attribute Vocabulary: https://istio.io/docs/reference/config/mixer/attribute-vocabulary.html +.. _Log Entry template: https://istio.io/docs/reference/config/template/logentry.html + +Where to log +============ + +For log, the handler defines where these information will be handled, in this +example, a fluentd daemon on fluentd-es.logging:24224. + +.. code-block:: yaml + + # Configuration for a fluentd handler + apiVersion: "config.istio.io/v1alpha2" + kind: fluentd + metadata: + name: handler + namespace: istio-system + spec: + address: "fluentd-es.logging:24224" + +In this example, handlers (``handler.fluentd``) configure `Adapters`_ +(``fluentd``) to handle the data delivered from the created instances +(``newlog.logentry``). + +An adapter only accepts instance of specified kind. For example, +`fluentd adapter`_ accepts logentry but not other kinds. + +.. _Adapters: https://istio.io/docs/concepts/policy-and-control/mixer.html#adapters +.. _fluentd adapter: https://istio.io/docs/reference/config/adapters/fluentd.html diff --git a/docs/release/release-notes/index.rst b/docs/release/release-notes/index.rst index 1c41113..c7f8f6c 100644 --- a/docs/release/release-notes/index.rst +++ b/docs/release/release-notes/index.rst @@ -12,4 +12,4 @@ OPNFV Clover Design Specification .. toctree:: :maxdepth: 1 - Fraser-release-notes + release-notes diff --git a/docs/release/release-notes/Fraser-release-notes.rst b/docs/release/release-notes/release-notes.rst index 3e864fb..f345f61 100644 --- a/docs/release/release-notes/Fraser-release-notes.rst +++ b/docs/release/release-notes/release-notes.rst @@ -1,100 +1,101 @@ -.. This work is licensed under a Creative Commons Attribution 4.0 International License.
-.. http://creativecommons.org/licenses/by/4.0
-.. SPDX-License-Identifier CC-BY-4.0
-.. (c) optionally add copywriters name
-
-
-This document provides the release notes for Fraser of OPNFV Clover.
-
-.. contents::
- :depth: 3
- :local:
-
-
-Version history
----------------
-
-+--------------------+--------------------+--------------------+--------------------+
-| **Date** | **Ver.** | **Author** | **Comment** |
-| | | | |
-+--------------------+--------------------+--------------------+--------------------+
-| 2018-03-14 | Fraser 1.0 | Stephen Wong | First draft |
-| | | | |
-+--------------------+--------------------+--------------------+--------------------+
-
-Important notes
-===============
-
-The OPNFV Clover project for Fraser can ONLY be run on Kubernetes version 1.9.3 or
-above
-
-Summary
-=======
-
-Clover provides tools to help run cloud native virtual network functions. These
-tools include service-mesh and associated policy-based-routing config (via
-Istio), logging (via fluentd), monitoring (via Prometheus), and tracing (via
-OpenTracing and Jaeger).
-
-Release Data
-============
-
-+--------------------------------------+--------------------------------------+
-| **Project** | Clover |
-| | |
-+--------------------------------------+--------------------------------------+
-| **Repo/commit-ID** | |
-| | |
-+--------------------------------------+--------------------------------------+
-| **Release designation** | Fraser |
-| | |
-+--------------------------------------+--------------------------------------+
-| **Release date** | 2018-04-xx |
-| | |
-+--------------------------------------+--------------------------------------+
-| **Purpose of the delivery** | OPNFV Fraser release |
-| | |
-+--------------------------------------+--------------------------------------+
-
-Version change
-^^^^^^^^^^^^^^^^
-
-Module version changes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Fraser marks the first release of OPNFV Clover
-
-Document version changes
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Fraser marks the first release of OPNFV Clover
-
-Reason for version
-^^^^^^^^^^^^^^^^^^^^
-
-Feature additions
-~~~~~~~~~~~~~~~~~~~~~~~
-<None> (no backlog)
-
-Bug corrections
-~~~~~~~~~~~~~~~~~~~~~
-<None>
-
-Known Limitations, Issues and Workarounds
-=========================================
-
-System Limitations
-^^^^^^^^^^^^^^^^^^^^
-TBD
-
-Known issues
-^^^^^^^^^^^^^^^
-TBD
-
-Workarounds
-^^^^^^^^^^^^^^^^^
-
-Test Result
-===========
-
-
-References
-==========
+.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. SPDX-License-Identifier CC-BY-4.0 +.. (c) Authors of Clover + + +This document provides Clover project's release notes for the OPNFV Fraser release. + +.. contents:: + :depth: 3 + :local: + + +Version history +--------------- + ++--------------------+--------------------+--------------------+--------------------+ +| **Date** | **Ver.** | **Author** | **Comment** | +| | | | | ++--------------------+--------------------+--------------------+--------------------+ +| 2018-03-14 | Fraser 1.0 | Stephen Wong | First draft | +| | | | | ++--------------------+--------------------+--------------------+--------------------+ + +Important notes +=============== + +The Clover project for OPNFV Fraser can ONLY be run on Kubernetes version 1.9 or +later + +Summary +======= + +Clover Fraser release provides tools for installation and validation of various +upstream cloud native projects including Istio, fluentd, Jaegar, and Prometheus. +In addition, the Fraser release also includes a sample VNF, its Kubernetes +manifest, simple tools to validate route rules from Istio, as well as an +example A-B testing framework. + +Release Data +============ + ++--------------------------------------+--------------------------------------+ +| **Project** | Clover | +| | | ++--------------------------------------+--------------------------------------+ +| **Repo/commit-ID** | | +| | | ++--------------------------------------+--------------------------------------+ +| **Release designation** | Fraser | +| | | ++--------------------------------------+--------------------------------------+ +| **Release date** | 2018-04-27 +| | | ++--------------------------------------+--------------------------------------+ +| **Purpose of the delivery** | OPNFV Fraser release | +| | | ++--------------------------------------+--------------------------------------+ + +Version change +^^^^^^^^^^^^^^^^ + +Module version changes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +OPNFV Fraser marks the first release for Clover + +Document version changes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +OPNFV Fraser marks the first release for Clover + +Reason for version +^^^^^^^^^^^^^^^^^^^^ + +Feature additions +~~~~~~~~~~~~~~~~~~~~~~~ +<None> (no backlog) + +Bug corrections +~~~~~~~~~~~~~~~~~~~~~ +<None> + +Known Limitations, Issues and Workarounds +========================================= + +System Limitations +^^^^^^^^^^^^^^^^^^^^ +TBD + +Known issues +^^^^^^^^^^^^^^^ +TBD + +Workarounds +^^^^^^^^^^^^^^^^^ + +Test Result +=========== + + +References +========== diff --git a/docs/release/userguide/Fraser-userguide.rst b/docs/release/userguide/Fraser-userguide.rst deleted file mode 100644 index 243c4e1..0000000 --- a/docs/release/userguide/Fraser-userguide.rst +++ /dev/null @@ -1,81 +0,0 @@ -.. This work is licensed under a Creative Commons Attribution 4.0 International License. -.. http://creativecommons.org/licenses/by/4.0 -.. SPDX-License-Identifier CC-BY-4.0 -.. (c) optionally add copywriters name - - -================================================================ -Clover User Guide (Fraser Release) -================================================================ - -This document provides the user guide for Fraser release of Clover. - -.. contents:: - :depth: 3 - :local: - - -Description -=========== - -Project Clover was established to investigate best practice to implement, -build, deploy, and operate virtual network functions as cloud native -applications. "Cloud native" has a ever evolving and expanding definition, -and in Clover, the focus is effectively running and operating VNFs built -in a micro-service design pattern running on Docker containers and -orchestrated by Kubernetes. - -The strength of cloud native applications is their operablity and -scalability. Essential to achieve these qualities is the use of service -mesh. As such, in Fraser release, Clover's emphasis is on demonstrating -running a sample micro-service composed VNF on Istio, the service mesh -platform of Clover's choice in Fraser, and how to maximize visibility -of this sample running in a service mesh. - -What is in Fraser? -================== - - * a sample micro-service composed VNF - - * logging module: fluentd and elasticsearch Kubernetes manifests, - installation validation, log data correlation in datastore - - * tracing module: jaeger Kubernetes manifest, installation validation, - jaegar tracing query tools, trace data correlation in datastore - - * monitoring module: prometheus Kubernetes manifest, installation - validation, prometheous query tools for Istio related metrics, - metrics correlation in datastore - - * Istio route-rules and circuit breaking sample yaml and validation - tools - - * Test scripts - - * Reference for a demo shown during ONS - -Usage -===== - - * each modules (service mesh, logging, tracing, monitoring) are Python - modules with their own set of library calls / API exposed. The descriptions - of these library calls are under doc/developer (TBD) - - * tools directory contains Python tools for generic use - python clover_validate_route_rules.py -s <service name> -n <number of tests> - [more TBD] - - * an example scenario: - - version 2 (v2) of a micro-service component is deployed - - Istio route rule is applied to send 50% traffic to v2 - - Clover tool validates traffic conformance with route rules - - user specify via yaml the "success" expectation of v2 (latency, - performance, session loss...etc) - - Clover tool validates sessions conformance with user defined expectations - - The "commit" action is invoked to move 100% traffic to v2 - - Clover tool validates traffic conformance with route rules - - A fault is injected for the path to the extra service of v2 which adds - a one second delay onto the path - - The same A-B testing script is invoked, this time, performance - test now fails - - The "rollback" action is invoked to move 100% traffic back to v1 diff --git a/docs/release/userguide/index.rst b/docs/release/userguide/index.rst index 41fcb1f..672c62c 100644 --- a/docs/release/userguide/index.rst +++ b/docs/release/userguide/index.rst @@ -10,4 +10,4 @@ OPNFV Clover Design Specification .. toctree:: :maxdepth: 1 - Fraser-userguide + userguide diff --git a/docs/release/userguide/userguide.rst b/docs/release/userguide/userguide.rst new file mode 100644 index 0000000..c01886e --- /dev/null +++ b/docs/release/userguide/userguide.rst @@ -0,0 +1,64 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. SPDX-License-Identifier CC-BY-4.0 +.. (c) Authors of Clover + + +================================================================ +Clover User Guide (Fraser Release) +================================================================ + +This document provides the Clover user guide for OPNFV Fraser release. + +.. contents:: + :depth: 3 + :local: + + +Description +=========== + +As project Clover's first release, Fraser release includes installation +and simple validation of foundational upstream projects including Istio, +fluentd, Jaeger, and Prometheus. Clover Fraser release also provides a +sample VNF which follows micro-service design pattern, its Kubernetes +manifest, and an automatic scipt to demonstrate a sample A-B testing use +case using the sample VNF running on Istio with trace data exposed to +Jaeger running in istio-system namespace. + +What is in Fraser? +================== + + * a sample micro-service composed VNF + + * logging module: fluentd and elasticsearch Kubernetes manifests, + and fluentd installation validation + + * tracing module: jaeger Kubernetes manifest, installation validation, + jaegar tracing query tools, module for trace data output to datastore + + * monitoring module: prometheus Kubernetes manifest, installation + validation, sample Prometheous query of Istio related metrics + + * Istio route-rules sample yaml and validation tools + + * Test scripts + + * Sample code for an A-B testing demo shown during ONS + +Usage +===== + + * Python modules to validate installation of fluentd, Jaeger, and + Prometheus + + * Installation and deployment of a sample VNF + - VNF designed and implemented with micro-service design pattern + - tested and validated via Istio service mesh tools + + * sample tool to validate Istio route rules: + tools/python clover_validate_route_rules.py -s <service name> -t <test id> + + * an example use case: A-B testing: + test/fraser_a_b_test.py -t yaml/fraser_a_b_test.yaml -p <tracing port num> + *** detail procedure to run sample A-B testing at docs/configguide/... diff --git a/samples/services/snort_ids/docker/grpc/snort.proto b/samples/services/snort_ids/docker/grpc/snort.proto index 8d69baa..f524bb4 100644 --- a/samples/services/snort_ids/docker/grpc/snort.proto +++ b/samples/services/snort_ids/docker/grpc/snort.proto @@ -27,8 +27,9 @@ message AddRule { string src_port = 4; string src_ip = 5; string msg = 6; - string sid = 7; - string rev = 8; + string content = 7; + string sid = 8; + string rev = 9; } message SnortReply { diff --git a/samples/services/snort_ids/docker/grpc/snort_alerts.py b/samples/services/snort_ids/docker/grpc/snort_alerts.py index 4cb87e2..25d1738 100644 --- a/samples/services/snort_ids/docker/grpc/snort_alerts.py +++ b/samples/services/snort_ids/docker/grpc/snort_alerts.py @@ -14,7 +14,7 @@ from idstools import unified2 HOST_IP = 'redis' -PROXY_GRPC = 'proxy-access-control:50054' +# PROXY_GRPC = 'proxy-access-control:50054' logging.basicConfig(filename='alert.log', level=logging.DEBUG) @@ -34,7 +34,7 @@ reader = unified2.SpoolRecordReader("/var/log/snort", def sendGrpcAlert(event_id, redis_key): try: - channel = grpc.insecure_channel(PROXY_GRPC) + channel = grpc.insecure_channel('proxy-access-control:50054') stub = nginx_pb2_grpc.ControllerStub(channel) stub.ProcessAlerts(nginx_pb2.AlertMessage( event_id=event_id, redis_key=redis_key)) @@ -45,13 +45,15 @@ def sendGrpcAlert(event_id, redis_key): for record in reader: try: if isinstance(record, unified2.Event): - snort_event = "snort_event:" + str(record['event-id']) - r.sadd('snort_events', str(record['event-id'])) - r.hmset(snort_event, record) - sendGrpcAlert(str(record['event-id']), 'snort_events') - # elif isinstance(record, unified2.Packet): - # print("Packet:") + event = record + elif isinstance(record, unified2.Packet): + packet = record # elif isinstance(record, unified2.ExtraData): # print("Extra-Data:") + snort_event = "snort_event:" + str(record['event-id']) + r.sadd('snort_events', str(record['event-id'])) + event.update(packet) + r.hmset(snort_event, event) + sendGrpcAlert(str(record['event-id']), 'snort_events') except Exception as e: logging.debug(e) diff --git a/samples/services/snort_ids/docker/grpc/snort_client.py b/samples/services/snort_ids/docker/grpc/snort_client.py index d59b4ee..ca71af8 100644 --- a/samples/services/snort_ids/docker/grpc/snort_client.py +++ b/samples/services/snort_ids/docker/grpc/snort_client.py @@ -30,6 +30,8 @@ def run(args, grpc_port='50052'): return add_tcprule(stub) elif args['cmd'] == 'addicmp': return add_icmprule(stub) + elif args['cmd'] == 'addscan': + return add_scanrule(stub) elif args['cmd'] == 'start': return start_snort(stub) elif args['cmd'] == 'stop': @@ -78,6 +80,20 @@ def add_icmprule(stub): return response.message +def add_scanrule(stub): + try: + response = stub.AddRules(snort_pb2.AddRule( + protocol='tcp', dest_port='any', dest_ip='$HOME_NET', + src_port='any', src_ip='any', + msg='MALWARE-CNC User-Agent ASafaWeb Scan', sid='10000003', + rev='001', content='"asafaweb.com"')) + print(stop_snort(stub)) + print(start_snort(stub)) + except Exception as e: + return e + return response.message + + def start_snort(stub): try: response = stub.StartSnort(snort_pb2.ControlSnort(pid='0')) diff --git a/samples/services/snort_ids/docker/grpc/snort_pb2.py b/samples/services/snort_ids/docker/grpc/snort_pb2.py index 93641ef..8828b78 100644 --- a/samples/services/snort_ids/docker/grpc/snort_pb2.py +++ b/samples/services/snort_ids/docker/grpc/snort_pb2.py @@ -19,7 +19,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( name='snort.proto', package='snort', syntax='proto3', - serialized_pb=_b('\n\x0bsnort.proto\x12\x05snort\"\x1b\n\x0c\x43ontrolSnort\x12\x0b\n\x03pid\x18\x01 \x01(\t\"\x88\x01\n\x07\x41\x64\x64Rule\x12\x10\n\x08protocol\x18\x01 \x01(\t\x12\x11\n\tdest_port\x18\x02 \x01(\t\x12\x0f\n\x07\x64\x65st_ip\x18\x03 \x01(\t\x12\x10\n\x08src_port\x18\x04 \x01(\t\x12\x0e\n\x06src_ip\x18\x05 \x01(\t\x12\x0b\n\x03msg\x18\x06 \x01(\t\x12\x0b\n\x03sid\x18\x07 \x01(\t\x12\x0b\n\x03rev\x18\x08 \x01(\t\"\x1d\n\nSnortReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\xac\x01\n\nController\x12/\n\x08\x41\x64\x64Rules\x12\x0e.snort.AddRule\x1a\x11.snort.SnortReply\"\x00\x12\x36\n\nStartSnort\x12\x13.snort.ControlSnort\x1a\x11.snort.SnortReply\"\x00\x12\x35\n\tStopSnort\x12\x13.snort.ControlSnort\x1a\x11.snort.SnortReply\"\x00\x62\x06proto3') + serialized_pb=_b('\n\x0bsnort.proto\x12\x05snort\"\x1b\n\x0c\x43ontrolSnort\x12\x0b\n\x03pid\x18\x01 \x01(\t\"\x99\x01\n\x07\x41\x64\x64Rule\x12\x10\n\x08protocol\x18\x01 \x01(\t\x12\x11\n\tdest_port\x18\x02 \x01(\t\x12\x0f\n\x07\x64\x65st_ip\x18\x03 \x01(\t\x12\x10\n\x08src_port\x18\x04 \x01(\t\x12\x0e\n\x06src_ip\x18\x05 \x01(\t\x12\x0b\n\x03msg\x18\x06 \x01(\t\x12\x0f\n\x07\x63ontent\x18\x07 \x01(\t\x12\x0b\n\x03sid\x18\x08 \x01(\t\x12\x0b\n\x03rev\x18\t \x01(\t\"\x1d\n\nSnortReply\x12\x0f\n\x07message\x18\x01 \x01(\t2\xac\x01\n\nController\x12/\n\x08\x41\x64\x64Rules\x12\x0e.snort.AddRule\x1a\x11.snort.SnortReply\"\x00\x12\x36\n\nStartSnort\x12\x13.snort.ControlSnort\x1a\x11.snort.SnortReply\"\x00\x12\x35\n\tStopSnort\x12\x13.snort.ControlSnort\x1a\x11.snort.SnortReply\"\x00\x62\x06proto3') ) @@ -106,19 +106,26 @@ _ADDRULE = _descriptor.Descriptor( is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='sid', full_name='snort.AddRule.sid', index=6, + name='content', full_name='snort.AddRule.content', index=6, number=7, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), _descriptor.FieldDescriptor( - name='rev', full_name='snort.AddRule.rev', index=7, + name='sid', full_name='snort.AddRule.sid', index=7, number=8, type=9, cpp_type=9, label=1, has_default_value=False, default_value=_b("").decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='rev', full_name='snort.AddRule.rev', index=8, + number=9, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=_b("").decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None, file=DESCRIPTOR), ], extensions=[ ], @@ -132,7 +139,7 @@ _ADDRULE = _descriptor.Descriptor( oneofs=[ ], serialized_start=52, - serialized_end=188, + serialized_end=205, ) @@ -162,8 +169,8 @@ _SNORTREPLY = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=190, - serialized_end=219, + serialized_start=207, + serialized_end=236, ) DESCRIPTOR.message_types_by_name['ControlSnort'] = _CONTROLSNORT @@ -200,8 +207,8 @@ _CONTROLLER = _descriptor.ServiceDescriptor( file=DESCRIPTOR, index=0, options=None, - serialized_start=222, - serialized_end=394, + serialized_start=239, + serialized_end=411, methods=[ _descriptor.MethodDescriptor( name='AddRules', diff --git a/samples/services/snort_ids/docker/grpc/snort_server.py b/samples/services/snort_ids/docker/grpc/snort_server.py index 3c2fdb1..223461a 100644 --- a/samples/services/snort_ids/docker/grpc/snort_server.py +++ b/samples/services/snort_ids/docker/grpc/snort_server.py @@ -33,9 +33,16 @@ class Controller(snort_pb2_grpc.ControllerServicer): # file_local = 'testfile' file_local = '/etc/snort/rules/local.rules' f = open(file_local, 'a') - rule = 'alert {} {} {} -> {} {} '.format( - r.protocol, r.src_ip, r.src_port, r.dest_ip, r.dest_port) \ - + '(msg:"{}"; sid:{}; rev:{};)\n'.format(r.msg, r.sid, r.rev) + if r.content: + rule = 'alert {} {} {} -> {} {} '.format( + r.protocol, r.src_ip, r.src_port, r.dest_ip, r.dest_port) \ + + '(msg:"{}"; content:{}; sid:{}; rev:{};)\n'.format( + r.msg, r.content, r.sid, r.rev) + else: + rule = 'alert {} {} {} -> {} {} '.format( + r.protocol, r.src_ip, r.src_port, r.dest_ip, r.dest_port) \ + + '(msg:"{}"; sid:{}; rev:{};)\n'.format( + r.msg, r.sid, r.rev) f.write(rule) f.close msg = "Added to local rules" |