<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andrei Fer</title>
    <description>The latest articles on DEV Community by Andrei Fer (@raklev20).</description>
    <link>https://dev.to/raklev20</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F873602%2F786f9c16-6929-4498-b44f-e96cffefbb86.jpeg</url>
      <title>DEV Community: Andrei Fer</title>
      <link>https://dev.to/raklev20</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raklev20"/>
    <language>en</language>
    <item>
      <title>Virus scan MinIO buckets using ClamAV, Fission and Kafka</title>
      <dc:creator>Andrei Fer</dc:creator>
      <pubDate>Tue, 07 Jun 2022 08:35:58 +0000</pubDate>
      <link>https://dev.to/raklev20/virus-scan-minio-buckets-using-clamav-fission-and-kafka-5hn7</link>
      <guid>https://dev.to/raklev20/virus-scan-minio-buckets-using-clamav-fission-and-kafka-5hn7</guid>
      <description>&lt;p&gt;All organizations want to protect their systems and have a good strategy in order to stay away from malware or other potential threats. Before introducing files and binaries into your system organization is very important to scan them  and respond immediately based on a predefined strategy.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Short introduction of Fission&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Fission is an open-source and Kubernetes-native serverless framework that lets developers to run code functions easily. Kubernetes has  powerful orchestration capabilities to manage and schedule containers while Fission takes advantage of them, being flexible. In other words, Fission can focus on developing the function-as-a-service (FaaS) features. Fission supports many programming languages such as Pyhton, NodeJs, PHP, Go and C#. Also, this tool allows you to create a message queue trigger like Apache Kafka, AWS SQS, AWS Kinesis, GCP Pub Sub, Nats Streaming. In this way, the product becomes an open-source version of AWS Lambda.&lt;/p&gt;

&lt;p&gt;Fission has three core concepts: Function, Environment , and Trigger. Their relationships are presented in the following figure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69izxtaf7fe1p74cfg6a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F69izxtaf7fe1p74cfg6a.png" alt="Trigger, Function, Environment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Function&lt;/strong&gt;: the code that is written by using a specific language for execution. In our case
we have Python code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment&lt;/strong&gt;: the special language environment that is used to run user function&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trigger&lt;/strong&gt;: used to associate functions and event sources&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Implementation in Action&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This walkthrough will show you how to build a pipeline in order to scan your MiniIO files using asynchronous triggers. When a new file will be pushed in our MinIO buckets &lt;strong&gt;(1)&lt;/strong&gt;a new notification will be send to the Kafka &lt;strong&gt;(2)&lt;/strong&gt; and the trigger will start the function &lt;strong&gt;(3)&lt;/strong&gt;, scanning the file for viruses &lt;strong&gt;(4)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmd7rto7mlt7oa0di0mz4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmd7rto7mlt7oa0di0mz4.png" alt="Process of scanning files"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this walkthrough, you should have the following prerequisites:&lt;/p&gt;

