<?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 Ben Kehoe on Medium]]></title>
        <description><![CDATA[Stories by Ben Kehoe on Medium]]></description>
        <link>https://medium.com/@ben11kehoe?source=rss-586bd5b557d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H3EHxRnhl5QvNF0uJBDG-g.jpeg</url>
            <title>Stories by Ben Kehoe on Medium</title>
            <link>https://medium.com/@ben11kehoe?source=rss-586bd5b557d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:26:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ben11kehoe/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[The Meaning(lessness) of Serverless]]></title>
            <link>https://ben11kehoe.medium.com/the-meaning-lessness-of-serverless-cc004936dee5?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc004936dee5</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Tue, 14 Mar 2023 18:59:42 GMT</pubDate>
            <atom:updated>2023-03-14T18:59:42.722Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.hanselman.com/blog/what-is-serverless-computing-exploring-azure-functions">People</a> <a href="https://serverlessfirst.com/serverless-definitions/">have</a> <a href="https://www.jeremydaly.com/stop-calling-everything-serverless/">been</a> <a href="https://medium.com/@ben11kehoe/the-serverless-spectrum-147b02cb2292">arguing</a> <a href="https://codeengineered.com/blog/2018/what-is-serverless/">about</a> <a href="https://redmonk.com/rstephens/2018/12/14/serverless-more-than-just-functions/">the</a> <a href="https://medium.com/swlh/what-is-serverless-the-2020-edition-5a2f21581fe5">meaning</a> <a href="https://mayoatte.com/what-it-really-means-to-be-serverless/">of</a> <a href="https://ben11kehoe.medium.com/serverless-is-a-state-of-mind-717ef2088b42">serverless</a> since the term came into vogue nearly a decade ago, and it seems to be <a href="https://www.thoughtworks.com/en-us/insights/podcasts/technology-podcasts/serverless-in-2023">quite</a> <a href="https://dev.to/aws-heroes/what-is-serverless-4d4p">active</a> <a href="https://www.gomomento.com/blog/what-is-serverless-podcast-with-khawaja-shams">recently</a> as well. Today, “serverless” as a term is close to meaningless. I won’t name names here, but we’ve all seen services get called “serverless” when they don’t scale to zero, when they are charged by hourly rates, when they still have maintenance windows. As a hardline proponent of serverless, I’d like to say: <strong>It’s fine. Don’t get worked up about it</strong>.</p><p>Every term that refers to something useful will become meaningless. Precisely <em>because </em>the original thing is useful, the term becomes valuable for marketing. This means that stretching the term to include things not quite under the original definition allows them to benefit from the perceived value of the original thing. And that establishes a precedent, allowing things even a little further away to get the label, and the scope creeps ever outward.</p><p>This has happened with terms like “cloud”, “DevOps”, “agile”…all of them referred to at least a reasonably well-scoped concept originally, and now are regularly applied to products and practices unrecognizable under the original definitions. You can stand like King Canute trying to stop the tide*, demanding people use a narrow definition, but you’re never going to succeed — and that’s okay!</p><p>So what’s important to focus on is the functional characteristics, what you’re trying to accomplish and how those characteristics aid in accomplishing the goals. I’ve been saying this for a long time. When it comes to actual technologies, I said <a href="https://medium.com/@ben11kehoe/the-serverless-spectrum-147b02cb2292">serverless is a spectrum</a>. I said that it’s not even about the technologies, <a href="https://ben11kehoe.medium.com/serverless-is-a-state-of-mind-717ef2088b42">it’s about the mindset</a>. The serverless mindset is still the most important thing: it’s about how you choose technologies when solving a business problem under your particular constraints, not about the specific technologies you choose. The technologies serverless purists call “serverless” are the technologies you end up choosing when you have the fewest constraints.</p><p>While we can’t stop the march towards meaninglessness for “serverless”, we <em>can</em> insist on the value of serverless concepts. When AWS calls something “serverless” that doesn’t scale to zero, we can continue to push them for that feature, and make sure people understand the tradeoff of using particular services.</p><p>Another way to retain meaning is to fully lean on the spectral nature. Instead of arguing about the line for where “serverless” ends, insist on talking comparatively. What services are <em>more</em> serverless than others? This not only reduces the problems of supposedly mislabeled services, but also provides people with a guide for what to choose when their constraints prevent them from using things at the far end of the spectrum.</p><p>In general, labels often aren’t the important thing. First, almost nothing in our industry (not to mention life in general) fits under strict binary labeling. There are few bright-line boundaries. Everything is a continuum. Embracing that means understanding terms based on their usefulness to the discussion you’re having, understanding that the utility of terms changes over time and that while you can shape those changes you can’t fully control them. “Serverless” may be close to meaningless, but the underlying concepts are more important than ever.</p><p>* Not coincidentally, <a href="https://en.wikipedia.org/wiki/King_Canute_and_the_tide">the original story</a>, which was about humility, has been generally coopted to be a metaphor for futility, because there’s lots of situations where it’s useful to employ such a metaphor.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc004936dee5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The “End of Programming” will look a lot like programming]]></title>
            <link>https://ben11kehoe.medium.com/the-end-of-programming-will-look-a-lot-like-programming-8b877c8efef8?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b877c8efef8</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 21:44:49 GMT</pubDate>
            <atom:updated>2023-01-02T21:44:49.951Z</atom:updated>
            <content:encoded><![CDATA[<p>Communications of the ACM has <a href="https://m-cacm.acm.org/magazines/2023/1/267976-the-end-of-programming/fulltext">a new article titled “The End of Programming”</a> by Matt Welsh. It posits that traditional programs “will be replaced by AI systems that are <em>trained</em> rather than <em>programmed</em>” (emphasis in the original). Welsh is “the CEO and co-founder of Fixie.ai, a recently founded startup developing AI capabilities to support software development teams”.</p><p>I’m generally skeptical of these broad claims. More than anything, I think when people imagine integrating AI (and especially LLMs) into software development (or any other process), they tend to be overly optimistic. But I want to focus on something in particular here. Welsh says “[w]e are rapidly moving toward a world where the fundamental building blocks of computation are temperamental, mysterious, adaptive agents.”</p><p>I think this is the least likely outcome. If you had to describe characteristics that drive users away from products, “temperamental and mysterious” system behavior would be high on that list (we usually just call it “buggy”). <em>Especially</em> because in this world, the people behind the product would likely say, “Ah, sorry, the AI did that. We’ll see if we can explain to it what needs to be fixed and maybe it’ll get fixed if we ask it the right thing”.</p><p>In general, a lot of the AI takes I see assert that AI will be able to assume the entire <em>responsibility</em> for a given task for a person, and implicitly assume that the person’s <em>accountability</em> for the task will just sort of…evaporate? Like, if the AI got it wrong, it’s not your fault? But if you have no real way to ensure the task is correctly performed, they’re probably going to find someone else to accomplish that task after it’s failed a few times.</p><p>So in a world where software still has to actually do the thing required of it, let’s imagine what it would look like if we no longer needed human software developers. A human is acting as a product manager, dictating their business requirements to an AI, which then constructs software. Let’s assume that the resulting software that is largely functional (that is, free of low-level bugs) — I think this is a long ways off, and there is lots to say about what it will look like until then, but that’s a separate discussion.</p><p>If you’ve worked as a software developer, you know that business requirements often come as vague, ill-defined, even contradictory ideas written down in ambiguous language. The primary question about this AI-only software development is, how will it make software that implements what the product manager <em>intends</em> the software to do?</p><p>I think there are two general directions, which are not mutually exclusive.</p><p>The first is that the AI has to ask the product manager about every individual choice and ambiguity. It has to do this because it is good enough to know what the choices and ambiguity are, but not good enough to consistently guess the correct answer. This back-and-forth will start in plain language, and take up a lot of time for the product manager. Over time, the AI’s designers will start offering shortcuts that allow the input requirements to mean specific things when framed a certain way, so the product manager can make their choice clear from the outset. So we’ve got a method for expressing system behavior with formal guarantees. That is, we’ve invented a new programming language. At this point, the product manager is now a software developer.</p><p>The other is that the AI <em>is</em> good enough to consistently correctly guess the right answer to choices and ambiguity in the requirements <em>and</em> good enough to know when it doesn’t have confidence it can guess correctly. To do this requires an enormous amount of human cultural knowledge and probably a high degree of knowledge of the specific person acting as the product manager. The AI is doing the work of translating the business requirements into formal system behavior requirements, as well as implementing them. At this point, the AI is now a software developer.</p><p>You could argue the second is the same as Welsh’s vision of “the end of programming”, as you’re still working without a formal language. I’m saying it’s different, because it’s not “temperamental and mysterious” any more than the software developers (the ones you <em>like</em> working with) are — it’s reliable and consistent.</p><p>I think the second direction, AI-as-software-developer, is quite a ways off, specifically because cultural context and self-awareness are hard things. I doubt you need AGI to get it, but it seems like it would be a good chunk of the way there. So if you’re bullish on AGI, you can hope we’ll get it sooner rather than later.</p><p>I’d love to see the first direction taken explicitly. One of my problems with GitHub Copilot (and similar systems) is that you still own the resulting code, and it does not provide any path to gaining confidence that it has given you a correct implementation, despite you owning the correctness of the code it generates (this also warrants its own article, I think). I’d love for it to identify common patterns and formalize them, such that developers could use some shorthand to express that complicated logic and have confidence they are getting what they expect. Maybe that can be done with the existing system, or maybe it’s an entirely new Copilot-oriented programming language.</p><p>I think my main takeaway here is that, when looking at claims AI is going to automate some process, look for what the really hard, inherent complexity of that process is, and whether the process would be successful if a large degree of (new) uncertainty was injected into that complexity. For software development, I think the answer is no. That doesn’t mean AI won’t be successful, it just means we need to look deeper to refine what and how (and when) automation will play a role in it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b877c8efef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS IAM Permissions Boundaries Are Incomplete Without Propagation]]></title>
            <link>https://ben11kehoe.medium.com/aws-iam-permissions-boundaries-are-incomplete-without-propagation-49dd0c72eeed?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/49dd0c72eeed</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-iam]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Fri, 29 Oct 2021 17:25:09 GMT</pubDate>
            <atom:updated>2021-10-29T17:25:09.635Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html">Permissions boundaries</a> are great in concept: an administrator can place restrictions on what IAM principals can possibly do, while letting developers determine the actual least privilege policy that principals should have — and this includes the principal for the developers themselves. But I don’t believe they are useful in their current form.</p><p>We’ll set aside for this article the way that permissions boundaries can be circumvented for IAM roles; <a href="https://ben11kehoe.medium.com/aws-iam-permission-boundaries-has-a-caveat-that-may-surprise-you-d8e7dcf8b649">read this article for details on that</a>.</p><p>In a serverful application running mostly on something like EC2, ECS, or Kubernetes is probably not going to need a ton of different IAM roles for their application. If the number of roles is few and rarely changing, roles could be provisioned by an administrator, with permissions boundaries, and then the developer would get permissions for <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_AttachRolePolicy.html">IAM.AttachRolePolicy</a> permissions but not <a href="https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreateRole.html">IAM.CreateRole</a>.</p><p>In serverless development, each Lambda function, Step Functions state machine, API Gateway integration, etc. should all have their own IAM role, so that their policies can be narrowly scoped to just what’s needed for that individual resource. Indeed, if you’re using <a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html">SAM</a>, an <a href="https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html">AWS::Serverless::Function</a> implicitly creates an IAM role. Trying to put an administrator in that loop would be a nightmare; either the developer is trying to reuse a small number of roles in a bunch of different places, shredding least privilege, or as they iterate on their architecture they are constantly asking for new roles.</p><p>What we need is for the developers to be able to create IAM roles themselves. However, if we want to use permissions boundaries we can’t just grant iam:CreateRole; if a developer’s permissions boundary denies them access to EC2 (we should all aspire to this 😁), they can just create a role that <em>does</em> have access to EC2, and either assume it directly or assign it to a Lambda function and then invoke that function.</p><p>Permissions boundaries has a solution for this: the <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_iam-condition-keys.html#available-keys-for-iam">iam:PermissionsBoundary</a> context key. You can create a policy for a developer that requires they put a specific permissions boundary on any role they create:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;CreateOrChangeOnlyWithBoundary&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;iam:CreateRole&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;,<br>      &quot;Condition&quot;: {<br>        &quot;StringEquals&quot;: {<br>          &quot;iam:PermissionsBoundary&quot;: &quot;arn:aws:iam::123456789012:policy/MyBoundaryPolicy&quot;<br>        }<br>      }<br>    }<br>  ]<br>}</pre><p>Note: this only shows iam:CreateRole for simplicity. All operations on a role, such as iam:AttachRolePolicy, include the iam:PermissionsBoundary context key, so you can limit, for example, the ability to attach policies to only roles with a specific permissions boundary.</p><p>The permissions boundary used in this condition could be the same or different from the permissions boundary on the developer.</p><p>This looks great, until you realize that this is only an IAM policy. The actual CreateRole API call needs to have the permissions boundary policy ARN explicitly specified for the call to be allowed. As it is designed today, <strong>the developer needs to explicitly understand and participate in the propagation of permissions boundaries.</strong></p><p>This bad. First, the permissions boundary ARN from the policy needs to be communicated to the developer, who needs to remember it. And then everywhere that they create infrastructure, they need to pass that value in.</p><p>It gets worse. A given developer has a permissions boundary that the policy enforces they must use with created roles, but a different developer might have a policy enforcing a different permissions boundary. So the boundary now becomes a parameter.</p><p>So <em>every</em> CloudFormation template, every CDK program, every infrastructure setup script, needs to take a permissions boundary policy ARN as an <em>optional</em> parameter — because some developers or CI/CD pipelines may not be required to specify a permissions boundary — and <em>everybody</em> needs to be aware of the value they are required or not to use.</p><p>This is a giant headache for everyone involved, and in general I don’t think it’s worth the trouble.</p><p>Now, imagine that when you put a permissions boundary on a principal, you could also specify a <em>transitive</em> permissions boundary. Like <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining">transitive role session tags</a> and the <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_monitor.html">source identity</a> property, this boundary would be placed on all created principals <em>without</em> it having to be specified in the API call — and probably without being able to be overridden (I’m less sure about this).</p><p>With a transitive permissions boundary, developers no longer need to be active participants in permissions boundary propagation. Their CloudFormation templates define their infrastructure without reference to permissions boundaries — note that a transitive permissions boundary may cause that infrastructure to fail to have the permissions defined in the template, but that’s exactly the point of permissions boundaries. Different developers may have different transitive boundaries, and a CI/CD pipeline may have none. All of it just works in the background.</p><p>Until something like transitive permissions boundaries exists, permissions boundaries will remain mostly unusable for organizations where developers need to create IAM principals as part of their normal software development process. As always, if you’ve got questions, <a href="https://twitter.com/ben11kehoe">you can find me on Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49dd0c72eeed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-account role trust policies should trust AWS accounts, not roles, part 2]]></title>
            <link>https://ben11kehoe.medium.com/cross-account-role-trust-policies-should-trust-aws-accounts-not-roles-part-2-79b6baba8993?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/79b6baba8993</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Fri, 22 Oct 2021 17:53:56 GMT</pubDate>
            <atom:updated>2021-10-22T18:00:00.707Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve gotten some responses to <a href="https://medium.com/@ben11kehoe/cross-account-role-trust-policies-should-trust-aws-accounts-not-roles-32737dfeaa03">my article</a> where I argue that cross-account role trust policies should trust accounts, not principals within the accounts. A lot of them took the form of “it provides an extra layer of defense” along with “it can’t hurt”. I think I adequately covered why it <em>can</em> hurt (that is, it provides a false sense of safety) in the article, but I want to go a little deeper on why that “extra layer” is extremely thin and not worth risking that false sense of security.</p><p>We’ll talk here only about trusting a source <em>role</em>, that is, not an IAM User (nor an IAM Role managed by AWS SSO) — I cover in the article why those are different.</p><p>Trusting a role instead of an account only prevents a privilege escalation when the following conditions are true:</p><ol><li>Access to a principal in the source account (other than the source role)</li><li>The principal has AssumeRole with resource * (never do that!), or access to change that principal’s policy to allow AssumeRole on the destination role. Note this likely implies the ability to allow AssumeRole on the source role in the same account.</li><li>The source role’s trust policy does not allow this principal to assume it.</li><li>The principal cannot change the source role’s trust policy.</li></ol><p>If any of these are not true, there is a path to privilege escalation that makes trusting the source role no better than trusting the account.</p><p>In particular, when you trust the source role, you don’t have any control over the source role’s own trust policy. For some other principal in the source account, while trusting the source role directly prevents it from being able to assume the destination role directly, <em>if it can assume the source principal, it can then assume the destination principal anyway.</em> So for trusting the source principal to provide additional security, we need to look at whether any other principals in the account are able to assume the source principal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fQFpLynwSyAznIfSVOh-w.png" /></figure><p>First, let’s talk about internal “threats”. One motivation to trust a source principal is that the source account is controlled by a different team than the destination account, and the team owning the destination account wants to make sure that an agreement that the source role should have access to their account doesn’t mean other things in the source account will get access.</p><p>However, as usual, technological solutions are not an adequate replacement for organizational health. If the team who owns the source account really wants to let something else access the destination account, they can just add that principal to the source principal’s trust policy, and access it that way, rather than engaging with the team to expand the destination role’s trust policy. So <em>the team who owns the destination account is better off thinking about what’s required to trust the entire source account anyway</em>.</p><p>Next, let’s talk about a compromised principal. This is where we get to the list of 5 conditions above. We’ll visit each one in turn.</p><p><strong>Access to a principal in the source account (other than the source role)</strong>. This is the basic assumption that we have a compromised role.</p><p><strong>The principal must be able to assume the destination role directly, but <em>cannot</em> assume the source role</strong>.</p><ol><li>The principal has sts:AssumeRole on at least the destination role</li><li>The source role’s trust policy does not allow the principal to assume it</li></ol><p>There’s one base case we can consider: the principal has AssumeRole on resource *. In this case, it would be allowed to directly assume the destination role if the destination role’s trust policy trusts the account, and it would <em>not</em> be allowed to directly assume the destination role if the destination role’s trust policy trusted only the source role, and it would <em>not</em> be allowed to assume the source role. In this situation, we do gain additional security by not trusting the whole account. However, the resource * here is a <em>bigger issue</em> and by addressing it, we would eliminate this case.</p><p>If we assume that when the principal is compromised, it does not have permission to directly assume the destination role, we find that the condition is:</p><p><strong>The principal must be able to make IAM changes to allow itself to directly assume the destination role, but <em>cannot</em> make IAM changes that allow it to assume the source role.</strong></p><p>If the compromised principal can make IAM changes that allow it to assume the source role, then it has access to indirectly assume the destination role even when the destination role’s trust policy only trusts the source role.</p><p>If we assume the compromised principal can give itself AssumeRole on the destination role, it likely means that it can give itself AssumeRole on the source role, <em>and</em> likely means it can give itself UpdateAssumeRolePolicy on the source role, which would then allow it to update the source role’s trust policy to allow it to assume it.</p><p>Can this be prevented with <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html">permissions boundaries</a>? Possibly, though that permissions boundary must allow some IAM actions, and that provides its own opportunities for privilege escalation (e.g., being able to create a new role without the permissions boundary — this is why permissions boundaries are incomplete without automatic propagation, but that’s a topic for another article), in addition to <a href="https://ben11kehoe.medium.com/aws-iam-permission-boundaries-has-a-caveat-that-may-surprise-you-d8e7dcf8b649">the way resource policies can enable escaping permissions boundaries</a>.</p><p>Hopefully this has clarified the very narrow path to privilege escalation that is prevented by trusting the source role directly, rather than the source account. And hopefully that clarifies why the benefits of treating the account as the security boundary outweigh the additional security given by trusting the source role directly. If you still think “well, it closes off something that shouldn’t be allowed, therefore it has to be better”, I would encourage you to think about broader risks in security posture, like the risk of overconfidence in one’s AWS IAM configuration (which is what trusting accounts rather than roles mitigates).</p><p>If you’ve got more questions or comments, <a href="https://twitter.com/ben11kehoe">you can find me on Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79b6baba8993" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cross-account role trust policies should trust AWS accounts, not roles]]></title>
            <link>https://ben11kehoe.medium.com/cross-account-role-trust-policies-should-trust-aws-accounts-not-roles-32737dfeaa03?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/32737dfeaa03</guid>
            <category><![CDATA[aws-iam]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Wed, 13 Oct 2021 16:56:32 GMT</pubDate>
            <atom:updated>2021-10-24T17:33:12.626Z</atom:updated>
            <content:encoded><![CDATA[<p>In my <a href="https://ben11kehoe.medium.com/principals-in-aws-iam-38c4a3dc322a?source=your_stories_page-------------------------------------">article on IAM principals</a>, I mentioned that when creating a cross-account role trust policy, it’s generally better to trust the entire account, rather than a particular principal within that account. I got some questions on why, so here are the details!</p><p><em>Note: </em><a href="https://ben11kehoe.medium.com/cross-account-role-trust-policies-should-trust-aws-accounts-not-roles-part-2-79b6baba8993"><em>there’s a follow-up to this article</em></a><em> that goes into even more detail on the particular topic of privilege escalation.</em></p><p>First, let’s establish what we’re talking about. We’ve got an IAM principal (an IAM Role or IAM User) — the <em>source principal</em> — in the <em>source account</em>, and an IAM Role — the <em>destination role</em> — in the <em>destination account</em>. The destination role must have a <a href="https://aws.amazon.com/blogs/security/how-to-use-trust-policies-with-iam-roles/">trust policy</a> that grants sts:AssumeRole permission to the source principal (potentially by granting it to the entire source account), and the source principal must have a principal policy (an IAM policy attached to the principal) that grants sts:AssumeRole for the destination role. As for all cross-account access, both sides must agree that the access is permitted!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a9jixTYKQh3fVLNhXAfAJQ.png" /></figure><p>We want our policies to be least privilege, to grant the necessary access and not allow access that is not needed. A role trust policy that trusts an entire account allows any principal with right permission to assume the role, even if only one principal inside that account needs to assume the role. So isn’t that a violation of least privilege?</p><h4>What does trusting a principal protect against?</h4><p>The destination role’s trust policy does not control who can use the source principal. If the source principal is an IAM Role — we’ll touch on IAM Users later—that role has its own trust policy. So potentially other principals within the account can assume the source role, and thus have access to the destination role. So privilege escalation can already happen through the source principal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fQFpLynwSyAznIfSVOh-w.png" /></figure><p>This means that <strong>by trusting the source role directly, you protect against this specific threat and only this specific threat</strong> versus trusting the account (thanks to Aidan Steele for <a href="https://twitter.com/__steele/status/1436208957983367172">the concise statement</a>):</p><ol><li>Access to a principal in the source account (other than the source role)</li><li>The principal does not have AssumeRole with resource * (never do that!)</li><li>Access to change that principal’s policy to allow AssumeRole on the destination role. Note this likely implies the ability to allow AssumeRole on the source role in the same account.</li><li>The source role’s trust policy does not allow this principal to assume it.</li><li>The principal cannot change the source role’s trust policy.</li></ol><p>That is, this only happens if a privilege escalation can happen but it <em>doesn’t</em> enable assuming the source principal. This scenario <em>can</em> happen, so isn’t it strictly better to prevent it?</p><h4>Narrowly-scoped trust policies can be misleading</h4><p>The argument here is that <strong>your role’s trust policy should be representative of the security boundary and not give a false sense of security</strong>.</p><p>You should plan for privilege escalation within an account. If you need to put a boundary around privilege escalation for a given principal, the account is the best boundary for that. Essentially, we are talking about thinking about cross-account access purely in terms of account-to-account relationships, and determining account structure from that.</p><p>It does <em>not</em> mean that granting one source principal cross-account access means any other principal in the account should be free to get access to the same destination role, any more than granting one principal access to a DynamoDB table in the same account means any other principal in the account should be able to access it. What it <em>does</em> mean is that any principal within the same account <em>may</em> be eligible for the same cross-account access.</p><p>What about if you don’t have control over the account structure? It’s still worth thinking about, from the perspective of the destination role, what the trust policy does and doesn’t have control over. Inspecting the destination role’s trust policy doesn’t provide any insight into the source principal, but it may give a false sense of security (“this role is safe because only this source principal has access”). When it trusts the entire account, access must be determined by inspection of the source account — but <em>we already need to do that</em>, to determine who can use the source principal. So whether you control the account structure or not, trusting the entire source account aligns more with the desired understanding of the system’s security.</p><h4>When trusting a principal is okay</h4><p>Now, this is general guidance, not a hard-and-fast rule. If the source principal is an IAM User actually used by a human (as opposed to used for long-lived access keys for, say, an on-prem server), the notion of “who can use the source principal?” is a little less in question than for an IAM Role. So trusting that IAM User directly is less likely to give the false sense of security discussed above.</p><p>If you’re using AWS SSO instead of IAM Users — and you should be — it’s a similar situation for trust policies. For IAM roles managed by AWS SSO, they are not modifiable from within the account (only through AWS SSO), and the trust policy only trusts the AWS SSO SAML provider (though I’d love to have control over this <a href="https://twitter.com/search?q=%23awswishlist">#awswishlist</a>). This means that you can be sure there are not other principals that can assume the AWS SSO-managed role. So trusting it directly is also less likely to give a false sense of security. Note that trusting the role grants access to all users with permission for that role; you can use the <a href="https://docs.aws.amazon.com/singlesignon/latest/userguide/using-predefined-attributes.html">identitystore:UserId</a> context key in the trust policy to specify individual users who can assume the destination role from an AWS SSO source role — though last I checked there is a bug that the context key is not populated when using a federated IdP.</p><p>If you’ve got well-secured infrastructure within the account, like common organization infrastructure protected by a <a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html">service control policy</a>, you can have more confidence about access to the source principal, and thus the destination role’s trust policy can rely on that higher confidence to use a narrow scope.</p><p>You can also include other conditions in the trust policy. There are <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html">many more</a> useful context keys, like aws:SourceIp and aws:MultiFactorAuthPresent, but a good overview of that will have to wait for another article.</p><p>A final situation is trusting a principal provided by a third party — you have don’t have visibility into their security controls, so you don’t have the same problem with overconfidence in the source principal, and so closing off the threat listed at the beginning is a small bonus.</p><p>A role trust policy that trusts a specific principal suggests that only that source principal has access to it, but it does not control access to that source principal, and so makes it seem like it limits access when it may not. Instead, trusting the account is representative of the security boundary involved (that is, the boundary between accounts). In most cases this is preferable, but there are exceptions.</p><p>If you’ve got comments (or, for this article, hate mail), <a href="https://twitter.com/ben11kehoe">you can find me on Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32737dfeaa03" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Never put AWS temporary credentials in env vars or credentials files — there’s a better way]]></title>
            <link>https://ben11kehoe.medium.com/never-put-aws-temporary-credentials-in-env-vars-or-credentials-files-theres-a-better-way-25ec45b4d73e?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/25ec45b4d73e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[aws-cli]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 16:40:33 GMT</pubDate>
            <atom:updated>2023-05-24T19:17:31.733Z</atom:updated>
            <content:encoded><![CDATA[<h3>Never put AWS temporary credentials in the credentials file (or env vars)—there’s a better way</h3><p>We need to talk about how AWS credential configuration works. Many people have more than one <a href="https://ben11kehoe.medium.com/principals-in-aws-iam-38c4a3dc322a">IAM principal</a> that they use on a regular basis, most likely because of multiple accounts, though they may also have multiple principals available to them within a given account. The ways I see a lot of people approach getting credentials for these principals and switching between principals are, in my opinion, inefficient and not making full use of the options provided by the AWS CLI and AWS SDKs. Or, as I put in a recent tweet:</p><h3>Ben Kehoe on Twitter: &quot;please, I&#39;m begging you, stop stuffing temporary credentials into ~/.aws/credentials 😡😭 / Twitter&quot;</h3><p>please, I&#39;m begging you, stop stuffing temporary credentials into ~/.aws/credentials 😡😭</p><p>The confusion is widespread. <a href="https://github.com/aws/aws-cli/issues/4982">Here’s a well-trafficked GitHub issue</a> on the CLI stating credentials stored by the CLI when AWS SSO do not conform to “AWS standards”, which is purportedly that the only location for credentials is ~/.aws/credentials. <a href="https://github.com/aws/aws-cli/issues/5877">Other</a> <a href="https://github.com/aws/aws-cli/issues/6357">issues</a> ask for setting environment variables, which isn’t much better. The <em>actual</em> AWS standard for <a href="https://github.com/boto/botocore/blob/1a507733acfc1829325d7972da01e8b8bf3ac10b/botocore/credentials.py#L56">credential resolution</a> is much richer than this — for example, credential resolution checks for an <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html">EC2 instance metadata server</a>, in case the code is running on an EC2 instance that has been given an IAM role.</p><p>The fundamental principle here is: <strong>code that uses temporary credentials should be able to refresh those credentials.</strong> The refreshing should not be required to come from a separate source. Neither environment variables nor ~/.aws/credentials work in a way that code reading credentials from them can refresh them. The good news is, there are better alternatives that do enable refreshable credentials. So let’s dive in and learn how refreshable temporary credentials work in the AWS CLI and SDKs.</p><h4>Principals and credentials</h4><p>First, to act as an IAM principal, we need AWS IAM credentials (the kind used for <a href="https://shufflesharding.com/posts/aws-sigv4-and-sigv4a">SigV4 signing</a>). These credentials consist of an access key ID, secret access key, and — in the case of temporary credentials — a session token. Temporary credentials also have an associated expiration timestamp. Only the AWS account root and IAM Users have non-temporary credentials — they receive long-term credentials that do not have an expiration (though they should be rotated periodically!). IAM Roles, assumed through <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html">STS.AssumeRole</a>, <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithSAML.html">STS.AssumeRoleWithSAML</a>, or <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html">STS.AssumeRoleWithWebIdentity</a>, only ever have temporary credentials. IAM Users and the account root can also get temporary credentials for themselves using <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_GetSessionToken.html">STS.GetSessionToken</a> (there’s also the legacy <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_GetFederationToken.html">STS.GetFederationToken</a>, but we’ll ignore that for simplicity — but it also returns temporary credentials).</p><p>On the command line, the AWS CLI, a program using an AWS SDK, or a program capable of SigV4 signing requests on its own, must be be given these credentials in order to successfully call AWS APIs — note that the code <em>using</em> the credentials does not need to know what principal they represent, though they can introspect using <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html">STS.GetCallerIdentity</a> (a very useful API call to be familiar with — in addition to the helpful information it returns, it requires no permissions, so will always work with any valid credentials).</p><p>So we need a way of providing the code credentials, and because we’re using multiple principals, we need a way of providing it <em>different</em> credentials at different times — including in the same terminal.</p><p>In the examples below, we’ll use the <a href="https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sts/get-caller-identity.html">aws sts get-caller-identity</a> command as a stand-in for any use of AWS APIs (or more precisely, the ones that require SigV4 signing, which is almost all of them).</p><p>One popular way of providing credentials is using environment variables. For an IAM User, that might look like this:</p><pre>$ export AWS_ACCESS_KEY_ID=&lt;benk key id&gt;<br>$ export AWS_SECRET_ACCESS_KEY=&lt;benk secret key&gt;<br>$ aws sts get-caller-identity<br>{<br>    &quot;UserId&quot;: &quot;AIDA...&quot;,<br>    &quot;Account&quot;: &quot;111122223333&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:iam::111122223333:user/benk&quot;<br>}</pre><h4>Assuming a role and using the credentials</h4><p>Now, to interact in a different account, it’s common for <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_common-scenarios_aws-accounts.html">the IAM User to have </a><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_common-scenarios_aws-accounts.html">AssumeRole permissions</a>. So the direct approach to getting credentials for that role, staying with environment variables, looks like this:</p><pre>$ export AWS_ACCESS_KEY_ID=&lt;benk key id&gt;<br>$ export AWS_SECRET_ACCESS_KEY=&lt;benk secret key&gt;<br>$ aws sts assume-role --role-arn arn:aws:iam::777788889999:role/MyRole --role-session-name ben<br>{<br>    &quot;Credentials&quot;: {<br>        &quot;AccessKeyId&quot;: &quot;&lt;MyRole key id&gt;&quot;,<br>        &quot;SecretAccessKey&quot;: &quot;&lt;MyRole secret key&gt;&quot;,<br>        &quot;SessionToken&quot;: &quot;&lt;MyRole:ben session token&gt;&quot;,<br>        &quot;Expiration&quot;: &quot;2021-10-06T20:12:56Z&quot;<br>    },<br>    ...<br>}</pre><p>Now, to act as that user, we have to export <em>those</em> credentials:</p><pre>$ export AWS_ACCESS_KEY_ID=&lt;MyRole key id&gt;<br>$ export AWS_SECRET_ACCESS_KEY=&lt;MyRole secret key&gt;<br>$ export AWS_SESSION_TOKEN=&lt;MyRole:ben session token&gt;<br>$ aws sts get-caller-identity<br>{<br>    &quot;UserId&quot;: &quot;AROA...:ben&quot;,<br>    &quot;Account&quot;: &quot;777788889999&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:sts::777788889999:assumed-role/MyRole/ben&quot;<br>}</pre><p>Great — but now if we want to switch back to using the benk IAM User, we have to re-export those credentials all over again. People write all sorts of scripts and utilities to set and change these environment variables, but there’s a much simpler way.</p><p>Additionally, these assumed role credentials expire. The default session duration is 3600 seconds (one hour). So the following (contrived) example will fail:</p><pre>$ export AWS_ACCESS_KEY_ID=&lt;MyRole key id&gt;<br>$ export AWS_SECRET_ACCESS_KEY=&lt;MyRole secret key&gt;<br>$ export AWS_SESSION_TOKEN=&lt;MyRole:ben session token&gt;<br>$ sleep 3700; aws sts get-caller-identity<br>An error occurred (ExpiredToken) when calling the GetCallerIdentity operation: The security token included in the request is expired</pre><p>Long-running processes shouldn’t have their credentials expire on them. Nor should you have to manually refresh these credentials when they expire, while you still have valid credentials to call AssumeRole again. And while you can set a longer session duration, you shouldn’t have to, and shorter durations are preferable for security. And again, there’s a much simpler way.</p><h4>Configuring and using named profiles</h4><p>What we’re going to do is give <em>names</em> to every configuration we want to use — where a configuration represents, at least, a principal and region. We’ll call these named configurations <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html"><em>profiles</em></a>. So we might have a profile for using the benk IAM User in us-east-1, and a separate profile for benk in us-west-2 — though we could also use the profile with us-east-1 in it and override the region (by setting the <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list">AWS_DEFAULT_REGION</a> environment variable).</p><p>We’ll call the profile for the benk IAM User, sensibly enough, benk, and for the role, MyRole.</p><p>First, let’s put our long-term credentials for the benk IAM User in the ~/.aws/credentials file. In this file, profile section headers are just the profile name.</p><pre>[benk]<br>aws_access_key_id = &lt;benk key id&gt;<br>aws_secret_access_key = &lt;benk secret key&gt;</pre><p>Now, we’ll put the rest of the profile configuration in ~/.aws/config. We only need the region, but you can put things here like what <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output-format.html">output format</a> you want the CLI to use (try output = yaml, though you may want to set <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list">AWS_DEFAULT_OUTPUT</a> in your .bashrc/.profile so that you don’t have to put it in every profile). In this file, profile section headers have the prefix profile.</p><pre>[profile benk]<br>region = us-east-1</pre><p>Why two files? The short answer is, you want to treat ~/.aws/credentials as a secret, like your SSH keys, but your configuration could be something you share or check into source control. For a detailed explanation of the difference, <a href="https://ben11kehoe.medium.com/aws-configuration-files-explained-9a7ea7a5b42e">see this article</a>.</p><p>So now we reference that profile name when making AWS calls:</p><pre>$ aws sts get-caller-identity --profile benk<br>{<br>    &quot;UserId&quot;: &quot;AIDA...&quot;,<br>    &quot;Account&quot;: &quot;111122223333&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:iam::111122223333:user/benk&quot;<br>}</pre><p>The --profile argument take precedence over options provided through environment variables.</p><p>Ideally, script and application writers also include a --profile option. For example, in Python, your program might look like:</p><pre>import argparse, boto3</pre><pre>parser = argparse.ArgumentParser()<br>parser.add_argument(&#39;--profile&#39;)<br># add other arguments<br>args = parser.parse_args()</pre><pre>session = boto3.Session(profile_name=args.profile)</pre><pre># use session<br># e.g., session.client(&#39;sts&#39;).get_caller_identity()</pre><p>If you use boto3 and you’re not familiar with sessions, <a href="https://ben11kehoe.medium.com/boto3-sessions-and-why-you-should-use-them-9b094eb5ca8e">here’s an article on what they are and why you should use them</a>.</p><p>However, not all programs provide this. So instead, you can set the <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html">AWS_PROFILE</a> (or AWS_DEFAULT_PROFILE, there is no difference) argument:</p><pre>$ export AWS_PROFILE=benk<br>$ aws sts get-caller-identity<br>{<br>    &quot;UserId&quot;: &quot;AIDA...&quot;,<br>    &quot;Account&quot;: &quot;111122223333&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:iam::111122223333:user/benk&quot;<br>}</pre><p>Note that due to a <a href="https://github.com/boto/botocore/issues/1460">long-standing bug</a> in the CLI and some SDKs, you must <em>un-export </em>these environment variables, not just set them to an empty string, otherwise you get an error, even if you’re using an explicit profile parameter:</p><pre>$ export AWS_PROFILE=&quot;&quot;<br>$ aws sts get-caller-identity --profile benk<br>The config profile () could not be found<br>$ export -n AWS_PROFILE<br>$ aws sts get-caller-identity --profile benk<br>{<br>    &quot;UserId&quot;: &quot;AIDA...&quot;,<br>    &quot;Account&quot;: &quot;111122223333&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:iam::111122223333:user/benk&quot;<br>}</pre><p>I’ve written <a href="https://gist.github.com/benkehoe/0d2985e56059437e489314d021be3fbe">a shell function to manage this environment variable</a>, including handling the un-export, and providing autocomplete for profile names (requires <a href="https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html">the AWS CLI v2</a>, which you should upgrade to!)</p><p>So, now we want to add a profile for MyRole. Do we need to call aws sts assume-role --profile benk --role-arn ... and then put the resulting credentials in a MyRole profile in ~/.aws/credentials? NO!! Please, don’t do this!</p><p>Remember that IAM Role credentials are temporary. So if you put them in environment variables or the ~/.aws/credentials file, at some point you’re going to have to refresh them — either because an API call failed, or by running some background process to periodically refresh them. Wouldn’t it be great if neither of those were necessary?</p><h4>Assumed role profiles</h4><p><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-role.html">You can directly configure a profile to assume a role</a>. The AWS CLI and SDKs understand this configuration, and make the AssumeRole call when the credentials are needed, and cache the results, including the expiration, and will call AssumeRole again when needed, without any extra work from you!</p><p>To make an assumed-role profile, you use the role_arn parameter. You then have to tell it what <em>other</em> credentials to use to make the AssumeRole call. If it’s another profile, you set source_profile to that profile name (and that could itself be an assumed-role profile, you can chain them!). Otherwise, you provide credential_source set to one of the self-explanatory Environment, Ec2InstanceMetadata, or EcsContainer.</p><p>So let’s do that. ~/.aws/credentials looks the same, but ~/.aws/config now looks like this:</p><pre>[profile benk]<br>region = us-east-1</pre><pre>[profile MyRole]<br>role_arn = arn:aws:iam::777788889999:role/MyRole<br>source_profile = benk<br>region = us-east-1</pre><p>Note that unlike when I was using aws sts assume-role, I didn’t provide a role session name. That’s optional for an assumed-role profile; one will be generated if it’s not provided.</p><p>So now we can do this:</p><pre>$ aws sts get-caller-identity --profile benk<br>{<br>    &quot;UserId&quot;: &quot;AIDA...&quot;,<br>    &quot;Account&quot;: &quot;111122223333&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:iam::111122223333:user/benk&quot;<br>}<br>$ aws sts get-caller-identity --profile MyRole<br>{<br>    &quot;UserId&quot;: &quot;AROA...:botocore-session-1633547576&quot;,<br>    &quot;Account&quot;: &quot;777788889999&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:sts::777788889999:assumed-role/MyRole/botocore-session-1633547576&quot;<br>}</pre><p>If you’re using an SDK, it will also work. In Python:</p><pre>import time, boto3</pre><pre>session = boto3.Session(profile_name=&#39;MyRole&#39;)<br>sts = session.client(&#39;sts&#39;)</pre><pre># AssumeRole is called for the first time when the credentials are needed, which is here:<br>arn = sts.get_caller_identity()[&#39;Arn&#39;]<br>assert arn.split(&#39;/&#39;)[1] == &#39;MyRole&#39;</pre><pre># if we make another call to the same or any other AWS API, AssumeRole *will not* be called, because the credentials are still valid<br>session.client(&#39;s3&#39;).list_buckets()</pre><pre># if we wait beyond the session duration, which has a default of 3600 seconds (1 hour), AssumeRole *will* get called again automatically because the credentials have expired<br>time.sleep(3700)<br>sts.get_caller_identity()</pre><p>The SDKs cache the credentials in-memory. The AWS CLI doesn’t have memory that persists in between calls, so (in v2 at least) it caches assumed-role credentials in the ~/.aws/cli/cache directory . This cache is <em>not</em> used by the SDKs, and please, <em>please</em> don’t read from it yourself.</p><p>If you need programmatic role assumption (that is, configuring an assumed role without the config file), some SDKs support that directly (e.g., <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ChainableTemporaryCredentials.html">JavaScript</a>), but Python does not, so I’ve made the <a href="https://github.com/benkehoe/aws-assume-role-lib">aws-assume-role-lib</a> library for that.</p><h4>AWS SSO profiles</h4><p>It also appears some people who use <a href="https://docs.aws.amazon.com/singlesignon/latest/userguide/what-is.html">AWS SSO</a> aren’t aware that <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html">you can configure profiles for AWS SSO usage</a> as well, and instead copy in credentials from the browser login page. An AWS SSO profile looks like this:</p><pre>[profile my-sso-profile]<br>sso_start_url = https://example.awsapps.com/start<br>sso_region = us-east-1 # the region AWS SSO is configured in<br>sso_account_id = 123456789012<br>sso_role_name = MyRoleName<br>region = us-east-2 # the region to use for AWS API calls</pre><p>Then, you authenticate using <a href="https://awscli.amazonaws.com/v2/documentation/api/latest/reference/sso/login.html">aws sso login --profile my-sso-profile</a>, though note you only need to call aws sso login once for all your profiles (<a href="https://ben11kehoe.medium.com/you-only-need-to-call-aws-sso-login-once-for-all-your-profiles-41a334e1b37e">read about that here</a>), and you can use it like any other profile, e.g., aws sts get-caller-identity --profile my-sso-profile.</p><p>You can configure these profiles manually, or using aws configure sso, or an even easier option is using <a href="https://github.com/benkehoe/aws-sso-util">aws-sso-util</a>, which has a command <a href="https://github.com/benkehoe/aws-sso-util/blob/master/docs/configure.md#aws-sso-util-configure-populate">aws-sso-util configure populate</a> that will create profiles for <em>all</em> accounts and roles you have access to.</p><h4>Federated sign-in (AssumeRoleWithSAML) — an obstacle</h4><p>Great, you say, I can configure an assumed-role profile if there are already source credentials with which to call STS.AssumeRole. And I can use AWS SSO profiles if my organization is using AWS SSO. But what if my organization has federated authentication using STS.AssumeRoleWithSAML? Here’s where we come to the way you can configuration profiles for any possible method of getting credentials!</p><p>First, I’ll note that if your organization uses STS.AssumeRoleWithWebIdentity, that can <em>also</em> be configured directly; your web identity token has to be stored in a file and then you use <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-settings">web_identity_token_file</a> instead of source_profile or credential_source.</p><p>Second, I’ll note that if your organization migrates to AWS SSO, that SAML federation happens server-side with AWS SSO, and as mentioned above, you can configure profiles to use it directly.</p><p>But with plain STS.AssumeRoleWithSAML, there are no easy answers. Most organizations either use an off-the-shelf tool like <a href="https://github.com/Versent/saml2aws">saml2aws</a> (one example among many) or write their own. These tools authenticate with your identity provider (with some identity-provider-specific code), cache the resulting session (e.g., a browser cookie), and then take the returned SAML assertion to STS.AssumeRoleWithSAML. Again we find ourselves at the situation we had at the beginning: these temporary credentials often get stuffed into environment variables (as in saml2aws script and saml2aws exec) or into the ~/.aws/credentials file (this is the default for saml2aws login).</p><h4>credential_process — the answer</h4><p>Enter <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sourcing-external.html">credential_process</a>. This is a configuration option that tells the CLI/SDKs a command to invoke, which must print credentials to stdout in a specific format:</p><pre>{<br>    &quot;Version&quot;: 1,<br>    &quot;AccessKeyId&quot;: &quot;...&quot;,<br>    &quot;SecretAccessKey&quot;: &quot;...&quot;,<br>    &quot;SessionToken&quot;: &quot;...&quot;,<br>    &quot;Expiration&quot;: &quot;&lt;ISO8601 timestamp when the credentials expire&gt;&quot;<br>}</pre><p>Expiration is optional; if it is not provided, the credential process will be invoked for every API call.</p><p>This means that a process that calls AssumeRoleWithSAML can take its configuration (e.g., user name, role ARN) as command line arguments and output the resulting credentials in this format, and then you can configure a profile like this:</p><pre>[profile my-saml-role]<br>credential_process = saml2aws login --role arn:aws:... --credential-process<br>region = us-east-1</pre><p>And then using aws sts get-caller-identity --profile my-saml-role will <em>just work</em>, including caching!</p><p>Note that there’s nothing special about credential_process that requires the credentials it returns be coming from AssumeRoleWithSAML. Suppose you’re on a <a href="https://cloud.google.com/compute">Google Compute Engine</a> instance that needs to communicate with AWS, and you’re doing this through long-term credentials creating using an IAM User (in fact, providing credentials to non-AWS machines is the only reason to continue using IAM “Users”). You could stash the credentials on the machine, and try to rotate them appropriately. Or, you could put them in GCP’s <a href="https://cloud.google.com/secret-manager">Secret Manager</a>, and create a credential process that uses the <a href="https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances">instance’s GCP credentials</a> to access Secrets Manager to retrieve the AWS credentials, providing an appropriate expiration that will allow the instance to automatically pick up the new credential values when you rotate them in Secrets Manager.</p><p>credential_process solves almost every “how do I get credentials in this weird situation?” problem I’ve seen. For example, with the launch of AWS SSO, not all AWS SDKs supported profiles with AWS SSO configuration. So I built a credential process (<a href="https://github.com/benkehoe/aws-sso-util/blob/master/docs/credential-process.md">docs</a>, <a href="https://github.com/benkehoe/aws-sso-util/blob/master/cli/src/aws_sso_util/credential_process.py">code</a>) using an SDK that <em>did</em> (<a href="http://boto3.amazonaws.com/v1/documentation/api/latest/index.html">boto3</a>), where it reads a profile’s AWS SSO configuration, gets the credentials and spits them back out. Because credential_process is lower in priority than AWS SSO configuration, a profile can be given AWS SSO configuration, which will be picked up by the SDKs that do understand it, <em>and</em> this credential_process <em>pointing to profile it’s in</em>, and the SDKs that don’t understand it will pick that up and still succeed. In fact, this is exactly what the profiles created by <a href="https://github.com/benkehoe/aws-sso-util/blob/master/docs/configure.md">aws-sso-util configure populate</a> look like! This setup allows for using the CDK with AWS SSO, because the CDK still uses the JavaScript v2 SDK, when only v3 got AWS SSO support (<a href="https://github.com/aws/aws-cdk/issues/5455">you can read the thread here</a> and see how many people respond that they are using credential-stuffing workarounds).</p><h4>Bridging the gap for configuration-oblivious tools</h4><p>There are situations where credential_process won’t work. The primary one, in particular, is tools that don’t understand the full range of AWS configuration. Maybe they do the signing themselves, and only load credentials from the environment or from the credentials file. Infuriatingly, AWS allows tools to be released that do not do full credential resolution, <a href="https://aws.amazon.com/premiumsupport/knowledge-center/athena-iam-jdbc-driver/">like the Athena JDBC driver</a>. Please don’t build tools that way yourself, but if you’re forced to use one, you have no choice but to provide explicit credentials (but open a feature request asking for proper support).</p><p>The approach I recommend is to set up your configuration properly, and then <strong>bridge the gap for tools that fail to correctly understand AWS configuration, rather than always working from the lowest common denominator</strong>.</p><p><em>Update 2023–05–24: The AWS CLI v2 now includes the command </em><a href="https://awscli.amazonaws.com/v2/documentation/api/latest/reference/configure/export-credentials.html"><em>aws configure export-credentials</em></a><em>, which includes some of the functionality covered by </em><em>aws-export-credentials (JSON and environment variables, including for Windows and PowerShell). It should be preferred to </em><em>aws-export-credentials where possible, though of course using neither is preferable!</em></p><p>Exactly for that gap-bridging, I’ve built <a href="https://github.com/benkehoe/aws-export-credentials">aws-export-credentials</a>, which does exactly one thing: reads configuration in the proper, complete way (because it uses <a href="https://github.com/boto/botocore">botocore</a>), retrieves credentials with whatever configuration is provided it, and prints out the resulting credentials. So if you need explicit credentials, and you need it for an assumed role, you can set up an assumed role profile as normal and use the --profile argument. It allows you to export credentials to environment variables, to the ~/.aws/credentials file, or to JSON (in the credential_process format, of course).</p><p>Another situation is where you’re running a Docker container, and you want AWS credentials from the host injected into it. One option is to use aws-export-credentials to get the credentials as environment variables, but remember, this doesn’t handle refreshing! However, there’s already a way to get refreshable credentials from inside a container: an <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html">EC2 IMDS</a> endpoint. aws-export-credentials <a href="https://github.com/benkehoe/aws-export-credentials#credential-serving-options-eg-for-providing-creds-to-containers">supports this</a>, providing a way to get refreshable credentials into your local containers. (Side note: it turns out the mechanism used by ECS for credentials doesn’t work because of a combination of Docker networking restrictions and AWS SDK restrictions on hostnames it can contact.)</p><p>I hope your takeaway from this article is that you almost never need to explicitly set temporary credentials in environment variables or put them into ~/.aws/credentials. Often you can accomplish it directly with profile configuration, and for everything else there’s credential_process, and you can then stuff credentials only if needed using aws-export-credentials. If you’re using a tool for STS.AssumeRoleWithSAML, check if it supports credential_process output, and if not, request it! Don’t be afraid to build your own credential_process tools to overcome credentialing obstacles.</p><p>As always, if you’ve got questions or comments, <a href="https://twitter.com/ben11kehoe">you can hit me up on Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25ec45b4d73e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS IAM Permission Boundaries Has A Caveat That May Surprise You]]></title>
            <link>https://ben11kehoe.medium.com/aws-iam-permission-boundaries-has-a-caveat-that-may-surprise-you-d8e7dcf8b649?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8e7dcf8b649</guid>
            <category><![CDATA[aws-iam]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Wed, 29 Sep 2021 15:34:18 GMT</pubDate>
            <atom:updated>2021-09-29T15:49:59.022Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS IAM Permission Boundaries Has A Caveat That May Surprise You</h3><p><em>Note: this article was originally published on September 1, 2021. It erroneously stated that the resource policy could reference the role, rather than the assumed role session. I removed it pending an update. The confusion, complexity, and poor documentation led me to publish </em><a href="https://ben11kehoe.medium.com/i-trust-aws-iam-to-secure-my-applications-i-dont-trust-the-iam-docs-to-tell-me-how-f0ec4c119e79"><em>I Trust AWS IAM to Secure My Applications. I Don’t Trust the IAM Docs to Tell Me How.</em></a><em> The updated version was published on September 29.</em></p><p><a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html">Permissions Boundaries</a> provide security admins a way to strike a balance between granting all the permissions a user might need and only granting them the permissions they are explicitly using. A permission boundary is a policy set on an IAM principal (User or Role), but the permissions granted by that policy are not immediately granted to the principal. Instead, they form the space of <em>possibly allowed</em> permissions. The principal needs a normal policy granting the permission as well to have that permission. If a policy attached to the principal has permissions that are <em>not</em> explicitly allowed by the permissions boundary, that permission is not granted. So the permissions on the principal are the intersection of the two.</p><p>You might think this is a great way to specify and observe exactly what an IAM principal can possibly perform, but unfortunately, there’s a serious limitation to this. The first clue to this is the flowchart for (non-cross-account) access policy evaluation <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html">from the IAM documentation</a>:</p><figure><img alt="Resource policies can short-circuit the evaluation before the permissions boundary is evaluated" src="https://cdn-images-1.medium.com/max/1024/0*vIhDXdm9nJ4rOxuu.png" /></figure><p>Note that resource policies are evaluated <em>before</em> permissions boundaries, and an Allow in the resource policy would result in the access being granted. This means that even if the action isn’t within the principal’s permissions boundary, <strong>a resource policy (in the same account) can potentially unilaterally grant access not allowed by a permissions boundary</strong>!</p><p>However, the story is a little more complicated. First of all, <strong>a </strong><strong>Deny always wins</strong>, so nothing can override statements with explicit Deny in the permissions boundary. And it doesn’t apply to IAM Users directly.</p><p>It turns out that IAM Roles, and particular legacy aspect of IAM Users, have a sort of two-stage evaluation process that <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html">allows resource policies to go outside a permissions boundary</a>. We’ll talk about roles first.</p><p>We often refer to IAM Roles as “principals” (indeed, I do above). A role ARN can be used in the Principal section of an IAM policy. But in a certain sense, they are <em>not</em> principals. In particular, there are no credentials associated with an IAM Role. You can’t call an API as a role. You have to <em>assume</em> the role, resulting in an <em>assumed role session</em>, which has credentials, to call APIs. It is this assumed role session that is the principal.</p><p>Evaluating the policies for an assumed role session is a two-step process. First, the <em>role</em> is evaluated for access, and then the session is evaluated. An therein lies the trick: the permissions boundary only applies to the <em>role</em>, not the session. So if, for a particular API call, the role is evaluated for access and the permissions boundary doesn’t grant access but does not explicitly deny, we haven’t found an Allow but haven’t found a Deny, so evaluation turns to the session. Then, <strong>if a resource policy grants permission to the assumed role session, this is not checked against the permissions boundary, and access is granted</strong>.</p><p>The resource policy can take two forms. Here we use as an example <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucket-policies.html">an S3 bucket policy</a>.</p><p>The first is to use the assumed role session in the Principal section:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Principal&quot;: &quot;arn:aws:sts::123456789012:assumed-role/MyRole/SessionName&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:s3:::my-bucket/*&quot;<br>    }<br>  ]<br>}</pre><p>The second is to use a condition on the <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-principalarn">aws:PrincipalArn</a> context key to reference the role. This context key is set to the role ARN for assumed role principals. From my testing, this appears to only work when Principal is set to * (or, obviously, the role session name), and not when Principal is set to the AWS account (i.e., {&quot;AWS&quot;: &quot;arn:aws:iam::123456789012:root&quot;}).</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Principal&quot;: &quot;*&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:s3:::my-bucket/*&quot;,<br>      &quot;Condition&quot;: {<br>        &quot;StringEquals&quot;: {<br>          &quot;aws:PrincipalArn&quot;: &quot;arn:aws:iam::123456789012:role/MyRole&quot;<br>        }<br>      }<br>    }<br>  ]<br>}</pre><p>I mentioned above this applies in an additional scenario. While an IAM User is (unlike an IAM Role itself) a principal, the <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_GetFederationToken.html">sts.GetFederationToken</a> API returns credentials for a “federated user” (this is different from the notion of “federated user” when using <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithSAML.html">sts.AssumeRoleWithSAML</a> or sts.AssumeRoleWithWebIdentity, which produce an assumed role session like AssumeRole); this works very much like an assumed role session, and similarly can get around the permissions boundary attached to the user. Note that sts.GetFederationToken predates roles, and roles should be used in preference to it.</p><p>This behavior is very counterintuitive, and I view it as a major mistake in the implementation of permissions boundaries, but it’s something we have to live with. So how can we use permissions boundaries to accomplish what we wanted: definitively setting the set of permissions a principal is allowed to have?</p><p>The only way to accomplish this is in the first column of the flowchart: an explicit Deny <em>anywhere</em> takes precedence over any Allow. So if a permissions boundary denies all actions that are outside the boundary, a resource policy will not be able to grant it. Instead of laying out what is allowed, lay out what <em>isn’t</em> allowed. Now, the semantics of permissions boundaries mean you still have to specify Allows, but because Deny overrides Allow, you can include broad Allow statements.</p><p>Let’s look at an example. Suppose we wanted a permissions boundary that only included S3 access. The direct approach would be the following:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;s3:*&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><p>The alternative approach would be:</p><pre>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Deny&quot;,<br>      &quot;NotAction&quot;: &quot;s3:*&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    },<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;*:*&quot;,<br>      &quot;Resource&quot;: &quot;*&quot;<br>    }<br>  ]<br>}</pre><p>This is rather simple, so the Allow statement could instead be only S3 rather than *:* to be more secure, but as the Deny statement got more complex it would become harder and more verbose to keep the Allow side simple.</p><p>A final approach is that <a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_scps.html">service control policies</a> can apply to all principals, and so a statement in an SCP, say based on a tag on the principal, could also work to prevent a resource policy from granting access, but space is SCPs is precious and I doubt this is a useful route for most people.</p><p>An additional complexity introduced by this is that using NotPrincipal (e.g., with a Deny to exclude all but a specific principal) may not work the way you expect. Setting NotPrincipal to the role ARN will match principals that are not your role ARN, <em>which includes the assumed role session ARN</em>. So while the statement won’t apply to the role, the second step of evaluating the session will match the statement. I think — though I have not verified this — that the opposite, NotPrincipal with the assumed role session ARN will face the same issue.</p><p>It’s extremely useful to familiarize yourself with <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html">the IAM docs page on policy evaluation</a> and <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic-cross-account.html">the companion page on cross-account policy evaluation</a>. IAM occasionally has surprises, and the documentation can help you wrap your head around it when it happens.</p><p>I have posted code to verify this behavior on GitHub: <a href="https://github.com/benkehoe/permissions-boundary-test">https://github.com/benkehoe/permissions-boundary-test</a></p><p>As always, if you’ve got questions or comments, <a href="https://twitter.com/ben11kehoe">you can find me on Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8e7dcf8b649" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Trust AWS IAM to Secure My Applications. I Don’t Trust the IAM Docs to Tell Me How.]]></title>
            <link>https://ben11kehoe.medium.com/i-trust-aws-iam-to-secure-my-applications-i-dont-trust-the-iam-docs-to-tell-me-how-f0ec4c119e79?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0ec4c119e79</guid>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[aws-iam]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Wed, 22 Sep 2021 15:27:21 GMT</pubDate>
            <atom:updated>2021-09-22T15:27:21.465Z</atom:updated>
            <content:encoded><![CDATA[<p>AWS IAM operates at an immense scale, <a href="https://aws.amazon.com/blogs/apn/iam-10th-anniversary-top-recommendations-for-working-with-iam-from-our-aws-heroes-part-1/">more than 400 million operations per second</a>, and the stakes are frankly terrifying; a substantial portion of the internet runs on AWS, and access to those resources is regulated by IAM.</p><p>I’m therefore glad that the people who design and run IAM are so smart that it’s also frankly terrifying. The depth of expertise and wisdom backing up IAM is such that I am confident that I’m being provided the tools to secure my AWS resources, and that those tools will work as designed.</p><p>But to secure my AWS resources, I need to know <em>how to use those tools</em>, not to mention what tools there are in the first place. And here IAM falls woefully short. The IAM documentation is too often incomplete, confusing, or out-of-date. It’s rarely <em>wrong</em>, per se, but it does not live up to the high standards that are required of security documentation, and worse, is not on a trajectory that shows it getting and staying substantially better. Customers are left to piece together the <em>how</em> of IAM from pages scattered across central IAM docs and those hidden deep within service docs, from examples, confusing terminology, and incomplete specifications.</p><p>We need documentation of AWS IAM — across IAM itself and all AWS services — to be both more accessible <em>and</em> to go further into comprehensive depth, so that we can confidently and successfully use the extensive power of IAM to gain the security we all want.</p><p>I was prompted to write this article because of a specific issue that relates the policy evaluation documentation not sufficiently distinguishing between IAM roles and IAM role sessions as relates to permissions boundaries and resource policy evaluation. It’s not important to explain it here; the IAM team are now aware of it and have assured me they are thinking through how that can be better presented.</p><p>I could compile a large catalog of IAM documentation deficiencies, but I’m not Martin Luther and the purpose of this article is not to nail 95 theses to IAM’s door. If I did, some of the problems would be within the control of the IAM team, like the iam:AssociatedResourceArn for iam:PassRole going undocumented. Others would be outside of their control, because the IAM section of every service’s documentation is the responsibility of that service team, not the central IAM team. So when API Gateway took over a year to document that their resource policies supported tag conditions, that’s on the API Gateway team. But as AWS customers, we shouldn’t have to care about that distinction. To us, it’s all one Identity and Access Management <em>system</em>, and the documentation for all parts of it should be held to the same high standard.</p><p>Any particular documentation issue can be addressed, but the issue here is with the foundation: these sorts of problems are ubiquitous and pervasive.</p><p>What frustrates me most is that IAM is an extremely well-understood system, <em>internally at AWS</em>. Its mechanics are so well-specified that they can build <a href="https://aws.amazon.com/blogs/security/protect-sensitive-data-in-the-cloud-with-automated-reasoning-zelkova/">automated reasoning systems to prove theorems about it</a>, which backs features like <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-concepts.html">IAM Access Analyzer</a>. They <a href="https://www.amazon.jobs/en/jobs/1743352/applied-science-manager">literally consider it a science</a>. But this precision does not extend to the documentation.</p><p>The IAM documentation is trying to balance being accessible while also having comprehensive depth, and I appreciate that is a difficult balance to strike, but we’re nowhere near close to the correct balance. The docs have <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session">three separate Venn diagrams</a> to show the interaction of permissions boundaries with each of resource policies, SCPs, and session policies, but don’t include how resource policies, SCPs, and session policies interact with each other. The docs use “federated user” to mean two completely separate things: a role session assumed using a federated identity provider, or a principal created using an IAM user through the GetFederationToken API (apparently a legacy system from before IAM roles). There is even <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_access-management.html">an IAM docs page</a> that uses <em>both</em> of these meanings on the same page, without mentioning the distinction.</p><p>In addition to being the wrong balance of accessible and in-depth (hint: the answer is to be both, separately), the docs are also incomplete. It’s left as an exercise for the community to <a href="https://gist.github.com/shortjared/4c1e3fe52bdfa47522cfe5b41e5d6f22">document the list of service principals</a>. The page of <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html">global context keys</a> should be for all keys that can be used regardless of the action being performed (so, not <a href="https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html#amazons3-policy-keys">s3:object-lock-mode</a> ), but only documents the keys with the aws: prefix, leaving out global keys like <a href="https://docs.aws.amazon.com/singlesignon/latest/userguide/using-predefined-attributes.html">identitystore:UserId</a>, which can also be used for any action; it’s not present for all principals, but neither is aws:username, which isn’t present on IAM roles. There’s a thrown-in <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html#condition-keys-other">section at the end</a> that basically says “other keys may exist” and gives some examples but abdicates from being a comprehensive list.</p><p>Amazon has <a href="https://www.amazon.jobs/en/principles">16 Leadership Principles</a>. AWS’s IAM documentation falls short on a lot of them:</p><p><strong>Are Right, A Lot</strong>: Too often the documentation is incomplete or confusing in a way that can cause customers to come away with an incorrect understanding.</p><p><strong>Insist on the Highest Standards</strong>: Can anyone really say with a straight face this the level of quality we should expect for IAM documentation?</p><p><strong>Ownership</strong>: The IAM team doesn’t own the IAM documentation within each AWS service, and the service teams don’t consider their IAM documentation to be a priority.</p><p><strong>Deliver Results:</strong> <a href="https://aws.amazon.com/blogs/aws/happy-10th-birthday-aws-identity-and-access-management/">IAM is 10 years old</a>. That’s more than enough time to become more mature than what we have today.</p><p><strong>Earn Trust: </strong>Most fundamentally, AWS IAM documentation is poor enough that, as a user, I can never take it at its word. I can’t use it as an authoritative reference when someone asks me a question. If I want to be confident in the answer I give them, I have to read the docs, and then <em>build a test suite to check whether the docs are telling me the whole story</em>. I wouldn’t even say it rises to the bar of “trust but verify”.</p><p>Which brings me to the path forward: <strong>Think Big</strong>. On the implementation side, AWS IAM scales to the massive footprint of AWS services and immense rate of change that comes with the pace of feature and service releases. On the documentation side, that’s filtered through a small set of humans who are tasked with producing docs that satisfy both “the docs are up-to-date” and “the docs are complete and comprehensible”, but they have no chance at accomplishing either, given the firehose of updates. This has been leaving customers in the lurch for years. IAM needs to figure out how to attach a pipeline to the programmatic information they <em>already have</em> to deliver it into customer documentation, to scale it out to the size and pace of AWS today. I don’t pretend this will be easy; for example, the much-needed central list of service principals needs to <em>not</em> show a new service’s principal until the moment the service is announced, and after launch, every minute of delay is a detriment to customers. The IAM documentation for individual services needs to get prioritized, and be accountable to the IAM team for its correctness and comprehensiveness.</p><p>All of this will be a huge undertaking. But I don’t question whether AWS can accomplish it. The IAM system itself stands as a testament to what AWS can achieve; we (rightly) put the security of our cloud resources in the hands of AWS IAM and we should believe AWS can give us documentation worthy of that trust.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0ec4c119e79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Principals in AWS IAM]]></title>
            <link>https://ben11kehoe.medium.com/principals-in-aws-iam-38c4a3dc322a?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/38c4a3dc322a</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-iam]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Wed, 08 Sep 2021 14:50:28 GMT</pubDate>
            <atom:updated>2021-09-16T15:23:22.519Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS Authentication: Principals in AWS IAM</h3><p><strong><em>Note:</em></strong> this article uses the boto3, the AWS Python SDK, as an example, but other SDKs have analogous features.</p><p>I’ve found that newcomers to AWS can sometimes get confused by what it means to have AWS credentials, and that people have notions of “logging into AWS” that don’t really correspond to the way AWS access works. This article aims to explain the basics of AWS <em>authentication</em> — that is, the way you gain an identity that you can use to access AWS services. It does not cover <em>authorization</em>, which is the granting of permissions to identity, that is, the domain of IAM policies, which is a separate topic.</p><p>All access to AWS is done by <em>principals</em>, which are either IAM Roles or IAM Users (which, despite the name, you should not use for humans). A principal gets <em>credentials</em> (access key id, secret access key, and for roles, session token). There is not a unique set of credentials for a principal; IAM Users can have two sets to allow for rotation (and can get short-lived credentials through <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_GetSessionToken.html">STS.GetSessionToken</a>), and IAM Roles only have short-lived credentials. Credentials are, when using boto3, represented by <a href="https://ben11kehoe.medium.com/boto3-sessions-and-why-you-should-use-them-9b094eb5ca8e">a Session</a>.</p><p>Credentials can be located in a number of places. Environment variables, ~/.aws/credentials (for long-lived IAM User creds; <a href="https://ben11kehoe.medium.com/aws-configuration-files-explained-9a7ea7a5b42e">credentials should <em>not</em> go in </a><a href="https://ben11kehoe.medium.com/aws-configuration-files-explained-9a7ea7a5b42e">~/.aws/config</a>), a local metadata server on EC2, or even configured to be based on an AssumeRole call with other credentials. A <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html">boto3 Session</a> that is created without specifying a config profile name will look in all these places to try to find credentials (if you give it the profile_name keyword argument, it only looks in the config files). When you’re using an AWS compute service, you can configure it to assume a role for you, and make the credentials available to your code; this is why session = boto3.Session() in a Lambda function (or EC2 instance, or ECS task, etc.) will get credentials for the role you’ve configured it to use.</p><p>An IAM principal has access granted to it by IAM policies. As stated above, this is <em>authorization</em> and is out of scope here, but it’s worth noting that the authorization model defines within-account access differently from cross-account access. The consequence here is that it is common to have identical or similar principals (e.g., IAM Roles) in multiple accounts, so that granting access in those accounts is simpler: the access is granted to the principal in the account, and the problem is shifted to becoming the right principal to access a given account, which is, in general, an easier problem to address.</p><p>IAM Roles require an outside source of identity; they are roles that another identity can assume. This can be an external identity provider, like Okta or ADFS. With AWS SSO, it’s the identity source for the AWS SSO instance (either an internal directory or an external provider). With a role assumed by a Lambda function, the source of identity is the Lambda service. But the source of identity can also be another role. That other role must itself have a source of identity, and so on. IAM Users, on the other hand, are their own identities. They have a username and password, which lets them be identities for humans, though AWS SSO is now the better way to provide that. We can therefore use IAM Users where there is no other source of identity available; primarily this is on-prem servers, or compute running in a different cloud provider.</p><p>An IAM Role has a <em>trust policy</em> that defines which identities/identity sources are allowed to assume it. The trust policy must grant permission for AssumeRole to succeed. They may trust an external identity provider (as a SAML provider, for <a href="https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithSAML.html">STS.AssumeRoleWithSAML</a>) to allow humans to assume them. AWS SSO roles specify the AWS SSO SAML provider, which allows humans to assume them, and this trust policy doesn’t depend on where the identity for AWS SSO is coming from (this is a benefit of AWS SSO). A role assumed by an IAM User or another IAM Role needs to specify either the other role itself, or the account that role is in. In fact, the permission needs to exist in both the trust policy on the role to be assumed, and the principal (Role/User) doing the assuming.</p><p>When granting cross-account access for role assumption, it’s generally the case that specifying the account in the trust policy is the right thing to do. The security boundary is the account; the trust policy has no control over who/what can log in as the user/assume the role in the remote account, so specifying that principal gives a bit of a false sense of added security over trusting the entire account.</p><p>AWS SSO adds a layer on top of this; when you log in to AWS SSO, you do <em>not</em> become an IAM principal. You are authenticated as an AWS SSO user, and this AWS SSO user <em>has permission to assume</em> IAM principals (IAM Roles, in particular) in AWS accounts. If you are <a href="https://docs.aws.amazon.com/singlesignon/latest/APIReference/API_CreateAccountAssignment.html">assigned</a> a permission set named Developer in a particular account, AWS SSO makes sure there’s an IAM Role in that account named after the permission set (it’ll be named AWSReservedSSO_Developer_&lt;random-tag&gt;), and grants you permission to retrieve credentials for that IAM Role. Note this isn’t through STS.AssumeRole(WithSAML) (that’s called by AWS SSO internally), it’s through <a href="https://docs.aws.amazon.com/singlesignon/latest/PortalAPIReference/API_GetRoleCredentials.htm">SSO.GetRoleCredentials</a>, which takes a credential that represents your AWS SSO user, and returns the familiar AWS credentials that represent the IAM Role you’re requesting.</p><p>Hopefully this helps illuminate how access to AWS services works in terms of authentication. It’s not simple, and there are a lot of little details that can remain confusing. If you’ve got questions, <a href="https://twitter.com/ben11kehoe">drop me a line on Twitter</a>.</p><p><strong>Appendix: SigV4</strong></p><p>If you’ve wondered what exactly the access key id, secret access key, and session token do, they are used to sign the HTTP requests you make to AWS services, verifying the principal accessing the service.</p><p>Many cloud services (e.g., <a href="https://cloud.google.com/storage/docs/authentication">GCP</a>) make use of a <a href="https://swagger.io/docs/specification/authentication/bearer-authentication/">bearer token</a> for authentication, where your entire credential is this token, and it is sent in its entirety to the service. While in theory this lets an attack snoop on your request, steal your token, and use it to access services, HTTPS goes a long ways towards preventing this. But it does mean that you have a higher exposure, are subject to replay attacks, etc. versus a secret that is not sent out.</p><p>With AWS, you have a secret (the secret access key) that never gets included in the request. Instead, you use it to create a cryptographic signature for the request, and it is this signature that is included in the request. AWS verifies the signature to check that you are indeed in possession of the secret key (and recently in possession, as there’s a timestamp involved).</p><p>One of the advantages of this is that it enables <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html">pre-signed URLs</a>; the signature gets embedded as query parameters, and because the signature is specific to the exact API call (including parameters), and time-limited, the URL is something that can be shared without sharing the actual access granted to the credentials themselves. There aren’t really standardized mechanisms to allow this with bearer tokens.</p><p>While SigV4 signing is embedded in all the AWS SDKs, it is not always exposed in a way that can be used independently. This is a problem as using IAM authentication for API Gateway requires SigV4 signatures on requests that can’t be made through the SDK. This leads to third party implementations like <a href="https://github.com/DavidMuller/aws-requests-auth">aws-requests-auth</a> for Python.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38c4a3dc322a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python multi-line string literals with textwrap.dedent()]]></title>
            <link>https://ben11kehoe.medium.com/python-multi-line-string-literals-with-textwrap-dedent-d4cf3c4a6d02?source=rss-586bd5b557d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4cf3c4a6d02</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ben Kehoe]]></dc:creator>
            <pubDate>Wed, 25 Aug 2021 14:48:44 GMT</pubDate>
            <atom:updated>2021-08-25T14:48:44.086Z</atom:updated>
            <content:encoded><![CDATA[<p>You’re writing some Python, and you need to write out a string containing newlines. You’ve got two options: a regular string with \n in it, or a <a href="https://docs.python.org/3/tutorial/introduction.html#strings">multi-line string literal</a> using three double quotes (are those sextuple quotes?), which looks like this:</p><pre>my_string = &quot;&quot;&quot;This<br>is a<br>multi-line string&quot;&quot;&quot;</pre><pre>assert my_string == &quot;This\nis a\nmulti-line string&quot;</pre><p>But you’ve got a problem. The point in your code where you’re putting the string is indented, and those indents are showing up in your string, like this:</p><pre>def get_string():<br>    return &quot;&quot;&quot;This<br>    is a<br>    multi-line string&quot;&quot;&quot;</pre><pre>assert get_string() == &quot;This\n    is a\n    multi-line string&quot;</pre><p>There’s a handy function in the standard library for this called <a href="https://docs.python.org/3/library/textwrap.html#textwrap.dedent">textwrap.dedent()</a>. It removes common leading whitespace from lines in the input. So you put that around your string, but it doesn’t help!</p><pre>def get_string():<br>    return textwrap.dedent(&quot;&quot;&quot;This<br>    is a<br>    multi-line string&quot;&quot;&quot;)</pre><pre>assert get_string() == &quot;This\n    is a\n    multi-line string&quot;</pre><p>You might have noticed that the first line, This does not have leading whitespace! You could manually add that leading whitespace, but there’s a better way: what if the first line of the string was actually on the next (indented) line? We can use the backslash as a line continuation character immediately after the opening quotes:</p><pre>def get_string():<br>    return &quot;&quot;&quot;\<br>    This<br>    is a<br>    multi-line string&quot;&quot;&quot;</pre><pre>assert get_string() == &quot;    This\n    is a\n    multi-line string&quot;</pre><p>Now that they all share the leading whitespace, textwrap.dedent() will do the right thing:</p><pre>def get_string():<br>    return textwrap.dedent(&quot;&quot;&quot;\<br>    This<br>    is a<br>    multi-line string&quot;&quot;&quot;)</pre><pre>assert get_string() == &quot;This\nis a\nmulti-line string&quot;</pre><p>See the docs for textwrap.dedent() <a href="https://docs.python.org/3/library/textwrap.html#textwrap.dedent">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4cf3c4a6d02" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>