
I’ve considered some measures to take in the event that a PC with the Systems Manager Agent installed is lost.
This article outlines my thoughts on the procedures to follow in the event that a PC with the Systems Manager Agent installed is lost.
Introduction
Last time, I wrote an article about installing Systems Manager Agent (hereinafter referred to as SSM Agent) and CloudWatch Agent.
In the article, I wrote, "The risk of terminal theft remains, so we must take measures." This time, I would like to think about the necessary countermeasures in case of loss or theft of a PC, so I will write an article.
This article is the author's personal opinion. Please keep it for reference only because it is the result of trial and consideration within the scope of personal use.
Prerequisites
- SSM Agent must be installed
- The OS of the PC that is expected to be lost is Ubuntu 24.04
- A IAM policy that rejects (Deny) all AWS operations must be created in advance
IAM policy that rejects (Deny) everything
Create a policy that rejects (Deny) all actions from all resources.
In this article, the IAM policy name is "AllDeny".
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllDeny", "Effect": "Deny", "Action": "*", "Resource": "*" } ]}
Expected risks when losing a PC
The following can be considered.
Abuse of temporary authentication information
SSM Agent communicates with the AWS side using the temporary authentication and permissions of the IAM role granted to hybrid activation. Temporary authentication information is stored in
/root/.aws/credentials . If you can log in to your PC, this authentication information may be read.If more than necessary IAM policies are attached and fall into the hands of malicious people, there is a risk of unintentional manipulation of AWS resources (such as high billing by creating a large amount of resources).
There is a risk that the authentication information will be misused not only from the lost PC, but also from other PCs and servers.
Hybrid activation ID and code are abused on other PCs
This is when the following three conditions are met, but there is a possibility.
- The number of registration limits set for hybrid activation has not reached the upper limit
- It must be within the expiration date set for hybrid activation
- The ID and code of hybrid activation are stored locally on the PC
The hybrid activation ID and code will be misused on another PC, and an unintended managed node will be registered. If you do so, there is a risk that unintentional operations of AWS resources will be performed from multiple terminals.
In the above case, both registered instances and registration limit are 1, so additional registrations cannot be made. In addition, the expiration date has also expired at the time of writing, so additional registration is not possible.
For example,
- Registration limit (Registration limit) is 10
- Registered instances are 7
- The expiration date is within the expiration date
In this state, if the ID and code of the hybrid activation pass into the hands of a third party, the SSM Agent may be installed and the managed node may be illegally registered.
If you notice that your PC is lost
If you notice that your PC is lost, the work to be carried out is as follows. 1. And 2. In view of the impact on other nodes, one or the other will be implemented.
Countermeasures | Purpose | Effects on other nodes | Need or not |
|---|---|---|---|
1. Disable IAM role | Disable existing temporary authentication information to prevent unauthorized manipulation of AWS resources | Yes | Necessary |
2. Unregister of managed node | Stop updating temporary authentication information | None | Necessary |
3. Removal of hybrid activation | Prevention of unauthorized registration of managed nodes | Yes | Depending on the situation |
4. Investigation of unauthorized manipulation in CloudTrail | Identification of the scope of damage | None | Necessary |
This task is performed with an account with an IAM policy that can operate Systems Manager and IAM.
1. Disable the IAM role
Disabling does not mean deleting the IAM role.
Attach an IAM policy that denies all access to the IAM role attached to the hybrid activation.
This is to prevent other PCs and other users from using and abusing temporary authentication stored in
/root/.aws/credentials .# Get the ARN of the IAM policy ("AllDeny" in this article) that rejects everything (Deny)
POLICY_NAME="AllDeny"
POLICY_ARN=$(aws iam list-policies \--Query "Policies[? PolicyName==\`${POLICY_NAME}\`]. Arn" \--Output text)
# Get the IAM role name attached to hybrid activation
ROLE_NAME="IAM_ROLE_NAME"
# Attach an IAM roll to deny everything
aws iam attach-role-policy \--Role-name ${ROLE_NAME}--Policy-arn ${POLICY_ARN}
If there is an IAM policy with explicit Deny, Deny will take precedence over other Allow policies. Therefore, you will not be able to operate using the temporary authentication information stored on your PC.
Disabling the IAM role will cause the following effects.①Other terminals using the same hybrid activation will not be able to operate AWS resource②Systems Manager will also stop working③If you have CloudWatch Agent installed, you will not be able to send metrics or logs
2. Unregister the managed node
If it is not acceptable to deactivate the IAM role and affect other nodes, or if the lost PC is unlikely to return to hand, unregister the lost PC from the managed node and cut off the path to AWS resources I think it's good.
aws ssm deregister-managed-instance \--Instance-id "mi-xxxxxxxxx"3. Removal of hybrid activation
If hybrid activation applies to all of the following 3 points, I think it would be better to delete it.
- The limit on the number of registrations for hybrid activation has not reached the upper limit
- Hybrid activation registration expiration date has not been reached
- The suspicion that the ID and code are stored locally on the lost PC does not disappear
If you want to delete it, execute the following command.
aws ssm delete-activation--Activation-id "Activation ID"4. Log investigation of unauthorized operation in CloudTrail
In CloudTrail, check for unauthorized logs from the node ID of the lost PC. If not, there is no problem, but if there is, there is a possibility that something has been unauthorized.
If you find a PC
When the PC is found, return it to the original environment.
Detach IAM policy to deny everything
If you detach a policy that Denys everything ("AllDeny" in this article), there will be no explicit Deny. Return to the original IAM policy settings.
# Get the ARN of the policy to deny everything ("AllDeny" in this article)
POLICY_NAME="AllDeny"
POLICY_ARN=$(aws iam list-policies \--Query "Policies[? PolicyName==\`${POLICY_NAME}\`]. Arn" \--Output text)
# Get the IAM role name attached to hybrid activation
ROLE_NAME="IAM_ROLE_NAME"
# Detach the IAM roll to deny everything. If it ends normally, nothing will be displayed.
aws iam detach-role-policy \--Role-name ${ROLE_NAME}--Policy-arn ${POLICY_ARN}
Re-registration to the managed node
Create a new hybrid activation and register it with the managed node.
I wrote about the registration procedure for managed nodes in the previous article, so I will skip it this time.
Preventive measures
It is advisable to check it in case the PC is lost. Of course, I think it should be reconsidered even after it is lost and found.
IAM policies that attach to IAM roles follow the principle of minimum authority
As I wrote in the previous article, it is necessary to set permissions according to the principle of minimum authority. Inventory the IAM policies that are regularly attached and detach unnecessary IAM policies.
Review of hybrid activation operation
To prevent the ID and code of the hybrid activation from being seen by third parties, you must not leave the ID and code on the PC where you installed the SSM Agent. In addition, do not set an unfounded limit on the number of registrations and the expiration date,
- Create a hybrid activation each time as a registration limit for the number of units to install SSM Agent
- Specify a short SSM Agent installation deadline
It is necessary to decide on the registration operation of hybrid activation, and regularly review the operation.
Finally
Even a personal PC may be lost or stolen. If the login information is also known, there is a risk that a third party will be able to operate the PC and access AWS resources. Although it is for personal use, I thought it would be better to summarize the response procedures in case of emergency, so I wrote an article this time. I hope this article will be helpful to someone.
Thank you for reading to the end!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article