&lt;p&gt;• MinIO Server and 2 buckets: &lt;strong&gt;test-bucket&lt;/strong&gt;, &lt;strong&gt;infected-objects&lt;/strong&gt;&lt;br&gt;
• Apache Kafka and 3 topics: &lt;strong&gt;bucketevents&lt;/strong&gt;, &lt;strong&gt;bucketevents-response&lt;/strong&gt;, &lt;strong&gt;bucketeventserror&lt;/strong&gt;&lt;br&gt;
• Fission in Kubernetes environment, install Fission client CLI.(please use this link: &lt;a href="https://fission.io/docs/installation/" rel="noopener noreferrer"&gt;https://fission.io/docs/installation/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to implement what was described you have to follow the steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1- Enable MinIO to send notification using Kafka when we put new objects in the bucket&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MinIO supports updating Kafka endpoints on a running MiniIO server process using the MinIO client (mc) and &lt;code&gt;mc admin config set&lt;/code&gt; command and the &lt;code&gt;notify_kafka&lt;/code&gt; configuration key.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mc admin config set ALIAS/ notify_kafka:IDENTIFIER brokers="&amp;lt;ENDPOINT&amp;gt;"
topic=”&amp;lt;string&amp;gt;”


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Replace &lt;code&gt;IDENTIFIER&lt;/code&gt; with a unique descriptive string for the Kafka service endpoint. Replace &lt;code&gt;ENDPOINT&lt;/code&gt; with a comma separated list of Kafka brokers (e.g: 192.168.10.10:9092,192.168.10.11:9092,192.168.10.12:9092). The topic name in our case is &lt;strong&gt;bucketevents&lt;/strong&gt;. You must restart the MinIO server process to apply any new or updated configuration settings.&lt;/p&gt;

&lt;p&gt;Use the &lt;code&gt;mc event add&lt;/code&gt; command to add a new bucket notification (when you put new objects) with the configured Kafka service as a target:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mc event add ALIAS/BUCKET arn:minio:sqs::IDENTIFIER:kafka --event put


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 2 - Create Python code which uses ClamAV&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here I’ve created a Python code which is available in &lt;a href="https://github.com/raklev20/fission-clamav-scan-objects/blob/main/minio-scan.py" rel="noopener noreferrer"&gt;Github&lt;/a&gt;.You have to change MinIO credentials in order to connect to it. Your objects will be copied inside the container and scanned using clamdscan from ClamAV. If the file is infected will be moved to “/tmp/infected-files/” and placed in a special bucket (infected-objects) for deep investigations.&lt;/p&gt;

&lt;p&gt;In a default scenario Fission use image based on language environments (in our case Python), but you can create your own image using Dockerfile. After that, you can upload new image in your Docker registry and when you create a new environment you will mention your custom image and secret if it’s necessary. Our custom image install ClamAV and what is necessary for scanning files.&lt;/p&gt;

&lt;p&gt;Now, let’s create a function with Python as environment:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

fission environment create --name python --image --image=YOUR_DOCKER_IMAGE
--imagepullsecret="regcred"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let’s assumed that Python code is saved in minio-scan.py file. Using this file you have to create your Fission function like so:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

fission function create --name=minio-scan --env python --code minio-scan.py


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can use the following command to create a Kafka-based message queue trigger mqttest.This trigger subscribes to messages of the input topic &lt;strong&gt;(bucketevents)&lt;/strong&gt;, and it immediately triggers function execution when it receives any message.The function execution result is written to the output topic &lt;strong&gt;(bucketevents-response)&lt;/strong&gt; if a function execution succeeds, or to the error topic &lt;strong&gt;(bucketevents-error)&lt;/strong&gt; if it fails.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

fission mqt create --name mqt-test --function minio-scan --mqtype kafka --
mqtkind keda --topic bucketevents --resptopic bucketevents-response --
errortopic bucketevents-error --metadata bootstrapServers=ENDPOINT:PORT --
metadata consumerGroup=fission-test --metadata topic=bucketevents


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Replace &lt;code&gt;ENDPOINT:PORT&lt;/code&gt; with a comma separated list of Kafka brokers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4 - Check the logs and Fission behaviour&lt;/strong&gt;&lt;br&gt;
Your function will be deployed as a pod in fission-function namespace into Kuberentes cluster. Using &lt;code&gt;kubectl logs -f -c python $POD_NAME&lt;/code&gt; you can check the logs in real time to see what happens there. Also you have to take a look at Kafka topics (response or error) in order to know the output of your function.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Fission is a versatile framework that can be used with many different programming languages and help us to build FaaS in Kubernetes. In this scenario, I used some basic feature of Fission for scanning new S3 object but I totally recommend you to read more regarding Fission technologies on &lt;a href="https://fission.io/blog/" rel="noopener noreferrer"&gt;Fission&lt;/a&gt; blog which are very interesting.&lt;/p&gt;

</description>
      <category>minio</category>
      <category>fissio</category>
      <category>clamav</category>
      <category>virus</category>
    </item>
  </channel>
</rss>
