<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>iam on Alperen Doc</title><link>https://blog.ulutasalperen.com/docs/aws/iam/</link><description>Recent content in iam on Alperen Doc</description><generator>Hugo</generator><language>en</language><atom:link href="https://blog.ulutasalperen.com/docs/aws/iam/index.xml" rel="self" type="application/rss+xml"/><item><title>create-iam-user-and-group</title><link>https://blog.ulutasalperen.com/docs/aws/iam/create-iam-user-and-group/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/create-iam-user-and-group/</guid><description>&lt;h1 id="create-iam-user-and-group"&gt;Create IAM User and Group&lt;a class="anchor" href="#create-iam-user-and-group"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;h2 id="create-an-admin-level-iam-user-for-day-to-day-account-management-_this-will-be-primary-aws-login-management-user-"&gt;Create an admin-level IAM user for day-to-day account management. _This will be primary AWS login management user .&lt;a class="anchor" href="#create-an-admin-level-iam-user-for-day-to-day-account-management-_this-will-be-primary-aws-login-management-user-"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Navigate to the &lt;a href="https://console.aws.amazon.com/iam"&gt;IAM dashboard&lt;/a&gt;. You can also use the search bar at the top of the console to find it.&lt;/li&gt;&#10;&lt;li&gt;Click on &amp;ldquo;Users&amp;rdquo; under &amp;ldquo;Access Management&amp;rdquo; in the menu on the left, then click &amp;ldquo;Create user.&amp;rdquo;&lt;/li&gt;&#10;&lt;li&gt;Give the IAM user a name like &lt;code&gt;alperen-admin&lt;/code&gt; (using your own name).&lt;/li&gt;&#10;&lt;li&gt;Check the box &amp;ldquo;Provide user access to the AWS Management Console.&amp;rdquo;&lt;/li&gt;&#10;&lt;li&gt;Have AWS auto-generate an initial password, and leave the box checked to require a password reset on first login.&lt;/li&gt;&#10;&lt;li&gt;Create a new group for this user, called &lt;code&gt;Administrators&lt;/code&gt;. Attach the &lt;code&gt;AdministratorAccess&lt;/code&gt; policy to the group. Only the one policy is needed.&lt;/li&gt;&#10;&lt;li&gt;Assign the IAM user that you&amp;rsquo;re creating to the new group.&lt;/li&gt;&#10;&lt;li&gt;On the &amp;ldquo;Review and create&amp;rdquo; step, if everything looks right, click &amp;ldquo;Create user.&amp;rdquo;&lt;/li&gt;&#10;&lt;li&gt;Download the credentials CSV file. Note that AWS gives you a sign-in URL, the IAM username, and the initial password. &lt;em&gt;The sign-in URL has your AWS account ID in it.&lt;/em&gt;&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;hr&gt;&#10;&lt;h2 id="in-the-web-console-log-out-of-your-root-user-then-log-in-as-the-new-iam-admin-user"&gt;In the web console, log out of your root user, then log in as the new IAM admin user.&lt;a class="anchor" href="#in-the-web-console-log-out-of-your-root-user-then-log-in-as-the-new-iam-admin-user"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Use the sign-in URL from the credentials CSV.&lt;/li&gt;&#10;&lt;li&gt;The account ID should be pre-populated on the sign-in page, but save the ID number in case you need it for any future logins.&lt;/li&gt;&#10;&lt;li&gt;Enter the username you created and the auto-generated initial password.&lt;/li&gt;&#10;&lt;li&gt;You&amp;rsquo;ll be prompted to set a new password for the IAM user. Create one and save it.&lt;/li&gt;&#10;&lt;li&gt;If prompted, set up MFA for the IAM user as well (not as critical as with the root user, but still recommended).&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;From this point on, use the IAM admin user unless a root user login is absolutely necessary. We&amp;rsquo;ll be learning a lot more about IAM and scoped security throughout this document.&lt;/p&gt;</description></item><item><title>identity-and-access-management</title><link>https://blog.ulutasalperen.com/docs/aws/iam/identity-and-access-management/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/identity-and-access-management/</guid><description>&lt;h1 id="identity-and-access-management-iam"&gt;Identity and Access Management (IAM)&lt;a class="anchor" href="#identity-and-access-management-iam"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;At some stage in building a project on AWS, you&amp;rsquo;ll need to give other people (or perhaps automated systems) access to your cloud resources as well. &lt;a href="https://aws.amazon.com/iam/"&gt;IAM&lt;/a&gt; is how AWS controls access to resources: who can log in, and what they can do once they&amp;rsquo;re in.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Who are you? (&lt;strong&gt;I&lt;/strong&gt;dentity)&lt;/li&gt;&#10;&lt;li&gt;What are you allowed to do? (&lt;strong&gt;A&lt;/strong&gt;ccess)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;img src="https://blog.ulutasalperen.com/images/aws/iam-users-groups-roles.png" alt="IAM users, groups and roles" /&gt;&lt;/p&gt;&#10;&lt;p&gt;IAM uses a few core pieces:&lt;/p&gt;</description></item><item><title>create-iam-user</title><link>https://blog.ulutasalperen.com/docs/aws/iam/create-iam-user/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/create-iam-user/</guid><description>&lt;h1 id="iam-users"&gt;IAM Users&lt;a class="anchor" href="#iam-users"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;Let&amp;rsquo;s make a new &lt;strong&gt;user&lt;/strong&gt;! Each user gets a &lt;strong&gt;username&lt;/strong&gt;/&lt;strong&gt;password&lt;/strong&gt; or &lt;strong&gt;API keys&lt;/strong&gt; to access AWS.&lt;/p&gt;&#10;&lt;p&gt;Users are &lt;strong&gt;long-lived identities&lt;/strong&gt;: they stick around until you delete them. Once you create a user and give them credentials, those credentials will work until they expire or you revoke them.&lt;/p&gt;&#10;&lt;p&gt;Managing more than a handful of users manually is painful. If your company already uses something like Azure&amp;rsquo;s &lt;a href="https://www.microsoft.com/en-us/security/business/identity-access/microsoft-entra-id"&gt;Active Directory&lt;/a&gt; or &lt;a href="https://workspace.google.com/"&gt;Google Workspace&lt;/a&gt;, you can use &lt;a href="https://aws.amazon.com/iam/identity-center/"&gt;AWS Identity Center&lt;/a&gt; to integrate with those services and manage users more easily.&lt;/p&gt;</description></item><item><title>inline-policies-iam-user</title><link>https://blog.ulutasalperen.com/docs/aws/iam/inline-policies-iam-user/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/inline-policies-iam-user/</guid><description>&lt;h1 id="inline-policies"&gt;Inline Policies&lt;a class="anchor" href="#inline-policies"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html"&gt;Policies&lt;/a&gt; &lt;strong&gt;allow&lt;/strong&gt; or &lt;strong&gt;deny&lt;/strong&gt; actions on specific resources. They look something like this:&lt;/p&gt;&#10;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;Version&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;2012-10-17&amp;#34;&lt;/span&gt;,&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;Statement&amp;#34;&lt;/span&gt;: [&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; {&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;Effect&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;Allow&amp;#34;&lt;/span&gt;, &lt;span style="color:#75715e"&gt;// &amp;lt;--- 1. Are we allowing or denying?&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;Action&amp;#34;&lt;/span&gt;: [&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#e6db74"&gt;&amp;#34;ec2:Describe*&amp;#34;&lt;/span&gt; &lt;span style="color:#75715e"&gt;// &amp;lt;--- 2. Which API actions are affected?&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ],&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;Resource&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;*&amp;#34;&lt;/span&gt; &lt;span style="color:#75715e"&gt;// &amp;lt;--- 3. Which targets are affected?&#10;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; }&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ]&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A policy has three main parts:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;Effect:&lt;/strong&gt; &lt;code&gt;Allow&lt;/code&gt; or &lt;code&gt;Deny&lt;/code&gt;. Are we permitting or denying these actions?&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Action:&lt;/strong&gt; The action to allow or deny. There are &lt;a href="https://github.com/awsles/AwsServices/blob/master/AwsServiceActions.txt"&gt;thousands&lt;/a&gt; of these, like &lt;code&gt;DescribeInstances&lt;/code&gt;, &lt;code&gt;CreateBucket&lt;/code&gt;, or &lt;code&gt;PutObject&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Resource:&lt;/strong&gt; Which resources the action targets. For example, &amp;ldquo;all EC2 servers,&amp;rdquo; or perhaps the &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html"&gt;ARN&lt;/a&gt; of just a specific one.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="assignment"&gt;Assignment&lt;a class="anchor" href="#assignment"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Vincent Vega needs to see EC2 instances for a dashboard he&amp;rsquo;s building, but make sure he can&amp;rsquo;t break anything.&lt;/p&gt;</description></item><item><title>iam-groups</title><link>https://blog.ulutasalperen.com/docs/aws/iam/iam-groups/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/iam-groups/</guid><description>&lt;h1 id="iam-groups"&gt;IAM Groups&lt;a class="anchor" href="#iam-groups"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;While inline policies are attached directly to a single user, the &lt;em&gt;preferred&lt;/em&gt; way to manage permissions in AWS is to create &lt;strong&gt;groups&lt;/strong&gt; and give &lt;em&gt;them&lt;/em&gt; the policies (sometimes called &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#customer-managed-policies"&gt;customer-managed policies&lt;/a&gt;).&lt;/p&gt;&#10;&lt;p&gt;This &lt;a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself"&gt;DRYs&lt;/a&gt; up your permissions management and makes it much easier to ensure that everyone has only the access levels they need.&lt;/p&gt;&#10;&lt;p&gt;Let&amp;rsquo;s convert our inline policy into a customer-managed policy, then attach it to a group.&lt;/p&gt;&#10;&lt;h2 id="assignment"&gt;Assignment&lt;a class="anchor" href="#assignment"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;PatientPing&amp;rsquo;s CISO has &amp;ldquo;thoughts&amp;rdquo; about our inline policies. Per last week&amp;rsquo;s security review: &lt;em&gt;no more inline policies on users&lt;/em&gt;.&lt;/p&gt;</description></item><item><title>iam-roles</title><link>https://blog.ulutasalperen.com/docs/aws/iam/iam-roles/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/iam-roles/</guid><description>&lt;h1 id="iam-roles"&gt;IAM Roles&lt;a class="anchor" href="#iam-roles"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;Okay, so we can give our users (e.g. developers) access to AWS resources&amp;hellip; but what happens when we need our &lt;em&gt;application server&lt;/em&gt; to be able to access a resource? For example, an EC2 instance that needs to read from an S3 bucket?&lt;/p&gt;&#10;&lt;p&gt;We &lt;em&gt;could&lt;/em&gt; create a &lt;strong&gt;user&lt;/strong&gt; for our server, but by using a username and password, but we&amp;rsquo;ll eventually encounter this dreadful message:&lt;/p&gt;&#10;&lt;p&gt;Luckily, IAM has &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html"&gt;roles&lt;/a&gt;. A role is a &lt;strong&gt;temporary identity&lt;/strong&gt; that can be used or &lt;strong&gt;assumed&lt;/strong&gt; by trusted parties.&lt;/p&gt;</description></item><item><title>aws-iam-deny-policies</title><link>https://blog.ulutasalperen.com/docs/aws/iam/aws-iam-deny-policies/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/aws-iam-deny-policies/</guid><description>&lt;h1 id="deny-policies"&gt;Deny Policies&lt;a class="anchor" href="#deny-policies"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;An explicit &lt;code&gt;Deny&lt;/code&gt; policy always wins; even if other policies &lt;code&gt;Allow&lt;/code&gt; the same action. This is your shield when you need to set absolute boundaries.&lt;/p&gt;&#10;&lt;p&gt;Follow the &lt;a href="https://en.wikipedia.org/wiki/Principle_of_least_privilege"&gt;principle of least privilege&lt;/a&gt;: grant people and resources only the permissions they actually need, nothing more. So don&amp;rsquo;t &amp;ldquo;allow all actions by default&amp;rdquo; and then add &lt;code&gt;Deny&lt;/code&gt; rules for dangerous actions. Prefer to add permissions as they&amp;rsquo;re needed.&lt;/p&gt;&#10;&lt;p&gt;That said, there are situations where &lt;code&gt;Deny&lt;/code&gt; policies are helpful:&lt;/p&gt;</description></item><item><title>aws-ssm-parameter-store</title><link>https://blog.ulutasalperen.com/docs/aws/iam/aws-ssm-parameter-store/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/aws-ssm-parameter-store/</guid><description>&lt;h1 id="ssm-parameters"&gt;SSM Parameters&lt;a class="anchor" href="#ssm-parameters"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;A ubiquitous problem with &lt;strong&gt;running applications in production&lt;/strong&gt; is &lt;em&gt;configuring&lt;/em&gt; servers and applications. For example:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;Should the app run in debug mode?&lt;/li&gt;&#10;&lt;li&gt;What domain name should it expect?&lt;/li&gt;&#10;&lt;li&gt;Where should it send logs?&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;On our own machines, we often use &lt;em&gt;environment variables&lt;/em&gt;: key-value pairs that are available to everything running in the local environment (e.g. &lt;code&gt;EDITOR=nvim&lt;/code&gt;). In Kubernetes, we use &lt;code&gt;ConfigMaps&lt;/code&gt; or &lt;code&gt;Secrets&lt;/code&gt; to store configuration values.&lt;/p&gt;&#10;&lt;p&gt;AWS provides a vendor-specific solution in &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html"&gt;AWS Systems Manager Parameter Store&lt;/a&gt; (SSM parameters). It&amp;rsquo;s a centralized safe where you can keep configuration data, secrets, and parameters that your applications need. It provides:&lt;/p&gt;</description></item><item><title>accessing-ssm-parameters-from-ec2</title><link>https://blog.ulutasalperen.com/docs/aws/iam/accessing-ssm-parameters-from-ec2/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/accessing-ssm-parameters-from-ec2/</guid><description>&lt;h1 id="accessing-ssm-parameters-from-ec2"&gt;Accessing SSM Parameters from EC2&lt;a class="anchor" href="#accessing-ssm-parameters-from-ec2"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;Storing parameters in the SSM Parameter Store is only half the equation. Your EC2 instances still need &lt;strong&gt;permission&lt;/strong&gt; to retrieve them, which they can get through IAM. To allow an instance to access SSM parameters, you need to:&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;Create or attach an IAM policy that grants &lt;code&gt;ssm:GetParameter&lt;/code&gt; permissions.&lt;/li&gt;&#10;&lt;li&gt;Attach that policy to the instance&amp;rsquo;s IAM role.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;However, doing this for each individual parameter would get tedious, real quick. Instead, we can scope access with parameter names or path namespaces using a policy like this:&lt;/p&gt;</description></item><item><title>use-ssm-from-ec2</title><link>https://blog.ulutasalperen.com/docs/aws/iam/use-ssm-from-ec2/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://blog.ulutasalperen.com/docs/aws/iam/use-ssm-from-ec2/</guid><description>&lt;h1 id="use-ssm-from-ec2"&gt;Use SSM from EC2&lt;a class="anchor" href="#use-ssm-from-ec2"&gt;#&lt;/a&gt;&lt;/h1&gt;&#10;&lt;p&gt;At this point, everything should be in place for our Pinger server to pull its config values from SSM:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;We created the params &lt;code&gt;/DATABASE_URL&lt;/code&gt; and &lt;code&gt;/CMO_NAME&lt;/code&gt; in the SSM Parameter Store.&lt;/li&gt;&#10;&lt;li&gt;We added an IAM policy &lt;code&gt;patientping-ssm-access&lt;/code&gt;, allowing those params to be read.&lt;/li&gt;&#10;&lt;li&gt;That IAM policy is attached to the role &lt;code&gt;patientping-ec2-readonly-role&lt;/code&gt;.&lt;/li&gt;&#10;&lt;li&gt;Our EC2 instance that runs the Pinger app is authorized to assume that IAM role.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;And the Pinger app code is already configured to try to pull config from SSM before falling back to a &lt;code&gt;.env&lt;/code&gt; file. So once we restart the app, it should &amp;ldquo;just work.&amp;rdquo;&lt;/p&gt;</description></item></channel></rss>