---
title: "AWS ReadOnlyAccess: Not Even Once"
author: Daniel Heinsen (hotnops)
date: 2021-08-27
url: https://blog.hotnops.dev/posts/aws-readonlyaccess-not-even-once/
tags: [aws, iam, cloud]
graph: https://blog.hotnops.dev/graph.json
---

# AWS ReadOnlyAccess: Not Even Once

## Agent brief

The post argues that the AWS managed ReadOnlyAccess policy is not harmless and behaves more like "Admin lite". Using a fabricated scenario, it shows that a role granted ReadOnlyAccess with an inline policy explicitly denying all IAM actions can still read IAM policy documents through AWS Config's config:SelectResourceConfig, which ReadOnlyAccess gained in an AWS-side policy update in February 2020. It also shows that ReadOnlyAccess's SSM permissions expose Parameter Store secrets and SSM command output, and concludes that deny-list (blacklist) permission modeling forces defenders to track every action in an ever-changing managed policy.

### Key findings
- The AWS managed ReadOnlyAccess policy (as of version 78) grants config:SelectResourceConfig, which lets the caller query the configuration state and attached documents of any entity in the account when AWS Config is enabled.
- A role with ReadOnlyAccess plus an inline policy denying all IAM actions can still list IAM policies via AWS Config's config:SelectResourceConfig, effectively bypassing the IAM deny rule.
- AWS added config:SelectResourceConfig to ReadOnlyAccess in early February 2020 (version 61 of the policy) without customers accepting an update, so an IAM-deny configuration that was safe before that date silently became bypassable.
- As of version 78, ReadOnlyAccess allows ssm:Get*, ssm:Describe*, and ssm:List*, including ssm:DescribeParameters and ssm:GetCommandInvocation, exposing SSM Parameter Store secrets and the output of SSM commands such as setting local administrator passwords on EC2.
- A ReadOnlyAccess role can decrypt SSM parameters without an explicit KMS decrypt grant, but only when the parameter is encrypted with the default KMS key.
- When access is modeled as a deny list on top of a broad managed policy, the onus is on the defender to understand every permission the policy grants and every action AWS later adds to it.

### Attack path: Bypass an explicit IAM deny using AWS Config on a ReadOnlyAccess role
Prerequisites: Access to a role with the AWS managed ReadOnlyAccess policy (version 61 or later, which includes config:SelectResourceConfig); IAM access removed only by an inline policy explicitly denying IAM actions, not by removing ReadOnlyAccess; AWS Config enabled in the account (not enabled by default)
1. Assume the role (in the scenario, the AD-federated CloudGeneral role).
2. Observe that direct IAM enumeration (listing users, groups, policies) is denied by the inline IAM deny policy.
3. Call config:SelectResourceConfig to query the configuration state and attached documents of entities in the account, including IAM policies.
Outcome: The caller lists and reads IAM policies despite the explicit IAM deny, effectively bypassing it.
MITRE ATT&CK: T1087.004 (inferred)

### Attack path: Read secrets and command output from SSM with ReadOnlyAccess
Prerequisites: Access to a role with the AWS managed ReadOnlyAccess policy (version 78 grants ssm:Get*, ssm:Describe*, ssm:List*); For decryption: SSM parameters encrypted with the default KMS key
1. Enumerate SSM parameters with ssm:DescribeParameters.
2. Retrieve and decrypt SSM parameter values with ReadOnlyAccess's ssm:Get* permissions, no explicit KMS decrypt grant needed (default KMS key only)
3. Use ssm:GetCommandInvocation to view the output of SSM commands, such as commands setting the local administrative password on EC2 deployments.
Outcome: Access to application secrets and sensitive command output; the authors used SSM permissions to elevate privileges in an AWS account.
MITRE ATT&CK: T1555.006 (inferred)

### Mitigations
- Avoid overly permissive managed policies like ReadOnlyAccess for generic access; treat roles built on broad managed policies plus a few denies as admin roles, not for large groups of users.
- Instead of denying permissions on top of a broad policy, reconsider why they were granted and remove them from the original policy.
- Hand-craft bespoke policies that grant only the exact permissions users require, adding more as needed.
- Prefer more granular managed policies such as AmazonEC2ReadOnlyAccess over ReadOnlyAccess, noting they are still AWS-managed and may change.
- If using AWS managed policies, track changes to them (e.g. with MAMIP or its Twitter bot).

### Status
- Early February 2020 (February 6, 2020, version 61 of ReadOnlyAccess): AWS updated ReadOnlyAccess to include config:SelectResourceConfig, enabling the AWS Config bypass of IAM deny policies.
- As of ReadOnlyAccess version 78 (at time of writing, August 2021) the policy grants AWS Config permissions and ssm:Get*, ssm:Describe*, ssm:List*.

