<?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 Sandeep Agarwal on Medium]]></title>
        <description><![CDATA[Stories by Sandeep Agarwal on Medium]]></description>
        <link>https://medium.com/@pensande?source=rss-38ee85bb35ac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OLwfj39Loymxd9fJPxYTyw.jpeg</url>
            <title>Stories by Sandeep Agarwal on Medium</title>
            <link>https://medium.com/@pensande?source=rss-38ee85bb35ac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 15:35:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pensande/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[Implement, Don’t Fuss]]></title>
            <link>https://medium.com/@pensande/implement-dont-fuss-d68bb6d7e6d5?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/d68bb6d7e6d5</guid>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Mon, 06 Jul 2026 05:47:39 GMT</pubDate>
            <atom:updated>2026-07-06T05:47:39.188Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2-py_Lha_hI69By_VeHGSg.png" /><figcaption>Image Credit: Gemini</figcaption></figure><p>I meet cybersecurity leaders all the time who finally get the budget to secure their network, and I watch where their energy goes. Which EDR (Endpoint Detection and Response) provider has the best quadrant rating. Vendor A vs. Vendor B. Cloud-native or hybrid. Hours of deliberation.</p><p>But I almost never hear the one question that will actually decide how things turn out: <em>how much time and diligence will you spend actually configuring it?</em></p><p>This is avoidance dressed as diligence. The choice of tool is interesting, endlessly debatable, something you can feel confident discussing in vendor meetings. The long, grinding work of properly configuring policies, patching systems, and training your team is dull and slightly painful. So the mind reaches for the smaller question to avoid the larger one.</p><p>Here is the reality that should change that habit.</p><p>Take two security teams. Team 1 buys an ordinary, middle-of-the-road security tool. It’s nothing fancy, but they spend months painstakingly configuring every rule, narrowing down permissions, and hardening their endpoints. Team 2 reads everything, buys the absolute top-tier, most expensive “Next-Gen AI” platform on the market, but they leave it on default settings because they are confident the tool’s advanced tech will just handle everything.</p><p>When a sophisticated attack hits, Team 1 blocks it cleanly because their basic defenses are watertight. Team 2 gets breached because a simple misconfiguration left a backdoor wide open. The top-tier tool’s advanced features couldn’t close the gap left by lazy implementation.</p><blockquote>The boring habit of meticulous implementation beats the exciting habit of buying the “best” tool.</blockquote><p>Why does this happen? In cybersecurity, no tool works perfectly out of the box. What actually stops attackers is the context you build into the system — the custom rules, the asset tagging, the relentless closing of gaps. The configuration does the heavy lifting. A hyper-expensive tool left on default settings is just an expensive siren that tells you you’ve been hacked after the fact.</p><p>And here is the irony. Most teams fixate on vendor choice exactly when it matters least, and run out of steam by the time the actual implementation — the part that matters most — begins.</p><p><strong>If you are upgrading your security, here is the order I would follow.</strong></p><ul><li>Work out exactly who is going to manage the system and how much time they have to tune it.</li><li>Only after you have committed to that operational diligence should you spend any energy picking a vendor.</li><li>Keep the tool choice sensible and standard. Let solid engineering do the rest.</li></ul><p>One warning though. Do not confuse this with permission to be careless. Buy a completely outdated, unmaintained firewall, and the tool becomes the problem. Trust your data to a sketchy, unverified freeware, and no amount of configuration will save you. But within sensible, enterprise-grade choices, the differences between vendors are small compared to how well you implement them.</p><p>Implement deeply. Choose sensibly. Stop fussing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d68bb6d7e6d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Was Wrong About the “A” in CIA — How Encryption Became Our Biggest Threat.]]></title>
            <link>https://medium.com/@pensande/why-i-was-wrong-about-the-a-in-cia-how-encryption-became-our-biggest-threat-a3ff61d67d54?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3ff61d67d54</guid>
            <category><![CDATA[resilience]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Wed, 31 Dec 2025 17:50:55 GMT</pubDate>
            <atom:updated>2026-01-02T13:50:28.173Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why I Was Wrong About the “A” in CIA — How Encryption Became Our Biggest Threat.</h3><h3>Information Security: The Era of Secrets (The 2000s)</h3><p>The first thing any security professional learns — regardless of the era — is the “CIA triad”: <strong>Confidentiality, Integrity, and Availability.</strong></p><p>When I started my career in the early 2000s, security meant Confidentiality first, Integrity second, and Availability… rarely. To be honest, I often questioned if Availability even belonged in the security bucket. I told myself it was only there to keep us in check — a “speed limiter” to ensure we didn’t make systems so secure they became useless.</p><p>I’d wager that even if you asked a security pro back then what they indexed on, the vast majority would pick Confidentiality. A few might argue for Integrity. Almost no one would have given Availability a second thought.</p><h3>Cybersecurity: The Era of Monetization (The 2010s)</h3><p>Two major shifts defined the 2010s: the explosion of “cyberspace” into our pockets and the professionalization of cybercrime.</p><p>Before this, high-level attacks were largely the domain of nation-states targeting massive corporations for intellectual property (IP). But IP is only valuable if you have the infrastructure to use it. If you gave a random person access to blueprints for a fighter jet or a proprietary search algorithm, they likely wouldn’t make it past the fifth page.</p><p>Everything changed with the smartphone. Suddenly, every individual held a programmable, connected device. To make matters worse, this device became a universal second factor for every login worth protecting and every payment made digitally!</p><p>Cloud computing also proved to be the great leveler. The ‘democratization of technology’ didn’t just help startups scale; it helped cybercriminals scale, too. In the 2000s, an attacker needed their own infrastructure; in the 2010s, they just needed a credit card (or stolen credentials) and a cloud console.</p><p>The cloud gave a kid in a basement the same compute power and global reach as a nation-state.</p><p>It was around this time that the term “<strong>Cyber Security</strong>” deservedly became commonplace (popularized, in my mind, by the Obama administration).</p><p>Then came 2017: <strong>The Year of Ransomware.</strong></p><h3>The Great Flip: Availability as the Ultimate Leverage</h3><p>2017 brought two forces together: ransomware and cryptocurrency. Ransomware provided the ultimate psychological lever over the C-suite, while crypto solved the age-old criminal problem of ‘how do we get paid without getting caught?’.</p><p>Attackers realized that while security pros obsess over Confidentiality, many business leaders don’t — at least not until a regulation or a lawsuit is involved. In fact, my IT peers and I used to joke that the data we were so obsessed with protecting wouldn’t find a single buyer in <em>Nehru Place</em> (Delhi’s bustling electronics and computer market).</p><p>But if you bring a system to a halt? You have the business’s full, undivided attention.</p><p>Ransomware became a powerful force because <strong>business interruption</strong> is what keeps executives awake at night. It is fascinating — and a bit ironic — how attackers used encryption — the very “shield” of confidentiality — as a weapon against availability!</p><p>Attackers finally found a way to turn cybercrime into a scalable business model — by turning business continuity into a hostage situation and using crypto as an anonymous way to collect the spoils.</p><p>After all, nothing motivates like a payday.</p><h3>From Security to Resilience (The 2020s and beyond)</h3><p>We’ve learned the hard way that a system is useless if it’s inaccessible. Today, downtime is often the first and most painful sign of a compromise.</p><p>This is why the industry is moving away from “Cyber Security” toward <strong>“Cyber Resilience.”</strong> While “security” can sound like a technical hurdle, “resilience” is a business objective.</p><p>After all, the ultimate goal of any modern security program isn’t just to lock the doors — it’s to maximize and protect the business’s ability to function.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3ff61d67d54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Encryption Key Control in SaaS Deployments]]></title>
            <link>https://medium.com/google-cloud/encryption-key-control-in-saas-deployments-fd67e8bc6af5?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd67e8bc6af5</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[regulatory-compliance]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Tue, 19 Aug 2025 09:23:28 GMT</pubDate>
            <atom:updated>2025-08-21T02:17:18.407Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p>The Reserve Bank of India has published its Master Direction on Outsourcing of Information Technology Services 2023 for Regulated Entities (REs). Section <strong>Cloud Services Management and Security Considerations</strong> of these guidelines requires that —</p><blockquote>REs shall prefer a technology architecture that provides for secure container-based data management, <strong>where encryption keys and Hardware Security Modules are under the control of the RE</strong>.</blockquote><p>The intent of the guideline is solid — the regulator wants to ensure REs have a lever to independently erase data in cloud environments through control over encryption keys (a concept commonly known as <em>crypto-shredding</em>).</p><h3>Problem</h3><p>REs running self-managed IaaS and PaaS environments find it easy to comply with this requirement as cloud providers offer a range of encryption and key management options.</p><p>However, when it comes to SaaS applications, keys used for encrypting data at-rest are typically managed by the SaaS provider as part of the overall underlying cloud infrastructure. This conflicts with the RBI guideline that mandates REs to have control over encryption keys.</p><p>This blog explores a spectrum of options available to REs for encryption key control in SaaS apps — the good, the bad and the ugly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jiHTkK3jdoecyHSq3pi3Zg.png" /><figcaption>Image Credit: Gemini by Google DeepMind</figcaption></figure><h3>Key Control Options</h3><h4>Do nothing. Let the SaaS provider be.</h4><p>Instead enforce controls related to key management and data sovereignty through clear and stringent legal and contractual measures. And then validate the design and operating effectiveness of SaaS provider’s controls using SOC 2 Type II reports.</p><p>A big reason why SaaS is popular is that it allows businesses to delegate undifferentiated tasks of developing, running, managing software to providers who can do this professionally, at scale and at a fraction of the cost. This option lets SaaS providers be, well, SaaS providers!</p><blockquote>This is my favorite option because it relies on the mechanics of free market theory. It rides on the belief that SaaS providers have the incentives, skills, resources and economies of scale to do the right thing for their customers.</blockquote><p>Introducing external key management into a SaaS provider’s well-oiled machine is like throwing a spanner in the works — a surefire way to cause some grinding of gears. But when the regulator calls, the gears must grind.</p><p>I understand this does not address the problem we set out to solve, but I could not help but list this for the sake of comprehensiveness.</p><h4>Import key materials from an RE-managed HSM into the SaaS KMS</h4><p>Under this option the RE uses any of its cloud or on-prem HSMs to generate a key material. The key material is then securely wrapped and exported out of the HSM. The wrapped key is then imported into the KMS managed by the SaaS provider in their own cloud tenancy.</p><p>REs adopting this approach live under a delusion that since the encryption key material was generated in an RE-managed HSM, it satisfies the need to have <em>encryption keys and Hardware Security Modules under their control</em>.</p><p>The reality is that once a key material is imported into KMS, who generated the key material and where becomes irrelevant. All that matters is who has IAM controls over the KMS system where the key material is stored — which is the same even if you had the cloud KMS generate the key materials.</p><blockquote>Evidently, this is by far the most useless of options. Ironically, this is also the most widely adopted option because of the way industry interprets RBI requirements.</blockquote><h4>Have the SaaS provider use KMS keys from your cloud tenancy</h4><p>This is where REs use KMS in their own cloud tenancy to create a key which are then used by the SaaS provider to configure encryption in their cloud tenancy. To facilitate this, REs need to grant Crypto Operator rights over this key to the SaaS provider’s service accounts.</p><p>These service accounts would likely be service agents, which is a specialized service account created and managed by Google Cloud services, in the SaaS provider’s cloud tenancy. These service agents call the KMS APIs to perform encrypt/decrypt operations. These could also be any service accounts created and managed by the SaaS provider to encrypt/decrypt data client-side (within the application).</p><p>In either case, given the RE <em>owns</em> and <em>controls admin access</em> over their KMS keys, they can terminate the SaaS provider’s access to such keys at will. With one swift action, they can render useless any data in the SaaS that has been encrypted with their keys. Or restore it easily if and when needed.</p><blockquote>This option best meets the letter and spirit of the RBI regulation. However, with great power comes great responsibility. While it gives REs total control over encryption keys, one mistake by the RE can bring down their entire SaaS app.</blockquote><p>I did not list this option as my favorite because —</p><ol><li>Like the first option, this too ultimately relies on the SaaS provider doing the right thing. E.g., a SaaS provider with malicious intent can provide bogus service accounts and continue using their own keys for encryption.</li><li>Multi-tenant SaaS applications — with common underlying cloud resources (such as buckets, node pools) — will find it difficult to support this model as they need to create per-customer resources. This could come in the way of operating a lost-cost SaaS setup at scale. That said, it could also help them win more customers by supporting their compliance requirements and enhance trust by giving back control.</li><li>Configuring encryption keys is best done when provisioning a tenant. Changing encryption keys after the tenant has been set up requires re-encrypting the data making it further difficult for the SaaS provider.</li></ol><h4>Have the SaaS provider grant Admin rights over their keys</h4><p>Under this option, the SaaS provider operates as usual, but adopts radical transparency and control by giving REs admin rights over their KMS keys.</p><p>The RE creates a group where they add designated key administrators (individuals or service accounts) from their organization. The SaaS provider grants this group KMS Admin roles over the keys that are used to perform cryptographic operations over the RE’s data.</p><p>REs can use these privileges for a range of tasks — from validating key properties such as protection level (hardware or software), algorithm, rotation period, destruction period, location, etc. to destroying the keys to crypto-shred their data in SaaS!</p><blockquote>This is a practical option that strikes a sweet spot between letting SaaS providers operate as they want to, while still giving customers control over encryption keys.</blockquote><p>Again, like the previous option, this too relies on the SaaS provider doing the right thing. Given the ability to grant (and, conversely, revoke) KMS admin rights rests with the SaaS provider, they can unilaterally terminate the ability of an RE to administer KMS keys in their cloud tenancy.</p><h3>Conclusion</h3><p>In the quest for the ultimate kill switch, we’ve explored a range of key management options. Yet, every path leads back to the same place: <strong>trust</strong>.</p><p>The RBI’s directive seeks a world where a Regulated Entity can pull the plug with the tangible turn of a key. The reality of SaaS, however, is that you’re being handed the keys to a house that someone else built, owns, and can change the locks on at any time.</p><p>So, choose your key management strategy wisely, but choose your SaaS provider even more wisely. After all, the most robust security control is still a vendor who has more to lose by failing you than by fooling you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd67e8bc6af5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/encryption-key-control-in-saas-deployments-fd67e8bc6af5">Encryption Key Control in SaaS Deployments</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Uncovering IAM Blindspots in Google Cloud]]></title>
            <link>https://medium.com/google-cloud/uncovering-iam-blindspots-in-google-cloud-cd584d5f7785?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd584d5f7785</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[identity-and-access]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[cloud-security]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Thu, 19 Jun 2025 13:43:58 GMT</pubDate>
            <atom:updated>2025-06-20T03:04:41.645Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><blockquote>Identity and Access Management (IAM) is the sine qua non of cloud security. The fanciest of firewalls or the sexiest of SIEMs can be undone by bad IAM in a matter of seconds.</blockquote><p>My blog — <a href="https://medium.com/google-cloud/get-real-time-notifications-on-iam-privilege-grants-in-google-cloud-b5b2aad1d6e3">Get real-time notifications on IAM privilege grants in Google Cloud</a> — shows how to get alerted of any incremental access to your cloud resources.</p><p>Sometimes, though, you may need <em>point-in-time</em> visibility of <em>who all</em> have <em>what permissions</em> to <em>which resources</em> across your cloud. Obtaining this comprehensive view through the console means hopping around different resource pages — like IAM, KMS, GCS, etc.— and stitching them together.</p><p>It gets further complicated when you adopt IAM best-practices for groups.</p><blockquote>Google Cloud IAM groups are best used to model job functions and grant access to resources based on roles, rather than assigning permissions directly to individual users. This approach simplifies access management, promotes least privilege, and reduces administrative overhead.</blockquote><p>In such cases, IAM policy bindings reflect groups; and group memberships can only be enumerated from the <a href="http://admin.google.com/">Google Admin console</a> or through the <a href="https://cloud.google.com/iam/docs/groups-in-cloud-console">Google Cloud console</a> at the Organization level — adding complexity.</p><p>This blog shows how <a href="https://cloud.google.com/asset-inventory/docs/overview">Cloud Asset Inventory</a> coupled with the <a href="https://developers.google.com/workspace/admin/directory/reference/rest">Directory API</a> can bring clarity to access grants across your Google Cloud resource hierarchy <em>down to the individual level</em>. This is particularly useful when you want to detect conflicting/overlapping roles to ensure Separation of Duties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*36X_X70xXU4txwfSP4oj_g.png" /></figure><h3>Obtaining User-Group Memberships</h3><p>First, let’s try and obtain a comprehensive list of users and their group memberships in our Google domain.</p><h4>Permissions Required</h4><p><em>You must be signed in as a </em><a href="https://support.google.com/a/answer/2405986#super_admin"><em>super administrator</em></a><em> for this task.</em></p><p>We will fetch User and Group information using the <a href="https://developers.google.com/workspace/admin/directory/reference/rest">Admin SDK: Directory API</a>. The full list of admin permissions available is listed <a href="https://support.google.com/a/answer/1219251?sjid=8049711530709956297-NC">here</a>. Of these, our code needs Read-only permissions to the Users and Groups API.</p><p>So we <a href="https://support.google.com/a/answer/2406043?sjid=8049711530709956297-NC">create a custom role</a> with these read-only API permissions. Console access is not required since we are going to run these reports programmatically.</p><p>Finally, we assign this custom role to a user or service account that will execute our code.</p><h4>Code Setup</h4><p>We will now create a Python script which calls the Directory API to obtain the list of users and group memberships and stores the results in a CSV file.</p><p><strong>requirements.txt</strong></p><pre>google-api-python-client</pre><p><strong>main.py</strong></p><pre>import os<br>import csv<br>import json<br>import googleapiclient.discovery<br><br>def group_memberships():<br>    # Get the list of users and their respective group memberships.<br>    customer_id = os.environ.get(&#39;CUSTOMER_ID&#39;, &#39;Specified environment variable is not set.&#39;)<br>    <br>    # Get the list of users.<br>    users = get_users(customer_id)<br>    <br>    # Process the list of users.<br>    if not users:<br>        print(&#39;No users found!&#39;)<br>    else:<br>        df = open(&#39;group_memberships.csv&#39;, &#39;w&#39;)<br>        cw = csv.writer(df)<br><br>        # Fetch the list of groups for each user.<br>        for user in users:<br>            group_membership = [user[&#39;name&#39;][&#39;fullName&#39;], user[&#39;primaryEmail&#39;]]<br>            groups = get_groups(user[&#39;primaryEmail&#39;])<br><br>            for group in groups:<br>                group_membership.append(f&quot;group:{group[&#39;email&#39;]}&quot;)<br>            <br>            cw.writerow(group_membership)<br>        <br>        df.close()<br><br>def get_users(customer_id):<br>    # Make the API call to get the list of users.<br>    users = service.users().list(customer=customer_id).execute()<br><br>    # Return the list of users.<br>    return users.get(&#39;users&#39;, [])<br><br>def get_groups(user_email):<br>    # Make the API call to get the list of groups.<br>    groups = service.groups().list(userKey=user_email).execute()<br><br>    # Return the list of groups.<br>    return groups.get(&#39;groups&#39;, [])<br><br># Create the Admin SDK Directory service object.<br>service = googleapiclient.discovery.build(&#39;admin&#39;, &#39;directory_v1&#39;)<br>group_memberships()</pre><h4>Executing Locally with User Credentials</h4><p>I will run the Python script locally on my terminal with my user account which has the necessary permissions (the custom role) assigned to it.</p><pre>gcloud auth application-default login \<br>  --scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/admin.directory.group.readonly<br><br>export CUSTOMER_ID=YOUR_CUSTOMER_ID<br><br>pip install -r requirements.txt<br>python3 main.py</pre><blockquote>You could also run this code in <a href="https://cloud.google.com/functions?e=48754805&amp;hl=en">Cloud Run Functions</a> using a service account and dump the CSV results to a Google Cloud Storage bucket.</blockquote><p>Take note of thegroup_memberships.csv file generated as output.</p><h3>Obtaining IAM Policy Bindings</h3><p>The next step is to obtain the list of IAM bindings we are interested in. We will use the Cloud Asset Inventory API to fetch this information.</p><p>Cloud Asset Inventory allows us to scope the request to a specific Project, Folder or an entire Organization. To view these bindings, you need the following IAM roles on the organization, folder, or project:</p><ul><li><a href="https://cloud.google.com/iam/docs/roles-permissions/cloudasset#cloudasset.viewer">Cloud Asset Viewer </a>(roles/cloudasset.viewer)</li><li><a href="https://cloud.google.com/iam/docs/roles-permissions/serviceusage#serviceusage.serviceUsageConsumer">Service Usage Consumer </a>(roles/serviceusage.serviceUsageConsumer)</li></ul><p>I further refine my query to only list bindings which have at least one of its members as a Google group. Providing a query is optional and omitting this will list all of the IAM bindings under the selected scope.</p><pre>nano iam-bindings.sh</pre><pre>#!/bin/bash<br><br>PROJECT_ID=PROJECT_NUMBER<br><br>gcloud asset search-all-iam-policies --scope=&#39;projects/$PROJECT_ID&#39; --query=&#39;memberTypes:group&#39; --format=&#39;json(assetType,resource,policy.bindings)&#39; | jq -r &#39;<br>  .[] | . as $resource_data |<br>  $resource_data.policy.bindings[] | . as $binding_data |<br>  [<br>    $resource_data.assetType,<br>    $resource_data.resource,<br>    $binding_data.role,<br>    $binding_data.members[]|tostring<br>  ] | @csv<br>&#39; &gt; iam_policies.csv</pre><pre>chmod +x iam-bindings.sh<br>./iam_bindings.sh</pre><p>Take note of the iam_policies.csv file generated as output.</p><h3>Constructing my IAM View</h3><p>As the final step, we use data from the 2 CSV files,group_memberships.csv and iam_policies.csv, put them in our favorite spreadsheet and use simple formulas to visualize the data as per our needs.</p><p>With my limited expertise, I use a MATCH function and some conditional formatting to figure out which users are part of which policy bindings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6VQz_vPHyf62lpvWJxxOag.png" /><figcaption>Matrix of Users vs Policy Bindings</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd584d5f7785" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/uncovering-iam-blindspots-in-google-cloud-cd584d5f7785">Uncovering IAM Blindspots in Google Cloud</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NotebookLM Enterprise Security]]></title>
            <link>https://medium.com/google-cloud/notebooklm-enterprise-security-d49f70784621?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/d49f70784621</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[ai-security]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[notebooklm]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Fri, 13 Jun 2025 09:40:26 GMT</pubDate>
            <atom:updated>2025-06-14T01:32:05.868Z</atom:updated>
            <content:encoded><![CDATA[<h4>Enterprise-grade security and compliance controls you can use</h4><h4>Introduction</h4><p><a href="https://notebooklm.google.com/">NotebookLM</a> is a useful tool that makes interacting with information genuinely fun and incredibly productive, all while keeping itself grounded in the sources you trust. You can upload PDFs, Google Docs, Google Slides, website URLs, YouTube videos and more to build a notebook.</p><p><a href="https://cloud.google.com/agentspace/notebooklm-enterprise/docs/overview">NotebookLM Enterprise</a> is the enterprise-ready form of the personal NotebookLM product. It includes all the NotebookLM functionality as well as enterprise-grade security and compliance.</p><p>This blog provides a summary of these compliance and administrative features that customers may find useful in corporate environments.</p><h4><strong>Identity and Authentication</strong></h4><p>NotebookLM Enterprise supports —</p><ol><li>Google Identity (both native Google logins, or via SSO), and</li><li>Bring Your Own ID (BYOID) via Workforce Pool Federation.</li></ol><p>Customers who use third-party identity providers (e.g., Azure AD, Okta) can have end-users leverage their corporate credentials to log in and access Notebook using Google Identity + SSO (the way they would access Google Cloud or Workspace services).</p><p>Alternatively, customers new to the Google ecosystem who don’t want to sync user identities into Google could use <a href="https://cloud.google.com/iam/docs/workforce-identity-federation">Workforce Identity Federation</a>.</p><p>For details on how to setup identity and authentication, refer <a href="https://cloud.google.com/agentspace/notebooklm-enterprise/docs/set-up-notebooklm">here</a>.</p><h4><strong>Authorization</strong></h4><p>Notebooks, by default, are private to the user.</p><p>NotebookLM Enterprise uses predefined GCP IAM roles (NotebookLM Owner, NotebookLM Editor, NotebookLM Viewer) that can be applied at the notebook level. IAM roles can be assigned directly from the NotebookLM web app and does not require users to go to the IAM page within the GCP console.</p><p>Notebooks can’t be shared publicly.</p><h4>Context-aware Access</h4><p>As of the writing of this blog, the NotebookLM Enterprise UI leverages a public endpoint. <a href="https://cloud.google.com/vpc-service-controls/docs/overview">VPC Service Controls</a> can enforce context-aware restrictions on the API calls made by that UI, ensuring requests originate from authorized networks or identities or devices.</p><p>You can use <a href="https://cloud.google.com/access-context-manager/docs/overview#access-levels">Access Levels</a> to define the context of authorized requests. This context could be device types, operating systems, device certificates, or public IP addresses of your internet proxies— whatever best represents traffic originating from your corporate environment. Requests lacking this context — such as users accessing NotebookLM from personal devices — will be rejected.</p><blockquote>The UI itself is still accessed via the public internet. Given this is end-user traffic, accessing the NotebookLM UI privately via a Landing Zone setup is neither recommended nor supported.</blockquote><h4>Data Loss Prevention</h4><p>Customers fully control their data and are responsible for ensuring that any content they ingest into NotebookLM is safe and compliant.</p><p>The good news is — when users access NotebookLM from corporate networks or using managed devices, any existing data loss prevention control — such as CASB, Web Proxy, Web DLP, Endpoint DLP — can seamlessly extend to monitor and protect data flowing in and out of NotebookLM, just as they would for any other SaaS application.</p><h4><strong>Data Residency and Isolation</strong></h4><p>Users access NotebookLM Enterprise through a project- and region-specific URL. All data resides within a customer’s project and it is not used to train or manipulate the underlying models.</p><p>As of the writing of this blog, NotebookLM Enterprise offers US, Global and EU region data residency. Support for more regions is coming soon.</p><h4>Data Encryption</h4><p>Like all Google Cloud services, NotebookLM Enterprise encrypts customer content at rest without any additional actions required from the customer. This is called Google-default encryption.</p><p>Customers have the option of controlling the encryption keys, using customer-managed encryption keys (CMEKs) in Cloud KMS. Refer <a href="https://cloud.google.com/agentspace/notebooklm-enterprise/docs/cmek">here</a> for details on limitations and setting up CMEK for NotebookLM Enterprise.</p><h4>Logging and Monitoring</h4><p>Administrators can use audit logs to gain insights into NotebookLM usage in their organization. Audit logs record user, timestamp, event/action, details, and impacted resource for both admin and user actions. Search queries are not logged.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d49f70784621" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/notebooklm-enterprise-security-d49f70784621">NotebookLM Enterprise Security</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scalable GCP KMS Governance: Minus the Centralization]]></title>
            <link>https://medium.com/google-cloud/scalable-gcp-kms-governance-minus-the-centralization-a3545f541cb3?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3545f541cb3</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[key-management]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Tue, 01 Apr 2025 12:03:43 GMT</pubDate>
            <atom:updated>2025-04-01T16:54:02.631Z</atom:updated>
            <content:encoded><![CDATA[<p>My friends in security, especially in regulated environments such as financial services, are often paranoid about encrypting data in the cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T1OLVTPy4gsXW8Rlkbr8Rg.jpeg" /><figcaption>Image Credit: Imagen 3 by Google DeepMind</figcaption></figure><p>Broadly speaking, their objective is to ensure:</p><ol><li>Data at-rest is encrypted using customer-managed encryption keys.</li><li>Customer-managed keys are of a certain type e.g. software or hardware.</li><li>Keys are rotated at a certain frequency, e.g. quarterly or yearly.</li><li>Keys cannot be deleted by anyone apart from Key Admins.</li><li>Keys are disabled for a certain duration before being permanently deleted.</li></ol><p>A natural response from security teams is to centralize all encryption keys. They get nervous delegating these responsibilities to Devops teams for fear of security or compliance violations that may later surface during audits. Consequently, they favor a model where a small, trusted group of security admins handles all key creation and configuration.</p><p>This may sound lucrative to security teams who are used to keeping things under tight central control but defeats the flexibility and autonomy that cloud computing brings to developers.</p><h3>Drawbacks of Centralized Key Management</h3><blockquote>There are no absolutes, only what we choose to believe absolutely. — Anonymous.</blockquote><p>With that disclaimer out of the way, I place on record my strong objection to key centralization, particularly in Google Cloud. My recommendation is to let KMS keys and the resources they encrypt coexist in the same project.</p><p>I say this for the following reasons:</p><ol><li><strong>KMS quotas and limits </strong>— Like with any service, Cloud KMS has certain <a href="https://cloud.google.com/kms/quotas">quotas and limits</a> many of which are aggregated and enforced on the host project. Although the limits are sufficiently high, centralizing keys means you are more likely to hit these limits than with a decentralized approach.</li><li><strong>Cross-project access</strong> — In Google Cloud, encryption is performed by <a href="https://cloud.google.com/iam/docs/service-agents">service agents</a> that act on behalf of a Google Cloud service. For example, each project has a specific Cloud Storage service account called a service agent that performs encryption and decryption with CMEKs. In a centralized model, each of these service agents would need permissions on the centralized keys, which is additional administrative work for every service in every project that you onboard.</li><li><strong>Key usage</strong> — The same concept as above applies to users or machine accounts (if using automation). To successfully specify a KMS key for cloud resources, the relevant service agent must be granted the ability to use that key for cryptographic operations, and the user setting the key must have the permissions to select (cloudkms.viewer) and assign that key (cloudkms.admin). Hence such users will need access to the centralized key project, making access governance more complex.</li><li><strong>VPC Service Controls</strong> — VPC SC helps you create service perimeters using which you can isolate API calls within a perimeter. Centralizing keys limits your flexibility to create multiple isolated perimeters since a project and API can only be in one perimeter at a time. This limitation makes key centralization an anti-pattern for customers who are extremely security-sensitive and care about fine-grained perimeters.</li><li><strong>Risks with broader keys</strong> — Having low granularity for encryption keys — such as using the same key across multiple projects requires more care to safely disable or delete key versions. Any mistake could mean that your data becomes inaccessible due to unavailability of encryption keys. Conversely, broader keys also prohibit you from taking full advantage of selective crypto-deletion — deleting an encryption key to render unreadable any data encrypted using that key (crypto-shredding).</li><li><strong>IaC Automation</strong> — Centralized key management is typically popular in environments with manual infra creation. If you use infrastructure-as-code extensively, you would prefer your infrastructure scripts to have autonomy and have less dependency on manual centralized processes.</li></ol><h3>Establishing Guardrails in a Decentralized Approach</h3><p>Prudent governance indeed requires guardrails to ensure that there are no violations in your environment. So, if not centralization, my security friends will ask, what are the other options?!</p><h4>Infrastructure as Code (IaC) and/or Policy as Code (PaC)</h4><p>One obvious way of achieving standardization in Cloud is through automation. When you adopt an Infrastructure as Code (IaC) approach, you can modularize the creation of keys in your Terraform or Ansible scripts. This lets you standardize parameters like protection level, key algorithm, rotation frequency consistently across your environment.</p><p>You can further augment this with Policy as Code (PaC) guardrails like <a href="https://www.hashicorp.com/en/sentinel">Hashicorp Sentinel</a>, <a href="https://www.pulumi.com/crossguard/">Pulumi CrossGuard</a>, or <a href="https://cloud.google.com/kubernetes-engine/enterprise/config-controller/docs/overview">Kubernetes Config Controller</a>.</p><p>However, this comes with an obvious drawback — what if not all your environments follow an IaC approach? What if developers and administrators create part of your infrastructure and keys manually?</p><p>This is where Google Cloud Organization Policies come to our rescue.</p><h4>Organization Policy Service</h4><p>The Organization Policy Service gives you centralized and programmatic control over your organization’s cloud resources. As the <a href="https://cloud.google.com/resource-manager/docs/organization-policy/using-constraints#add-org-policy-admin">organization policy administrator</a>, you can configure constraints across your entire <a href="https://cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy">resource hierarchy</a> or for specific folders / projects.</p><p>Listed below are key (pun intended) Org Policy constraints that can help you enforce KMS configuration across your Google Cloud organization.</p><ol><li><strong>Require CMEK keys — </strong>Most regulatory regimes are not comfortable with provider-managed keys. Regulated entities are expected to maintain ownership and control of keys including choice of location, protection level, access control, rotation, usage, logging and destruction. Hence, to enforce CMEK usage across your environment you can use the organization policy constraint constraints/gcp.restrictNonCmekServices to block requests to create certain resource types without specifying a CMEK key.</li><li><strong>Enforce allowed protection levels for CMEKs — </strong>Say you have a regulatory requirement to ensure that all KMS keys across your environment have a certain protection level (such as Hardware keys). You can use constraints/cloudkms.allowedProtectionLevels to enforce that new keys, key versions, and import jobs consistently use the protection levels that you allow.</li><li><strong>Require a minimum schedule for destruction duration — </strong>Google Cloud recommends that you set a minimum schedule for destruction duration. Key destruction is an irreversible operation that can result in data loss. By default, this duration is 30 days. However, it is possible for someone with the Cloud KMS Admin role to create a key with a scheduled for destruction duration as low as 24 hours, which might not be sufficient time for you to detect an issue and restore the key. Hence, to ensure that all keys created adhere to a minimum scheduled for destruction duration, you can use the organization policy constraint constraints/cloudkms.minimumDestroyScheduledDuration with your preferred duration, such as 7 days, 30 days, etc.</li><li><strong>Set a key rotation period using custom constraints</strong> — You can use a custom constraint such as demonstrated <a href="https://cloud.google.com/kms/docs/custom-org-policies#example_constraints">here</a> to enforce the maximum lifetime of a key version before it is rotated. In the example below, I use a custom constraint to ensure all KMS keys, irrespective of protection level, have a rotation period of exactly 1 year.</li></ol><pre>name: organizations/ORG_ID/customConstraints/custom.maxRotationPeriod<br>resource_types: cloudkms.googleapis.com/CryptoKey<br>method_types:<br>  - CREATE<br>  - UPDATE<br>condition: resource.rotationPeriod == duration(&#39;31536000s&#39;)<br>action_type: ALLOW<br>display_name: maxrotationperiod<br>description: Enforces keys to be rotated every 365 days</pre><h4>IAM Deny Policies</h4><p><a href="https://cloud.google.com/iam/docs/deny-overview">IAM deny policies</a> let you set guardrails on access to Google Cloud resources. You can define deny rules that prevent certain principals from using certain permissions, regardless of the roles they’re granted.</p><p>This comes in handy if you wish you protect keys from accidental deletion. For example, to ensure security keys can be deleted only by Key Admins.</p><ul><li>Create a deny rule that denies the cryptoKeyVersions.destroy permission to all users, except users in the key-admins group:</li></ul><pre>{<br>  &quot;deniedPrincipals&quot;: [<br>    &quot;principalSet://goog/public:all&quot;<br>  ],<br>  &quot;exceptionPrincipals&quot;: [<br>    &quot;principalSet://goog/group/key-admins@example.com&quot;<br>  ],<br>  &quot;deniedPermissions&quot;: [<br>    &quot;cloudkms.googleapis.com/cryptoKeyVersions.destroy&quot;,<br>  ]<br>}</pre><ul><li>Then, attach the deny policy to your organization.</li></ul><p>Now, only members of the key-admins group are able to delete keys, even if other users have the required permissions.</p><h4>Constraints to enforce key centralization</h4><p>Lastly, I am including two org policy constraints for those who aren’t convinced and wish to go down the road of centralizing encryption keys.</p><ol><li><strong>Restrict which projects may supply KMS CryptoKeys for CMEK — </strong>Centralizing keys involves defining which projects may be used to supply Customer-Managed Encryption Keys (CMEK) when creating resources. Setting the organization policy constraint constraints/gcp.restrictCmekCryptoKeyProjects to Allow (i.e. only allow CMEK keys from these projects) ensures that CMEK keys from other projects cannot be used to protect newly created resources. Say your organization is segregated by dev, test, prod — and you want the corresponding keys to be in dev-kms, test-kms, prod-kms projects held within a common folder. You can define an org-level constraint specifying that CMEK keys should come from the common folder, and folder-level constraints for the dev, test, prod environments specifying that keys should come from the respective &lt;env&gt;-kms projects.</li><li><strong>Enforce project liens</strong> — Once you have identified projects to be used for CMEK keys, we recommend that you <a href="https://cloud.google.com/resource-manager/docs/project-liens#placing_a_lien_on_a_project">protect projects with liens</a> to avoid accidental deletion. When a project lien is enforced, the Cloud KMS key project(s) are blocked from deletion until the lien is removed.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3545f541cb3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/scalable-gcp-kms-governance-minus-the-centralization-a3545f541cb3">Scalable GCP KMS Governance: Minus the Centralization</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing Cloud Run function calls from your Frontend app]]></title>
            <link>https://medium.com/google-cloud/securing-cloud-run-function-calls-from-your-frontend-app-80a0454648c1?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/80a0454648c1</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Tue, 31 Dec 2024 11:01:41 GMT</pubDate>
            <atom:updated>2025-01-03T10:23:38.295Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p>Imagine you have a headless application which makes API calls to a backend service. Cloud Run or Cloud Run functions are great options for you to host these backend services.</p><p>Authorization for Cloud Run is managed using <a href="https://cloud.google.com/security/products/iam">IAM</a> where you can grant the Cloud Run Invoker role to a principal (user or service accounts).</p><p>If these APIs originate from a trusted backend, this principal would be:</p><ul><li>a Service Account (backends on Google Cloud e.g. GCE, GKE, Run)</li><li>or Workload Identity Federation (backends outside of Google Cloud).</li></ul><p>In both options, credentials are managed and rotated within a trusted environment (metadata service operated by the cloud provider). Your application code uses these access tokens securely via client libraries.</p><h3>Problem</h3><p>The challenge arises when these API calls originate from your frontend code running on browsers or mobile apps.</p><p>If your frontend code directly embeds API keys or Service Account secrets needed to authenticate with the backend, anyone can easily inspect your code and steal those credentials. This compromises your entire backend.</p><p>Let’s examine a few options to solve this problem.</p><h3>Solutions</h3><h4><strong>Use OAuth2.0 Authentication</strong></h4><p>The ideal solution is to adopt a modern OAuth2.0 based authentication for your application.</p><p><strong>Internal Users: </strong>Let’s say your app is used by internal employees having a Google account managed within your <a href="https://cloud.google.com/identity">Cloud Identity</a> tenant. Your frontend can use the google-auth client library to obtain an ID token with the audience value as the Cloud Run function’s URL. The frontend then uses this ID token to authenticate and invoke the function securely.</p><p><strong>End Users in Identity Platform: </strong>Now imagine you have a consumer app where user identities are managed within your <a href="https://cloud.google.com/security/products/identity-platform">Identity Platform</a> tenant. In this case, you use <a href="https://cloud.google.com/iap/docs/enabling-cloud-run">IAP for Cloud Run or functions (2nd Gen)</a> with <a href="https://cloud.google.com/iap/docs/external-identities">external identities</a>.</p><p><strong>End Users with 3rd Party Logins:</strong> Asking your consumers to switch their login identities to another platform is always a daunting task. The good news is that Identity Platform supports multiple authentication methods — such as Social Logins (Google, Apple, Microsoft, Facebook, etc.) or any SAML, OIDC or custom auth provider — to provide flexible integration options for any identity solution. All you need to do is configure your Identity Platform tenant to allow sign-ins from your chosen 3rd party IdPs.</p><p><a href="https://www.googlecloudcommunity.com/gc/Community-Blogs/Securing-web-applications-in-Google-Cloud-with-external-identity/ba-p/648842">This blog</a> presents a sample server-less architecture that supports a wide range of identity providers giving you the most secure and scalable option.</p><p>If you are not ready to modify your app to adopt OAuth2.0, you can take this up as a long-term solution and look at other options in the near term.</p><blockquote>It is always advisable to use a professionally-managed identity solution instead of self-managing user databases and credentials in your app. The security benefits you gain will more than justify your re-engineering efforts.</blockquote><h4>Handling Auth in Code</h4><p>You can allow unauthenticated Cloud Run functions, and let your function code handle authentication and authorization as a short-term solution.</p><p>This is pretty much the approach you follow in a traditional backend. E.g., your app may use HTTP cookies to store a unique session identifier on the client-side, which is sent with each request to the backend. The backend validates this identifier against a database or cache to associate the request with a particular user session.</p><p><strong>Org Policy Restrictions:</strong> One of the security best practices in Google Cloud is to implement an organization policy for <a href="https://cloud.google.com/resource-manager/docs/organization-policy/domain-restricted-sharing">domain restricted sharing</a>. This prevents any resources from being publicly accessible.</p><p>You need to relax the domain restriction organization policy if you have it enforced on the project of your Cloud Run function. Since the domain restriction org policy is not retroactive, you can relax the policy for the project, make your function unauthenticated, and then re-apply the policy.</p><p>This option lets you strike a balance between agility and security — it let’s you get a reasonable level of protection with minimal re-engineering.</p><blockquote>The drawback of this approach is your function is public which means anyone on the internet can invoke it if they know the URL. While your code will process and reject any unauthorized requests, you may incur higher cloud function costs due to unauthorized invocations if someone abuses it.</blockquote><h4><strong>Adding a Web Application Firewall</strong></h4><p>In case your Cloud Run function processes confidential or sensitive data (which makes the previous option unacceptable to security or audit teams), you can implement an additional layer of network security.</p><p>A Web Application Firewall can be this additional layer to safeguard your backend APIs. Use it to scrub incoming requests for DDoS and application attacks or other Layer 7 attributes to block abusive traffic.</p><p><a href="https://cloud.google.com/armor/docs/cloud-armor-overview">Google Cloud Armor</a> is a web-application firewall where you can configure filters like IPs, geolocations, rate-limits, headers for incoming requests before it reaches your load-balanced backend services. Examples include:</p><ul><li>Blocking requests from specific countries;</li><li>Allowing requests only from specific IP address ranges;</li><li>Blocking requests without a matching header, host or path value;</li><li>Limiting requests from any source exceeding a specific threshold;</li><li>Blocking requests that match OWASP Top 10 attack signatures.</li></ul><p>You architect this by creating a <a href="https://cloud.google.com/load-balancing/docs/negs/serverless-neg-concepts">Serverless NEG</a> that points to your Cloud Run function service. You then configure this NEG as a backend service that sits behind a Global External application load balancer. Finally, you associate a <a href="https://cloud.google.com/armor/docs/cloud-armor-overview">Cloud Armor</a> security policy with this backend service.</p><blockquote>Do not forget to restrict ingress for your Cloud Run function to “internal and cloud load balancing”. This will ensure that any requests sent directly to your function’s URL are blocked.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lC5pyH6NN2QHlR5zeoPTew.png" /><figcaption>Securing Serverless Backends</figcaption></figure><h3>Conclusion</h3><p>This blog explored some critical aspects of securing Cloud Run function calls from your frontend app.</p><p>Relying on API keys or embedded secrets is a major security risk. While short-term solutions like handling authentication within your function code or using a WAF can offer reasonable protection, migrating to a robust identity solution with OAuth2.0 is the ideal long-term strategy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80a0454648c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/securing-cloud-run-function-calls-from-your-frontend-app-80a0454648c1">Securing Cloud Run function calls from your Frontend app</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Cloud Storage Signed URLs with Workload Identity Federation]]></title>
            <link>https://medium.com/google-cloud/google-cloud-storage-signed-urls-with-workload-identity-federation-74e6d5a1e774?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/74e6d5a1e774</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[signed-urls]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[infrastructure]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Mon, 02 Dec 2024 09:44:50 GMT</pubDate>
            <atom:updated>2024-12-02T15:16:29.384Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p>Creating Signed URLs in Google Cloud can be simple. You follow the instructions on <a href="https://cloud.google.com/storage/docs/access-control/signing-urls-with-helpers">this page</a> and use the client libraries for your favorite programming language. No sweat, right?</p><p>This method of using Google Cloud CLI and Cloud Storage client libraries to create signed URLs, requires a service account key file.</p><blockquote>You can not use this if you are using Application Default Credentials from Google Compute Engine or from the Google Cloud SDK.</blockquote><p><a href="https://cloud.google.com/iam/docs/best-practices-service-accounts">Google Cloud security best-practices</a> strongly recommend that you avoid using service account keys whenever possible. Service account keys can become a security risk if not managed carefully. You should <a href="https://cloud.google.com/docs/authentication#auth-decision-tree">choose a more secure alternative for authentication</a> whenever possible.</p><blockquote>Like a username and password, service account keys are a form of credential. If a user can access a valid service account key, they can use it to authenticate and access the resources the respective service account has been granted access to.</blockquote><p>The best way to mitigate this threat is to <a href="https://cloud.google.com/iam/docs/best-practices-service-accounts#service-account-keys">avoid user-managed service account keys</a> and to use <a href="https://cloud.google.com/iam/docs/best-practices-service-accounts#using_service_accounts">other methods to authenticate service accounts</a>.</p><p>This blog shows how to generate Signed URLs following security best-practices by using <a href="https://cloud.google.com/iam/docs/workload-identity-federation">Workload Identity Federation</a>. I will use an AWS Lambda function, but the concept can be successfully applied to any environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*bZX9XFbcH2zh5RqlynC4aw.png" /><figcaption>Workload Identity Federation</figcaption></figure><h3>Pre-requisites</h3><p>Create a Workload Identity Federation setup with AWS Lambda using the steps mentioned <a href="https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds">here</a>. While configuring this setup, make sure you:</p><ul><li>Create a mapping for the aws_role attribute (as shown below).</li></ul><pre>attribute.aws_role=assertion.arn.extract(&#39;assumed-role/{role}/&#39;)</pre><ul><li>Grant the Workload Identity User role on your Google Cloud service account to the workload identity pool principalSet where the attribute aws_role matches the execution role of your Lambda function.</li></ul><pre>principalSet://iam.googleapis.com/projects/<em>PROJECT_ID</em>/locations/global/workloadIdentityPools/<em>WIF_POOL_ID</em>/attribute.aws_role/<em>AWS_IAM_ROLE_NAME</em></pre><p>Once created, download the resulting Client Library Config file and store it as credentials.json. You will need it to connect to Google Cloud APIs from your application.</p><h3><strong>Creating the Lambda Deployment Package</strong></h3><p>First, let’s create a simple Python application to generate Signed URLs.</p><p>Create the following files in a directory using your favorite editor.</p><pre>mkdir lambda &amp;&amp; cd lambda</pre><p><strong>requirements.txt</strong></p><pre>six<br>google-cloud-iam</pre><p><strong>lambda_function.py</strong></p><pre>import os<br>import sys<br>import collections<br>import datetime<br>import hashlib<br>from urllib.parse import quote<br><br># pip install six<br>import six<br><br># pip install google-cloud-iam<br>from google.oauth2 import service_account<br>from google.cloud import iam_credentials_v1<br><br>def generate_signed_blob(service_account_email, payload_blob):<br>    # Create an IAM client<br>    client = iam_credentials_v1.IAMCredentialsClient()<br><br>    # Initialize request argument(s)<br>    request = iam_credentials_v1.SignBlobRequest(<br>        name=f&quot;projects/-/serviceAccounts/{service_account_email}&quot;,<br>        payload=payload_blob.encode(),<br>    )<br><br>    # Make the request<br>    signed_blob = client.sign_blob(request=request)<br><br>    # Handle the response<br>    return signed_blob<br><br>def generate_signed_url(https://medium.com/%3Cbr%3E%20%20%20%20service_account_email,%3Cbr%3E%20%20%20%20bucket_name,%3Cbr%3E%20%20%20%20object_name,%3Cbr%3E%20%20%20%20subresource=None,%3Cbr%3E%20%20%20%20expiration=900,%3Cbr%3E%20%20%20%20http_method=&quot;GET&quot;,%3Cbr%3E%20%20%20%20query_parameters=None,%3Cbr%3E%20%20%20%20headers=None,%3Cbr%3E):<br>    if expiration &gt; 604800:<br>        print(&quot;Expiration Time can&#39;t be longer than 604800 seconds (7 days).&quot;)<br>        sys.exit(1)<br><br>    escaped_object_name = quote(six.ensure_binary(object_name), safe=b&quot;/~&quot;)<br>    canonical_uri = f&quot;/{escaped_object_name}&quot;<br><br>    datetime_now = datetime.datetime.now(tz=datetime.timezone.utc)<br>    request_timestamp = datetime_now.strftime(&quot;%Y%m%dT%H%M%SZ&quot;)<br>    datestamp = datetime_now.strftime(&quot;%Y%m%d&quot;)<br><br>    credential_scope = f&quot;{datestamp}/auto/storage/goog4_request&quot;<br>    credential = f&quot;{service_account_email}/{credential_scope}&quot;<br><br>    if headers is None:<br>        headers = dict()<br>    host = f&quot;{bucket_name}.storage.googleapis.com&quot;<br>    headers[&quot;host&quot;] = host<br><br>    canonical_headers = &quot;&quot;<br>    ordered_headers = collections.OrderedDict(sorted(headers.items()))<br>    for k, v in ordered_headers.items():<br>        lower_k = str(k).lower()<br>        strip_v = str(v).lower()<br>        canonical_headers += f&quot;{lower_k}:{strip_v}\n&quot;<br><br>    signed_headers = &quot;&quot;<br>    for k, _ in ordered_headers.items():<br>        lower_k = str(k).lower()<br>        signed_headers += f&quot;{lower_k};&quot;<br>    signed_headers = signed_headers[:-1]  # remove trailing &#39;;&#39;<br><br>    if query_parameters is None:<br>        query_parameters = dict()<br>    query_parameters[&quot;X-Goog-Algorithm&quot;] = &quot;GOOG4-RSA-SHA256&quot;<br>    query_parameters[&quot;X-Goog-Credential&quot;] = credential<br>    query_parameters[&quot;X-Goog-Date&quot;] = request_timestamp<br>    query_parameters[&quot;X-Goog-Expires&quot;] = expiration<br>    query_parameters[&quot;X-Goog-SignedHeaders&quot;] = signed_headers<br>    if subresource:<br>        query_parameters[subresource] = &quot;&quot;<br><br>    canonical_query_string = &quot;&quot;<br>    ordered_query_parameters = collections.OrderedDict(sorted(query_parameters.items()))<br>    for k, v in ordered_query_parameters.items():<br>        encoded_k = quote(str(k), safe=&quot;&quot;)<br>        encoded_v = quote(str(v), safe=&quot;&quot;)<br>        canonical_query_string += f&quot;{encoded_k}={encoded_v}&amp;&quot;<br>    canonical_query_string = canonical_query_string[:-1]  # remove trailing &#39;&amp;&#39;<br><br>    canonical_request = &quot;\n&quot;.join(<br>        [<br>            http_method,<br>            canonical_uri,<br>            canonical_query_string,<br>            canonical_headers,<br>            signed_headers,<br>            &quot;UNSIGNED-PAYLOAD&quot;,<br>        ]<br>    )<br><br>    canonical_request_hash = hashlib.sha256(canonical_request.encode()).hexdigest()<br><br>    string_to_sign = &quot;\n&quot;.join(<br>        [<br>            &quot;GOOG4-RSA-SHA256&quot;,<br>            request_timestamp,<br>            credential_scope,<br>            canonical_request_hash,<br>        ]<br>    )<br><br>    signature = generate_signed_blob(service_account_email,string_to_sign).signed_blob.hex()<br>    <br>    scheme_and_host = &quot;{}://{}&quot;.format(&quot;https&quot;, host)<br>    signed_url = &quot;{}{}?{}&amp;x-goog-signature={}&quot;.format(<br>        scheme_and_host, canonical_uri, canonical_query_string, signature<br>    )<br><br>    return signed_url<br><br>def lambda_handler(event, context):<br>    <br>    print(&#39;Loading function...&#39;)<br>    <br>    os.environ[&quot;GOOGLE_CLOUD_PROJECT&quot;] = event[&#39;project_id&#39;]<br>    os.environ[&quot;GOOGLE_APPLICATION_CREDENTIALS&quot;] = &quot;credentials.json&quot;<br><br>    sa_email    = event[&#39;sa_email&#39;]<br>    bucket_name = event[&#39;bucket_name&#39;]<br>    object_name = event[&#39;object_name&#39;]<br><br>    signed_url   = generate_signed_url(https://medium.com/sa_email,%20bucket_name,%20object_name,%20subresource=None,%20expiration=900,%20http_method=&quot;GET&quot;,%20query_parameters=None,%20headers=None,)<br>    <br>    return { <br>        &#39;signed_url&#39; : signed_url<br>    }</pre><p><strong>credentials.json</strong></p><p>Move the credentials.json file you created in the previous step to the current directory.</p><p>Once the program files have been created, execute the commands below in your local Linux terminal to create the Lambda deployment package.</p><pre>#create and activate a virtual environment in your project directory<br>sudo apt install python3.11-venv<br>python3 -m venv .venv<br>source .venv/bin/activate<br><br>#install your required libraries using pip<br>pip install -r requirements.txt<br><br>#deactivate the virtual environment<br>deactivate<br><br>#navigate into the directory containing the libraries installed with pip<br>cd .venv/lib/python3.11/site-packages<br><br>#install the zip utility<br>sudo apt-get install zip<br><br>#create a .zip file in your project directory with the installed dependencies at the root<br>zip -r ../../../../my_deployment_package.zip .<br><br>#move back to the project directory where your .py file is located<br>cd ../../../../<br><br>#add the python function to the root of your .zip package<br>zip my_deployment_package.zip lambda_function.py<br><br>#add the workload identity config to the root of your .zip package<br>zip my_deployment_package.zip credentials.json</pre><h3>Creating the AWS Lambda Function</h3><h4>Create a Lambda Function</h4><p>Visit the AWS Management Console and create a Lambda Function using the “Author from scratch” option and the following configuration:</p><ul><li>Function name as signed-url-demo</li><li>Runtime as Python 3.11 (matching our python virtual environment)</li><li>Execution role as the aws_role you configured in Workload Identity Federation trust relationship</li><li>Timeout configuration as 30 seconds</li></ul><p>Once the function is created, use the “Upload from .zip file” option and select the my_deployment_package.zip file from your project directory.</p><h3>Test and Verify</h3><p>Under the “Test” section, create a Test event such as the sample below. Replace values from that of your Google Cloud Storage setup.</p><pre>{<br>  &quot;project_id&quot;  : &quot;PROJECT_ID&quot;,<br>  &quot;sa_email&quot;    : &quot;wif-demo@PROJECT_ID.iam.gserviceaccount.com&quot;,<br>  &quot;bucket_name&quot; : &quot;pensande_test_bucket&quot;,<br>  &quot;object_name&quot; : &quot;Sandeep PAN.pdf&quot;<br>}</pre><p>Click on Test button. If everything is set up correctly, you’ll see the following output on the console with the signed_url.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oXToXdqaCnjmTTRvUQxsBQ.png" /></figure><p>Finally, I use the signed_url in an incognito browser to view the object. \o/</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*WKfjVGcyX5sEu8gc6tSEPg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74e6d5a1e774" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/google-cloud-storage-signed-urls-with-workload-identity-federation-74e6d5a1e774">Google Cloud Storage Signed URLs with Workload Identity Federation</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing Signed URL Risks in Google Cloud]]></title>
            <link>https://medium.com/google-cloud/managing-signed-url-risks-in-google-cloud-4d256bd58735?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d256bd58735</guid>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[signed-urls]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Thu, 31 Oct 2024 13:55:01 GMT</pubDate>
            <atom:updated>2024-11-04T09:00:45.626Z</atom:updated>
            <content:encoded><![CDATA[<h3>What are Signed URLs?</h3><p><a href="https://cloud.google.com/storage/docs/access-control/signed-urls">Signed URLs</a> are a great way to grant limited-time access to private content stored in Google Cloud Storage (GCS) buckets.</p><p>Let’s say, you want users to directly read or write objects in GCS buckets without requiring them to have a Google account. You can do this by using your application-specific logic to provide a signed URL to a user, which gives them read, write, or delete access to that resource for a limited time.</p><p>There are 2 types of signed requests in Cloud Storage — <a href="https://cloud.google.com/storage/docs/authentication/hmackeys">HMAC-signed URLs</a> and <a href="https://cloud.google.com/storage/docs/access-control/signing-urls-with-helpers">RSA-signed URLs</a>.</p><h3>Risks with Signed URLs</h3><p>Signed URLs contain authentication information in their query string, allowing users without credentials to perform specific actions on a resource. Once generated, anyone who knows the URL can access the resource until the expiration time for the URL is reached or the key used to sign the URL is rotated.</p><p>This behavior poses a security risk, as it allows a malicious insider to generate and share signed URLs, potentially granting unauthorized access to sensitive GCS resources.</p><h3>Mitigating Risks with Signed URLs</h3><p>Below are a few controls to manage risks associated with signed URLs.</p><h4><strong>Detecting Usage of Signed URLs</strong></h4><p>You can detect signed URL requests across both HMAC and RSA authentication types by using the pre-built authn/authentication_count storage metric available in Cloud Monitoring. For details, refer <a href="https://cloud.google.com/monitoring/api/metrics_gcp#gcp-storage">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1BD6DvXkdWNoZFdjqE_tTA.png" /><figcaption>Metric that counts project-wide HMAC/RSA signed requests</figcaption></figure><p>You can also configure metric-based alerts should you wish to be notified any time such requests cross a particular threshold. For details, refer <a href="https://cloud.google.com/monitoring/alerts/using-alerting-ui">here</a>.</p><p>Further, Signed URL requests record the credentials used to create them. This lets you identify misuse by checking <a href="https://cloud.google.com/logging/docs/audit#data-access">Data Access audit logs</a>. However, these logs are disabled by default (except for BigQuery). To track Cloud Storage access with these logs, you must <a href="https://cloud.google.com/logging/docs/audit/configure-data-access">explicitly enable them</a> for a cost.</p><h4><strong>Preventing Creation of Signed URLs</strong></h4><p><strong>HMAC-signed URLs</strong> — You can use the pre-built org policy constraint constraints/storage.restrictAuthTypes to restrict requests signed by HMAC keys and apply it at the organization level. For details, refer <a href="https://cloud.google.com/storage/docs/org-policy-constraints#restrict-auth-types">here</a>.</p><blockquote>You can restrict requests signed by service account HMAC keys, user account HMAC keys, or both. HMAC keys of the restricted type can no longer be created or activated in the resource that the constraint is enforced upon. Existing HMAC keys remain but are no longer usable. They can be deactivated or deleted, but cannot be reactivated.</blockquote><p><strong>RSA-signed URLs</strong> — As of date, the only way to prevent creation of RSA-signed URLs is to not give someone the <a href="https://cloud.google.com/storage/docs/access-control/signing-urls-with-helpers#roles-and-permissions">relevant read/write permissions</a> for Cloud Storage. There are no specific permissions exclusively to create signed URLs. Principals that have permissions to get/create/delete storage objects can create corresponding signed URLs.</p><blockquote>Arguably, if a principal already has access, then whether they do it directly or via creating a signed-URL is a moot point.</blockquote><h4>Preventing Usage of Signed URLs</h4><p>Signed-URLs are bound by any <a href="https://cloud.google.com/vpc-service-controls/docs/overview">VPC Service Controls</a> that you define. Hence, you can mitigate the risk of data exfiltration via signed URLs by creating a <a href="https://cloud.google.com/vpc-service-controls/docs/service-perimeters">service perimeter</a> that includes the Cloud Storage API as a protected service. Doing so will block access to storage objects from outside the perimeter.</p><p>You can optionally <a href="https://cloud.google.com/vpc-service-controls/docs/use-access-levels">allow controlled access to protected services from <em>outside</em> the perimeter</a>, via <strong>access levels</strong>. An access level defines a set of attributes that must be met for a request to be honored. Access levels can include various criteria, such as IP address, user or device identity. Doing so will only allow signed requests that meet the criteria you specify.</p><h3>Conclusion</h3><p>Signed URLs are a useful tool for scenarios where you want to balance security with utility. This blog identifies mitigation controls for customers for whom the security risks of signed URLs outweigh its benefits.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d256bd58735" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/managing-signed-url-risks-in-google-cloud-4d256bd58735">Managing Signed URL Risks in Google Cloud</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Aadhaar Data Vault on Google Cloud can be 10x simpler than in AWS]]></title>
            <link>https://medium.com/google-cloud/aadhaar-data-vault-on-google-cloud-can-be-10x-simpler-than-in-aws-eea996dca988?source=rss-38ee85bb35ac------2</link>
            <guid isPermaLink="false">https://medium.com/p/eea996dca988</guid>
            <category><![CDATA[aadhaar]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[gcp-security-operations]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Sandeep Agarwal]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 08:31:47 GMT</pubDate>
            <atom:updated>2024-09-21T09:26:13.912Z</atom:updated>
            <content:encoded><![CDATA[<p>I always credit Amazon Web Services (AWS) for having introduced me to the fascinating world of cloud computing. Several individuals at AWS have shaped my philosophy not just on cloud security, but security in general.</p><p>In this case, my ex-colleagues at AWS who wrote <a href="https://aws.amazon.com/blogs/publicsector/build-aadhaar-data-vault-aws/">this blog</a> inspired me to think how a similar <a href="https://uidai.gov.in/images/resource/FAQs_Aadhaar_Data_Vault_v__1_0_13122017.pdf">Aadhaar Data Vault</a> (ADV) may look on Google Cloud.</p><p>It turns out that implementing Aadhaar Data Vault on Google Cloud can be much simpler, scalable, cost-effective and highly-secure.</p><h3>Aadhaar Data Vault</h3><p>Keeping in view the security and privacy of Aadhaar data, the <a href="https://uidai.gov.in/">UIDAI</a> makes it compulsory to store all collected Aadhaar numbers in a centralized dedicated storage in encrypted form identified as <strong>Aadhaar Data Vault (ADV)</strong>. Any service/application that stores Aadhaar numbers must do so in such secure and encrypted ADV system.</p><h3>Solution Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tsTm-Mzid-_AmTZV4sNVuA.png" /><figcaption>Aadhaar Data Vault Architecture on Google Cloud</figcaption></figure><h3>Solution Components</h3><ol><li><a href="https://cloud.google.com/sensitive-data-protection/docs/apis"><strong>Cloud DLP API</strong></a> allows you to de-identify and re-identify sensitive data synchronously through stateless transformation methods from custom workloads, applications, or pipelines. Our solution uses DLP (now Sensitive Data Protection) to tokenize/detokenize Aadhaar numbers.</li><li><a href="https://cloud.google.com/security/products/secret-manager"><strong>Secret Manager</strong></a> offers a secure and convenient storage system for API keys, passwords, certificates, etc. Our solution uses Secret Manager to store the wrapped 256-bit AES key used in DLP tokenization operations.</li><li><a href="https://cloud.google.com/kms/docs/hsm"><strong>Cloud KMS</strong></a>, offers a cloud-hosted Hardware Security Module (HSM) service to host encryption keys and perform cryptographic operations in a cluster of <a href="https://csrc.nist.gov/publications/detail/fips/140/2/final">FIPS 140–2 Level 3</a> certified HSMs. Our solution uses HSM keys to wrap/unwrap the AES key used in DLP tokenization operations.</li><li><a href="https://cloud.google.com/run"><strong>Cloud Run</strong></a> is a fully managed platform that enables you to run your code directly on top of Google’s scalable infrastructure. Our solution uses Run to host the app backend for the Aadhaar Data Vault service.</li><li><a href="https://cloud.google.com/security/products/iap"><strong>Identity Aware Proxy</strong></a> (IAP) uses identity and context to guard access to your applications. Our solution uses IAP to manage access to the Aadhaar Data Vault service.</li><li><a href="https://cloud.google.com/load-balancing/docs/l7-internal"><strong>Internal Application Load Balancer</strong></a> (ILB) is a proxy-based layer 7 load balancer that distributes HTTP(S) traffic to backends hosted on a variety of compute platforms such as GCE, GKE, and Cloud Run. Our solution uses ILB to front-end requests to the Aadhaar Data Vault service.</li><li><a href="https://cloud.google.com/vpc/docs/configure-private-service-connect-producer"><strong>Private Service Connect</strong></a> (PSC)<strong> </strong>helps a service producer to publish services that are accessible to service consumers by using internal IP addresses in the consumer VPC networks. Our solution uses PSC to achieve private, secure connectivity to the Aadhaar Data Vault service.</li><li><strong>App Project</strong> hosts the Consumer VPC network with a Compute Engine VM-based application. The VM connects to the Aadhaar Data Vault service using a <a href="https://cloud.google.com/vpc/docs/about-accessing-vpc-hosted-services-endpoints">PSC endpoint</a> to tokenize/de-tokenize Aadhaar numbers.</li></ol><h3>Benefits</h3><p>The entire Aadhaar Data Vault solution is serverless which accrues the following benefits for your business.</p><ol><li><strong>Management</strong> — Google manages the underlying infrastructure, patching, high-availability of these components so that developers can focus on writing code and optimizing business logic instead of managing servers. For example, with Cloud HSM, Google manages a fleet of HSMs running in a Region, so you don’t need to worry about clustering, scaling, or patching.</li><li><strong>Security</strong> — Our solution does not store Aadhaar numbers anywhere. There are no databases, key-value pairs or any other storage where sensitive Aadhaar Data is persisted in clear text. DLP <a href="https://cloud.google.com/sensitive-data-protection/docs/concepts-method-types#content-methods">content methods</a> do not store your data on Google Cloud. Your request data is processed synchronously and statelessly in memory and is not cached.</li><li><strong>Scalability</strong> — Serverless solutions can scale up and down automatically in response to traffic. Our solution can easily serve tens of millions of requests without any changes to your infrastructure or architecture.</li><li><strong>Cost-efficient</strong> — Serverless means you only pay per use, and save money by avoiding infrastructure costs. For example, Cloud HSM charges $1.00 per month per key versus AWS’s $2.05 per hour per HSM. Accounting for resiliency, the cost for a cluster of AWS HSMs can easily run into upwards of $3000 per month. Add to it the cost of components such as RDS database and management instances, you are easily talking several thousand $s per month <em>whether or not the service is utilized</em>.</li></ol><h3>Deployment</h3><h4>Creating the App Backend Container Image</h4><p>Create the following files that serves as the app backend for the service.</p><p><strong>src/requirements.txt</strong></p><pre>Flask<br>gunicorn<br>google-cloud-dlp<br>google-auth<br>cryptography</pre><p><strong>src/aadhaar-vault-demo.py</strong></p><pre>import os<br>from flask import Flask, request, jsonify<br>from google.cloud import dlp<br>from google.auth.transport import requests<br>from google.oauth2 import id_token<br><br>import logging<br>logger = logging.getLogger(__name__)<br>logging.basicConfig(level=logging.INFO)<br><br># read os environment variables<br>KMS_KEY       = os.environ.get(&#39;KMS_KEY&#39;)<br>WRAPPED_KEY   = os.environ.get(&#39;WRAPPED_KEY&#39;)<br>PROJECT_NAME  = os.environ.get(&#39;PROJECT_NAME&#39;)<br>REGION_NAME   = os.environ.get(&#39;REGION_NAME&#39;)<br>parent        = f&quot;projects/{PROJECT_NAME}/locations/{REGION_NAME}&quot;<br><br># create a dlp client for this project<br>dlp_client = dlp.DlpServiceClient()<br><br>app = Flask(__name__)<br><br>def tokenize(content):<br>  # The infoTypes of information to match<br>  INFO_TYPES = [&#39;INDIA_AADHAAR_INDIVIDUAL&#39;]<br>  inspect_config = {&quot;info_types&quot;: [{&quot;name&quot;: info_type} for info_type in INFO_TYPES]}<br>  deidentify_config = {<br>    &quot;info_type_transformations&quot;: {<br>      &quot;transformations&quot;: [<br>        {<br>          &quot;info_types&quot;: [{&quot;name&quot;: info_type} for info_type in INFO_TYPES],<br>          &quot;primitive_transformation&quot;: {<br>            &quot;crypto_deterministic_config&quot;: {<br>              &quot;crypto_key&quot;: {<br>                &quot;kms_wrapped&quot;: {<br>                  &quot;crypto_key_name&quot;: KMS_KEY,<br>                  &quot;wrapped_key&quot;: WRAPPED_KEY<br>                }<br>              },<br>              &quot;surrogate_info_type&quot;: {<br>                &quot;name&quot;: &quot;TOKENIZED_VALUE&quot;<br>              }<br>            }<br>          }<br>        }<br>      ]<br>    }<br>  }<br><br>  response_text = dlp_client.deidentify_content(<br>    request={<br>      &quot;parent&quot;: parent,<br>      &quot;deidentify_config&quot;: deidentify_config,<br>      &quot;inspect_config&quot;: inspect_config,<br>      &quot;item&quot;: {&quot;value&quot;: content},<br>    }<br>  )<br>  return jsonify( { &quot;dlp_response&quot;:  response_text.item.value } )<br><br>def detokenize(content):<br>  # The infoTypes of information to match<br>  inspect_config = {&quot;custom_info_types&quot;: [{&quot;info_type&quot;: {&quot;name&quot;: &quot;TOKENIZED_VALUE&quot;},&quot;surrogate_type&quot;: {}}]}<br>  reidentify_config = {<br>    &quot;info_type_transformations&quot;: {<br>      &quot;transformations&quot;: [<br>        {<br>          &quot;info_types&quot;: [{&quot;name&quot;: &quot;TOKENIZED_VALUE&quot;}],<br>          &quot;primitive_transformation&quot;: {<br>            &quot;crypto_deterministic_config&quot;: {<br>              &quot;crypto_key&quot;: {<br>                &quot;kms_wrapped&quot;: {<br>                  &quot;crypto_key_name&quot;: KMS_KEY,<br>                  &quot;wrapped_key&quot;: WRAPPED_KEY<br>                }<br>              },<br>              &quot;surrogate_info_type&quot;: {<br>                &quot;name&quot;: &quot;TOKENIZED_VALUE&quot;<br>              }<br>            }<br>          }<br>        }<br>      ]<br>    }<br>  }<br><br>  response_text = dlp_client.reidentify_content(<br>    request={<br>      &quot;parent&quot;: parent,<br>      &quot;reidentify_config&quot;: reidentify_config,<br>      &quot;inspect_config&quot;: inspect_config,<br>      &quot;item&quot;: {&quot;value&quot;: content},<br>    }<br>  )<br>  return jsonify( { &quot;dlp_response&quot;:  response_text.item.value } )<br><br>def validate_creds(type, creds, expected_audience):<br>    try:<br>      if type == &quot;iap&quot;:<br>        decoded_jwt = id_token.verify_token(<br>          creds,<br>          requests.Request(),<br>          audience=expected_audience,<br>          certs_url=&quot;https://www.gstatic.com/iap/verify/public_key&quot;,<br>        )<br>      else:<br>        decoded_jwt = id_token.verify_oauth2_token(<br>          creds,<br>          requests.Request(),<br>          audience=expected_audience,<br>        )<br><br>      return decoded_jwt[&quot;email&quot;]<br>      <br>    except Exception as e:<br>        return f&quot;**ERROR: JWT validation error {e}**&quot;<br><br>@app.route(&#39;/&#39;, methods=[&#39;POST&#39;, &#39;GET&#39;])<br>def aadhaar_vault():<br>  try:<br>    # identify who triggered the iap service<br>    if &quot;x-goog-iap-jwt-assertion&quot; in request.headers:<br>      iap_jwt = request.headers.get(&quot;x-goog-iap-jwt-assertion&quot;)<br>      iap_email = validate_creds(&quot;iap&quot;, iap_jwt, None)<br>    else:<br>      iap_email = &quot;IAP header not present&quot;<br><br>    if &quot;X-Goog-Authenticated-User-Email&quot; in request.headers:<br>      user_header = request.headers.get(&quot;X-Goog-Authenticated-User-Email&quot;)<br>    else:<br>      user_header = &quot;User header not present&quot;<br><br>    # identify who triggered the cloud run service<br>    if &quot;X-Serverless-Authorization&quot; in request.headers:<br>      auth_header = request.headers.get(&quot;X-Serverless-Authorization&quot;)<br>    elif &quot;Authorization&quot; in request.headers:<br>      auth_header = request.headers.get(&quot;Authorization&quot;)<br>    else:<br>      auth_header = &quot;Anonymous Token&quot;<br><br>    # split the auth type and value from the header.<br>    auth_type, auth_jwt = auth_header.split(&quot; &quot;, 1)<br><br>    # extract the email claim from the jwt<br>    if auth_type.lower() == &quot;bearer&quot;:<br>      auth_email = validate_creds(&quot;oauth&quot;, auth_jwt, None)<br>    else:<br>      auth_email = f&quot;Unhandled header format ({auth_type})&quot;<br><br>    if request.method == &#39;POST&#39;:<br>      request_json  = request.get_json()<br>      mode          = request_json[&#39;mode&#39;]<br>      content       = request_json[&#39;content&#39;]<br>      <br>      logger.info(f&quot;Processing {mode} request by IAP User: {iap_email} User: {user_header}, Run User: {auth_email}!&quot;)<br><br>      if mode == &quot;tokenize&quot;:<br>        return tokenize(content)<br>      elif mode == &quot;detokenize&quot;:<br>        return detokenize(content)<br>      else:<br>        return jsonify({&quot;dlp_response&quot;:  &quot;unrecognized mode&quot;})<br>    else:<br>        logger.info(f&quot;Saying &#39;Hi&#39; to IAP User: {iap_email} User: {user_header}, Run User: {auth_email}!&quot;)<br>        return jsonify({&quot;dlp_response&quot;:  &quot;hello from aadhaar vault!&quot;})<br>  except Exception as e:<br>    return jsonify( { &quot;errorMessage&quot;: str(e) } ), 400<br><br>if __name__ == &quot;__main__&quot;:<br>  app.run(host=&quot;0.0.0.0&quot;, port=int(os.environ.get(&#39;PORT&#39;, 8080)), debug=True)</pre><p><strong>Dockerfile</strong></p><pre>FROM python:3.12-alpine<br>COPY ./src /src<br>WORKDIR /src<br>RUN pip3 install -r requirements.txt<br>CMD python3 aadhaar-vault-demo.py</pre><p>To build the container and store the resulting image in Artifact Registry, run the following command from the directory containing the Dockerfile.</p><pre>gcloud builds submit --region=asia-south1 --tag asia-south1-docker.pkg.dev/PROJECT_ID/REPO_NAME/aadhaar-vault-demo:latest</pre><p>Note the sha256 image digest value from the resulting output. You will need to specify this value in your Cloud Run service configuration.</p><h4>Deploying the Aadhaar Data Vault Solution</h4><p>You can deploy the solution using the Terraform code <a href="https://github.com/pensande/solutions-terraform-cloudbuild-gitops/blob/dev/environments/dev/main.tf#L1540-L1873">here</a>. You may want to customize and replace certain variables to make it work for your setup.</p><p>Generate a base-64 encoded AES key and wrap it using the HSM key using <a href="https://cloud.google.com/sensitive-data-protection/docs/create-wrapped-key">these instructions</a>. Store the wrapped AES key in the Secret Manager <a href="https://cloud.google.com/secret-manager/docs/add-secret-version">secret</a>.</p><blockquote>Delete the unwrapped AES key from all systems ensuring it can only be used in DLP tokenization operations with HSM keys of our Aadhaar Data Vault service.</blockquote><h4>Preparing the Consumer environment</h4><p>Create a VM inside the Consumer VPC which has the PSC attachment to our Aadhaar Data Vault service.</p><p>Then, login to the VM and create a DNS entry in the /etc/hosts file that resolves the domain aadhaarvault.com to the PSC attachment’s private IP address. For production usage, I recommend you create a <a href="https://cloud.google.com/dns/docs/zones#create-private-zone">private DNS zone</a> for your VPC network using Cloud DNS.</p><h4>Connecting to the Aadhaar Data Vault service</h4><p>Grant the VM’s service account the IAP-secured Web App User role on the IAP-enabled backend service. You can then access the Aadhaar Data Vault service programmatically using the following Python function.</p><pre>from google.auth.transport.requests import Request<br>from google.oauth2 import id_token<br>import requests<br>import os<br>import json<br><br>def make_iap_request(url, client_id, method, json_data, **kwargs):<br>    &quot;&quot;&quot;<br>    Args:<br>      url:       &#39;https://aadhaarvault.com&#39; - The Identity-Aware Proxy-protected URL to fetch<br>      client_id: The client ID used by Identity-Aware Proxy.<br>      method:    &#39;POST&#39;<br>      json_data: json string {&quot;mode&quot;:&quot;USER_MODE&quot;,&quot;content&quot;:&quot;USER_CONTENT&quot;} <br>          where USER_MODE could be &quot;tokenize&quot; or &quot;detokenize&quot;.<br>    &quot;&quot;&quot;<br>    # Set the default timeout, if missing<br>    if &quot;timeout&quot; not in kwargs:<br>        kwargs[&quot;timeout&quot;] = 90<br><br>    # Obtain an OpenID Connect (OIDC) token from metadata server or using service account.<br>    open_id_connect_token = id_token.fetch_id_token(Request(), client_id)<br><br>    # Fetch the Identity-Aware Proxy-protected URL, <br>    # using the Google-issued OpenID Connect token for the service account.<br>    resp = requests.request(<br>        method,<br>        url,<br>        headers={&quot;Authorization&quot;: &quot;Bearer {}&quot;.format(open_id_connect_token),&quot;Content-Type&quot;: &quot;application/json&quot;},<br>        data=json_data,<br>        verify=False,<br>        **kwargs<br>    )<br>    if resp.status_code == 403:<br>        raise Exception(<br>            &quot;Service account does not have permission to access the IAP-protected application.&quot;<br>        )<br>    elif resp.status_code != 200:<br>        raise Exception(<br>            &quot;Bad response from application: {!r} / {!r} / {!r}&quot;.format(<br>                resp.status_code, resp.headers, resp.text<br>            )<br>        )<br>    else:<br>        return resp.text</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eea996dca988" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/aadhaar-data-vault-on-google-cloud-can-be-10x-simpler-than-in-aws-eea996dca988">Aadhaar Data Vault on Google Cloud can be 10x simpler than in AWS</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>