<?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 Akshay Siwal on Medium]]></title>
        <description><![CDATA[Stories by Akshay Siwal on Medium]]></description>
        <link>https://medium.com/@akshaysiwal?source=rss-f1380db2d8ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Akshay Siwal on Medium</title>
            <link>https://medium.com/@akshaysiwal?source=rss-f1380db2d8ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 01:22:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshaysiwal/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[Interview Question: How to Analyze iostat Output]]></title>
            <link>https://medium.com/@akshaysiwal/interview-question-how-to-analyze-iostat-output-dce59c52a1dd?source=rss-f1380db2d8ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/dce59c52a1dd</guid>
            <category><![CDATA[netflix]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Akshay Siwal]]></dc:creator>
            <pubDate>Tue, 17 Dec 2024 21:04:51 GMT</pubDate>
            <atom:updated>2024-12-17T21:04:51.308Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*63w25MB0dq6fwl2HCPwn1A.jpeg" /></figure><h4>Scenario: Diagnosing Disk I/O Latency</h4><p>You suspect that a disk is experiencing high latency during peak traffic. To monitor real-time disk performance, you run:</p><pre>iostat -y -x 5 3</pre><h4>Output:</h4><pre>avg-cpu:  %user   %nice %system %iowait  %steal   %idle  <br>           1.50    0.00    0.40    0.10    0.00   98.00  <br>  <br>Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util  <br>sda                 0.00     1.00    10.00   20.00     0.50     1.00    100.00     0.50   25.00    20.00    30.00   5.00   15.00  <br>  <br>avg-cpu:  %user   %nice %system %iowait  %steal   %idle  <br>           2.00    0.00    0.50    0.20    0.00   97.30  <br>  <br>Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util  <br>sda                 0.00     2.00    15.00   25.00     0.75     1.25    120.00     0.60   30.00    25.00    35.00   6.00   20.00</pre><h3>What is iostat?</h3><p>iostat is a Linux/Unix command-line utility that provides detailed statistics about CPU usage and input/output (I/O) performance of storage devices (disks, partitions, or logical volumes). It is part of the <strong>sysstat</strong> package and is widely used by system administrators and SREs to diagnose performance bottlenecks related to disk I/O and CPU utilization.</p><p>Let’s go through the <strong>full output of </strong>iostat step by step, explaining each section and metric in detail.</p><pre>iostat -x 5 2</pre><ul><li>-x: Displays extended statistics for devices.</li><li>5: Interval in seconds between reports.</li><li>2: Number of reports (including the first one).</li></ul><h3>Section 1: CPU Statistics</h3><p>The first section of the output shows <strong>CPU utilization</strong> metrics.</p><h4>Header:</h4><pre>avg-cpu:  %user   %nice %system %iowait  %steal   %idle</pre><h4>Metrics Explained:</h4><ul><li><strong>%user</strong>: Percentage of CPU time spent on user processes (non-kernel processes).</li><li><strong>%nice</strong>: Percentage of CPU time spent on user processes with a “nice” priority (low-priority tasks).</li><li><strong>%system</strong>: Percentage of CPU time spent on kernel/system processes.</li><li><strong>%iowait</strong>: Percentage of CPU time spent waiting for I/O operations (e.g., disk or network) to complete.</li><li><strong>%steal</strong>: Percentage of CPU time “stolen” by the hypervisor for other virtual machines (in virtualized environments).</li><li><strong>%idle</strong>: Percentage of CPU time spent idle (not doing any work).</li></ul><h4>Example:</h4><pre>avg-cpu:  %user   %nice %system %iowait  %steal   %idle  <br>           2.50    0.00    1.00    5.00    0.00   91.50</pre><p><strong>Interpretation:</strong></p><ul><li>2.5% of the CPU is being used by user processes.</li><li>1% is being used by system/kernel processes.</li><li>5% of the CPU is waiting for I/O operations to complete (this is significant and could indicate a disk bottleneck).</li><li>91.5% of the CPU is idle, meaning there is plenty of CPU capacity available.</li></ul><h3>Section 2: Device I/O Statistics</h3><p>The second section provides detailed statistics for each storage device (e.g., /dev/sda).</p><h4>Header:</h4><pre>Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util</pre><h4>Metrics Explained:</h4><ol><li><strong>Device</strong>: The name of the storage device (e.g., sda, nvme0n1).</li><li><strong>rrqm/s</strong>: The number of read requests merged per second. If multiple read requests are queued for the same block, they are merged into one request.</li><li><strong>wrqm/s</strong>: The number of write requests merged per second.</li><li><strong>r/s</strong>: The number of read requests completed per second.</li><li><strong>w/s</strong>: The number of write requests completed per second.</li><li><strong>rMB/s</strong>: The amount of data read from the device per second (in megabytes).</li><li><strong>wMB/s</strong>: The amount of data written to the device per second (in megabytes).</li><li><strong>avgrq-sz</strong>: The average size of I/O requests (in sectors). Larger values indicate larger I/O operations.</li><li><strong>avgqu-sz</strong>: The average number of I/O requests in the queue. Higher values indicate more queuing and potential contention.</li><li><strong>await</strong>: The average time (in milliseconds) for I/O requests to be completed, including both queue time and service time. High await values indicate that I/O operations are taking too long, which could be due to disk contention or slow storage.</li><li><strong>r_await</strong>: The average time (in milliseconds) for read requests to be completed.</li><li><strong>w_await</strong>: The average time (in milliseconds) for write requests to be completed.</li><li><strong>svctm</strong>: The average service time (in milliseconds) for I/O requests. This is the time the device spends servicing requests, excluding queue time.</li><li><strong>%util</strong>: The percentage of time the device was busy handling I/O requests. If this value is close to 100%, the device is saturated and may be a bottleneck.</li></ol><h4>Example:</h4><pre>Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util  <br>sda                 0.00     1.00    10.00   20.00     0.50     1.00    100.00     0.50   25.00    20.00    30.00   5.00   15.00</pre><p><strong>Interpretation:</strong></p><ul><li><strong>rrqm/s</strong> and <strong>wrqm/s</strong>: Very low values (0.00 and 1.00), meaning there is little merging of I/O requests.</li><li><strong>r/s</strong> and <strong>w/s</strong>: The device is handling 10 read requests and 20 write requests per second.</li><li><strong>rMB/s</strong> and <strong>wMB/s</strong>: The device is reading 0.5 MB/s and writing 1 MB/s.</li><li><strong>avgrq-sz</strong>: The average request size is 100 sectors (50 KB per request, as 1 sector = 512 bytes).</li><li><strong>avgqu-sz</strong>: The average queue size is 0.5, meaning there is some queuing but not excessive.</li><li><strong>await</strong>: The average time for I/O requests is 25 ms, which is relatively high and could indicate a performance issue.</li><li><strong>r_await</strong>: Read requests take 20 ms on average.</li><li><strong>w_await</strong>: Write requests take 30 ms on average.</li><li><strong>svctm</strong>: The service time is 5 ms, meaning the device itself is fast, but the queuing time is causing delays.</li><li><strong>%util</strong>: The device is 15% utilized, so it is not saturated.</li></ul><h3>Second Report</h3><p>The second report shows updated statistics after 5 seconds.</p><pre>Device             rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s  avgrq-sz avgqu-sz   await  r_await  w_await  svctm  %util  <br>sda                 0.00     2.00    15.00   25.00     0.75     1.25    120.00     0.60   30.00    25.00    35.00   6.00   20.00</pre><p><strong>Changes:</strong></p><ul><li><strong>r/s</strong> and <strong>w/s</strong>: Read and write requests have increased to 15 and 25 per second, respectively.</li><li><strong>rMB/s</strong> and <strong>wMB/s</strong>: Read and write throughput have increased to 0.75 MB/s and 1.25 MB/s.</li><li><strong>await</strong>: The average time for I/O requests has increased to 30 ms, indicating worsening performance.</li><li><strong>%util</strong>: The device utilization has increased to 20%, meaning the disk is busier.</li></ul><h3>How to Use This Data</h3><p><strong>High </strong>await and %util:</p><ul><li>If await is high and %util is close to 100%, the disk is likely a bottleneck.</li><li>Solution: Upgrade to faster storage (e.g., SSDs) or optimize the application to reduce disk I/O.</li></ul><p><strong>High </strong>avgqu-sz:</p><ul><li>If avgqu-sz is high, it indicates queuing, which could be due to contention or insufficient IOPS.</li><li>Solution: Increase IOPS (e.g., provisioned IOPS on AWS EBS) or reduce the number of concurrent I/O operations.</li></ul><p><strong>Low </strong>svctm but High await:</p><ul><li>If svctm is low but await is high, the delay is in the queue rather than the device itself.</li><li>Solution: Investigate the application or workload causing excessive I/O.</li></ul><p><strong>High </strong>r_await or w_await:</p><ul><li>If read or write latency is significantly higher than the other, it could indicate a specific issue with read or write operations.</li><li>Solution: Optimize the workload (e.g., caching for reads, batching for writes).</li></ul><h3>Conclusion</h3><p>The iostat command provides a wealth of information about CPU and disk performance. By understanding the metrics and their relationships, you can diagnose performance bottlenecks and take corrective actions. In this example, the high await values and increasing %util suggest that the disk is becoming a bottleneck, and further investigation or optimization is needed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dce59c52a1dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tech Interview Series: What Happens When You malloc 2 GB but Don’t Use It?]]></title>
            <link>https://medium.com/@akshaysiwal/tech-interview-series-what-happens-when-you-malloc-2-gb-but-dont-use-it-0b95cd2aa3a5?source=rss-f1380db2d8ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/0b95cd2aa3a5</guid>
            <dc:creator><![CDATA[Akshay Siwal]]></dc:creator>
            <pubDate>Tue, 17 Dec 2024 13:51:09 GMT</pubDate>
            <atom:updated>2024-12-17T13:51:09.503Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pajDeigQ4OR5jHLvg3DcjA.jpeg" /></figure><h3>What Happens When You malloc 2 GB but Don’t Use It?</h3><blockquote>malloc reserves virtual memory, not physical memory:</blockquote><ul><li>When you call malloc(2GB), the operating system <strong>reserves</strong> 2 GB of address space for your process in the virtual memory.</li><li><strong>No physical RAM is allocated yet</strong> because you haven’t accessed (touched) the memory.</li></ul><blockquote>RES and VIRT behavior:</blockquote><ul><li>VIRT will increase by 2 GB because the reserved memory adds to your process&#39;s virtual address space.</li><li>RES will <strong>not</strong> increase at this point because physical memory (RAM) has not been allocated.</li></ul><blockquote><strong>When does </strong>RES increase?</blockquote><ul><li>Physical memory is only allocated when you <strong>touch</strong> (read/write) the memory.</li><li>For example, if you write to a page of the allocated memory, the kernel will allocate a physical RAM page to your process. This will reflect in the RES size.</li></ul><h3>Question:</h3><p>If I malloc 2 GB of memory but don’t use it (i.e., the pages are allocated virtually but not yet touched), will it count toward the RES (resident memory)? And since the memory hasn&#39;t been touched, can other processes still use that space?</p><h3>1. If I malloc 2 GB and do not use it, will it be counted in RES?</h3><p><strong>No, it will not be counted in </strong>RES.</p><p>Here’s why:</p><ul><li>When you call malloc(2GB), the operating system <strong>reserves virtual address space</strong> for the requested memory.</li><li>However, <strong>no physical memory (RAM) is allocated</strong> until you actually access or “touch” those pages.</li><li>This is due to the <strong>lazy allocation strategy</strong> used by modern operating systems. Pages are only backed by physical memory (loaded into RAM) when they are accessed for the first time.</li></ul><p><strong>In </strong>top command:</p><ul><li>VIRT will increase by 2 GB because the virtual memory address space has been reserved.</li><li>RES will remain unchanged because no physical memory is used yet.</li></ul><h3>2. What happens when you “touch” the memory?</h3><p>The first time you write to a page in the allocated memory:</p><ol><li>The operating system generates a <strong>page fault</strong>.</li><li>It assigns a physical page (RAM) to the virtual address space.</li><li>That page now counts towards the RES value.</li></ol><p>So, <strong>RES only grows as you actually use the memory.</strong></p><h3>3. Can other processes use the unallocated memory (from malloc)?</h3><p><strong>Yes, absolutely.</strong></p><p>Here’s why:</p><ul><li>When you call malloc, you are only <strong>reserving virtual address space</strong> in your process. The physical memory (RAM) is <strong>not yet allocated</strong>.</li><li>Since the physical RAM is <strong>not committed</strong> to your process, it remains <strong>free for other processes</strong> to use.</li><li>Until you “touch” the memory (write to it), the operating system doesn’t allocate RAM to it.</li></ul><h3>Analogy to Simplify</h3><p>Think of the OS as a hotel manager and memory as rooms:</p><ul><li><strong>Virtual Address Space</strong>: You’ve “booked” 2 GB of rooms (via malloc), but the hotel manager only writes your name in the reservation book.</li><li><strong>Physical Memory</strong>: Rooms in the hotel (RAM). The manager doesn’t hand over any rooms to you yet.</li><li><strong>Touching Memory</strong>: When you enter the rooms (write to the memory), the manager actually allocates rooms (physical memory) for you.</li><li>Until you use the rooms, they are <strong>still available</strong> for other guests (processes).</li><li>Your name in the reservation book (VIRT) just says you’ve reserved them <strong>if needed</strong>.</li></ul><h3>Quick Example with Code</h3><p>Here’s a C example to test this:</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;unistd.h&gt;<br><br>int main() {<br>    printf(&quot;PID: %d\n&quot;, getpid());<br>    printf(&quot;Allocating 2 GB using malloc...\n&quot;);<br>    char *ptr = malloc(2L * 1024 * 1024 * 1024); // Allocate 2 GB<br>    if (!ptr) {<br>        perror(&quot;malloc failed&quot;);<br>        return 1;<br>    }<br>    printf(&quot;Press Enter to touch memory...\n&quot;);<br>    getchar(); // Pause to check top command before touching<br>    for (long i = 0; i &lt; 2L * 1024 * 1024 * 1024; i += 4096) {<br>        ptr[i] = 0; // Touch memory 4KB at a time<br>    }<br>    printf(&quot;Memory touched. Press Enter to exit...\n&quot;);<br>    getchar(); // Pause to check top command after touching<br>    free(ptr);<br>    return 0;<br>}</pre><p><strong>Steps to Test</strong>:</p><ol><li>Compile and run the program: gcc test.c -o test &amp;&amp; ./test</li><li>Note the <strong>PID</strong> and check the top command output:</li></ol><p>Before touching memory:</p><ul><li>VIRT increases by 2 GB.</li><li>RES remains small.</li></ul><p>After touching memory:</p><ul><li>RES increases to reflect the actual physical memory used.</li></ul><h3>Conclusion</h3><ol><li>malloc without usage:</li></ol><ul><li>Increases VIRT, but <strong>not </strong>RES.</li><li>Physical RAM is <strong>not allocated</strong>.</li></ul><ol><li><strong>Other processes</strong>:</li></ol><ul><li>The unallocated memory is still free for other processes to use.</li><li>Physical RAM is only committed to your process when you “touch” the memory.</li></ul><ol><li><strong>Key Point</strong>:</li></ol><ul><li>malloced but unused memory increases VIRT but <strong>not </strong>RES.</li><li>Virtual memory reservation (VIRT) does not mean physical memory usage (RES).</li><li><strong>Physical memory is allocated lazily</strong> — only when you <strong>access</strong> the memory.</li></ul><p>Let me know if you’d like further clarification! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0b95cd2aa3a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Choose the Right AWS Region: Key Factors and Real-Life Lessons]]></title>
            <link>https://medium.com/@akshaysiwal/how-to-choose-the-right-aws-region-key-factors-and-real-life-lessons-15441f81d74c?source=rss-f1380db2d8ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/15441f81d74c</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[services]]></category>
            <dc:creator><![CDATA[Akshay Siwal]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 00:15:30 GMT</pubDate>
            <atom:updated>2024-10-28T00:15:30.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1F8dmjMmgxh4NNrqhfcj3A.jpeg" /></figure><h3>How to Choose the Right AWS Region: Key Factors and Real-Life Lessons</h3><p>Picking an AWS Region may seem like a small detail at first, but it’s one of the most impactful decisions you can make in setting up your cloud infrastructure. Getting it right means better performance, compliance, and cost savings; getting it wrong can lead to unforeseen challenges. Here’s a straightforward guide to the top factors you should consider, with real-life examples of companies who’ve nailed it — or learned the hard way.</p><h3>1. Stay Compliant with Data Laws and Governance Rules</h3><ul><li><strong>Why It Matters</strong>: Choosing an AWS Region means deciding where your data is stored. For industries with tight data residency laws, like finance or healthcare, this decision is critical. AWS Regions keep your data in specific locations, so it won’t leave the region without your approval.</li><li><strong>When It Works</strong>: <strong>Salesforce</strong> leveraged AWS to launch its Hyperforce infrastructure, which allows the company to deploy its services in various regions while ensuring compliance with local data residency regulations. This strategic move enables Salesforce to quickly adapt to data sovereignty laws in different countries. <a href="https://aws.amazon.com/solutions/case-studies/salesforce-hyperforce-video-case-study/">Read more here</a>.</li><li><strong>When It Doesn’t</strong>: <strong>Google</strong> found itself in hot water when it didn’t offer similar regional storage flexibility, which led to regulatory pushback in Europe. They faced hefty fines and damage to user trust. <a href="https://www.politico.eu/article/france-hits-google-with-e50-million-fine-for-gdpr-violation/">Read more here</a>. <strong>Meta (Facebook) </strong>incurred a €1.2 billion fine for non-compliance with GDPR, highlighting the importance of choosing the right AWS region to avoid legal repercussions. <a href="https://www.bbc.com/news/technology-65669839">Read more here</a>.</li><li><strong>Pro Tip</strong>: Before choosing your region, check in with your legal or compliance team to ensure you’re aligning with any local regulations.</li></ul><h3>2. Choose a Region Close to Your Customers for Faster Performance</h3><ul><li><strong>Why It Matters</strong>: Just like how having a warehouse near your customers reduces delivery times, placing your servers close to users reduces the time it takes for data to travel. This leads to smoother, faster user experiences.</li><li><strong>When It Works</strong>: <strong>Netflix</strong> does this well, hosting data near key user populations across the globe to minimize buffering and keep viewers engaged. <a href="https://aws.amazon.com/solutions/case-studies/innovators/netflix/">Read more here</a>.</li><li><strong>When It Doesn’t</strong>: <strong>Snapchat</strong> struggled initially due to geographical distance from users, resulting in high latency and frustrating app performance. <a href="https://aws.amazon.com/solutions/case-studies/snap-dynamodb/">Read more here</a>.</li><li><strong>Pro Tip</strong>: Use <a href="https://docs.aws.amazon.com/whitepapers/latest/best-practices-deploying-amazon-workspaces/how-to-check-latency-to-the-closest-aws-region.html">AWS’s network tools</a> to test latency for different regions, and choose one close to your main users to ensure great performance.</li></ul><h3>3. Ensure the Services You Need Are Available in Your Region</h3><ul><li><strong>Why It Matters</strong>: Not every AWS service is available in every region. Sometimes, new or niche services, like machine learning or real-time applications, are only offered in select regions first.</li><li><strong>When It Works</strong>: <strong>Airbnb</strong> chose AWS Regions where all the services it needed were ready and fully supported, allowing them to offer a seamless experience for travelers without delays. <a href="https://aws.amazon.com/solutions/case-studies/innovators/airbnb/">Read more here</a>.</li><li><strong>When It Doesn’t</strong>: Some startups in Europe faced delays when their chosen AWS region lacked essential services, driving up costs and slowing projects.</li><li><strong>Pro Tip</strong>: The <a href="https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/">AWS Regional Service Availability Guide</a> is an excellent resource for finding the AWS services you need and verifying their availability in your selected region.</li></ul><h3>4. Check the Regional Pricing Differences</h3><ul><li><strong>Why It Matters</strong>: AWS costs vary by region due to factors like local operating expenses. Just like some cities are pricier to live in than others, some AWS Regions are pricier to run in.</li><li><strong>When It Works</strong>: <strong>Expedia</strong> made use of regional pricing differences by selecting regions where they could maximize cost savings without compromising on quality. <a href="https://aws.amazon.com/solutions/case-studies/expedia/">Read more here</a>.</li><li><strong>When It Doesn’t</strong>: Smaller companies have learned this lesson the hard way, finding themselves over budget after choosing pricier regions and later moving to less costly options for sustainability.</li><li><strong>Pro Tip</strong>: The <a href="https://calculator.aws/#/">AWS Pricing Calculator</a> is a great tool to compare costs by region and help you choose a budget-friendly option.</li></ul><h3>Final Thoughts</h3><p>Choosing an AWS Region is a strategic decision that will impact your project for years to come. From compliance and latency to service availability and cost, each factor affects your application’s performance and your bottom line. By carefully weighing each of these aspects and learning from the experiences of others, you can make the best choice for your business and your users.</p><p><strong><em>Stay Informed</em></strong>: Check AWS’s <a href="https://aws.amazon.com/about-aws/global-infrastructure/">global infrastructure updates</a> to track new region launches and service availability for optimal planning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15441f81d74c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Do you know AWS EBS snapshots can expose your sensitive data even if you have deleted it before…]]></title>
            <link>https://medium.com/@akshaysiwal/do-you-know-aws-ebs-snapshots-can-expose-your-sensitive-data-even-if-you-have-deleted-it-before-a0cbfae14736?source=rss-f1380db2d8ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0cbfae14736</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Akshay Siwal]]></dc:creator>
            <pubDate>Sat, 06 Jun 2020 14:12:16 GMT</pubDate>
            <atom:updated>2020-07-22T00:44:41.824Z</atom:updated>
            <content:encoded><![CDATA[<h3>Is Your Data Really Safe in the Cloud?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*v-I-iXk9E04UPz_Ju85mjQ.png" /></figure><p>I am sure you or the company you work for never want to see such a message on the website of the company. Unfortunately, for some companies, this worst nightmare has come to reality, and few out of them were almost on the verge of losing business until they recovered or negotiated with hackers.</p><h3>One sad story</h3><p>Ashley Madison, which got hacked on 15 July 2015 by a group called &quot;The Impact Team&quot; and threatened to expose users&#39; identities, if its parent company, Avid Life Media, did not shut down Ashley Madison and its sister site, Established Men. Few users committed suicide as their highly personal data was made public on torrent. The story does not end here. It is 2020 now, and Ashley Madison users are still being blackmailed.</p><p>After being attacked depending on what a company does, consequences may vary, but one side effect is always there.</p><p>Any guesses?</p><p>Yes, You are correct. The company loses its customers&#39; trust, which does not come in one day.</p><p>Enough of this sad story. Let us end it here and think about how you can prevent this from happening with your product. These days most of the companies are offering SAAS and are on Cloud because being on Cloud gives much flexibility. However, just like all good things come with some side effects, the Cloud is no exception. It has a side effect of inadvertently exposing Cloud resources to the public.</p><p>We already know how much damage a publically exposed resources can cause to a company, that is why every company has a security team that proactively keeps scanning for unauthorized access or resources that one accidentally let open to the world and bombards with a lot of JIRAs for explanations.</p><p>In my opinion, security is just perception, and no product is 100% secure. It is either hard or easy to hack. Now it depends upon how hard we can make our product to be hacked.</p><p>Coming to the main point that motivated me to write this blog, my very first blog on medium.com was <a href="https://www.youtube.com/watch?v=77qLAl-lRpo">AWS EBS</a>. One day my manager paged me to find out all the EC2 instances with unencrypted EBS volume and to encrypt them as soon as possible without affecting any production service and without making any changes in EC2 private IP. While working on this task out of curiosity, I ended up Googling hacks that had happened because of unencrypted EBS, and results were scary. The case I highlighted above was one of them where people at AshleyMadison made two mistakes. First, they hardcode secrets in source code, and second, all this critical information was unencrypted. If EBS were encrypted, hackers would have had a hard time getting this data even if the snapshot of EBS was publicly accessible until a hacker gets access to its KMS keys.</p><p>Let me tell you one unencrypted publicly accessible snapshot can make you live your worst nightmare. Public Snapshot! Now, if you might think I am an Idiot, who does that? Right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*nqmKkJb2z_Vb3uEcsmoOKw.gif" /></figure><p>Wait. Do not judge too early read this report written on Ben Morris&#39;s findings, which he presented at <strong>DEF CON 27 </strong>in August 2019. Several major private companies and even federal agencies unknowingly exposing their sensitive data like admin passwords, application keys, and VPN configuration, which can be exploited to tunnel to their corporate network.</p><p><a href="https://techcrunch.com/2019/08/09/aws-ebs-cloud-backups-leak/">Hundreds of exposed Amazon cloud backups found leaking sensitive data</a></p><h3><strong>This nightmare is real</strong></h3><p>This nightmare is real. Most of the time, we are just one misconfiguration away from a potential hack. If you are still not convinced, read this interesting comment from &quot;Hacker News&quot; which enlighten a case when a user needs to share an EBS snapshot between two AWS accounts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DKPXuW92ofAY_URsQIGVSw.png" /></figure><p>If someone exposes snapshot publically for just a couple of minutes, there are bots planted by Hackers in every region looking for such exposed snapshots and copy as soon as they see it. Hackers can create EBS volume out of it and attach to an EC2 instance to view its data and if there are any secrets or hardcoded API keys present in this then.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*JycN4V-O6qZYBNoHIKe6TQ.gif" /></figure><p>Now, consider a scenario where you have a use-case that requires you to share a snapshot with other accounts. While implementing this use-case, you realize that EBS volume contains confidential information and you deleted this sensitive information from EBS before creating a snapshot. SMART!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*7SkgGd9uC_2Oi5_o7XnRpg.gif" /></figure><p>What if I tell you that others can still see the file you have deleted before creating a snapshot. They can still see your sensitive information. Scary! Isn&#39;t it?</p><h3>Here is proof of what I have just said</h3><p>I created an EC2 instance with Ubuntu AMI ami-0caae0b310f01ff33, which had an EBS volume of 8 GB. For the demonstration, I created a file production.json with some fake credentials under the/home/ubuntu/test_directory directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*B0DqCe0NJbj5v2gMixwZwA.png" /></figure><p>To prove the point, I deleted production.json and created a snapshot of this EBS volume. Let&#39;s say I accidentally shared it with unintended person or made it public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_hLs90eTjDmfkLhmCluuvQ.png" /></figure><p>To simulate hackers, I created an EBS volume from the snapshot snap-0f4a66cec80757 , which I created after deleting production.json and attached this volume to another EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sy0Ag9ljuWcv2FajOXvCgw.png" /></figure><p>On new EC2 instance, I ranlsblk command to see the device name of the new volume, which is nvme1n1 in this case, and mounted it to /data_from_snapshot directory. Once it is mounted /data_from_snapshot will appear in the output of df command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*26eScIWxXyOgaODpQRYhnQ.png" /></figure><p>Now we are almost set to steal victim&#39;s confidential data. All we need is a utility like extundelete or testdisk based on the underlying filesystem, which can recover deleted data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*9oqFf1GKabNquWXckZZbVQ.png" /></figure><p>I used extundelete as my test EC2 has ext4 filesystem. extundelete puts all recovered files in a directory called RECOVERED_FILES with a similar directory structure as of the original volume. Therefore RECOVERED_FILES directory is all that I need to examine to see deleted files.</p><p>In this example, we already know we deleted file production.json containing secrets under /home/ubuntu/test_directory directory, so we should check a similar directory structure inside the RECOVERED_FILES directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*0vBB7B5JBiHQxPYvNrInuA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Etnmfem69FZ-l-nAOUUZRA.png" /></figure><p>Voilà! Now I can see the password and other secrets of the file production.json, which was not even present when the snapshot was created. This means information can leak from not just currently available files on EBS but also from old deleted files. Therefore never share a snapshot if your EBS ever had any confidential data.</p><h3><strong>Why can Hacker see it?</strong></h3><p>When we delete a file, it only gets unlinked. Delete command only breaks the link between name and inode and marks the inode as unused so that it can be used again. It does not wipe out data from filesystem blocks. If data blocks are not overwritten by new data, then it is possible to recover data based on the underlying filesystem. There are lots of details on how the operating system and filesystem works behind the scene when we delete a file and what all things it checks. I will discuss these things in detail in my future blogs.</p><h3>What can we do to avoid such scenarios?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*XkE7K2r9Mb-yWONb0KjSVw.png" /></figure><p>AWS has provided a straightforward solution, which is nothing but encrypted EBS volume, So even if you accidentally share an encrypted EBS snapshot with unintended user or AWS accounts, only users with appropriate permission on KMS key used for encryption can see what is inside it. Data is encrypted before it leaves the EC2 instance, which ensures security of data-at-rest as well as data-in-transit between an instance and its attached EBS storage.</p><p>I will share how you can automatically find and encrypt unencrypted-volumes without impacting your production services in my future blogs.</p><h3>Impact on performance</h3><p>As per AWS, encrypted EBS volume has the same IOPS performance as unencrypted EBS volume. However, encryption does add some overhead on I/O requests since data get encrypted before it leaves the EC2 instance. To minimize overhead on I/O latency, the EBS encryption feature is available on only a few instances type.</p><h3>Final Note</h3><p>Always use encrypted EBS volumes as encrypted volumes automatically create encrypted snapshots and never share a snapshot with sensitive data with anyone or whom you do not trust until you have any unavoidable use-case. Even if you have use-case, always think twice because you are just one mistake away from being hacked.</p><p>Additional Links —</p><ul><li><a href="https://inshorts.com/en/news/hundreds-of-amazon-cloud-backups-leaking-sensitive-data-report-1565503231724">Hundreds of Amazon cloud backups leaking sensitive data: Report</a></li><li><a href="https://www.theregister.co.uk/2015/09/08/ashley_madison_made_dumb_security_mistakes_researcher_says/">Ashley Madison made dumb security mistakes, researcher says</a></li><li><a href="https://krebsonsecurity.com/2015/07/online-cheating-site-ashleymadison-hacked/">Online Cheating Site AshleyMadison Hacked</a></li><li><a href="https://www.forbes.com/sites/zakdoffman/2020/02/01/ashley-madison-hack-returns-to-haunt-its-victims-32-million-users-now-have-to-watch-and-wait/#337a353c5677">Ashley Madison Hack Returns To &#39;Haunt&#39; Its Victims: 32 Million Users Now Watch And Wait</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0cbfae14736" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>