<?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 Somesh Srivastava on Medium]]></title>
        <description><![CDATA[Stories by Somesh Srivastava on Medium]]></description>
        <link>https://medium.com/@someshsrivastava1983?source=rss-71f8e1d56be5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AU-DTE0o1Cjz8MxGTe-Anw.jpeg</url>
            <title>Stories by Somesh Srivastava on Medium</title>
            <link>https://medium.com/@someshsrivastava1983?source=rss-71f8e1d56be5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:25:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@someshsrivastava1983/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[How to retain the same RDS Endpoint after restoring the DB instance, without having to alter any…]]></title>
            <link>https://someshsrivastava1983.medium.com/how-to-retain-the-same-rds-endpoint-after-restoring-the-db-instance-without-having-to-alter-any-88ef71b8b029?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/88ef71b8b029</guid>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws-database]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 17:33:59 GMT</pubDate>
            <atom:updated>2022-06-21T17:33:59.806Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to retain the same RDS Endpoint after restoring the DB instance, without having to alter any application code</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*1eenvqYjm_juhK56u3Imcg.png" /></figure><p>RDS DB snapshot helps us backing up the DB instance. As per the official AWS documentation:</p><blockquote>Amazon RDS creates a storage volume snapshot of your DB instance, backing up the entire DB instance and not just individual databases.</blockquote><p>When restoring from the DB instance from the snapshot, AWS creates a new DB instance. You can’t restore from a DB snapshot to an existing DB instance. Which means the RDS DB endpoint (DNS) changes which further requires change in the application code to update this new DB endpoint. No matter how big or small the application is, introducing configurations changes are always a challenge.</p><p>To help avoid changing the RDS DB endpoint in the application code, it needs a small trick :)</p><p>*Note: It is always recommended to perform any operation in the database during the downtime window, to avoid any DB read/write miss.</p><p>For example, there is a RDS database called ‘mydb’ which the application is connecting to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*CAwOkL5vYY5BYF4REL7RHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*-eka6x3qyHIBt_XocEe_OQ.png" /></figure><p>DBA is also able to connect to the database using SQL developer utility:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*-BW8S2Knu_HXpnIVcSh_yQ.png" /></figure><p>The database has a table called ‘rds_restore_demo’ which has three records in it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*AYcFdEugkFRGqKb_xAVFSQ.png" /></figure><p>A DB snapshot of this DB instance has been taken :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*pSpbhwuriVLuPGScMoNKJg.png" /></figure><p>Now, lets say this snapshot needs to be restored and as we know restoring from snapshot will create a new DB instance. It will ask for the new DB instance identifier, you can’t use the similar DB identifier within your AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*0RkaMyuOF0kNAHPt4g8N7Q.png" /></figure><p>When restore completes, it shows up as a new DB instance which has the new DB endpoint — “mydb-restored.clm08rjsqrnr.us-east-1.rds.amazonaws.com”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*fJ1ZuWywap5-xpdlWrdxcg.png" /></figure><p>DBA is able to connect to this new DB as well, which has the same table and records:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*zcKwnnVVrS3VQzYHyrmgSw.png" /></figure><p>Now, to have the same DNS endpoint — mydb.clm08rjsqrnr.us-east-1.rds.amazonaws.com in this case), the first DB instance ‘mydb’ needs to be renamed to some other name e.g. mydb-old</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*JegtPZld8pcaNXgkAwAA8A.png" /></figure><p>apply the changes immediately:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*B4ZWIovNaH-niiH8r0faOQ.png" /></figure><p>RDS will start renaming, then reboot the instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*ojOj2ZCF5TJSwEHImkNzXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*9Tab1ozYOVaCNgBv30J98w.png" /></figure><p>finally it will be in available state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*7yqgwxcCAix4esxO49dEXA.png" /></figure><p>Now, next step is to rename the restored DB instance to the original db i.e. mydb</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*HaNkA_UmELegKdXJDgNc4Q.png" /></figure><p>again, on modifying the DB, RDS will reboot the DB instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*0-xBVVkaNyPFR55yrs33pQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*ltfdffjAmyDQRbJWPcDmmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*GiZeG1VrKKRFq4ELKZmiBg.png" /></figure><p>the DNS endpoint of the renamed instance will be similar to the original one — mydb.clm08rjsqrnr.us-east-1.rds.amazonaws.com, which was the objective to achieve.</p><p>DBA has connected to this newly restored database with the same older connection string:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*egKMFJd5RDVS77lkPBXb_g.png" /></figure><p>and the restored DB instance is no longer exist. It can be deleted now from the AWS console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*KJBwHYigAluxlDY_gPcS0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNyZXwMMvNA0C-Hw0WfVJA.png" /></figure><p>This way the application code doesn’t need to be changed, when the database instance is restored.</p><p>However, please note that the time to restore the database instance may vary depending on the size of the database. Please refer the <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html">Restoring from a DB snapshot</a> before you plan to restore the database from the snapshot.</p><p>I hope this blog would have helped you in someway or another. :)</p><p>Happy Learning!</p><p>Be AWSome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88ef71b8b029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to provide restricted & secure access to a third party, to your AWS accounts, using Attribute…]]></title>
            <link>https://someshsrivastava1983.medium.com/how-to-provide-restricted-secure-access-to-a-third-party-to-your-aws-accounts-using-attribute-30472fe3229c?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/30472fe3229c</guid>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[aws-security]]></category>
            <category><![CDATA[aws-identity]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Mon, 02 May 2022 02:05:11 GMT</pubDate>
            <atom:updated>2022-05-02T02:05:11.595Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to provide restricted &amp; secure access to a third party, to your AWS accounts, using Attribute Based Access Control (ABAC)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rsG02jyI1Ukb5OHnOCxoaA.jpeg" /></figure><p>Many Organizations work with different vendors or third parties, to provide or consume services or you may have outsourced your work completely to the vendor. Often there is a need for Organizations to provide access to their resources like server, storage, database etc. to third parties but then the questions comes<em> “HOW to give them secure access?” . </em>The question becomes more important when your resources are on the cloud.</p><p>This blog post will showcase a secure solution to answer above question. There are services and features in AWS which can be leveraged to achieve the above goal. Services like IAM, Attribute Based Access Control (ABAC) are much powerful to help in this regard. IAM provides permissions and policies, allows switching between IAM roles, and other features.</p><p>For the scope of this blog, Attribute Based Access Control (ABAC), IAM Role &amp; Switch role functionalities have been used to derive the solution. Here is how the solution looks like-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkEAFihwP-n2tX9BdBoPVA.png" /><figcaption>Solution architecture — Attribute Based Access Control (ABAC)</figcaption></figure><p>What is Attribute Based Access Control (ABAC) and how it is different from traditional Role Based Access Control (RBAC)?</p><blockquote><em>As per</em> <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html"><strong>AWS documentation</strong></a> - “Attribute-based access control (ABAC) is an authorization strategy that defines permissions based on attributes. In AWS, these <strong>attributes </strong>are called <strong><em>tags</em></strong>. You can attach tags to IAM resources, including IAM entities (users or roles) and to AWS resources. You can create a single ABAC policy or small set of policies for your IAM principals. These ABAC policies can be designed to allow operations when the principal’s tag matches the resource tag. ABAC is helpful in environments that are growing rapidly and helps with situations where policy management becomes cumbersome.”</blockquote><blockquote>While <strong>RBAC </strong>defines permissions based on a <strong>person’s job function</strong>, known outside of AWS as a role. Within AWS a role usually refers to an IAM role, which is an identity in IAM that you can assume. IAM does include managed policies for job functions that align permissions to a job function in an RBAC model. In IAM, you implement RBAC by creating different policies for different job functions. You then attach the policies to identities (IAM users, groups of users, or IAM roles). As a best practice, you grant the minimum permissions necessary for the job function. This is known as <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege">granting least privilege</a>. Do this by listing the specific resources that the job function can access. The disadvantage to using the traditional RBAC model is that when employees add new resources, you must update policies to allow access to those resources.</blockquote><p>Learn more about ABAC here:</p><p><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html">What is ABAC for AWS?</a></p><p>Here is what you need for this to get implemented:</p><ol><li>an AWS account for the third party whom you want to give access to. Better to have a dedicated OU for the third party.</li><li>AWS account(s) which you want to give access of. OU strategy may differ per organization</li><li>IAM policies which need to be associated with IAM role for third parties</li></ol><p>Below is what I have created for the purpose of this demo.</p><h3><strong>Step 1: OU s</strong>tructure <strong>in AWS Organization</strong></h3><p>An OU called <em>‘OU-3rd-party</em>’ and an AWS Account underneath it, for the third party and another OU called <em>‘OU-development’ </em>and an AWS account underneath for the development which belongs to the organization want to build their workload on.</p><blockquote>Both these are root accounts, hence MUST be restricted from giving access to anybody.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*J6_T4lXmbDZdMi_jHcRS5w.png" /><figcaption>AWS Organization structure</figcaption></figure><p>Note there is no Service Control Policy (SCP) on the 3rd-party OU. <strong><em>I’ll explain later why</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*9qSjxWWny3TV6JQe3Nm_Tw.png" /></figure><h3>Step 2: Create IAM users for third party</h3><p>Create an IAM user for the 3rd party, so that it can assume the IAM role from the development (or any other) AWS account(s) <strong>but only when the user and role tags match</strong>. The following policy allows a user to assume any role in your account with the ‘3rdPartyAccessRole’ name prefix. The role must also be tagged with the same team tag as the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YwEjo7qLBymdCLTd8OxfDw.png" /><figcaption>IAM Policy called ‘assumerolepolicy-3rdparty’ for third party user</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*uHhzkTAKvGz9knevr3HNUg.png" /><figcaption>3rd party IAM user with IAM policy attached</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*hpM7PfMl9yJsSOZ4AKZ86g.png" /><figcaption>3rd party IAM user with tag</figcaption></figure><p>Now, login to the Development AWS account, in my case it is <strong><em>836016191915</em></strong><em>. </em>An IAM role which needs to be assumed by the third party user is to be created.</p><h3>Step 3: Create ABAC Policy &amp; IAM role to be assumed by the third party user, in the development account</h3><p>The following policy called ‘<em>3rdparty-access-policy’</em> allows principals to read secrets, start and stop EC2s but only when those resources are tagged with the same key-value pairs as the principal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kYVft-PX7FwDsSRZNEpjEA.png" /><figcaption>policy for the third party user(s) in the development account</figcaption></figure><p>Following IAM role 3rdPartyAccessRoleis created and the 3rdparty-access-policythat was created in the previous step is attached to it. The role also needs to be tagged with the same tag as the resource and the principal tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZYobp5gFZ8_BFpdauetEg.png" /><figcaption>IAM role in the development account</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GA0S0a5TgB2m-2QkJpcURA.png" /><figcaption>tag on the IAM role in the development account</figcaption></figure><p><strong>All done now! </strong>It is the time to test.</p><p>Login to the AWS Console, with the third party IAM user created. In my case, it is the user <strong><em>‘3rd-party-vendor-user’. </em></strong>Upon login, it <strong>doesn’t have </strong>access to any of the resources in its AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mGq0TgICcjqkMIEa-50dXg.png" /><figcaption>No access to S3 service</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*trz1XnN49LqtERFkWEN8mA.png" /><figcaption>No access to EC2 service</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ut2ULjIfk-7fZ1wNV1ORlQ.png" /><figcaption>No permission to access Secrets manager service</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rcdEa8s2VwRFN3rYPKvE-g.png" /><figcaption>No permission to access IAM service</figcaption></figure><p>Now lets ask the third party user to assume the role 3rdPartyAccessRole from the development account 836016191915 via <strong>Switch role </strong>functionality OR the switch role link generated in the IAM role can be shared with them -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F9CHONEbGsOOvqPHnMeX5g.png" /><figcaption>Link to Switch role</figcaption></figure><p>I’ll use the Switch role option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*3NCl1coudL726_resfBn-A.png" /></figure><p>Enter the development account number, the IAT role created and the display name (optional) and click on Switch Role button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/1*Z5CbwQzcrCNeOprf4RzGlw.png" /></figure><p>Upon login, click the account information drop down to see additional details. Notice the <strong><em>‘currently active as’</em></strong> &amp; <strong><em>‘Account ID’ </em></strong>fields, it is the IAM role &amp; the AWS Account ID, the 3rd party user assumed. To verify who has assumed the role, see the <strong><em>‘Signed is as’</em></strong> field below on the same panel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XcXezMWeQuFNAnO-gmrq8Q.png" /><figcaption>Switch role information</figcaption></figure><p>Now, lets test the permissions. While in the development account, third party user is allowed to list and get the value of only those secrets which are tagged as same as the user’s tag i.e. access-team = 3rdpartyuser. The policy also allows the third party user to start and stop only those EC2s which are tagged as same as the user’s tag.</p><p>OK. In the Secrets manager service, there are two secrets stored: First, the ‘demo-secret’ which <strong>doesn’t have</strong> the tag <em>access-team = 3rdpartyuser</em> which means the third party user can’t retrieve the password whereas the second secret, <strong>‘secret-3rdparty’ </strong>is accessible to the third party user. See the setup below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4HXPoN29RMyWMW6jNsupbQ.png" /><figcaption>Secret in the ASM which can NOT be accessed by the third party user</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1UWBfgyRi8y4mA3hHjHcA.png" /><figcaption>Secret in the ASM which can be accessed by the third party user</figcaption></figure><p>Third party user, as per the permissions, can list the secrets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmB2zih_M-sAJZnZ1la7Ww.png" /></figure><p>When trying to access the demo-secret (remember it doesn’t have the same tag as the IAM user) it gets an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4vgVBlydxw1VHf4VJ3DEg.png" /></figure><p>Now, when accessing the second secret ‘secret-3rdparty’, it is able to retrieve the password successfully <strong>since the resource tag matches the principal tag:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wsr4yMbqKeBA3EgdG8PcgA.png" /></figure><p>Great! Lets test the EC2 permissions as well. In the Development account, there is one EC2 in stopped state and tagged as access-team = aws-community-builder which means logged in third party user should not be able to start this EC2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a9I8n796MjClbWdoJR1ybQ.png" /><figcaption>EC2 in Development account</figcaption></figure><p>Lets see and as expected, it can not Start the instance:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*Ksp6TjB3EIlsD_rhgpSnbA.png" /></figure><p>They can verify why they can not access as the resource doesn’t belong to them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*cPo_Y1IeRagZWLt5Tbjwcw.png" /></figure><p>Well done! :)</p><p>Now, the answer why there is no Deny SCP buy still the third party user doesn’t have permissions to any AWS resources, is because an IAM principal is denied access by default, they must be explicitly allowed to perform an action. Otherwise, they are<strong><em> implicitly denied</em></strong> access.</p><p>Here, the third party IAM user has explicit Allow in the Identity based policy, for sts:AssumeRole only, rest of the permissions are implicitly denied. Here is how the policy evaluation logic works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PSTfbOTgt7Rj7OBtw17wfQ.png" /><figcaption>source: AWS documentation <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html">Policy evaluation logic</a></figcaption></figure><p>If your use case requires the use of AWS CLI or AWS API to assume that role then you can introduce more security by using the External ID;refer below documentation:</p><p><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html">How to use an external ID when granting access to your AWS resources to a third party</a></p><p>If your company uses a SAML-based identity provider (IdP) to manage corporate user identities, you can use SAML attributes for fine-grained access control in AWS. Attributes can include cost center identifiers, user email addresses, department classifications, and project assignments. When you pass these attributes as session tags, you can then control access to AWS based on these session tags. Follow the AWS documentation <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_abac-saml.html">IAM tutorial: Use SAML session tags for ABAC</a>.</p><p>With this blog post, I have showcased how you can provide secure access to the AWS resources in your AWS accounts, to the Third parties which require access to those AWS resources, through AWS Console, using attribute based access control.</p><p>I hope you have learned something from this blog post. If you liked reading this blog post, please clap and follow me for more interesting posts.</p><p>Till then Happy Learning!</p><p>Be AWSome! Be Happy! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30472fe3229c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Power of AWS Organization ID in controlling access to AWS resources]]></title>
            <link>https://someshsrivastava1983.medium.com/power-of-aws-organization-id-in-controlling-access-to-aws-resources-e128baf3e278?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e128baf3e278</guid>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[aws-security]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Sat, 02 Apr 2022 10:59:29 GMT</pubDate>
            <atom:updated>2022-04-02T11:06:30.803Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rbdPIzzgeco0oRzGIv91Iw.png" /></figure><p>If you are using a single or multiple AWS Accounts then you may already be aware of the AWS Organizations service. It is a service which is used to centrally manage the AWS Accounts. It gives a <em>unique ID </em>called ‘Organization ID’ per master AWS Account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*_83V6V4JQVVTAhFzZO6Qsw.png" /><figcaption>AWS Organizations</figcaption></figure><blockquote>If you are not familiar with AWS Organizations, please read it <a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html">here</a></blockquote><p>Different companies use different strategy to use and manage the AWS Accounts. AWS Organizations provide several features, which not only helps managing the AWS Accounts but also gives power to central cloud COE/Ops teams restricting permissions, apply security guardrails, managing cost across AWS Accounts within one AWS Organization.</p><p>One of the ways to restrict access to only certain AWS services &amp; principals is using the policies. AWS offers different <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies">policy types</a>, but two most commonly &amp; widely used policies are <em>Identity-based policies</em> and <em>Resource-based policies.</em></p><blockquote>As per official <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies">AWS documentation</a>, Identity-based policies are JSON permissions policy documents that control what actions an identity (users, groups of users, and roles) can perform, on which resources, and under what conditions while, <em>Resource-based policies</em> are JSON policy documents that you attach to a resource such as an Amazon S3 bucket.</blockquote><p>While using the resource based policies, AWS provides ‘condition keys’, which can be used to apply more granular control over actions allowed, to be performed by AWS service or principal.</p><p>The condition key — <strong><em>aws:PrincipalOrgID </em></strong>is very useful in this context. It verifies the organization id, in the AWS Organization, belongs to the principal who is making the request to use the resource such as S3 bucket, VPC endpoint, KMS keys etc. One of the examples is, restricting access of the S3 bucket to the principals belong to one specific AWS Organization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/1*nUasTkXZDksUdmmIXM3YZA.png" /><figcaption>S3 bucket policy</figcaption></figure><p>The above policy explain that, all the users from the member AWS Accounts under Organization ID ‘o-fgxx1zr’ are allowed to put objects in the mentioned S3 bucket resource. Here the aws:PrincipalOrgID under the condition block will be matched against the key &amp; value in request context. If it is evaluated as true, then only the permission will be granted to take mentioned actions on the given resource(s).</p><p>Another good use of the aws:PrincipalOrgID is with the <strong><em>policy attached to VPC Endpoints</em></strong>, I have used it in many of the scenarios. Most of the big enterprises whether it is Financial service or any other, use the controlled AWS environment to make it secure.</p><p><strong><em>One of the examples from the actual customer use case is, where customer wanted to allow internal AWS accounts only (belong to customer’s organization) to retrieve &amp; update secrets from the central Secrets Manager store.</em></strong></p><p>The solution I provided was to <strong>1</strong>. create a secret in AWS Secrets Manager and <strong>2.</strong> attach a resource policy to the Secret which allows users to retrieve &amp; update secrets only when the request comes through the VPC endpoint — <em>vpce-03aa191527a0d1dfc</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*M8YIAr9uREK_Zzqq3OjLdQ.png" /><figcaption>Secrets Manager — Secret</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*Yzn-ctaNVpzq8cwdHcwKUQ.png" /><figcaption>Secrets Manager — Resource-based policy</figcaption></figure><p><strong>3.</strong> Next step was to, create a VPC Endpoint policy for AWS Secrets Manager service, so that service can be accessed from within a VPC only, (since this VPC was acting as a Hub VPC and principals from the other AWS Accounts were able to access this Hub VPC) and attach a resource-based policy which allows principals from the AWS Accounts but only if they are a member of Organization ID — o-fg6xxx1zr.</p><p>Below policy Deny mentioned permissions on any Secrets from any Principal if they don’t belong to the member AWS account falls under Organization ID — ‘o-fgxx1zr’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*nL86Gpx2wls2uK9qJ78bWg.png" /><figcaption>Secrets manager VPC endpoint policy</figcaption></figure><p>You can use the aws:PrincipalOrgID in any resource-based policy to control access (if supported) to that resource. It is specially useful when you have 100s of 1000s of AWS Accounts to manage.</p><p>In this blog post, I have shown how you can control access of resources to the member AWS Accounts of an AWS Organization with the help of the condition key — aws:PrincipalOrgID.</p><p>Recently, AWS announces support of PrinciplaOrgID in Lambda function resource-based policies, read it <a href="https://aws.amazon.com/about-aws/whats-new/2022/03/aws-lambda-principalorgid-resource-policies/">here</a>. A blog is also available <a href="https://aws.amazon.com/blogs/compute/using-organization-ids-as-principals-in-lambda-resource-policies/">here</a>.</p><p>Hope this blog post will help you securing your resources. I’ll write another blog on another real world use case very shortly.</p><p>Till then Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e128baf3e278" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Event-Driven serverless architecture to automatically remediate security findings]]></title>
            <link>https://someshsrivastava1983.medium.com/event-driven-serverless-architecture-to-automatically-remediate-security-findings-using-aws-44f2c0e1e4a1?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/44f2c0e1e4a1</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[awsserverless]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Fri, 14 Jan 2022 14:01:49 GMT</pubDate>
            <atom:updated>2022-03-30T16:53:00.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hfiH0i-vzKkVnNXevk3dMw.png" /><figcaption>Security remediation framework — Architecture</figcaption></figure><p>We all love to design, build and deploy on AWS. But as the cloud adoption is growing, the security concerns in and around the cloud is also growing. We see and hear about the security breaches and incidents very often now a days.</p><p>Having spent a good amount of time in migrating, building and deploying applications on AWS for multiple customers, I can say that organizations take their cloud security very seriously, specially the financial firms. I’ve seen the most strict and controlled AWS environments, the best implementations of DevOps pipelines, maturity level of firms to built in their internal processes into the AWS environment and the security of cloud resources through extensive preventive and detective controls.</p><p>If you are owing an AWS platform in your firm and looking for a fully automated security solution or do not want to spend huge money in buying the managed security solution from vendors then this blog will help you implement the security solution in-house no matter how big or small your firm is.</p><p><em>In this bog, I’ll walk you through the solution, based on the event-driven architecture, to detect and remediate the security findings automatically using AWS managed security services.</em></p><p>The logic behind this solution is to collect the security findings at central place, so making it easy to detect, capture and respond; irrespective of the number of AWS Accounts being used.</p><p>Next question is how to implement it?</p><p>In AWS, there are services which work on master-member model to centralize logs/findings/events, few example are AWS Security Hub, AWS Guard Duty, Config etc.</p><ol><li><a href="https://aws.amazon.com/guardduty/features/">Amazon GuardDuty</a> — a threat detection service which continuously monitors for malicious activity and capable of analyzing tens of billions of events across multiple AWS data sources, such as AWS CloudTrail event logs, Amazon Virtual Private Cloud (VPC) flow Logs, and DNS query logs.</li><li>AWS <a href="https://aws.amazon.com/security-hub/features/">Security Hub</a> — a cloud security posture management service that performs automated, continuous security best practice checks against your AWS resources.</li><li>AWS Config — This service enables you to assess, audit, and evaluate the configurations of your AWS resources. Config continuously monitors and records your AWS resource configurations and allows you to automate the evaluation of recorded configurations against desired configurations.</li></ol><p>Let’s take an assumption that there are 10 AWS Accounts, where the workloads are running, let’s call them ‘AWS Solution&#39; accounts</p><p>We then need one AWS account which will work as a central place to collect the security findings and events, let’s call it &#39;Core-compliance&#39; account.</p><p>We know that every action that is performed in AWS is basically an API call and every action emits an event — a signal that a system’s state has changed. These events get collected in the event bus in <a href="https://aws.amazon.com/eventbridge/">Amazon Event Bridge </a>service.</p><p>I have enabled AWS GuardDuty as member, in each of the AWS Solution accounts where are Master can either be your core-compliance AWS Account or your root/master AWS account, because AWS Security Hub will used to detect the findings from Amazon GuardDuty.</p><p>Since, Security Hub is integrated with AWS services like IAM Access Analyzer, Macie, Firewall Manager, Amazon Inspector etc. I have enabled Security Hub as member in each of the AWS Solution accounts and as Master in the central core-compliance AWS Account, hence with this setup, all the Security Hub findings will be pushed &amp; collected at a central place.</p><p>I have also enabled IAM Access Analyzer, which helps identifying the resources in organization and accounts, such as Amazon S3 buckets or IAM roles, shared with an external entity. Findings from IAM Access Analyzer will also be sent to Security Hub member which eventually goes to master Security Hub.</p><blockquote>You might be aware that Security Hub processes these findings using a standard findings format called the AWS Security Finding Format (ASFF).</blockquote><p>To enable AWS Config, I have used the AWS Config Conformance pack. The Conformance pack is a collection of AWS Config rules and remediation actions that can be easily deployed as a single entity in an account and a Region or across an organization in AWS Organizations. <em>More details are available </em><a href="https://docs.aws.amazon.com/config/latest/developerguide/conformance-packs.html"><em>here</em>.</a> AWS provides ready-made <a href="https://docs.aws.amazon.com/config/latest/developerguide/conformancepack-sample-templates.html">sample conformance pack</a> which can be deployed easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_pzuzT4Gu5eUXZrwt3BdBQ.png" /><figcaption>AWS Config — conformance pack</figcaption></figure><blockquote>Security Hub doesn’t get findings from AWS Config by default, hence a solution needs to be in place to send Config rule evaluations as findings into Security Hub, <em>use the official AWS blog </em><a href="https://aws.amazon.com/blogs/security/how-to-import-aws-config-rules-evaluations-findings-security-hub/"><em>here</em></a><em>,</em> this will import AWS Config rules evaluations as findings in Security Hub in the ASFF format which Security Hub uses.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*wUicVb8xAwvYe01bWErIZw.png" /></figure><p>Now, I have all the findings from all 10 AWS Accounts into the member Security Hub and <strong>eventually into the Security Hub (Master).</strong></p><blockquote>By default, Security Hub automatically sends all new findings and all updates to existing findings to EventBridge as <strong>Security Hub Findings — Imported</strong> events. Please refer <a href="https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-cwe-integration-types.html">here</a> for more details</blockquote><p>The security findings do not get detected instantly, it take few minutes to reflect in the services like GuardDuty, Security Hub or AWS Config but I wanted to capture some high severity events in near real time such as someone tries to attach internet gateway in AWS Account, or someone has applied unrestricted S3 bucket policy, or someone is adding 0.0.0.0/0 as Inbound rule in a security group.</p><p>As I said earlier, every actions in AWS is an API call and every action generates events, <strong><em>hence a custom event pattern is created to capture all the events from the solution account </em></strong>with target set as the ARN of the default event bus of core-compliance AWS Account. These events takes no time to be available in Event Bridge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*j-DMDeclUVWY4kMM3QAV-A.png" /><figcaption>event pattern to capture all Events of solution AWS account</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*8npBwRVlVODlSTBX1hDWKQ.png" /><figcaption>Event rule target — Event bus of core-compliance account</figcaption></figure><p>Now, I have all the findings generating out of different Security services, all the events generating from actions from all AWS Solution accounts, at one place.</p><p>Next step is, how do we capture these events? The answer is using the Event patterns in Event Bridge service e.g. to capture the event of an action when someone adds internet gateway to the VPC; for that the custom event pattern looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*L06D04xLWWuu-wJ1ED0nPQ.png" /><figcaption>custom event pattern for capturing event from action</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*oQtWexvLlJdKMfJUwTqYTQ.png" /><figcaption>custom event pattern for capturing event from Security Hub findings</figcaption></figure><p>Now that the event is captured, it is now time to take action. I have used a fleet of lambda functions to do this job - code that reads the event, retrieves the AWS account details from it, then gains access into the AWS account and finally takes action to do what it is supposed to do; <em>in above scenario detaching the internet gateway from the VPC.</em></p><p>Wondering how does lambda gained access to the impacted AWS Account? Answer is by assuming an IAM Role, <em>which is already deployed in each of the AWS Solution accounts, for Lambda to assume.</em></p><p>Now the last step is, to notify the AWS account owner or a contacts DL, if configured for an account, which can be used to send the Email notification to, regarding the remediation which took place in their AWS Account. The best way to send notifications is by using AWS SNS service.</p><p>With every custom event pattern along with Lambda as a target, SNS topic as a target which sends the notification to the owner/DL.</p><p>That’s all !! It’s done! :)</p><p>You have a security framework in place which monitors AWS accounts for any unwanted activities, takes action and notifies you that too automatically. A complete peace of mind ☺️ isn’t it?</p><p>You can improve this framework, by introducing more services such as Amazon Detective, Macie, Audit Manager and also integrate it with change management tools such as JIRA, Service Now etc, or deploy the framework in all AWS regions, to make it more powerful.</p><p>Hope this blog will help you in building the security framework which automatically remediates the security findings. Feel free to put your questions in the comment section, I’ll try my best to answer those at the earliest. Also, do clap if you find this blog useful.</p><p>Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44f2c0e1e4a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to configure the Application Load Balancer-type Target Group for Network Load Balancer]]></title>
            <link>https://someshsrivastava1983.medium.com/how-to-configure-the-application-load-balancer-type-target-group-for-network-load-balancer-9b0c39106699?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b0c39106699</guid>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[vpc-endpoint]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Sat, 18 Dec 2021 22:20:45 GMT</pubDate>
            <atom:updated>2021-12-19T08:22:51.263Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*1eenvqYjm_juhK56u3Imcg.png" /></figure><blockquote>While Application Load Balancer (ALB)has advanced routing features like query string, path and host based routing etc. but the IP addresses of the application load balancer are dynamic in nature, which makes the implementation of use cases difficult, where you need a static IPs to be whitelisted in your data center’s firewall or any other use case where you need static IPs to connect to.</blockquote><blockquote>As a workaround, to get the private IP address, we front the ALB with the Network Load Balancer (NLB), also implement a Lambda watcher which does the dns lookup of ALB DNS to get the latest IPs and update the NLB target group. refer the AWS blog <a href="https://aws.amazon.com/blogs/networking-and-content-delivery/using-aws-lambda-to-enable-static-ip-addresses-for-application-load-balancers/">here</a></blockquote><p>Recently this year, AWS has introduced a new target group type for Network Load Balancer — ‘Application Load Balancer’. This new feature allows you to directly register an ALB as an NLB target, eliminating the need to actively manage changing ALB IP addresses. You can now easily combine the benefits of NLB, including PrivateLink and zonal static IP addresses, with the advanced routing offered by ALB to load balance traffic to your applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fh-Uk-Iy_wqDSMDl69eLtQ.png" /><figcaption>Application Load Balancer target type for NLB (<a href="https://aws.amazon.com/blogs/networking-and-content-delivery/application-load-balancer-type-target-group-for-network-load-balancer/">image source</a>)</figcaption></figure><p>In this blog, I’ll demo how you can use this new feature of NLB.</p><p>Pre-requisites:</p><ul><li>2 VPCs (You can use only 1 VPC, however second VPC will only be required if you want to Enable PrivateLink on NLB)</li></ul><p><strong>Steps for VPC 2:</strong></p><ol><li>Create an Application Load Balancer (Internal/Internet facing) with a target group</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*FwtC1_H3t15E7wVkw5nS0w.png" /><figcaption>Application Load Balancer listener</figcaption></figure><p>Note the IPs of ALB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*GNQmOPSpOz6B7iMU4MCBEg.png" /></figure><p>I have created a simple Hello World lambda function as a backend for ALB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*l1JEMmrnPWxZlvUXhXxQ7A.png" /><figcaption>ALB target group</figcaption></figure><p>My Lambda function is running inside a VPC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7P5oggL0ksjwt2m2SIDBNw.png" /><figcaption>Lambda config</figcaption></figure><p>My Lambda code in Node js:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*5hGwxign_d3I5_Pb-n6zPA.png" /><figcaption>Lambda code (node.js)</figcaption></figure><p>And it works perfectly when I invoke it via ALB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*nytZckVEWZplRgGunec36g.png" /><figcaption>ALB response</figcaption></figure><p>2. Create a network load balancer with a target group of target type ALB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*cfe1l9J-upHX-XJF8Kn2Pg.png" /><figcaption>Network Load balancer listener</figcaption></figure><p>select ALB as target type while creating the target group:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*EueNQxHK8WJL-_t8tFzNKA.png" /><figcaption>Target group types</figcaption></figure><p>After few minutes, the NLB’s target (i.e. ALB) will be healthy: (if your ALB doesn’t show as healthy, please verify if the security group associated with ALB has correct routes)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5qOOeaui19IKjpTWwGx1w.png" /><figcaption>NLB target group config</figcaption></figure><p>Now that our NLB is also created, lets test it out by hitting the NLB’s dns endpoint and it works!! <br>You can now use the static IP addresses of NLB to whitelist them in the data center’s firewall and use the DNS endpoint to access the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*pLZy2EOgTvtTuquUScF1Ew.png" /><figcaption>NLB response</figcaption></figure><p>Now next step is enabling PrivateLink on NLB. <br><em>(Note: From here, steps are Optional. it is to use the Network Load Balancer that you set up in the previous step as an endpoint for private connectivity, you can enable AWS PrivateLink. This establishes a private connection to your load balancer as an endpoint service.)</em></p><p>3. Click the ‘Create Endpoint Service’ button from the ‘Integrated services’ tab of your NLB. On clicking, you’ll be redirected to Endpoint service page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*HVnpgnVRuHuau-rCy0cNRw.png" /><figcaption>Enabling the private link</figcaption></figure><blockquote>If you are interested in learn more about PrivateLink technology of AWS. Please do read by article <a href="https://someshsrivastava1983.medium.com/leverage-aws-privatelink-to-securely-connect-amazon-rds-from-on-premise-9bf4bd3184b3">here</a>, where I have explained in detail about it.</blockquote><p>Go ahead and create the VPC Endpoint service as per below configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*Ynp-DlEeun2gP3SPG4UQww.png" /><figcaption>Private Link Enablement</figcaption></figure><p>Note down the ‘Service name’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Gs17SOaOg1IHlUBAYgOPg.png" /><figcaption>VPC Endpoint service</figcaption></figure><p>you should see the AZs of your NLB nodes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*htGxS6q6gKOSA9kZVYgu8w.png" /></figure><p>Until this point we have done all configurations for VPC 2:</p><p><strong>Steps for VPC 1:</strong></p><ol><li>Create an Interface endpoint using the endpoint of the VPC Endpoint service name created at step 3 earlier and click verify:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LrIJ0v6lnbr3mROyWg8VXQ.png" /><figcaption>VPC Interface Endpoint</figcaption></figure><p>Upon creation the Interface endpoint configuration should be as below. Note the DNS name of the Interface endpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YfwGKacb2jao5XDHYzdmWg.png" /><figcaption>Interface Endpoint configuration details</figcaption></figure><p>Step 2: Go to Endpoint Services of the VPC 2 and accept the interface endpoint connect. It should show available after few seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*pwgPF69tE1NkPGAP_PVnhg.png" /><figcaption>Endpoint connection status</figcaption></figure><p>It is a time to test the whole set up. And for that, we need one EC2 instance in VPC 1. Go ahead and create an EC2 instance. (I have created a small EC2 instance (Linux))</p><p>use the curl command to test your interface endpoint:<br>curl -v http://&lt;dns of the interface endpoint&gt;</p><p>You should see the response from the target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzNLMZeCYE44rW63AO-GDw.png" /><figcaption>curl response on hitting VPC Interface endpoint</figcaption></figure><p>There are a few things to keep in mind when making use of this feature:<br>(information <a href="https://aws.amazon.com/blogs/networking-and-content-delivery/application-load-balancer-type-target-group-for-network-load-balancer/">source</a>)</p><ol><li>TLS listeners on Network Load Balancers cannot forward to ALB-type target groups. If you have a use case to terminate TLS, we recommend using HTTPS listeners on your ALB.</li><li>You are only able to configure a single ALB in an ALB-type target group for NLB.</li><li>You can associate an Application Load Balancer as a target of a maximum of two Network Load Balancers. To do this, the Application Load Balancer must reside in separate target groups, and be assigned to two different Network Load Balancers. (see <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/application-load-balancer-target.html">here</a>)</li><li>The communication between an NLB and ALB only happens over IPv4 even though you can configure dualstack scheme for your ALB.</li><li>You are unable to delete an ALB while it’s registered behind an NLB. The ALB will first have to be removed from the ALB Target Group to break the dependency.</li><li>AWS strongly recommend that ALB target Availability Zones match those enabled for your NLB to optimize availability, scaling, and performance.</li><li>ALB (Internet-facing or internal) and NLB (Internet-facing or internal) must be in the same VPC and same account when using the ALB-type target group.</li><li>If ALB (Internet-facing or internal) and NLB (Internet-facing or internal) are in different accounts or different VPC’s, then please refer to the AWS Lambda based solution described <a href="https://aws.amazon.com/blogs/networking-and-content-delivery/using-aws-lambda-to-enable-static-ip-addresses-for-application-load-balancers/">here</a>.</li><li>AWS recommend that you keep the cross-zone load balancing attribute on NLB disabled (default option) for better performance and to prevent cross-zone data transfer charges.</li></ol><p>I hope this blog will help you understand the new feature introduced by AWS for NLB where ALB can be selected as a target type.</p><p>Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b0c39106699" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to get the same Private Static IP, always attached to an EC2 instance in Auto scaling group…]]></title>
            <link>https://someshsrivastava1983.medium.com/how-to-get-the-same-private-static-ip-always-attached-to-an-ec2-instance-in-auto-scaling-group-c4bc26d14b49?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4bc26d14b49</guid>
            <category><![CDATA[aws-networking]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Sat, 13 Nov 2021 21:57:56 GMT</pubDate>
            <atom:updated>2021-11-15T15:34:43.637Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to get the same Private Static IP, always attached to an EC2 instance in Auto scaling group, using lifecycle hook</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*j-rpCBqduEyzcLnf.png" /></figure><blockquote>When you launch an EC2 instance, a primary private IPv4 address for the instance gets allocated to it. An instance receives a primary private IP address from the IPv4 address range of the subnet. A private IPv4 address, remains associated with the network interface when the instance is stopped and started, or hibernated and started, and is released when the instance is terminated and new instance gets new private IP address.</blockquote><p>What if, your use case requires, retaining the same specific Private IP address for an EC2 instance, even after it is released on termination ? e.g. you need specific static private IP 10.8.16.34/32 always attached to an EC2 instance, irrespective of termination.</p><p>One of the solutions is to use the <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/elastic-ip-addresses-eip.html">Elastic IP address</a> but since EIP gives the public IP address, it would not work if you are building infrastructure in an organisation where public cloud platform is very restricted and controlled such as Bank, due to its reachability from Internet.</p><p>This solution utilizes Secondary ENI (Elastic Network Interface) provided by AWS along with lifecycle hook, Lambda and parameter store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*o1-beFSCqSxWeP_VSv9TEQ.png" /><figcaption>solution diagram</figcaption></figure><p><em>If you do not know how the lifecycle hook works then please refer the link </em><a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html"><em>here</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/0*UtTalVCk0ynu7vdt.png" /><figcaption>Auto Scaling instance states</figcaption></figure><p>The main challenge in designing this solution was, making sure the Secondary ENI gets disassociated from the terminated EC2 instance and gets associated with the new EC2 instance <strong><em>automatically,</em></strong> even in the event of multiple EC2 termination.</p><p>Another challenge was the management of the ENIs which was solved by using the Parameter store.</p><p>Now lets assume EC2 instances running in an auto scaling group, where desired capacity in the auto scaling group is 3. As a pre-requisite, all the EC2 instances have been given tag key:name=value:peer1, peer2 etc and a secondary ENI has been associated with each of them.</p><p>Here is how the solutions works:</p><ol><li>Lets consider that EC2 instance tagged as ‘peer 1’ goes down or say gets terminated.</li><li>The lifecycle hook gets triggered and EC2 Auto scaling submits an event for a lifecycle action to EventBridge. (Notice the ‘Instance terminate’ is selected in ‘Lifecycle transition’ field.)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*wEFIeYJByAyt0Vh-Ok5Vyg.png" /><figcaption>EC2 auto scaling lifecycle hook — terminate</figcaption></figure><p>3. Next step is to <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html?icmpid=docs_ec2as_console#preparing-for-notification">receiving the event</a> in the EventBridge, which triggers a lambda function which does the job to detach the secondary ENI from the terminating EC2 instance and save the tag &amp; 2nd ENI into the parameter store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*RZ2tC6M0xASj4wFrApiG5w.png" /></figure><p>4. Lambda function is very simple which reads the event data, fetches the tag key/value, secondary ENI value, put it in a parameter store and completes the lifecycle action.</p><p>5. When auto scaling spins up a new EC2 instance, (it goes into the pending:wait state) and another lifecycle hook gets triggered and EC2 Auto scaling submits an event for a lifecycle action to EventBridge. (This time notice the ‘Instance launch’ is selected in ‘Lifecycle transition’ field.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*OHZ1nEBhao3DRSISPvTTUQ.png" /><figcaption>EC2 auto scaling lifecycle hook — launch</figcaption></figure><p>6. EventBridge rule to receive the launch lifecycle hook event which invokes another lambda function which fetches the saved tag key/value &amp; secondary ENI from the parameter store and attaches it to the newly created EC2 instance and completes the lifecycle hook action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*ZTWqYKnD1PevVO5kS7oYSQ.png" /></figure><p>In case of multiple EC2 termination, the launch lambda function fetches the tag &amp; secondary ENI pair which were stored first in the parameter store.. think of it as FIFO queue :). lambda function also deletes the tag &amp; secondary ENI pair from the parameter store once it successfully associates them with EC2 instance.</p><p>By implementing this solution you can not only automatically disassociate and reattach the secondary ENI to an EC2 instance in the auto scaling group but also use the same secondary ENI.</p><p>Hope this blog would have helped you!</p><p>Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4bc26d14b49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure Custom Origin with Cloud Front custom header and AWS WAF]]></title>
            <link>https://someshsrivastava1983.medium.com/secure-custom-origin-with-cloud-front-custom-header-and-aws-waf-9156dc7b5d5b?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9156dc7b5d5b</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-networking]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws-security]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Sat, 21 Aug 2021 22:25:34 GMT</pubDate>
            <atom:updated>2021-08-21T22:45:13.216Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*i4yOhjU82Q0-NtQrRHpfig.jpeg" /></figure><p>Amazon CloudFront as we know is the content delivery service from AWS which in addition to its core functionality, provides security features like Field level encryption, TLS etc. as well as integration with AWS security services like IAM, AWS Web Application Firewall (WAF). Learn more about Amazon Cloud Front <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html">here</a>.</p><p>Below figure shows how CloudFront delivers content to the users. It uses Edge locations (CloudFront POP) to cache the contents and deliver it to the users for better user experience. CloudFront speeds up the distribution of your content by routing each user request through the AWS backbone network to the edge location that can best serve your content. Read more <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/HowCloudFrontWorks.html">here</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/362/1*dgSqo3tcI6nxnsNdNDSSPQ.png" /><figcaption>How CloudFront works</figcaption></figure><p>We have seen customers using Amazon Cloud Front as content (static or dynamic) delivery service with S3 or custom origin. Although the Cloud Front is a managed service by AWS and is secure by design by the AWS global network security procedures.</p><p>But what if users try bypassing CloudFront and try accessing your origin content directly? There are ways to secure your Origin such as using Origin Access Identity with Bucket policy, if the origin is S3 and use Security Groups, NACLs, WAF to Allow/Deny specific traffic to custom origin like API Gateway , Application load balancer targeting EC2 or any other origin.</p><p>In this Blog post, I’ll walk you through how you can use Cloud Front Custom Header with AWS WAF to secure the custom origin - Amazon API Gateway.</p><p>The solution consists of below configurations:</p><ol><li>Amazon WAF ACL to block traffic not containing custom header in the request</li><li>Amazon API Gateway with lambda integration and WAF ACL applied to it</li><li>Create CloudFront distribution with a custom header</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oEwO1nmXGnuXOxGS_0wGuA.png" /><figcaption>Solution architecture</figcaption></figure><p><strong>Step 1</strong> is to create a WAF ACL.</p><blockquote>AWS WAF is a web application firewall that helps protect web applications or APIs against common web exploits and bots that may affect availability, compromise security, or consume excessive resources. AWS WAF gives control over how traffic reaches applications by enabling you to create security rules that control bot traffic and block common attack patterns, such as SQL injection or cross-site scripting. Learn more about AWS WAF <a href="https://aws.amazon.com/waf/">here</a></blockquote><p>Go to AWS WAF service, select the resource type you like to apply the WAF to. In this demo, I’m applying WAF on an API stage in Amazon API Gateway, hence selected the resource type as Regional and the API resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*gRh40GqrQhGotfb0xEAd9w.jpeg" /></figure><p>click Next and add a rule ‘Add my own rules and rule groups’ using rule builder. Here we need to create a rule to monitor the requests based on the a condition that If the request matches the Header key ‘x-origin-verify’ and exactly matches the header value (you can give any value or best way is to generate the random string programmatically).</p><p>Select the action to take when a request matches the statements above. In our case select ‘Allow’ because we want to allow all requests with this header &amp; header value. Click ‘Add Rule’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*Opc7eX6YzvdusBLsXfVpEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*Er-A-Zjeox6xDzsOA4HgsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*q6zRSuLJUuyORGqU6cYRzw.png" /></figure><p>Now select the default web ACL action for requests that don’t match the above rule. We want to Block all requests which DO NOT match the rule:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*kRx5T1QqNKjsR2onkX2fKg.png" /></figure><p>Click Next, review and create Web ACL. We are all set to allow/block the requests on API Gateway.</p><p><strong>Step 2 </strong>Lets now configure the API in Amazon API Gateway. For the simplicity, I have integrated a very simple lambda function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*jjZGydNJ-ylirZ_MpYWvIQ.png" /><figcaption><em>API in Amazon API Gateway</em></figcaption></figure><p>My API is working fine:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*AWiFDuqGFmNLspAx1NEd6g.png" /></figure><p>Now, lets apply the Web ACL we created in step 1 to the API Gateway stage called test:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*k4mmFKRy0tElvHVtdf5IcA.png" /></figure><p><strong>Step 3</strong> is to create a CloudFront distribution with API Gateway as a custom origin and add the custom header in the origin setting.</p><p>Use API endpoint as the Origin domain name which CloudFront will recognize as custom origin. Origin path will be the API stage/API resource. Rest all setting you can configure as per your requirement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*amYDrez4SomFiIwHXsIHFA.png" /><figcaption>Cloud Front distribution</figcaption></figure><p>Now the fun part, the Custom Header. Configure the CloudFront distribution with the exact same header key and value you have configured in the web ACL.</p><p>We have now configured the CloudFront to add custom header to the requests that it sends to the origin - API Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*Y3e3moSPkpMpZKxGozi0jg.png" /></figure><p>I have a domain name with PHZ in the R53, which I have used to create the A records and CNAMEs records for this CloudFront distribution and configured the same in the CloudFront distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*7sXG2k-fEAqJY2-MyqfHyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*HzZYbMxLVO445354jy9b_w.png" /><figcaption>Route53 configuration</figcaption></figure><p>All set now!! Here is how this will work, I’ll send the request to API Gateway endpoint via CloudFront. Upon receiving the request, CloudFront will add the custom header in the request <em>(the viewer (or user) of the request is </em><strong><em>not aware</em></strong><em> that the CloudFront is adding this header) </em>and forwards it to the API Gateway where the WAF Web ACL is monitoring all the requests, with a rule which only A<strong><em>llows </em></strong>the requests having custom header name ‘x-origin-verify’ and the value we have set, all other requests will be <strong><em>Blocked</em></strong>.</p><p>If the user tries to bypass the CloudFront distribution somehow, and tries to access the API Gateway endpoint directly, the request will be <strong><em>Blocked </em></strong>by WAF since the request will not have the custom header in it.</p><p><strong>Let’s TEST</strong></p><p>I have hit the url in the browser and it successfully reaches to the API Gateway. Here CloudFront is adding the custom header to my request which goes successfully to the API Gateway and gets the response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*5uZNtvQyPH8ZcqP5CvfV_g.png" /></figure><p>I have also used postman to show you that I’m not passing any header in the request from my side (CloudFront adds it) and it gets the successful response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*S1wVNccahNxvzQviiRGR1Q.png" /></figure><p>Now, lets see what happens if I try to bypass the CloudFront and accessing the API Gateway endpoint directly. <strong>Great! WAF works! </strong><em>My request is </em><strong><em>Blocked </em></strong><em>by WAF here, since there was no header ‘x-origin-verify’ and its corresponding value in the request.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*TjykVJpWjjmv-Ao7ToCedw.png" /></figure><p>Same test using Postman - Request Blocked by WAF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*VegMlKG4LkCy5ow8kyxgZg.png" /></figure><p>Now, lets add the custom header and the value to the request to pretend that the request is coming from CloudFront. <strong>Good stuff!</strong> Request if <strong>Allowed </strong>by WAF.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*iOBv6I8j-5LBbOvP_PCZ5A.png" /></figure><p>In this blog, I explained and showcased how you can use CloudFront custom header along with WAF to secure the custom origin. If you want to learn more about custom header do read it <a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/add-origin-custom-headers.html">here</a>.</p><p>Please do let me know you queries and feedback on this post and let me know the use case you want me to explain with a demo.</p><p>I’ll write another blog on another interesting use case shortly.</p><p>Happy Learning!!</p><p>Stay safe!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9156dc7b5d5b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement multi-dimensional security in AWS]]></title>
            <link>https://someshsrivastava1983.medium.com/implement-multi-dimensional-security-in-aws-9a573e5ee687?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a573e5ee687</guid>
            <category><![CDATA[aws-security]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Mon, 15 Mar 2021 19:37:20 GMT</pubDate>
            <atom:updated>2021-03-15T19:37:20.003Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OulXxkPGxCpq7QUOGplYpg.jpeg" /></figure><p>In any application or system, whether it is running on premises or in cloud, security is utmost important. By securing your application(s) or system(s) from various attacks, accidental deletion, data leakage/theft etc., you can build confidence in your customers/users/stakeholders, focus on innovation, focus on business growth. There is no one way to implement security or there is not a single layer or level to protect, the security should be multi-dimensional which means every layer, every entry and exit point and the smallest bit of your data should be protected.</p><p>This post talks about, what is to be protected, how to protect and which AWS service can help you in achieving the multi-dimensional security of the system as a whole.</p><p><strong>Security Design Principles</strong></p><p>In the cloud, there are number of principles that can help you strengthen your system security:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMXUNnBSjbpoVUDShGlOvQ.png" /></figure><p><strong>Understand Shared Security Responsibility Model</strong></p><blockquote>AWS provides secure global infrastructure. However, AWS has principal of Shared Responsibility Model where AWS and Customers work together to secure data, assets and infrastructure on AWS cloud.</blockquote><p>AWS says, <strong>“Security of the cloud”</strong> is their responsibility and <strong>“Security in the cloud”</strong> is the responsibility of the customers. <em>Security of the cloud</em> means AWS is responsible for protecting the physical locations where their data centers are residing, and the underlying foundational services such as compute, network, database and storage. Whereas <em>Security in the cloud</em> means, the customer is responsible for securing resources running/provisioned above the AWS managed layer such as OS, network, firewall, platform and application management, customer data, client side and server side encryption, network traffic protection etc. To understand better, let’s take an example of EC2, AWS is protecting the physical infrastructure and related services/resources from which the EC2 instances gets provisioned, once you provisioned the EC2 instance, it is your responsibility to secure everything you run onto it including the OS patching. If your EC2 instance gets compromised or there has been an attack which leads to data theft, then AWS will be not responsible for it.</p><p>There are some services like RDS and EMR, where AWS manages the underlying infrastructure and foundation services, the operating system and the application platform. Customer is only responsible to protect their data along with proper security measures, backup and recovery, high availability, disaster management, business continuity etc., using AWS provided tools for that service.</p><p>Services like S3 and DynamoDB, where AWS operates the infrastructure layer, the operating system, and platforms and you access the endpoints to store and retrieve data. You need to make sure only authorized users are accessing your data. You don’t need to worry about the high availability, security, patching of the service, AWS manages everything for you.</p><h3>Enable Security | Identity and Access Management</h3><p>Right level of access is very much important, it determines which user or service is eligible to access which AWS service(s). AWS provides IAM service to manage AWS accounts, groups, roles and IAM Users. IAM works on policies which describe permissions you like to give to a user/service or group of users. IAM policies are written JSON format.</p><p>When you create an AWS account, it creates the root level account which has unrestricted access to all AWS services, consider it as a “God Mode” user, who can do wonders. You can create as many IAM users you want under the root account but they will have limited or admin level access.</p><p>AWS services can be accessed via AWS management console, AWS CLI and AWS SDK.</p><p>AWS recommends following actions a user should perform as soon as a user creates an AWS account:</p><ol><li>Delete root access keys</li><li>Create an IAM users</li><li>Enable MFA (multi factor authentication) for root user</li><li>Use groups to assign permissions</li><li>Apply an IAM policy for your users to create strong passwords and rotate their passwords</li></ol><p>There should be an <strong>IAM user</strong> with admin level permissions for day to day management and administrator activities. AWS provides ‘<em>AdministratorAccess</em>’ policy which gives full access to all AWS services and resources but restrict access to billing. Having said that, admin user should also safeguard his credentials as well and should give access to other users on a basis of least privilege principal. As a thumb rule, a user in an organization should have corresponding IAM user to access AWS services, if required access.</p><p>If you have medium or large enterprise then consider using Identity Federation. Identity federation is a system of trust between two parties for the purpose of authenticating users and conveying information needed to authorize their access to resources. In this system, an identity provider (IdP) is responsible for user authentication, and a service provider (SP), such as a service or an application, controls access to resources.</p><p>Federation commonly uses open identity standards, including Security Assertion Markup Language 2.0 (SAML 2.0), Open ID Connect (OIDC), and OAuth 2.0.</p><p>Users, based on their job roles or access levels, can be grouped together using <strong>IAM groups.</strong> Admin user can group users into an IAM group and assign the required policy(s) to that group. E.g. an IT company has departments such as HR, Finance, Legal, IT admins etc., hence all the users under HR department can be grouped together in a IAM group called ‘HR’ and admin can give them limited access by assigning required permissions to HR IAM group. IAM group gives the central control over users under than group, and ease of managing their permissions. It is also quite easy to add or remove users from a group.</p><p>Many AWS services may require access to other AWS service(s) on user’s behalf, may be read only access/limited/full access. AWS has <strong>IAM roles</strong> for this type of requests. Create an IAM role with required permissions for the service and assign it to it. E.g. application running on EC2 might want access to S3 service to read and put objects in S3 buckets, and IAM role for EC2 with ‘<em>AmazonS3FullAccess’ </em>can be attached to EC2 for this purpose.</p><p>There are scenarios where your application or users that don’t normally have access to your AWS services, need access but on a temporary basis. IAM role along with <strong>temporary security credentials</strong> solve this problem. In these scenarios, the IAM role is not assigned to any user or service, instead the role is ‘assumed’ by the IAM user, AWS service or application running on EC2. When any role is assumed, it returns the temporary security credentials which will be used by application or user to access the AWS services programmatically. Every temporary security credentials have expiration which can be configured as per need.</p><p>Any user, role or group of users, need permissions to access AWS services. <strong>IAM policy</strong> provide you with set of permissions which you can use to give IAM users/role required level of access. Any IAM policy has following elements in it:</p><ul><li>Version- Specify the version of the policy language that you want to use. As a best practice, use the latest 2012–10–17 version.</li><li>Statement — Use this main policy element as a container for the following elements. You can include more than one statement in a policy.</li><li>Sid (optional) — Include an optional statement ID to differentiate between your statements.</li><li>Effect — Use Allow or Deny, to indicate whether the policy allows or denies access.</li><li>Principal (optional) — Indicate the account, user, role, or federated user to which you would like to allow or deny access. If you are creating a policy to attach to a user or role, you cannot include this element. The principal is implied as that user or role.</li><li>Action — Include a list of actions that the policy allows or denies.</li><li>Resource — Specify a list of resources to which the actions apply.</li><li>Condition (optional) — Specify the circumstances under which the policy grants permission.</li></ul><p>A simple IAM policy allows the implied principal to list a single Amazon S3 bucket named example_bucket:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*F2l0v7i0ioHKreGGq79nRQ.png" /></figure><p>The policy allows members of a specific AWS account to perform any Amazon S3 actions in the bucket named ‘mybucket’ or objects within it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*Za0T0fCzHXpO5i42hRt9kQ.png" /></figure><h3>Enable Security | Detective Controls</h3><p>While IAM enables you to manage users, their permissions and restrict access to AWS services or application, it is not enough to declare or consider your application as secure. Anyone who gains unauthorized access to your root access keys, can login to your AWS environment programmatically and may perform malicious activities.</p><p>Placing detective controls in your application or as a process, help you in detecting potential threats or security incidents. In AWS, following will help you in setting up the detective controls:</p><ol><li>Capture and analyze logs</li><li>Integrate auditing controls with notification and workflow</li></ol><p><strong>Capture and analyze logs</strong></p><p>There are many approaches through which logs can be captured and analyzed — agent-based tools, API services can be used to capture and send the logs to central location on a server or to an object level storage or direct events to real-time log processing service.</p><p>In AWS, <strong>CloudTrail </strong>records every API activity call in your AWS account and when you create your AWS account the CloudTrail is enabled by default, you can see the API activities of past 90 days and by default CloudTrail stores logs in S3 bucket. You can create a new trail and direct the trail to <strong>CloudWatch logs</strong> for monitoring and analysis. You can enable CloudTrail for all regions and for all accounts under an AWS organization. You can configure CloudTrail to send the trails to CloudWatch logs for analysis. You can also use <strong>Amazon Macie</strong> service to analyze CloudTrail logs to identify suspicious API activities and protect any sensitive data such as API keys, secret keys, PII etc. in your AWS account or organization.</p><p><strong>VPC Flow logs </strong>is a feature that captures IP traffic going in and out from network interfaces in your VPC. Flow log data gets stored in CloudWatch logs. Flow logs can be created at three levels: VPC, Subnets and Network Interface level. However, following traffic is NOT monitored by Flow logs:</p><ul><li>Traffic generated by instances when they contact Amazon DNS server</li><li>Traffic to the reserved IP addresses to that default VPC router</li><li>Traffic generated by windows instances for activation of Amazon Windows license</li><li>Traffic to and from the <a href="http://169.154.169.154/">http://169.154.169.154</a> for instance metadata</li><li>DHCP traffic</li></ul><p>Another AWS service called <strong>Athena</strong>, can be used to analyze logs using simple interactive queries using standard SQL. Athena uses machine learning. You just need to point the S3 bucket towards Athena and there you go. Athena can process unstructured, semi-structured, and structured data sets such as CSV, JSON, Avro or columnar data formats such as Apache Parquet and Apache ORC. Athena integrates with AWS QuickSight to give you interactive dashboard.</p><p><strong>Integrate auditing controls with notification and workflow</strong></p><p>Though it is important, but it is not enough to capture and analyze collected logs or event history. It is a best practice to integrate the flow of security events and findings with notification and workflow system such as ticketing system or event management system.</p><p><strong>CloudWatch events</strong> are best suited for this. You can configure CloudWatch Events, by creating rules based on event pattern or schedule and invoke targets such as Lambda or SNS (Simple Notification Service) to receive alerts on Email/text or you can invoke any other service to mitigate the security event.</p><p><strong>AWS Config</strong> is another service, which continuously monitors and records your AWS resource configurations and allows you to automate the evaluation of recorded configurations against desired configurations. AWS Config helps you in compliance as well, e.g. ‘<strong>ec2-managedinstance-patch-compliance-status-check’</strong> config rule checks whether the compliance status of the AWS Systems Manager patch compliance is COMPLIANT or NON_COMPLIANT, after the patch installation on the instance. The rule is compliant if the field status is COMPLIANT. AWS Config is integrated with SNS to send you alerts in case of Non-Complaint events.</p><p><strong>Amazon Inspector</strong> is an automated security assessment service that helps improve the security and compliance of applications deployed on AWS. Amazon Inspector automatically assesses applications for exposure, vulnerabilities, and deviations from best practices. After performing an assessment, Amazon Inspector produces a detailed list of security findings prioritized by level of severity. These findings can be reviewed directly or as part of detailed assessment reports which are available via the Amazon Inspector console or API.</p><p>Amazon Inspector runs assessments for the assessment target against rules package(s):</p><ul><li>Network Reachability-1.1</li><li>Security Best Practices-1.0</li><li>Common Vulnerabilities and Exposures-1.1</li><li>CIS Operating System Security Configuration Benchmarks-1.0</li><li>Runtime Behavior Analysis-1.0</li></ul><p>During an assessment run, the rules described in this section generate findings only for the EC2 instances that are running Linux-based operating systems. The rules do not generate findings for EC2 instances that are running Windows-based operating systems.</p><p>While setting up CI/CD pipeline, Amazon Inspector agent can be installed in production instances or in a build pipeline, it notifies developers and engineers when security findings are present.</p><p><strong>Amazon GuardDuty</strong> is a managed threat detection service that uses <em>machine learning and anomaly detection to </em>continuously monitor for malicious or unauthorized behavior to help you protect your AWS accounts and workloads. GuardDuty analyses billions of events from DNS logs, VPC Flow logs and CloudTrail logs to detects threats. You can enable automated response using CloudWatch Events and Lambda with GuardDuty.</p><p>Some examples of what GuardDuty detects:</p><ul><li>Unusual API calls, calls from known malicious IPs</li><li>Attempts to disable CloudTrail logging</li><li>Unauthorized deployments</li><li>Compromised Instances</li><li>Port scanning, failed logins</li><li>UDP flood attacks and other DDoS attacks</li></ul><h3>Enable Security | Infrastructure Protection</h3><p>Protecting your Infrastructure is like the first layer of defense. AWS is responsible for protecting the Global Infrastructure such as Regions, AZs, Edge locations. AWS handles the maintenance and security overhead of host operating systems, virtualization layer and the physical security of the facilities where services operate.</p><p>Below figure shows the shared responsibility model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2gnLtj7srUbLtwdSOevY2Q.png" /><figcaption>AWS Shared Security Model</figcaption></figure><p>Next question would be how AWS secure its global infrastructure and services?</p><p>AWS has many years of experience in designing, constructing, operating and maintaining large scale data centers. This experience has been applied to the AWS platform and infrastructure. Their data centers are operating in highly secured facilities. Physical access is strictly controlled at parameter and at building entry/exit points by trained security guards with the help of video surveillance cameras, biometric security, intrusion detection systems and other means. Authorized staff must pass two-factor authentication a minimum of two times to access data center floors. All visitors and contractors are required to present identification and are signed in and continually escorted by authorized staff. AWS only provides data center access and information to employees and contractors who have a legitimate business need for such privileges. When an employee no longer has a business need for these privileges, his or her access is immediately revoked, even if they continue to be an employee of Amazon or Amazon Web Services. All physical access to data centers by AWS employees is logged and audited routinely.</p><p>These facilities have automatic fire detection and suppression equipment, electrical power systems, Uninterruptible Power Supply (UPS) units to provide back-up power, Climate control, Storage Device decommissioning process, life support systems and equipment.</p><p>All of the AWS data centers are online, running and serving customers, no data center is “cold”. Data center operating in one AZ for a customer might be operating in a different AZ for another customer. AWS always shuffles the data center allocation deliberately so that all facilities are utilized and serve customers.</p><p>e.g. use1-az3 under AZ us-east-1e might be allocated to us-east-1b for another customer AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fXPp_iztsE_veerQj8VdQ.png" /></figure><p>AWS has world-class Network infrastructure to enable you to secure your workload. Network devices, including firewalls are in place at the network boundary to implement access control lists, traffic flow policies.</p><p>Multiple layers of defense are advisable in any type of environment. You can protect your infrastructure within your AWS account, by enforcing boundary protection, allowing and monitoring of ingress and egress traffic, tailor or harden configuration of infrastructure services, using VPC (Virtual private cloud), Security groups, NACL (Network access control list), NAT gateways/instances, Bastian hosts, Route tables, public and private subnets.</p><p>Protection of guest operating systems, its patching and updates, application software, client data protection, access control are the responsibility of the customer, AWS has no liability in it.</p><p>AWS Marketplace has many security products, provided by third party providers or vendors, which you can purchase and use and save your time from configuring or hardening the raw resource. These security products can be — Firewalls, Hardened operating systems, Security Monitoring tools etc.</p><p>You can use AWS services which provides protection to your application.</p><p><strong>AWS WAF</strong> is a layer 7 Web Application Firewall that helps protect your web applications from common web exploits that could affect application availability, compromise security, or consume excessive resources. AWS WAF is deployed on either Amazon CloudFront or Application Load Balancer.</p><p><strong>AWS Shield</strong> is a managed Distributed Denial of Service (DDoS) protection service that safeguards applications running on AWS against the layer 3 and 4 attacks.</p><p>There are two flavors of AWS Shield: Standard and Advanced. AWS Shield Standard is enabled by default when anyone sign up and opens an AWS account. All AWS customers benefit from the automatic protections of AWS Shield Standard, at no additional charge.</p><p>While AWS Shield Advanced comes at a cost of $3000/month and provides protection from much more sophisticated layer 3 &amp; 4 attacks.</p><p>Here is the comparison table of AWS Shield Standard and Advanced features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YsmFTCmBdocYS5FKYBT-og.png" /><figcaption>AWS Shield Basic and Advanced</figcaption></figure><p><strong>Amazon CloudFront</strong> is fast, highly secure and programmable content delivery network (CDN) that delivers application, videos, data and APIs to global customers with high transfer speed and low latency. CloudFront use Edge locations to deliver contents by caching the contents. CloudFront origin can be S3 bucket, EC2 instance, Elastic Load Balancer, or Route53.</p><p>CloudFront uses TTL (Time to live) to determine how long the cached content will stay in CloudFront caches before CloudFront makes another request to your origin to determine whether the object has been updated. TTL is always in seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*VtyzTU7RA7IQQDql-Iuodg.png" /></figure><p>If you use S3 bucket as the origin and you want your users to access the S3 content using CloudFront URL only instead of S3 URLs then you can use ‘Restrict Bucket Access’ feature which will create a special CloudFront user — Origin access identity — to the origin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*tx1QRV1gwBg3o0VNXDrojA.png" /></figure><p>You would also need to update the bucket policy to allow special CloudFront user i.e. Origin access identity, to be able to access S3 bucket objects; you can select an option to let CloudFront update the bucket policy for you or you can manually update it. Either way, you should review the bucket permissions once you update it.</p><p>AWS WAF is integrated with CloudFront and if you are using WAF and want WAF to allow or block requests based on the conditions you specify the you can do that by associating the web ACL with CloudFront distribution.</p><p>Although you are ensuring that host level protection is implemented but now consider how EC2 hosts (virtual servers) uses key pairs to protect login information; EC2 uses public key cryptography for this purpose. In public-key cryptography, public key is used to encrypt the data and the recipient uses private key to decrypt the data. Public-private keys together called “key-pair”.</p><p>There two ways you can generate EC2 key-pair,</p><ol><li>In the AWS Management console, go to EC2 dashboard under on the left-hand menu you’ll find the ‘Key Pairs’ option; from where a new key pair can be generated.</li><li>You can import a key pair generated by the third-party software.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*aD6ym9KZpwz54PfoLHQxcg.png" /></figure><p>Amazon EC2 stores public key only and the AWS user stores the private key. If you lose the private key, there is no way to recover it and the instance which this lost key pair was attached to, becomes inaccessible. In this case, a new EC2 key-pair should be created and that EC2 instance must be terminated and a new EC2 instance will have to be launched with new key-pair.</p><h3>Enable Security | Data Protection</h3><p>Let’s focus on protecting the data. Businesses stores some key information in the form of employee records, customer details, credit history records etc. These can be name, address, contact number, email, health information, card details etc. Important and sensitive data needs to be protected, if this information is stolen, it can then be used for identity theft, phishing scams or other types of fraudulent activities.</p><p>To ensure that the important and sensitive data is secure, the first step is to classify the data into categories then implement the security accordingly. One way to classify the data, is to categorize it on the level of its sensitivity such as Critical, Medium &amp; Low. Based on the data classification, appropriate access should be given; e.g. Data classified as Low category may be public facing which can be accessible to anyone, while data resides in Critical category should be given access to only who are authorized to access those data.</p><p>Applications also need access to data, it can be data at rest or data in transit. Encryption is the best way to secure your data in both cases. In AWS, <strong>KMS (Key Management Service)</strong> provides encryption keys which you can use to encrypt-decrypt your <strong>data at rest</strong>. AWS KMS is integrated with AWS services to simplify using your keys to encrypt data across your AWS workloads. It is also integrated with AWS SDK to enable you to provide data protection within your application. AWS KMS uses FIPS 140–2 validated hardware security modules (HSMs) to generate and protect keys.</p><p>There are two types of KMS keys:</p><ol><li>AWS managed keys</li><li>Customer managed keys</li></ol><p>AWS managed keys as the name suggests, are fully managed by AWS which means AWS generates, manages and rotates the keys. Customer managed keys however provide flexibility in terms of how you want to generate, manage and rotate encryption keys. Customer managed keys provides options for how you want to generate key material:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*a7OO0fOqeHLn6PVwaWq-YA.png" /><figcaption>AWS KMS</figcaption></figure><ul><li><strong>KMS</strong>: Use this option if you want AWS to generate key material and you manage the key and the rotation.</li><li><strong>External</strong>: If you want to use the key material which is generated by you, then you can use this option to import the external key material into AWS.</li><li><strong>CloudHSM</strong>: If you have any corporate, contractual or regulatory compliance requirement such as licensing compliance where the encryption keys must reside on dedicated HSM cluster. Although AWS KMS are generated in and protected by hardware security modules (HSMs) that are FIPS 140–2 validated cryptographic modules but if you want more granule control of your HSMs then CloudHSM is the answer for it. When you generate encryption keys in CloudHSM, AWS generates 256 bit, persistent, AES symmetric keys in AWS CloudHSM cluster in your account while you retain the full control of the HSM cluster and keys generated.</li></ul><p>To reduce the risk of unauthorized access to your data residing on different storages such as block storage, object storage, databases or any storage medium where it persists, it is a best practice to protect data at rest. Services such as S3, Amazon EBS (Elastic Block Store), Glacier, RDS (Relational Database Service) at integrated with AWS KMS to provide protection to data at rest.</p><p>Protecting <strong>data in transit</strong> is equally important as protecting data at rest. Data gets transferred from one system, service or application to another. Protecting data in transit protects the confidentiality and integrity of data. In AWS you can protect data in transit through some of the following ways:</p><ol><li><strong>AWS Certificate Manager</strong> is the certificate management service provided by AWS, which can be used to generate, manage, deploy and renew SSL/TLS certificates. Various AWS services such as Elastic Load balancer, Amazon CloudFront, Amazon API Gateway, AWS CloudFormation are integrated with AWS Certificate Manager service to serve secure content over SSL/TLS.</li><li><strong>VPN (Virtual Private network)</strong>: Use IPsec VPN for securing connections between VPC and on premises data center/office.</li><li><strong>Configure Protocol Policy:</strong> Configure HTTPS protocol in Amazon CloudFront and HTTPS listeners in application load balancer.</li><li><strong>Enforce encryption in transit: </strong>You can enforce encryption in transit using resource policies or host level security. For example, in S3 bucket policy you can include following condition with Deny effect to enforce SSL requests only:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*2KQbhfZ1dPXWZT_Su9bn4Q.png" /></figure><p>Another example is to use security groups to accept only HTTPS traffic.</p><h3>Enable Security | Incident Response</h3><p>Even though you have followed all the best practices in securing your infrastructure, data, network etc., there is always a chance of your resources getting unauthorized access, data prone to get leaked or attack on your systems. It is very important to act calmly, quickly and take the correct steps in first go to respond to the security incident. Keep the tools and access in place before the security incident is not enough until you practice the incident response periodically.</p><p>Consider a scenario where your EC2 instance has been compromised, what would you do to minimize the damage? You might know the actions you need to perform but how quickly do you perform, that’s what matters in the situation like this. Here comes the power of automation, AWS CloudFormation gives you power to quickly launch a trusted isolated environment where you can perform the investigation on the compromised instance(s).</p><p>Your organization might have the Incident response team in place but during the incident it is equally important that the team has appropriate access to necessary tools and services. Your response team may need to work with other teams as well during the incident, it is important to know how to get access for the other people or team otherwise there could be a delay in responding to incident. Services such as AWS CloudTrail, Amazon CloudWatch Events, AWS Step Functions can assist you in the investigations.</p><p>Use <strong>AWS Security Hub</strong> to aggregate, organize, and prioritize your security alerts, or findings, from multiple AWS services, such as Amazon GuardDuty, Amazon Inspector, Amazon Macie, AWS Identity and Access Management (IAM) Access Analyzer, AWS Systems Manager, and AWS Firewall Manager, as well as from AWS Partner Network (APN) solutions.</p><h3>Security Best Practices</h3><p>Although there are lot of security best practices to follow to protect your data and assets of your organization, but here are a few which you can start with and define your Information Security Management System.</p><ol><li>Enforce least privilege access</li><li>Logging and monitoring tools</li><li>Apply Multi Factor Authentication wherever possible</li><li>Use encryption</li><li>Apply automation</li><li>Get notified</li><li>Backup and recovery plan and tools</li><li>Updates and security patching</li><li>Restrict traffic</li><li>Test your security periodically</li></ol><h3>Conclusion</h3><p>Security is an important part of your system design and especially when you are running your workloads in the cloud. Even a smallest security error may lead to huge data or financial loss. You need to protect your infrastructure, data, network, application etc. and have the controls in place which keeping you updated about what is happening in and around your system and notify you when any security incident happens, so you can act upon the incident in a quick and efficient way to minimize the impact of the incident.</p><p>AWS services help you in securing your assets and data in all possible way.</p><p>Let me know your thoughts and any security service you want me to write about in detail. I tried to kept this blog short but covering all aspects of security in AWS.</p><p>Happy learning!</p><h3>References and further reading</h3><p>Amazon Web Services Security Pillar whitepaper <a href="https://d1.awsstatic.com/whitepapers/architecture/AWS-Security-Pillar.pdf">https://d1.awsstatic.com/whitepapers/architecture/AWS-Security-Pillar.pdf</a></p><p>AWS Security Best Practices whitepaper <a href="https://d1.awsstatic.com/whitepapers/Security/AWS_Security_Best_Practices.pdf">https://d1.awsstatic.com/whitepapers/Security/AWS_Security_Best_Practices.pdf</a></p><p>AWS documentation <br><a href="https://docs.aws.amazon.com/">https://docs.aws.amazon.com/</a></p><p>AWS re:invent 2017: Best Practices for Implementing AWS Key Management Service (SID330) <br><a href="https://www.youtube.com/watch?v=X1eZjXQ55ec">https://www.youtube.com/watch?v=X1eZjXQ55ec</a></p><p>AWS Cloud Best Practices <a href="https://media.amazonwebservices.com/AWS_Cloud_Best_Practices.pdf">https://media.amazonwebservices.com/AWS_Cloud_Best_Practices.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a573e5ee687" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Invoking Private REST APIs (Amazon API Gateway) with custom domain name and SSL, from On-premise]]></title>
            <link>https://someshsrivastava1983.medium.com/invoking-private-rest-apis-amazon-api-gateway-with-custom-domain-name-and-ssl-from-on-premise-946eacdf295e?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/946eacdf295e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[amazon-api-gateway]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Fri, 26 Feb 2021 11:04:39 GMT</pubDate>
            <atom:updated>2021-02-26T15:37:26.040Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*0b-kw-u9Fa5PmURJUFeCLg.png" /></figure><h3>Introduction</h3><blockquote>Lot of AWS customers are having hybrid deployment where their systems running at their data center need to access APIs running in AWS environment over Direct Connect/VPN. Enabling Private APIs running in AWS environment and accessing it using custom domain names, from systems running in data center, can help customers building the secure Hybrid environment and run their API-powered applications in a seamless manner specially when paradigm is shifting towards building microservices application design pattern.</blockquote><p>One of the customers I worked with is a worldwide bank that has been migrating its on-premise workloads to AWS but due to some technical limitations, their Enterprise API gateway would need to remain at on-premise and keep Authenticating and Authorizing the API requests (with SAML token) for APIs hosted on AWS serverless compute via Amazon API Gateway Private Endpoints. The hybrid environment setup required the use of custom domain name (such as abcbank.com) for private REST APIs, so that these API URLs can be exposed at their Enterprise API gateway.</p><blockquote>At the time of writing this article, and as per official AWS documentation, Custom domain names are not supported for private APIs.</blockquote><h3><strong>Solution overview</strong></h3><p>For demo perspective, I have simplified the solution; I’m using the public certificate from ACM, Public R53 hosted zone and Simulated On-premises environment with VPC and VPC Peering.</p><p><em>Following are the steps taken to build the solution:</em></p><ol><li>Request/Import private certificate(s) in Amazon Certificate Manager (I’m using Public certs for demo)</li><li>Create Interface VPC Endpoint for execute-api with private DNS enabled</li><li>Create APIs in either Lambda/ECS/EKS (I’m using Lambda for demo)</li><li>Create API Gateway with Private Endpoint</li></ol><p>a. Create API integration<br>b. Create custom domain names with certificates and configure API mapping<br>c. Create API resource policy to allow traffic from VPC endpoint only<br>d. Deploy APIs</p><p>5. Create Network Load Balancer or Application Load balancer with private certificate and target to the VPC endpoint ENI (I’m using Network Load balancer for demo)</p><p>6. Create Amazon Route 53 Alias records in the Private hosted zone with traffic routing to NLB (I’m using Public hosted zone for demo)</p><p>7. Simulated On-premises environment with VPC and VPC Peering (Additional step for demo purpose only)</p><p><strong>High-level architecture of the implemented solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5cRJECKM5_mRir0CvatsLw.png" /></figure><p>I have taken the use case to showcase the real-world scenario where customer may have multiple APIs or single API with multiple methods and resources.</p><h3><strong>Getting started</strong></h3><p>To follow along with this post, you must have:</p><p>1. Already have the VPN or Direct Connect connection between your On-Premise and AWS environment<br>2. AWS account having an application VPC with connectivity to On-premise<br>3. Private subnets for deploying the workloads &amp; infrastructure<br>4. A registered domain name in order to set up custom domain names for your APIs</p><p>For full disclosure, I have already setup Two VPCs — Default VPC for deploying workloads &amp; Simulated On-premise and have created the VPC Peering connection between them (Step# 7):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*aNOnaBQs2bkUyuWUYP6AwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*N6llAuLC4CPl_gnwTp2H3A.png" /></figure><p><strong>Step 1: Request/Import certificate in AWS Certificate Manager:</strong></p><p>I already have a Public certificate requested from Amazon. If you need guidance about how to Import/request Public or Private certificate via AWS Certificate Manager, I’d suggest <a href="https://docs.aws.amazon.com/acm/latest/userguide/gs.html">Issuing and Managing Certificates</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8kyN5Gg2mc1TUt3oOJGfg.png" /><figcaption>ACM</figcaption></figure><p><strong>Step 2: Create Interface VPC Endpoint for API Gateway:</strong></p><p>API Gateway private endpoints are made possible via AWS PrivateLink interface VPC endpoints. Interface endpoints work by creating elastic network interfaces in subnets that you define inside your VPC. If you like to understand more on API Gateway evolution, do refer <a href="https://aws.amazon.com/blogs/compute/introducing-amazon-api-gateway-private-endpoints/">Introducing Amazon API Gateway Private Endpoints</a></p><p>1. Open the Amazon VPC console<br>2. In the left navigation pane, choose Endpoints, Create Endpoint<br>3. For Service category, keep it set to “AWS Services”<br>4. For Service Name, set it to “com.amazonaws.{region}.execute-api”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5hlKnbV3Wo89DhM29Vflcw.png" /></figure><p>5. For VPC, select the Application VPC where you want to deploy the APIs. APIs can only be accessed using the deployed ENIs in the VPC you choose.</p><p>6. For Subnets, select the private subnets from application VPC. Make sure that you provide multiple interfaces in your VPC i.e. endpoint in each subnet in each Availability Zone for which the VPC is configured.</p><p>7. For Enable Private DNS Name, keep it checked as Enabled for this endpoint.</p><p>8. Attach the security group which only allows the desired traffic to invoke the APIs. If you are planning to use the Application Load Balancer, then this security group should only allow specific port &amp; protocol from ALB security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2XbZLs-a4E7JIKZF6grkKw.png" /></figure><p>9. For Resource policy, keep the default</p><p>10. Choose Create Endpoint</p><p>11. VPC Endpoint will be created with pending state, wait for few minutes until it shows the status as ‘available’. I’d suggest to refer <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpce-interface.html">Interface VPC endpoints (AWS PrivateLink)</a></p><p>In the Subnets tab, you’ll get the private IP address of the ENIs, if you have chosen multiple subnet (one in each AZ) then you should see IP address for each subnet. I’ll use this IP address as target of ELB.</p><p>Also note the Endpoint ID, it will be used while creating the Private API in API Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RuBi5chmzq_O-NqUAargKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ar6QX4_NtsDIHfIj1LyVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMNwVNNCnNu65K4A98dYHw.png" /></figure><p>Security group used by VPC Interface endpoint, allows Port 80 &amp; 443 traffic from application VPC and Simulated On-premise only -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HhzGIb4gMUmYtdT5hdhcAQ.png" /></figure><p><strong>Step 3: Creating APIs:</strong></p><p>For simplicity, I have created very basic Lambda functions in Python runtime environment. I will use three Lambdas for two APIs.</p><p>These Lambda functions are created in the subnet of application VPC where the API Gateway ENIs are deployed. Security group used by Lambdas, allows Port 80 &amp; 443 traffic from application VPC only.</p><p>1. Lambda 1 will work as <strong>1st resource of First API </strong>in API Gateway<br>2. Lambda 2 will work as<strong> 2nd resource of First API</strong> in API Gateway<br>3. Lambda 3 will work as <strong>Second API</strong> in API Gateway</p><blockquote>You can deploy your APIs in ECS or EKS with Fargate/EC2 also, depending on your requirements and use case.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*QdQFMdvdQf-rmGzb0WeHGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TcIAavJ4a7fs44UzDGyOag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1drsJk5ORLTbN1LLfVh3cw.png" /><figcaption>Lambda 1 configurations</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IgiGJUWCXLH7Fmgoo3vmBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*14LuTMdp0g9wN1f_E1VP8A.png" /><figcaption>Lambda 2 configurations</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTDQwwXWoLMRbaF9OzXJsQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZS2qYNsvSW8nD77X42pJw.png" /><figcaption>Lambda 3 configurations</figcaption></figure><p><strong>Step 4: Creating API Gateway with Private Endpoint</strong></p><p><strong>4a.</strong> I’ll create two Private REST APIs in API Gateway. One API with two resources and One API with single resource. Refer <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-apis.html#apigateway-private-api-create-using-console">Creating a private API in Amazon API Gateway</a></p><p>1. Go to API Gateway service<br>2. Choose REST API Private and click on Build</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*CzqPIQlekYAxkUXtnDFIXA.png" /></figure><p>3. Select ‘New API’ checkbox –</p><p>a. Enter your API name<br>b. Enter description (Optional)<br>c. Choose the Endpoint Type as ‘Private’<br>d. In the VPC Endpoint IDs textbox, enter the VPC ID created earlier (refer step# 11)<br>e. Click on Create API button</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yQYO0V1JjNwzo6RSg5VM3A.png" /></figure><p>4. Under Resources, you’ll see nothing but /. This is the root-level resource, which corresponds to the base path URL for your API (https://&lt;API id&gt;. execute-api.&lt;region&gt;.amazonaws.com/{stage-name}).</p><p>From the Actions dropdown menu, choose Create Method.</p><p>5. Select the method type for your API. Here I’m going to get the value from the Lambda hence I’m using GET method.</p><p>6. In the / — GET — Setup pane, for Integration type, choose Lambda Function. If you have not created your APIs in Lambda, then choose the appropriate Integration type. I’d suggest to refer <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-integration-types.html">Choose an API Gateway API integration type</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGYSOtng0AelQyNKrvZa0Q.png" /></figure><p>7. Choose Use Lambda proxy integration.</p><p>8. For Lambda Region, choose the Region where you created your Lambda function.</p><p>9. In the Lambda Function field, type any character and then choose the appropriate Lambda (or whatever name you gave the function that you created in the previous step) from the dropdown menu. (If the dropdown menu doesn’t appear, delete the character you just typed to make the dropdown menu appear.) Leave Use Default Timeout checked. Choose Save to save your choice.</p><p>I have used the First Lambda function ‘Hello-lambda1’ which is the 1st resource of our First API.</p><p>10. When the Add Permission to Lambda Function popup appears (saying “You are about to give API Gateway permission to invoke your Lambda function…”), choose OK to grant API Gateway that permission.</p><p>11. Now you’ll see a / — GET — Method Execution pane:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gkgZqU5qBS2loN7G6sKmlg.png" /></figure><p>We are now good with our First resource for our 1st API. I need to create a child resource for this API where I’ll choose our Second Lambda function ‘Hello-lambda2’.</p><p>12. From the Actions dropdown menu, choose Create Resource. Name the resource and click on Create Resource</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*29rXL6OW2-mORXkv6eTaOQ.png" /></figure><p>13. Repeat step# 7–11 to integrate the second Lambda function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dhvRlSP3XlLqd4QsqLrxYA.png" /></figure><p>14. Now you’ll see a /test-resource — GET — Method Execution pane:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jp7tzK83igBkm9UP_2Ijfg.png" /></figure><p>Till this point we have built our First API — ‘Pvt-lambda-test-api’ with two API resources — one is the default resource integrated with ‘Hello-lambda1’ lambda function and second is the child resource integrated with ‘Hello-lambda2’ lambda function.</p><p><strong>4b. Create Resource Policy</strong></p><p>Before I deploy the APIs, I need to configure access control to this private API using a Resource Policy. Access can be controlled by IAM condition elements, including conditions on AWS account, Source VPC, VPC Endpoints (Private API), and/or IP range.</p><p>Learn more <a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html">Controlling access to an API with API Gateway resource policies</a></p><p>For demo perspective, are using a simple Resource policy which ensure that the API is accessible only through the VPC Interface Endpoint –</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*XP4Rrg4kdIsOxIYeQLS9CQ.png" /></figure><p><strong>4c. Deploy your REST API</strong></p><p>Once you complete above step, you’ve created an API, but you can’t actually use it yet. This is because it needs to be deployed.</p><p>1. From the Actions dropdown menu, choose Deploy API<br>2. From the Deployment stage dropdown menu, choose [New Stage]<br>3. For Stage name, enter the stage name (I used demo)<br>4. Choose Deploy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*4ixGXI0Kqbgm5KU-5s8CDw.png" /></figure><p>In the Stage Editor, note the Invoke URL at the top. It should be in this format: (https://nwnx6564r0.execute-api.us-east-1.amazonaws.com/demo). If you choose the Invoke URL, it will open a new browser tab with that URL since but you’ll NOT any response from Lambda because it is not the Publicly accessible endpoint, I have created this Private API to be accessible only from the VPC endpoint deployed within the VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gObdtCUp-vMCCGa6_LgZpA.png" /></figure><p><strong>4d. Create custom domain name for Private API</strong></p><p>1. Choose Custom domain names from the main navigation pane<br>2. Choose Create<br>3. For Domain name, enter a domain name<br>4. Under Configuration, choose Regional<br>5. Choose a minimum TLS version<br>6. Choose an ACM certificate. The certificate must be in the same Region as the API<br>7. Choose Create<br>8. Follow the Route 53 documentation on <a href="https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html">configuring Route 53 to route traffic to API Gateway.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ni-7CaXwpZd2M8Fq2HRf9A.png" /></figure><p>The following procedure sets up API mappings to map paths from your custom domain name to your API stages.</p><p>1. Choose a custom domain name in the API Gateway<br>2. Choose Configure API mappings<br>3. Choose Add new mapping<br>4. Specify the API, Stage, and Path for the mapping<br>5. Choose Save</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y9x2GDLt9WIUvBdAzM94tw.png" /></figure><p>More on<strong> </strong><a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html">Setting up custom domain names for REST APIs</a></p><p><strong>We have our First Private API with two API resources (default and test-resource) and custom domain name — ‘pvt-api.awshero.co.uk’</strong></p><p>Repeat step 4 to create a second Private API with Integration with Lambda ‘Hello-lambda3’, attach a Resource policy and associate a custom domain name with API mapping. This API will be treated as Second API with default resource.</p><p>I have gone ahead and created and Second API and deployed it -</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U25KsvB6hCAVO81UhaIpCQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*oryt63AFoSaBdm9FGrwKXg.png" /></figure><p><strong>I have also created the custom domain name ‘pvt-api2.awshero.co.uk’ and configured the API mapping –</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m-QOyKq-macMqCiuQQC1nw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mN_vQ7szi7BKDgiZ1gcA4w.png" /></figure><p>Now that I have TWO APIs with custom domain name:</p><p><strong>1. pvt-api.awshero.co.uk<br>2. pvt-api2.awshero.co.uk</strong></p><p><strong>Step 5: Create Network Load Balancer or Application Load balancer with SSL certificate and target to the VPC Interface endpoints</strong></p><p>1. In the navigation pane, under LOAD BALANCING, choose Load Balancers<br>2. Choose Create Load Balancer<br>3. For Network Load Balancer, choose Create<br>4. For Name, type a name for your load balancer<br>5. For Scheme, select ‘internal’<br>6. For Listeners, select TLS (Secure TCP) and port as 443</p><p>7. For Availability Zones, select the VPC that you used for deploying your workloads. For each Availability Zone that you used to deploy VPC Interface endpoints, select the Availability Zone and the subnets</p><p>8. By default, AWS assigns an IPv4 address to each load balancer node from the subnet for its Availability Zone</p><p>9. Choose Next: Security Settings</p><p>a. For Certificate type: Choose a certificate from ACM</p><p>b. For Certificate name: Select the appropriate certificate, same as you used while creating custom domain name in API gateway</p><p>c. For Security policy: Select ELBSecurityPolicy-TLS-1–2–2017–1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7YcSme_rDC9Dt3oloGpaDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sn09BBdGkHNtRI3PSXQ2LA.png" /></figure><p>10. Choose Next: Configure Routing<br>11. For Target group, keep the default, New target group</p><p>a. For Name, type a name for the new target group</p><p>b. Keep Protocol as TLS, Port as 443, and Target type as IP</p><p>c. For Health checks, keep the default protocol</p><p>12. Choose Next: Register Targets</p><p>a. Select the application VPC where the VPC Interface endpoints are deployed</p><p>b. For IP: enter the IP address of the endpoint (if you have multiple ENIS then enter all IP addresses) and click Add</p><p>13. On the Review page, choose Create</p><p>14. Load balancer will take some time to create and to evaluate the Health of the Interface Endpoints. You should see the Healthy status after some time. If Unhealthy, then check the Security group of the Interface Endpoints whether they are configured to allow traffic from VPC CIDR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*riwvy7SlkqkIPXOXMSRf8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gjy7xtSvPYc3JQxKgY4d3g.png" /></figure><p><strong>Step 6: Create Amazon Route 53 Alias records in the Private hosted zone with traffic routing</strong> to NLB</p><ol><li>In the navigation pane, choose Hosted zones</li><li>If you already have a hosted zone for your domain, skip to step 5. If you don’t, perform the applicable procedure to create a hosted zone:</li></ol><p>a. To route internet traffic to your resources, such as Amazon S3 buckets or Amazon EC2 instances, see Creating a public hosted zone</p><p>b. To route traffic in your VPC, see Creating a private hosted zone</p><p>3. Choose Create record<br>4. Select the Simple routing, click next<br>5. Click Define Simple record as per below –</p><blockquote>Important note: Record name in R53 MUST match the Record name created in the Custom domain name in API Gateway. Refer step 4d</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*llQuR27QgA3PELpMPjGZSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J6_Cpry-ZplVd0tLGBu1Kg.png" /></figure><p><strong>Testing</strong></p><p>For testing, I have Simulated the On-Premise environment with a VPC and have a VPC Peering connection with application VPC.</p><p>Let’s test the two APIs-</p><p><strong>Test:</strong> Pvt APIs — Amazon domain name with Endpoints</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rdH7C5PAF1DQoSJvfNEATA.png" /></figure><p><strong>Test:</strong> Pvt APIs — custom domain name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L9k3PYwZb6dnKaWSN0pwQg.png" /></figure><p><strong>Conclusion</strong></p><p>I have showcased a workaround on how the Private APIs (Amazon API Gateway) can be invoked securely using custom domain names with SSL certificates, from On-Premise environment.</p><p>You can also use AWS Direct Connect to establish a dedicated private connection from an on-premises network to Amazon VPC and access your private API endpoint over that connection by using public DNS names. You cannot use private DNS names to access your private API from an on-premises network.</p><p>I hope that you’ll be benefited from this Blog post on how you can Implement a small workaround to overcome the limitation of using custom domain name with Private APIs in Amazon API Gateway.</p><p>Happy Learning!!<br>Be AWSome!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=946eacdf295e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Federate your Organization’s Active Directory users to AWS Console & AWS CLI, using Okta & AWS SSO]]></title>
            <link>https://someshsrivastava1983.medium.com/federate-your-organizations-active-directory-users-to-aws-console-aws-cli-using-okta-aws-sso-82e69f1e9a53?source=rss-71f8e1d56be5------2</link>
            <guid isPermaLink="false">https://medium.com/p/82e69f1e9a53</guid>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[aws-sso]]></category>
            <category><![CDATA[active-directory]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Somesh Srivastava]]></dc:creator>
            <pubDate>Tue, 19 Jan 2021 17:04:42 GMT</pubDate>
            <atom:updated>2021-01-19T17:04:42.828Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*OulXxkPGxCpq7QUOGplYpg.jpeg" /></figure><p>If you or your organization is using Microsoft Active Directory and Okta; this article will help you integrate AWS SSO with Okta so that you can federate your Active Directory users to AWS Console and AWS CLI via Okta using existing Active Directory credentials.</p><p>(*You can also Connect AWS SSO to a <a href="https://docs.aws.amazon.com/singlesignon/latest/userguide/manage-your-identity-source-ad.html">self-managed Active Directory</a>; but this post of mine is specific for Enterprises/customers who are using Okta for extending SSO to applications.)</p><p>Organizations adopting the AWS Cloud require to manage identities with single source of truth. They may have already been using external identity providers such as Okta and onboarded their Enterprise applications or SaaS application such as Workday, so their users don’t have to create, maintain and remember credentials for every application.</p><blockquote>Identity federation is a system of trust between two parties for the purpose of authenticating users and conveying information needed to authorize their access to resources. In this system, an identity provider (IdP) is responsible for user authentication, and a service provider (SP), such as a service or an application, controls access to resources.</blockquote><blockquote>Federation is a common approach to building access control systems which manage users centrally within a central IdP and govern their access to multiple applications and services acting as SPs.</blockquote><blockquote>Single sign-on (SSO) is an authentication scheme that allows a user to log in with a single ID and password to any of several related, yet independent, software systems.</blockquote><p>Here are the high-level steps towards the solution (you can start from step 2 if you have your existing MS Active Directory):</p><p>1. Download and install Okta agent on domain controller</p><p>2. Setup &amp; configure Okta to connect to MS Active Directory</p><p>3. Setup AWS SSO in AWS</p><p>4. Configure AWS SSO application in Okta</p><p>5. Assign Groups/users to AWS SSO application in Okta</p><p>Step 0: For demo perspective, I have created a SimpleAD <strong><em>(with DNS name: simplead.awshero.co.uk)</em></strong> in AWS account instead of Microsoft Active Directory. Here, my organization’s domain is <strong>awshero.co.uk</strong>; yours can be example.com or something else and you would be using a Microsoft Active Directory at on-premise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wcA5oGUlOX9_4AaoRyr3vA.png" /></figure><p>A Windows 2019 Server EC2 instance to connect and manage Active Directory and join the Active Directory domain, to act as domain controller:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5bQ67d25Ot3jWA01lEmnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udbO8C3gArsGpLCTRgfLKw.png" /></figure><p>Once running, login to EC2 using Administrator of the domain:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*nMkoION3irNgXL0cRWS32w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rgQ6DgiG6k46X0bQnv4kbQ.png" /></figure><p>Install the required tools to interact with AD:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aHUhLpy9QZxss8L-f_pwUw.png" /></figure><p>If everything gets successful, the Active Directory tools will be available in the Windows Start menu:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XXWMiCoF-57c-m0UAENtwQ.png" /></figure><p>Go to ‘Active Directory Users and Computers’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wI3a2-5gI-GU7squS_W0g.png" /></figure><p>Created one Group — ‘AWS-AdminAccess’ and two admin users under it. (you may be having lots of Groups and User in your Active Directory)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Ed7K_P0EPZz4qQ8wEKYhA.png" /></figure><p><strong><em>Now let’s move to setup and configure Okta (I presume that Okta is already setup in your organization, if not then refer the Okta </em></strong><a href="https://help.okta.com/en/prod/Content/Topics/users-groups-profiles/usgp-self-register-for-end-users.htm"><strong><em>documentation</em></strong></a><strong><em> to create an Okta account and get start with Okta)</em></strong></p><p><strong>Step 1: </strong>Download and install Okta agent on the domain controller of Active Directory. (Refer the Okta <a href="https://help.okta.com/en/prod/Content/Topics/Directory/ad-agent-new-integration.htm">documentation</a> for detailed instructions.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*LvC3ZGs585E4XM2o-WFg5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*3KJLRZXQkW7QdIdVmZaANw.png" /></figure><p>Once installed successfully, Active Directory should be visible on Okta Directory Integrations page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*1DG1ItfNn9iuJTUQhm-KBA.png" /></figure><p><strong>Step 2: Now, it’s time to configure Active Directory in Okta. </strong>You would see the OUs (Organization Units) from the Active Directory are visible in Okta which you would like to sync the users and the groups from. Select and move to Next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*BXiSSo9IO_FA-WqpLQlaIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*SU2vj8lcBSYTa0l6duoSuQ.png" /></figure><p>Next step is to identify the attributes from the Active Directory. Here is the Okta <a href="https://help.okta.com/en/prod/Content/Topics/Directory/Directory_AD_Field_Mappings.htm">documentation</a> for help on attribute mapping. I’ll stick to the defaults and click Next and your Active Directory configuration is done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W_cX1xJD6kdNJnJMAf2vOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6xt-I2qqIjCPjdHFefAdg.png" /></figure><p>Before proceeding to the next step, let me explain the ways, users and groups can be synced in Okta.</p><blockquote>1. <strong>Just-In-Time provisioning:</strong> JIT provisioning enables automatic user account creation in Okta the first time a user authenticates with Active Directory (AD) Delegated Authentication. <a href="https://help.okta.com/en/prod/Content/Topics/Directory/ad-agent-add-update-JIT.htm">Link</a></blockquote><blockquote>2. <strong>Schedule import</strong>: How often you want Okta to import users from Active Directory (AD). <a href="https://help.okta.com/en/prod/Content/Topics/Directory/ad-agent-schedule-imports.htm">Link</a></blockquote><p><strong>Option 1: Schedule import</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MjDhNXwSJ17fR9DHB4dpuA.png" /></figure><p>On ‘Import’ tab, clicking ‘Import Now’ button which will start importing the users and groups from Active Directory:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FZ1JGqCn5fHksddBCawHUg.png" /></figure><p>Two users which I created in Active Directory are now in Okta along with the Group ‘AWS-AdminAccess’:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1Odv9a6nVXEUj6ERrlZlg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ga4IrAONpVvkFgSM-_FjWw.png" /></figure><p>OR <strong>Option 2: Just-in-Time (JIT) provisioning</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TXIyH1IeAe_JgiSns5s5WA.png" /></figure><p>There are some configurational changes need to be made before importing the users from MS Active Directory which automatically confirms and activate new users. Go to ‘Provisioning’ tab and make the changes as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*46NiKnCM53NsIe0mnO8I0Q.png" /></figure><p>Since it is JIT provisioning, users will only be created in Okta at the time of their login attempt via Okta: (I’ll be using JIT for this demo)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*on_G8PXDFrdfFTs6UhJEeQ.png" /></figure><p>(*ignore the value 1 in the imported users confirmed; I tested this demo twice hence it is showing 1 user)</p><p><em>Next step is to configure this AWS Single Sign-On application in AWS and in Okta both.</em></p><p><strong>Step 3: Configure AWS SSO in AWS by following this step by step </strong><a href="https://saml-doc.okta.com/SAML_Docs/How-to-Configure-SAML-2.0-for-AWS-Single-Sign-on.html"><strong>guide</strong></a></p><p><strong>Step 4: Configure AWS SSO application in Okta</strong></p><p>Under Applications → Applications → ‘Add Application’ button and search for AWS Single Sign On and click Add:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZWJojgsJaYeydf8pJj6ILQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1vjayuljEO89mo6ad_Y_yw.png" /></figure><p>Give it a name and Done:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yinyRHm8LlkaTpUZlYIk8A.png" /></figure><p>AWS SSO application will be added to Okta:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*9i8hFtR6E8gipDZlfn7Y7g.png" /></figure><p><strong>Step 5: When done, Assign the desired group(s) to the AWS SSO application in Okta:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ShV429vI8NAexHJuEHLBaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzKHMfb93zJTy7MQpGhFmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0-6-IzVTCNCs1UsH2ZXEQ.png" /></figure><p><strong>We are ready for login. </strong>Use the AWS SSO URL as starting point; it will be redirected to the Okta login page. (*make sure you are logged out from any active AWS session or use the new browser window Firefox or Chrome Cognito).</p><p>You can get the AWS SSO URL by login into the AWS Account → AWS SSO service:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vxuq6gv0KQH8YnV0LTuiBQ.png" /></figure><p>I’ll login with one of the Active Directory users which was imported in Okta, upon hitting the AWS SSO portal url Okta authentication page will be displayed where user has to use his existing Active Directory credentials:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*ueF8qkeeve9s2ld4OfmBhQ.png" /></figure><p>Upon successful authentication, request will be redirected to the AWS SSO page but there will not be any AWS Accounts to show as the users do not have any AWS account(s) assigned to them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7EnR3yQuClYbq5ZYU9MmKQ.png" /></figure><p>Since, I used the JIT provisioning method in Okta, I can now see the second user admin2 in Okta, who attempted the login to AWS (* user admin1 was a part of my earlier test, please ignore)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCXEp6InjznmmY2xc5qq3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w37Tx43QvIizpsISlRcfyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h_M_TOXjgQR1ccYcdvjOIg.png" /></figure><p>Now, lets assign this user an AWS Account. To do that, login to AWS Account →AWS SSO →Users</p><p>You can see that the user admin2 is pushed by Okta to AWS SSO. To assign the user access, follow this AWS <a href="https://docs.aws.amazon.com/singlesignon/latest/userguide/useraccess.html">documentation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-7iwQJaT7mc0O3JDsrqliw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1rGIxvZfRwbKrVtgYHJ7ag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2i4tj-h8ZNKgwQZqwh_fA.png" /></figure><p>You can assign to the imported group as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*mKN2LnHKaKg-w-1bj2fiig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omEojn_r5jfcoW9Eir19tg.png" /></figure><p>Assignment completed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZbwiCB19KyywevusOpTzkA.png" /></figure><p>Logout and hit AWS SSO portal URL again with same user (I have admin2 user) and sign in again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*K89wLxfN80DpJlwUBSP0iA.png" /></figure><p>Now admin2 user has an AWS Account to sign in with the permission set he has been assigned to use:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_FcJxn6bvzYfIstaRmlS-A.png" /></figure><p>admin2 user logged in successfully to AWS Console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3qGMzQgbGfeUuKNE88Lu8A.png" /></figure><p><strong>Now, admin2 user wants to federate to AWS CLI with his Active Directory credentials. To access AWS CLI using SSO, user needs to follow below steps.</strong></p><p>Click on the Command line or programmatic access from the AWS SSO widget page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GR5-suQJtAIS-hfm8WB5_g.png" /></figure><p>Copy the details as per the OS and select Option 2 (you can also follow other given options as well) and update the AWS credentials file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bY7UQV4mDskwdwo5UrVk2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wqmz1OhvjsVFAdIIstonBQ.png" /></figure><p>Copy the AWS SSO URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Aeyffv3dUP8N0EmymADj2A.png" /></figure><p><strong><em>(make sure you have AWS CLI v2 installed before you continue to next step)</em></strong></p><p>Open the windows command prompt Type command ‘aws configure sso’ and enter the details as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SKZQrbIMx49WbVLKfzjNaA.png" /></figure><p>After hitting the enter, the AWS CLI will be redirected to the Okta page where user has to enter the Active Directory credentials:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x7e89ALccU7q4ToVU8JI5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*ZB6NUAVMqylB6FazjAgsCA.png" /></figure><p>(*If you are not a browser person then you use the device url &amp; the code AWS generated in AWS CLI)</p><p>Upon successful authentication, Sign-in to AWS CLI window will be displayed. Clicking the button will authorize the user to the AWS CLI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*NaHDaykrBONQ6ur-2P2ZsA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*dQr2eSSYSL0Xnelj98fQ6w.png" /></figure><p>AWS CLI will ask for a few details, after which user can interact with any AWS service he is authorized to use:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GYnnzi7VY-G3w_KPVCqgoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z9lniagQZ1fYgiRbTeU7kQ.png" /></figure><p>To logout from SSO, type aws sso logout command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0brl9iP8mMRGSVt7JujdXA.png" /></figure><p>If all went well, I hope with the help of this article you would have been able to integrate your Active Directory with Okta and AWS SSO. And the users would have been able to federate to AWS Console and AWS CLI with their Active Directory credentials.</p><blockquote>You no longer need to manage &amp; store AWS credentials for AWS console and AWS CLI; you are just using your existing Active Directory credentials to login to console and AWS CLI.</blockquote><p>I’ll share another article where I’ll be showcasing Azure AD Integration with AWS SSO, so if you have migrated from on-premise Microsoft Active Directory to Azure AD, you can federate your Azure AD users to AWS.</p><p>If you have any queries or issues do let me know in comments section, I’ll do my best to resolve your queries. If you want me to write an article on any AWS service or use case, do let me know that as well, I’ll try my best to write it up.</p><p>Please clap and follow me if you liked this article 😊</p><p>Thank you! Be safe.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82e69f1e9a53" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>