<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marcelo Almeida on Medium]]></title>
        <description><![CDATA[Stories by Marcelo Almeida on Medium]]></description>
        <link>https://medium.com/@marcelo.almeida?source=rss-9ce3a22780aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xYy1E8MdjqJkfQWt.</url>
            <title>Stories by Marcelo Almeida on Medium</title>
            <link>https://medium.com/@marcelo.almeida?source=rss-9ce3a22780aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 10:46:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marcelo.almeida/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Simplifying DNS Management with Terraform DNS Helper]]></title>
            <link>https://medium.com/@marcelo.almeida/simplifying-dns-management-with-terraform-dns-helper-01bec91b3698?source=rss-9ce3a22780aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/01bec91b3698</guid>
            <category><![CDATA[spf]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[dmarc]]></category>
            <category><![CDATA[terraform-provider]]></category>
            <category><![CDATA[dns]]></category>
            <dc:creator><![CDATA[Marcelo Almeida]]></dc:creator>
            <pubDate>Sun, 06 Apr 2025 18:50:01 GMT</pubDate>
            <atom:updated>2025-04-06T18:50:01.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wZFLc1aymwshNxtF-dH_zA.png" /></figure><p>DNS is critical to modern infrastructure, yet managing records like <strong>SPF, DMARC, and CAA</strong> remains frustrating. These records are essential for security and email authentication, but they come with <strong>strict constraints, tricky syntax, and room for errors.</strong></p><p>Inspired by <a href="https://dnscontrol.org/"><strong>DNSControl</strong></a>, I built <strong>Terraform DNS Helper</strong> — a Terraform provider that <strong>enhances existing DNS providers (AWS Route 53, Cloudflare, etc.) by providing functions to generate complex DNS records automatically.</strong></p><p>🚀 <strong>DNS Helper does NOT replace your existing Terraform DNS provider.</strong> Instead, it works alongside it, simplifying record generation so you can manage DNS infrastructure <strong>with less manual effort and fewer mistakes.</strong></p><h3><strong>What Does Terraform DNS Helper Do?</strong></h3><p>Terraform DNS Helper introduces extra <strong>functions</strong> that help you generate complex DNS records dynamically. It works <strong>alongside</strong> existing DNS management providers (e.g., AWS Route 53, Cloudflare, Google Cloud DNS).</p><p>With <strong>DNS Helper</strong>, you can:</p><p>✅ <strong>Build SPF records dynamically</strong>, flattening includes to stay within <a href="https://datatracker.ietf.org/doc/html/rfc7208">RFC 7208</a>’s 10-lookup limit.</p><p>✅ <strong>Split oversized TXT records automatically</strong>, ensuring compliance with DNS size restrictions.</p><p>✅ <strong>Generate DMARC records from human-readable inputs</strong>, reducing syntax errors.</p><p>✅ <strong>Create CAA records effortlessly</strong>, controlling certificate issuance with a simple structure.</p><p>Rather than hardcoding long, error-prone DNS strings, <strong>DNS Helper generates them for you</strong>, making Terraform configurations <strong>cleaner, more maintainable, and scalable.</strong></p><h3><strong>SPF: Smarter Record Flattening</strong></h3><p>SPF (Sender Policy Framework) defines which mail servers can send email on behalf of a domain. <strong>But SPF records can’t exceed 10 DNS lookups</strong> — otherwise, email delivery fails with a permerror.</p><p><strong>Terraform DNS Helper helps by flattening SPF records</strong>, replacing includes with direct IPs to stay under the limit.</p><p>💡 <strong>Before (hardcoded SPF record):</strong></p><pre>v=spf1 include:_spf.google.com include:spf.protection.outlook.com include:sendgrid.net include:amazonses.com include:mailgun.com ~all</pre><p>In the following examples where used the records dnshelper-exceeded-lookups-example.malmeida.dev and dnshelper-flatten-example.malmeida.dev for demonstration purposes, these domains aren&#39;t used to send emails.</p><p>💥 <strong>Too many lookups! SPF will fail.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BROJIUv2DwQulD9Ede-kYw.png" /></figure><p>✅ <strong>Using Terraform DNS Helper</strong></p><pre>locals {<br>  domain               = &quot;dnshelper-flatten-example.malmeida.dev&quot;<br>  overflow             = &quot;_spf%d&quot;<br>  txt_max_size         = 512<br>  domain_on_record_key = false<br>  parts = [<br>    &quot;v=spf1&quot;,<br>    &quot;include:_spf.google.com&quot;,<br>    &quot;include:spf.protection.outlook.com&quot;,<br>    &quot;include:sendgrid.net&quot;,<br>    &quot;include:amazonses.com&quot;,<br>    &quot;include:mailgun.com&quot;,<br>    &quot;~all&quot;,<br>  ]<br>  flatten = [<br>    &quot;_spf.google.com&quot;,<br>    &quot;spf.protection.outlook.com&quot;,<br>    &quot;sendgrid.net&quot;,<br>    &quot;spf.mandrillapp.com&quot;,<br>    &quot;amazonses.com&quot;,<br>    &quot;mail.zendesk.com&quot;,<br>    &quot;mailgun.com&quot;,<br>    &quot;_netblocks.google.com&quot;,<br>    &quot;_netblocks2.google.com&quot;,<br>    &quot;_netblocks3.google.com&quot;,<br>    &quot;_spf.mailgun.org&quot;,<br>    &quot;_spf.eu.mailgun.org&quot;,<br>    &quot;spf.protection.outlook.com&quot;,<br>    &quot;aspmx.pardot.com&quot;,<br>    &quot;mail.zendesk.com&quot;,<br>    &quot;_spf1.mailgun.org&quot;,<br>    &quot;_spf2.mailgun.org&quot;,<br>    &quot;ab.sendgrid.net&quot;,<br>    &quot;et._spf.pardot.com&quot;<br>  ]<br><br>  flatten_example = provider::dnshelper::spf_builder(<br>    local.domain,<br>    local.overflow,<br>    local.txt_max_size,<br>    local.domain_on_record_key,<br>    local.parts,<br>    local.flatten,<br>  )<br>}<br><br>resource &quot;cloudflare_dns_record&quot; &quot;txt&quot; {<br>  for_each = {<br>    for k, v in local.flatten_example :<br>    replace(format(&quot;%s.%s&quot;, k, &quot;dnshelper-flatten-example&quot;), &quot;@.&quot;, &quot;&quot;) =&gt; {<br>      value : join(&quot; &quot;, formatlist(&quot;\&quot;%s\&quot;&quot;, v))<br>    }<br>  }<br><br>  zone_id = var.cloudflare_zone_id<br><br>  name      = each.key<br>  content   = each.value.value<br>  type      = &quot;TXT&quot;<br>  ttl       = lookup(each.value, &quot;ttl&quot;, &quot;1&quot;)<br>  proxied   = lookup(each.value, &quot;proxied&quot;, false)<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dBNhJbL_7ixSfLhtw86YmQ.png" /></figure><h4><strong>Choosing the 512-Byte Limit for TXT Records in DNS</strong></h4><p>When dealing with DNS TXT records, especially for SPF (Sender Policy Framework) configurations, size constraints play a crucial role in ensuring compatibility and performance. In this example, I’ve chosen a <strong>512-byte maximum size</strong> for each TXT record. Here’s why.</p><p><strong>Understanding TXT Record Size Limits</strong></p><p>DNS imposes certain restrictions on TXT record sizes:</p><ul><li>Each individual <strong>TXT string is limited to 255 bytes</strong>.</li><li>The total DNS response size was historically limited to <strong>512 bytes</strong> (without EDNS0).</li><li>With <strong>EDNS0</strong>, responses can go up to <strong>4096 bytes</strong>, but not all resolvers fully support it.</li></ul><p><strong>Why 512 Bytes?</strong></p><p>Even though EDNS0 allows for larger responses, many legacy systems, firewalls, and DNS resolvers still expect DNS responses to fit within <strong>512 bytes</strong>. Keeping TXT record sizes within this limit ensures:</p><ul><li><strong>Better compatibility</strong> across different DNS servers and clients.</li><li><strong>Lower risk of truncation</strong>, which can break SPF lookups.</li><li><strong>Avoiding fragmentation</strong>, which can lead to failures in environments that block large UDP packets.</li></ul><h3><strong>DMARC: No More Messy Syntax</strong></h3><p>DMARC (Domain-based Message Authentication, Reporting, and Conformance) records help prevent phishing and spoofing. But writing them manually is <strong>error-prone</strong>.</p><p>With Terraform DNS Helper, you can define a <strong>DMARC policy in simple terms</strong>:</p><p>💡 <strong>Using Terraform DNS Helper:</strong></p><pre>locals {<br>  version          = &quot;DMARC1&quot;<br>  policy           = &quot;reject&quot;<br>  subdomain_policy = &quot;quarantine&quot;<br>  alignment_spf    = &quot;relaxed&quot;<br>  alignment_dkim   = &quot;strict&quot;<br>  percent          = 100<br>  rua              = [&quot;mailto:ruf@example.com&quot;]<br>  ruf              = [&quot;mailto:rua@example.com&quot;]<br>  failure_options  = 0<br>  failure_format   = &quot;afrf&quot;<br>  report_interval  = 86400<br><br>  dmarc_record = provider::dnshelper::dmarc_builder(<br>    local.version,<br>    local.policy,<br>    local.subdomain_policy,<br>    local.alignment_spf,<br>    local.alignment_dkim,<br>    local.percent,<br>    local.rua,<br>    local.ruf,<br>    local.failure_options,<br>    local.failure_format,<br>    local.report_interval<br>  )<br>}<br><br>resource &quot;aws_route53_record&quot; &quot;dmarc&quot; {  <br>  zone_id = &quot;Z12345678&quot;  <br>  name    = &quot;example.com&quot;  <br>  type    = &quot;TXT&quot;  <br>  ttl     = 300  <br>  records = [local.dmarc_record]<br>}</pre><h3><strong>CAA: Simplified Certificate Authority Rules</strong></h3><p>CAA records specify <strong>which certificate authorities</strong> can issue SSL/TLS certificates for a domain.</p><p>Rather than manually writing CAA records, <strong>DNS Helper makes them declarative</strong>:</p><p>💡 <strong>Using Terraform DNS Helper:</strong></p><pre>locals {<br>  iodef          = &quot;mailto:domain-names@malmeida.dev&quot;<br>  iodef_critical = true<br>  issue = [<br>    &quot;amazon.com&quot;,<br>    &quot;comodoca.com&quot;,<br>    &quot;digicert.com; cansignhttpexchanges=yes&quot;,<br>    &quot;letsencrypt.org&quot;,<br>    &quot;pki.goog; cansignhttpexchanges=yes&quot;,<br>    &quot;sectigo.com&quot;,<br>    &quot;ssl.com&quot;,<br>  ]<br>  issue_critical = false<br>  issuewild = [<br>    &quot;amazon.com&quot;,<br>    &quot;comodoca.com&quot;,<br>    &quot;digicert.com; cansignhttpexchanges=yes&quot;,<br>    &quot;letsencrypt.org&quot;,<br>    &quot;pki.goog; cansignhttpexchanges=yes&quot;,<br>    &quot;sectigo.com&quot;,<br>    &quot;ssl.com&quot;,<br>  ]<br>  issuewild_critical = false<br><br>  caa_records = provider::dnshelper::caa_builder(<br>    local.iodef,<br>    local.iodef_critical,<br>    local.issue,<br>    local.issue_critical,<br>    local.issuewild,<br>    local.issuewild_critical,<br>  )<br>}<br><br>resource &quot;google_dns_record_set&quot; &quot;caa&quot; {  <br>  name = &quot;example.com.&quot;  <br>  type = &quot;CAA&quot;  <br>  ttl  = 3600  <br>  managed_zone = google_dns_managed_zone.example.name  <br>  rrdatas      = local.caa_records<br>}  </pre><h3><strong>How DNS Helper Works with Terraform Providers</strong></h3><p>DNS Helper <strong>does not manage DNS zones directly</strong> — that’s the job of Terraform providers like:</p><ul><li><strong>AWS Route 53</strong> (<a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record">aws_route53_record</a>)</li><li><strong>Cloudflare</strong> (<a href="https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/dns_record">cloudflare_dns_record</a>)</li><li><strong>Google Cloud DNS</strong> (<a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/dns_record_set">google_dns_record_set</a>)</li></ul><p>Instead, <strong>DNS Helper generates the correct record values dynamically</strong>, so your DNS provider can apply them.</p><h3><strong>Final Thoughts</strong></h3><p>Terraform DNS Helper is <strong>not a replacement for your existing DNS provider</strong> — instead, it <strong>supercharges Terraform with extra DNS-related functions.</strong></p><p>By using DNS Helper <strong>alongside</strong> providers like AWS Route 53, Cloudflare, or Google Cloud DNS, you can:</p><p>✅ <strong>Reduce complexity</strong> — No more manually writing SPF, DMARC, or CAA records.</p><p>✅ <strong>Prevent email failures</strong> — SPF flattening ensures compliance with lookup limits.</p><p>✅ <strong>Improve security</strong> — CAA enforcement is easier and error-free.</p><p>✅ <strong>Automate everything</strong> — Keep DNS configurations version-controlled and dynamic.</p><p>🚀 <strong>Try it today:</strong> <a href="https://github.com/marceloalmeida/terraform-provider-dnshelper">GitHub Repo</a></p><h3>References</h3><ul><li><a href="https://easydmarc.com/blog/spf-too-many-dns-lookups-error/">https://easydmarc.com/blog/spf-too-many-dns-lookups-error/</a></li><li><a href="https://dmarcly.com/blog/spf-permerror-too-many-dns-lookups-when-spf-record-exceeds-10-dns-lookup-limit">https://dmarcly.com/blog/spf-permerror-too-many-dns-lookups-when-spf-record-exceeds-10-dns-lookup-limit</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01bec91b3698" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Orchestrating Cyber Defense: Crafting a Simple SSH Server Honeypot in Golang]]></title>
            <link>https://medium.com/@marcelo.almeida/orchestrating-cyber-defense-crafting-an-advanced-ssh-server-honeypot-in-golang-701a261788a2?source=rss-9ce3a22780aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/701a261788a2</guid>
            <category><![CDATA[honeypot]]></category>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[influxdb]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[opentelemetry]]></category>
            <dc:creator><![CDATA[Marcelo Almeida]]></dc:creator>
            <pubDate>Fri, 26 Jan 2024 00:54:44 GMT</pubDate>
            <atom:updated>2024-01-26T01:01:17.782Z</atom:updated>
            <content:encoded><![CDATA[<p>Orchestrating Cyber Defense: Crafting a Simple SSH Server Honeypot in Golang</p><p>In the dynamic world of cybersecurity, proactively defending against potential threats requires a combination of innovative techniques and intelligent design. In this post, we’ll explore the creation of an SSH server honeypot in Golang, leveraging <a href="https://go.dev/tour/concurrency/1">goroutines</a> for non-blocking processing, implementing a global cache to manage rate limits from ip-api.com, and incorporating exponential backoff for graceful error handling. The goal is to build a responsive and resilient defense system capable of efficiently handling multiple attack attempts while gathering valuable insights into potential threats.</p><h3>Setting Up the SSH Honeypot with Goroutines</h3><p>To create a highly responsive SSH server honeypot, we’ve embraced the power of goroutines in Golang. By employing concurrent programming, our honeypot can handle multiple attack attempts simultaneously without blocking the processing of subsequent requests. This optimisation not only enhances the honeypot’s scalability but also ensures that potential attackers are not deterred by slow response times. Performing all the heavy processing (e.g. fetching more information about the attacker and writing the information to the database) allows us to gather more data and insights.</p><pre>func main() {<br><br>// ...<br><br> ssh.Handle(func(s ssh.Session) {<br><br>  go processRequestExponentialBackoff(writeAPI, s.Context(), ctx, tracer)<br><br>  i := 0<br>  for {<br>   i += 1<br>   log.Printf(&quot;Session active seconds: %d&quot;, i)<br>   select {<br>   case &lt;-time.After(time.Second):<br>    continue<br>   case &lt;-s.Context().Done():<br>    log.Printf(&quot;Closed connection from &#39;%s&#39; to &#39;%s@%s&#39;&quot;, s.RemoteAddr().String(), s.User(), s.LocalAddr().String())<br>    return<br>   }<br>  }<br> })<br><br>// ...<br><br> log.Printf(&quot;Starting ssh server on port &#39;%s&#39;...&quot;, sshPort)<br> server := &amp;ssh.Server{<br>  Addr:        &quot;:&quot; + sshPort,<br>  MaxTimeout:  DeadlineTimeout,<br>  IdleTimeout: IdleTimeout,<br>  Version:     &quot;OpenSSH_7.4p1 Debian-10+deb9u7&quot;,<br>  PublicKeyHandler: func(s ssh.Context, key ssh.PublicKey) bool {<br>   go processRequestExponentialBackoff(writeAPI, s, ctx, tracer)<br><br>   return false<br>  },<br>  PasswordHandler: func(s ssh.Context, password string) bool {<br>   go processRequestExponentialBackoff(writeAPI, s, ctx, tracer)<br><br>   return false<br>  },<br> }<br><br> server.AddHostKey(hostKey)<br> log.Fatal(server.ListenAndServe())<br>}</pre><h3>Global Cache for Intelligent Rate Limiting</h3><p>The integration of <a href="http://ip-api.com/">ip-api.com</a> for IP information retrieval brings with it rate limits on API requests. To efficiently manage these limits and prevent service disruptions, we’ve implemented a global cache. This cache intelligently tracks recent requests, enabling the honeypot to stay within the specified limits and implement retries with exponential backoff . The result is a continuous flow of valuable IP information while strategically handling rate limits to avoid potential disruptions in service.</p><pre>var (<br> c = cache.New(5*time.Minute, 10*time.Minute)<br>)<br><br>func getIpApi(host string, ctx context.Context, tracer trace.Tracer) (IpApi, error) {<br><br> wait, found := c.Get(&quot;getIpApiRt&quot;)<br> if found &amp;&amp; wait.(time.Duration) &gt; 0*time.Second {<br>  log.Printf(&quot;Rate limit key found on cache, sleeping for %s&quot;, wait)<br>  time.Sleep(wait.(time.Duration))<br> }<br><br>// ...<br><br> url := fmt.Sprintf(&quot;http://ip-api.com/json/%s?fields=%s&quot;, host, strings.Join(fields, &quot;,&quot;))<br> req, err := http.NewRequest(&quot;GET&quot;, url, nil)<br> if err != nil {<br>  if found {<br>   log.Printf(&quot;Error creating request for ip-api.com, re-invoking request after sleeping for %s&quot;, wait)<br>   c.Set(&quot;getIpApiRt&quot;, wait.(time.Duration)+1*time.Second, wait.(time.Duration)+1*time.Second)<br>  } else {<br>   log.Printf(&quot;Error creating request for ip-api.com, re-invoking request after sleeping for 1 second&quot;)<br>   c.Set(&quot;getIpApiRt&quot;, 1*time.Second, 1*time.Second)<br>  }<br><br>  return IpApi{}, err<br> }<br>}</pre><h3>Exponential Backoff and Error Handling</h3><p>Errors, an inevitable part of internet interactions, require a nuanced approach. Exponential backoff is an intelligent retry mechanism designed to gracefully handle errors during processing. By exponentially increasing the time between retry attempts, our honeypot mitigates disruptions caused by rate limits and other transient issues, aligning with emphasis on fault tolerance.</p><pre>func processRequestExponentialBackoff(writeAPI InfluxdbWriteAPI, sshContext ssh.Context, ctx context.Context, tracer trace.Tracer) error {<br> backoffSettings := backoff.NewExponentialBackOff()<br> backoffSettings.MaxElapsedTime = 30 * time.Minute<br> backoffContext := backoff.WithContext(backoffSettings, childCtx)<br><br> operation := func() error {<br>  return processRequest(writeAPI, sshContext, backoffContext.Context(), tracer)<br> }<br><br> err := backoff.Retry(operation, backoffContext)<br> if err != nil {<br>  log.Printf(&quot;Failed to process request: %v&quot;, err)<br>  return err<br> }<br><br> log.Printf(&quot;Successfully processed request&quot;)<br> return nil<br>}</pre><h3>Visualising Attack Patterns with Grafana</h3><p>Our honeypot’s data finds its home in InfluxDB, and Grafana becomes the canvas for visualisation. A custom Grafana dashboard allows us to monitor attacker locations in real-time, providing a comprehensive view of potential threats. This integration is a commitment to powerful visualisation tools enhancing situational awareness and aiding swift responses to emerging security challenges.</p><pre>func writeToInfluxDB(writeAPI InfluxdbWriteAPI, ipInfo IPInfo, sshInfo SSHInfo, ctx context.Context, tracer trace.Tracer) error {<br><br> point := influxdb2.NewPointWithMeasurement(&quot;request&quot;).<br>  AddField(&quot;latitude&quot;, ipInfo.Latitude).<br>  AddField(&quot;longitude&quot;, ipInfo.Longitude).<br>  AddTag(&quot;ip&quot;, ipInfo.IP).<br>  AddTag(&quot;country&quot;, ipInfo.Country).<br>  AddTag(&quot;city&quot;, ipInfo.City).<br>  AddTag(&quot;region&quot;, ipInfo.Region).<br>  AddTag(&quot;org&quot;, ipInfo.Org).<br>  AddTag(&quot;timezone&quot;, ipInfo.Timezone).<br>  AddTag(&quot;user&quot;, sshInfo.User).<br>  AddTag(&quot;remote_host&quot;, sshInfo.RemoteHost).<br>  AddTag(&quot;remote_port&quot;, sshInfo.RemotePort).<br>  AddTag(&quot;local_host&quot;, sshInfo.LocalHost).<br>  AddTag(&quot;local_port&quot;, sshInfo.LocalPort).<br>  AddTag(&quot;client_version&quot;, sshInfo.ClientVersion).<br>  AddTag(&quot;function&quot;, sshInfo.Function).<br>  AddTag(&quot;password&quot;, sshInfo.Password).<br>  AddTag(&quot;key&quot;, sshInfo.Key).<br>  SetTime(sshInfo.Timestamp)<br><br> if os.Getenv(&quot;INFLUXDB_NON_BLOCKING_WRITES&quot;) == &quot;true&quot; {<br>  log.Printf(&quot;Writing to InfluxDB in non-blocking mode&quot;)<br>  errorsCh := writeAPI.WriteAPI.Errors()<br>  go func() error {<br>   for err := range errorsCh {<br>    log.Printf(&quot;write error: %s\n&quot;, err.Error())<br>    return err<br>   }<br><br>   return nil<br>  }()<br>  writeAPI.WriteAPI.WritePoint(point)<br> } else {<br>  log.Printf(&quot;Writing to InfluxDB in blocking mode&quot;)<br>  err := writeAPI.WriteAPIBlocking.WritePoint(context.Background(), point)<br>  if err != nil {<br>   log.Printf(&quot;failed to write to InfluxDB: %v&quot;, err)<br>   return err<br>  }<br> }<br><br> return nil<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e9z94XgJ7u5nZpR-XB2UMw.png" /><figcaption>Grafana dashboard with attackers statistics</figcaption></figure><h3>Manual Otel Instrumentation</h3><p>One of the motivations for this project was to better understand how to instrument a Golang application with Otel for comprehensive monitoring. Considering this requirement two major approaches were found. The first one is <a href="https://github.com/open-telemetry/opentelemetry-go-instrumentation">automatic</a> — Go libraries are instrumented by <a href="https://ebpf.io/">eBPF</a>. The second one is to manually instrument all the methods. This was the chosen path, since the purpose of this project is to better understand all the Otel+Golang world. With that, this addition empowers us with in-depth insights into our honeypot’s performance, enabling the identification of vulnerabilities and optimisation for enhanced security</p><pre>func processRequest(writeAPI InfluxdbWriteAPI, sshContext ssh.Context, ctx context.Context, tracer trace.Tracer) error {<br> childCtx, span := tracer.Start(<br>  ctx,<br>  &quot;processRequest&quot;)<br> defer span.End()<br><br> span.AddEvent(&quot;Request inccoming&quot;)<br> log.Printf(&quot;Request to &#39;%s&#39; from &#39;%s&#39;&quot;, sshInfo.Function, remote_host)<br> ipInfo, err := getIpInfo(sshInfo.RemoteHost, childCtx, tracer)<br> if err != nil {<br>  span.RecordError(err)<br>  span.SetStatus(codes.Error, err.Error())<br>  log.Printf(&quot;Failed to get IP info: %v&quot;, err)<br>  return err<br> }<br>  <br> if writeToInfluxDB(writeAPI, ipInfo, sshInfo, childCtx, tracer) != nil {<br>  span.RecordError(err)<br>  span.SetStatus(codes.Error, err.Error())<br>  log.Printf(&quot;Failed to write to InfluxDB: %v&quot;, err)<br>  return err<br> }<br><br> span.AddEvent(&quot;Request successfully processed&quot;)<br> span.SetStatus(codes.Ok, fmt.Sprintf(&quot;Request to &#39;%s&#39; from &#39;%s&#39; successfully processed&quot;, sshInfo.Function, remote_host))<br> return nil<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UntS55hWMKOZH-4TXhHPDQ.png" /><figcaption>Screenshot of the last 8 hour of traces</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_7cjjEBESuC0qflwYl8Sw.png" /><figcaption>Screenshot of the last 8 hour of attacks</figcaption></figure><p>As it can be seen on the previous image, around 10PM the error rate and the 95th percentile increased — this was due to an increase on requests to the server and the need to limit the rate of the requests to ip-api.com due to service imposed rate limits. In this case these errors are merely informative, but other errors are also captured; one example are the errors related to failed writes to InfluxDB — these ones can be filtered and alerts can be created in order to alert the maintainers of the application to take actions to mitigate the issue.</p><h3>A Symphony of Components</h3><p>The orchestrated interplay of goroutines, global caching, exponential backoff, InfluxDB, Grafana, and Otel transforms our SSH honeypot into a resilient and responsive defense mechanism. This architecture not only improves the efficiency of handling attacks but also ensures adaptability in the face of potential disruptions.</p><p>In crafting a simple SSH server honeypot in Golang, our narrative echoes the principles of embracing concurrency, caching, and intelligent error handling. In the ever-shifting landscape of cybersecurity, staying agile and secure is not just a goal; it’s a way of life.</p><h3>Useful links</h3><ul><li><a href="https://github.com/marceloalmeida/ssh-honeypot/">https://github.com/marceloalmeida/ssh-honeypot</a></li></ul><h3>References</h3><ul><li><a href="https://github.com/open-telemetry/opentelemetry-go-instrumentation">https://github.com/open-telemetry/opentelemetry-go-instrumentation</a></li><li><a href="https://github.com/open-telemetry/opentelemetry-go">https://github.com/open-telemetry/opentelemetry-go</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=701a261788a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>