### Resources
- [MAMIP: Monitor AWS Managed IAM Policies Changes](https://github.com/z0ph/MAMIP/)
- [MAMIP Twitter bot (@mamip_aws)](https://twitter.com/mamip_aws)
- [AWS docs: Managed policies and inline policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html)

---

## Full text

[figure]

You need to give your AWS role a set of permissions, but you still want to feel **warm** and **safe** on the inside.

_“Why not ReadOnlyAccess?”_ you ask.

_“I can just deny the permissions I don’t like”_ you proclaim.

Let me show you how your faith in ReadOnly access will betray you and leave you with trust issues.

### Read First:

-   [GitHub - z0ph/MAMIP: \[MAMIP\] Monitor AWS Managed IAM Policies Changes](https://github.com/z0ph/MAMIP/)
-   [Managed policies and inline policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html)

### Drink First:

[Trader Vic's Grog](https://www.threeofstrong.com/trader-vics-grog/)

> “It’s only ReadOnlyAccess, it’s not like they have privileged permissions or anything” — An actual thing that was typed at me once, 2021

I have about 30 hours left on my Macbook restore so I wanted to give a quick thought on a trend I have observed in some AWS environments regarding permissions management. According to [AWS documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege), and virtually everyone else, users and roles are supposed to have the least amount of privileges assigned to them in order to successfully accomplish their task. This is nothing new. I’m sure you are all sick of hearing it. However, this is **_particularly_** true for AWS, as it’s a constantly changing environment where a role’s permissions can vary across policy versions. To demonstrate this, I’m going to walk through a fabricated scenario that borrows from a few AWS environments I have encountered.

_L337 Thins, Inc_ is a multi-national baked goods conglomerate that uses a CI/CD pipeline to deploy infrastructure and applications to AWS. They are developing an app that lets cracker enthusiasts put virtual sunglasses on crackers or something, I dunno, I just wanted to use the pun.

Since the organization already uses Active Directory (AD) for on-premise workstations and identity management, they use [AD to federate their logins to AWS.](https://docs.microsoft.com/en-us/azure/active-directory/hybrid/whatis-fed) In this organization, all employees belonging to the Software Products group (engineers, testers, QA) belong to the “CloudGeneral” AD group. This group will map to an AWS _CloudGeneral_ role, which will allow any user in the “CloudGeneral” group to assume the _CloudGeneral_ role in AWS to do “cloud things”.

In addition, since L337 Thins, Inc is super cloud savvy, they are also using [AWS configuration services](https://aws.amazon.com/config/) (this will come into play in a minute).

Below is a screenshot with the attached policies for the _CloudGeneral_ role.

[figure]

_CloudGeneral attached policies_

You can see that the organization gave the _CloudGeneral_ role the AWS managed _ReadOnlyAccess_ policy in addition to inline policies that allow write access to Elastic Container Registry (ECR) and the corporate general simple storage service (S3) bucket.

After a security pass, a cloud engineer notes that the _ReadOnlyAccess_ policy gives the _CloudGeneral_ role the ability to [list out all users, groups, and policies](https://aws.amazon.com/iam/) in the account, and that’s probably not a good thing.

[figure]

_IAM permissions granted to the ReadOnlyAccess policy. What do you think the Generate stuff does?_

Being the forward thinking engineer they are, they suggest to deny the _CloudGeneral_ role access to all Identity and Access Management (IAM) actions.

This is a really good suggestion.

However, instead of replacing the _ReadOnlyAccess_ policy with a better scoped policy that omits access to IAM, the cloud engineering team adds an inline policy to the _CloudGeneral_ role to explicitly deny access to anything IAM. The policy attached to the role now looks like this:

[figure]

Let’s stop right here. It’s important to remember that **_all permissions in AWS are denied by default_**, and they must be explicitly allowed via policy. If there are conflicting statements regarding permissions, **_deny will take priority_**. In this example, the _ReadOnlyAccess_ policy grants IAM access, but the inline policy denies it, so the inline policy wins and IAM access is denied. _Order of entries do not matter, this is not a firewall._

Removing access to IAM, in and of itself, is a good thing. Users shouldn’t have access to enumerate the access control policies of an entire account. But note that they are now granting the _CloudGeneral_ role a set of permissions, and then selectively taking some away.

If you are following **and** are a reasonable adult, this should sound silly. They are granting a role a set of permissions, and then denying them. In addition to being redundant and confusing, they are now starting to treat access as a “blacklist”, where they remove the dangerous actions, in contrast to the intended “whitelist” approach, where only intended permissions are granted.

**Side Note**: To be fair ([_to be faiiiirrrrr_](https://www.youtube.com/watch?v=jv7jcciKB_s)_),_ there is a reasonable use case for granting a role a managed AWS policy with tons of permissions, and then blacklisting a few extra sensitive actions, but those roles should be treated as admin roles, not for large groups of users.

As of the policy version 78, the _ReadOnlyAccess_ policy also grants _awsconfig_ permissions, which means it’s granted to the _CloudGeneral_ role. Of particular importance is the _config:SelectResourceConfig_ action. _(Note: config isn’t enabled by default, but we’ve seen it used in multiple environments, and it’s used at L337 Thins, Inc.)_.

Using this permission, we can query the configuration state and attached document of any entity in the account, **_effectively bypassing the IAM deny rule_**.

[figure]

_CloudGeneral shouldn’t have access to list policies, but can through aws:config_

And here is the main point I want you to take away from this article:

> **When you model access control like a blacklist, the onus is now on you to understand every single permission granted in the policy.**

_ReadOnlyAccess_ contains permission entries for just about every AWS service offered. Even if you _do_ understand every single one of the 100’s of AWS services (I certainly don’t. If _y_ou do, please teach me your ways), you need to stay up-to-date on every action introduced to the policy to ensure that any new permission doesn’t negatively impact the policy.

For example, lets say _L337 Thins_ created this _CloudGeneral_ policy with the additional “block IAM” inline policy before February 6th, 2020 (Version 61 of _ReadOnlyAccess_ Policy). At the time of creation, it would not have been affected by the _aws:config_ bypass. They would have been high and mighty knowing that all things IAM are kept secret from the lowly commoners of _CloudGeneral_.

And then, one fateful day in early February 2020, without warning or even accepting an update, AWS updates their _ReadOnlyAccess_ policy to include _config:select-resource-config._ Just like that, any user with access to the _CloudGeneral_ role can bypass their IAM blocking policy, making _L773 Thins_ look 👏 like 👏 a 👏 chump.

### What happened?

So where did they go wrong? First, I would recommend staying away from overly-permissive policies like _ReadOnlyAccess_ for generic access. It’s lazy, it’s prone to change, and if utilized, you are responsible for not only understanding the impact for each access granted; you are also responsible for keeping track of the changes. There are more granular policies, for example, _AmazonEC2ReadOnlyAccess_, which is only the EC2 related permissions. While these may have a bit more access than what is needed, they are also managed by Amazon and may change in the future, which may or may not be beneficial.

_It’s important to be precise, especially in access control._

If you ever find yourself denying access in a policy, it may be beneficial to reconsider why it was granted in the first place and remove it from the original policy. Usually, it’s worth the time to hand craft policies that strictly limit users to the permissions they require. You can always add permissions to the list should users require them.

### So much more than aws:config

The fun doesn’t stop at _awsconfig_. _ReadOnlyAccess_ is full of fun permissions that can provide an attacker with sensitive information.

As an example, we were recently able to use the AWS Systems Manager (SSM. I know…) permissions to elevate our privileges in an AWS account. As of Version 78, the _ReadOnlyAccess_ policy allows ssm:Get\*, ssm:Describe\*, ssm:List\*. This includes fun things like ssm:DescribeParameters.

**_What are SSM parameters?_**

Oh, it’s no big deal, it’s just where [AWS recommends you store your sensitive variables, like application secrets](https://aws.amazon.com/blogs/mt/the-right-way-to-store-secrets-using-parameter-store/). Also, let’s not forget about ssm:GetCommandInvocation, which allows the caller to view the output of SSM commands, like say, setting the local administrative password on EC2 deployments.

[figure]

_CloudGeneral can decrypt SSM parameters even though KMS decrypt is not granted. Edit: SSM parameter decrypt will only work if it’s encrypted with the default KMS key, otherwise ReadOnlyAccess is not sufficient._

### Bring it home

_ReadOnlyAccess_ is not the harmless policy you’ve been led to believe. Think of it more like “Admin lite”™. If you are on the offensive side, I highly suggest sifting through AWS managed policies, like _ReadOnlyAccess,_ and looking for more fun things to prove my point. There’s even a really nifty twitter bot that shoots out a tweet every time an AWS managed policy is changed:

[https://twitter.com/mamip\_aws](https://twitter.com/mamip_aws)

If you are a cloud engineer responsible for IAM, remember that if you decide to treat AWS policies with a blacklist approach, you are signing yourself up for a lot of extra, unnecessary work. You are likely better off making bespoke policies that grant the exact permissions you need. So when someone offers you some _ReadOnlyAccess_, Just Say No =).

### Thanks to:

-   @0xdabbad00 and @z0ph for their work on [https://github.com/z0ph/MAMIP/](https://github.com/z0ph/MAMIP/)

* * *

[AWS ReadOnlyAccess: Not Even Once](https://medium.com/specter-ops-posts/aws-readonlyaccess-not-even-once-ffbceb9fc908) was originally published in [Posts By SpecterOps Team Members](https://medium.com/specter-ops-posts) on Medium, where people are continuing the conversation by highlighting and responding to this story.
