AWS Systems Manager identity-based policy examples
By default, AWS Identity and Access Management (IAM) users and roles don't have permission to create or modify AWS Systems Manager resources. They also can't perform tasks using the Systems Manager console, AWS Command Line Interface (AWS CLI), or AWS API. An IAM administrator must create IAM policies that grant users and roles permission to perform specific API operations on the specified resources they need. The administrator must then attach those policies to the IAM users or groups that require those permissions.
The following is an example of a permissions policy that allows a user to delete
documents with names that begin with MyDocument-
in the
US East (Ohio) (us-east-2) AWS Region.
{ "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "ssm:DeleteDocument" ], "Resource" : [ "arn:aws:ssm:us-east-2:111122223333:document/MyDocument-*" ] } ] }
To learn how to create an IAM identity-based policy using these example JSON Policy documents, see Creating IAM policies in the IAM User Guide.
Topics
Policy best practices
Identity-based policies are very powerful. They determine whether someone can create, access, or delete Systems Manager resources in your account. These actions can incur costs for your AWS account. When you create or edit identity-based policies, follow these guidelines and recommendations:
-
Get started using AWS managed policies – To start using Systems Manager quickly, use AWS managed policies to give your employees the permissions they need. These policies are already available in your account and are maintained and updated by AWS. For more information, see Get started using permissions with AWS managed policies in the IAM User Guide.
-
Grant least privilege – When you create custom policies, grant only the permissions required to perform a task. Start with a minimum set of permissions and grant additional permissions as necessary. Doing so is more secure than starting with permissions that are too lenient and then trying to tighten them later. For more information, see Grant least privilege in the IAM User Guide.
-
Enable MFA for sensitive operations – For extra security, require IAM users to use multi-factor authentication (MFA) to access sensitive resources or API operations. For more information, see Using multi-factor authentication (MFA) in AWS in the IAM User Guide.
-
Use policy conditions for extra security – To the extent that it's practical, define the conditions under which your identity-based policies allow access to a resource. For example, you can write conditions to specify a range of allowable IP addresses that a request must come from. You can also write conditions to allow requests only within a specified date or time range, or to require the use of SSL or MFA. For more information, see IAM JSON policy elements: Condition in the IAM User Guide.
Using the Systems Manager console
To access the Systems Manager console, you must have a minimum set of permissions. These permissions must allow you to list and view details about the Systems Manager resources and other resources in your AWS account.
To fully use Systems Manager in the Systems Manager console, you must have permissions from the following services:
-
AWS Systems Manager
-
Amazon Elastic Compute Cloud (Amazon EC2)
-
AWS Identity and Access Management (IAM)
You can grant the required permissions with the following policy statement.
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ssm:*", "ec2:describeInstances", "iam:ListRoles" ], "Resource": "*" }, { "Effect": "Allow", "Action": "iam:PassRole", "Resource": "*", "Condition": { "StringEquals": { "iam:PassedToService": "ssm.amazonaws.com" } } } ] }
If you create an identity-based policy that is more restrictive than the minimum required permissions, the console won't function as intended for entities (IAM users or roles) with that policy.
You don't need to allow minimum console permissions for users that are making calls only to the AWS CLI or the AWS API. Instead, allow access to only the actions that match the API operation that you're trying to perform.
Allow users to view their own permissions
This example shows how you might create a policy that allows IAM users to view the inline and managed policies that are attached to their user identity. This policy includes permissions to complete this action on the console or programmatically using the AWS CLI or AWS API.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": ["arn:aws:iam::*:user/${aws:username}"] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }
Customer managed policy examples
You can create standalone policies that you administer in your own AWS account. We refer to these as customer managed policies. You can attach these policies to multiple principal entities in your AWS account. When you attach a policy to a principal entity, you give the entity the permissions that are defined in the policy. For more information, see Customer managed policy examples in the IAM User Guide.
The following examples of user policies grant permissions for various Systems Manager actions. Use them to limit the Systems Manager access for your IAM users and roles. These policies work when performing actions in the Systems Manager API, AWS SDKs, or the AWS CLI. For users who use the console, you need to grant additional permissions specific to the console. For more information, see Using the Systems Manager console.
All examples use the US West (Oregon) Region (us-west-2) and contain fictitious
account IDs. The account ID shouldn't be specified in the Amazon Resource
Name (ARN) for AWS public documents (documents that begin with
AWS-*
).
Examples
Example 1: Allow a user to perform Systems Manager operations in a single Region
The following example grants permissions to perform Systems Manager operations only in the US East (Ohio) Region (us-east-2).
{ "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "ssm:*" ], "Resource" : [ "arn:aws:ssm:us-east-2:
aws-account-ID
:*" ] } ] }
Example 2: Allow a user to list documents for a single Region
The following example grants permissions to list all document names that
begin with Update
in the
US East (Ohio) Region (us-east-2).
{ "Version": "2012-10-17", "Statement" : [ { "Effect" : "Allow", "Action" : [ "ssm:ListDocuments" ], "Resource" : [ "arn:aws:ssm:us-east-2:
aws-account-ID
:document/Update*" ] } ] }
Example 3: Allow a user to use a specific SSM document to run commands on specific nodes
The following example IAM policy allows a user to do the following in the US East (Ohio) Region (us-east-2):
-
List Systems Manager documents (SSM documents) and document versions.
-
View details about documents.
-
Send a command using the document specified in the policy. The name of the document is determined by the following entry.
arn:aws:ssm:us-east-2:
aws-account-ID
:document/Systems-Manager-document-name
-
Send a command to three nodes. The nodes are determined by the following entries in the second
Resource
section."arn:aws:ssm:us-east-2:
aws-account-ID
:instance/i-02573cafcfEXAMPLE", "arn:aws:ssm:us-east-2:aws-account-ID
:instance/i-0471e04240EXAMPLE", "arn:aws:ssm:us-east-2:aws-account-ID
:instance/i-07782c72faEXAMPLE" -
View details about a command after it has been sent.
-
Start and stop workflows in Automation, a capability of AWS Systems Manager.
-
Get information about Automation workflows.
If you want to give a user permission to use this document to send
commands on any node for which the user has access (as determined by their
user account), you could specify an entry similar to the following in the
Resource
section and remove the other node entries. The
following example uses the US East (Ohio) Region
(us-east-2).
"arn:aws:ssm:us-east-2:*:instance/*"
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "ssm:ListDocuments", "ssm:ListDocumentVersions", "ssm:DescribeDocument", "ssm:GetDocument", "ssm:DescribeInstanceInformation", "ssm:DescribeDocumentParameters", "ssm:DescribeInstanceProperties" ], "Effect": "Allow", "Resource": "*" }, { "Action": "ssm:SendCommand", "Effect": "Allow", "Resource": [ "arn:aws:ssm:us-east-2:
aws-account-ID
:instance/i-02573cafcfEXAMPLE", "arn:aws:ssm:us-east-2:aws-account-ID
:instance/i-0471e04240EXAMPLE", "arn:aws:ssm:us-east-2:aws-account-ID
:instance/i-07782c72faEXAMPLE", "arn:aws:ssm:us-east-2:aws-account-ID
:document/Systems-Manager-document-name
" ] }, { "Action": [ "ssm:CancelCommand", "ssm:ListCommands", "ssm:ListCommandInvocations" ], "Effect": "Allow", "Resource": "*" }, { "Action": "ec2:DescribeInstanceStatus", "Effect": "Allow", "Resource": "*" }, { "Action": "ssm:StartAutomationExecution", "Effect": "Allow", "Resource": [ "arn:aws:ssm:us-east-2:aws-account-ID
:automation-definition/*" ] }, { "Action": "ssm:DescribeAutomationExecutions", "Effect": "Allow", "Resource": [ "*" ] }, { "Action": [ "ssm:StopAutomationExecution", "ssm:GetAutomationExecution" ], "Effect": "Allow", "Resource": [ "*" ] } ] }
Viewing Systems Manager documents based on tags
You can use conditions in your identity-based policy to control access to
Systems Manager resources based on tags. This example shows how you might
create a policy that allows viewing an SSM document. However, permission is
granted only if the document tag Owner
has the value of that user's
user name. This policy also grants the permissions necessary to complete this
action on the console.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ListDocumentsInConsole", "Effect": "Allow", "Action": "ssm:ListDocuments", "Resource": "*" }, { "Sid": "ViewDocumentIfOwner", "Effect": "Allow", "Action": "ssm:GetDocument", "Resource": "arn:aws:ssm:*:*:document/*", "Condition": { "StringEquals": {"ssm:ResourceTag/Owner": "${aws:username}"} } } ] }
You can attach this policy to the IAM users in your account. If a user named
richard-roe
attempts to view an Systems Manager document, the
document must be tagged Owner=richard-roe
or
owner=richard-roe
. Otherwise they're denied access. The
condition tag key Owner
matches both Owner
and
owner
because condition key names aren't case-sensitive. For
more information, see IAM
JSON policy elements: Condition in the IAM User Guide.