EC2 Virtual Machine User

Rotating AWS EC2 Virtual Machine accounts with Keeper

In this guide, you will learn how to rotate AWS EC2 Virtual Machine (VM) Accounts on your AWS Environment using Keeper Rotation. The EC2 VM is an AWS managed resource where the EC2 VM Admin Credentials are linked to the PAM Machine record and the identity of the EC2 VM Users are defined in the PAM User record type.

For EC2 VM Accounts, normal operating system commands are used to change the password. Keeper will connect to the target machine and send command-line commands to change the password.

Prerequisites

This guide assumes the following tasks have already taken place:

  • Keeper Secrets Manager is enabled for your role

  • Keeper Rotation is enabled for your role

  • A Keeper Secrets Manager application has been created

  • A Keeper Rotation gateway is already installed, running, and is able to communicate via SSH or WinRM with your target AWS Virtual Machine(s).

  • Your AWS environment is configured per our documentation

1. Set up PAM Machine Records

Keeper can rotate any local user account on either the Gateway machine or any other machine on the network. A PAM Machine record should be created for every machine. This PAM Machine record should link to an administrative credential that has the rights to change passwords for users on the machine.

Once a PAM Machine record is created for every machine, a PAM User record needs to be created for each local user account that will be rotated.

Keeper will use the referenced admin credential to rotate the password or SSH key of AWS Virtual Machine users in your AWS environment. These admin credentials need to have the sufficient permissions in order to successfully change the credentials of these user accounts.

If you are running a rotation on a PAM Machine record which also happens to be the same machine running the Keeper Gateway, Keeper will attempt to rotate the password or SSH key for the account using the keeper-gw user. Assuming that keeper-gw has sudoers privilege, it will be able to perform rotations on the local Gateway machine.

The following table lists all the required fields on the PAM Machine record:

Field
Description

Title

Name of the Record i.e AWS Linux 1

Hostname or IP Address

Machine hostname or IP as accessed by the Gateway

Port

Typically 5985 or 5986 for WinRM, 22 for SSH.

Administrative Credentials

Linked PAM User record that contains the username and password (or SSH key) of the Admin account.

Operating System

The VM Operating System, i.e Windows or Linux

SSL Verification

For WinRM, if selected, will use SSL mode port 5986. Ignored for SSH.

This PAM Machine Record with the linked admin credential needs to be in a shared folder that is shared to the KSM application created in the prerequisites. Only the KSM application needs access to this privileged account, it does not need to be shared with any users.

PAM Machine record

2. Set up PAM Configuration

Note: You can skip this step if you already have a PAM Configuration set up for this environment.

Make sure the following items are completed:

  • A Keeper Secrets Manager application has been created

  • A Keeper Rotation gateway is already installed, running, and is provisioned in the Keeper Secrets Manager application you created.

  • PAM Machine records have been created for each target machine

If you are creating a new PAM Configuration, login to the Keeper Vault and select "Secrets Manager", then select the "PAM Configurations" tab, and click on "New Configuration". The following table lists all the required fields that needs to be filled on the PAM Configuration.

Field
Description

Title

Configuration name, example: AWS VM Configuration

Environment

Select: AWS

Gateway

Select the Gateway that is configured on the Keeper Secrets Manager application and has network access to your Active Directory server from the prerequisites

Application Folder

Select the Shared folder where the PAM Configuration will be stored. We recommend placing this in a shared folder with the admin accounts, not the machines.

AWS ID

A unique ID for this instance of AWS. This is for your reference and can be anything, but its recommended to be kept short Ex: AWS-1

Access Key ID

Set this field to USE_INSTANCE_ROLE if you are using EC2 role policy (default). Otherwise use a specific Access Key ID.

Secret Access Key

Set this field to USE_INSTANCE_ROLE if you are using EC2 role policy (default). Otherwise use a specific Secret Access Key.

For more details on all the configurable fields in the PAM Configuration record, visit this page.

PAM Configuration for AWS

3. Set up PAM User Records

Keeper will use the credentials linked from the PAM Machine record to rotate the PAM User records in your AWS environment. The PAM User credential needs to be in a shared folder that is shared to the KSM application created in the prerequisites.

The following table lists all the required fields that need to be filled on the PAM User record:

Field
Description

Title

Keeper record title i.e. AWS Machine1 ec2-user

Login

Case sensitive username of the user account being rotated, e.g. ec2-user.

Password

This is only required if the user logs in with a password. If the password is left blank, performing a rotation will set one.

Private PEM Key

SSH private key. This is only required if you are planning to rotate the PEM key instead of rotating the password.

Linux PAM User record

4. Configure Rotation on the Record - AWS VM User

Select the PAM User record(s) from Step 3, edit the record and open the "Password Rotation Settings".

  • Select the desired schedule and password complexity.

  • The "Rotation Settings" should use the PAM Configuration setup previously.

  • The "Resource Credential" field should select the PAM Machine credential setup from Step 1.

  • Upon saving, the rotation button will be enabled and available to rotate on demand, or via the selected schedule.

Password Rotation Settings on AWS Instance User

Any user with edit rights to a PAM User record has the ability to setup rotation for that record.

SSH Key Rotation Notes

When rotating the private PEM Key credential on a target machine or user, Keeper will update the authorized_keys file on the machine with the new public key. The first time that a rotation occurs, the old public key is left intact in order to prevent system lockout. The second public key added to the file contains a comment that serves as an identifier for future rotations. For example:

[ec2-user@host .ssh]$ cat authorized_keys
ssh-rsa AAAAB3NzaC1...11xZrfOxYXG6RV84mCZ3uldesEyV/ghLxAb7Fcz awsdemo
ssh-rsa AAAAB3NzaC...un+frl9Q== keeper-security-ec2user

By default, Keeper will not remove other keys from the .ssh/authorized_keys file since some providers will place in their own keys in order to control the virtual machine (ie Google Cloud Provider).

If the first rotation is successful, you can optionally delete the old public key entry in the authorized_keys file. On subsequent rotations, Keeper will update the line which contains the "keeper-security-xxx" comment.

Rotation will also create backup of the prior .ssh/authorized_keys inside of the .ssh directory.

For private key rotation, the new private key will be same algorithm and key size (bits) as the current private key. For example, if the current private key is ecdsa-sha2-nistp256 the new private key will be ecdsa-sha2-nistp256. This can be overridden by adding a custom text field, with the label Private Key Type , and setting the value to one support algorithms:

  • ssh-rsa - 4096 bits

  • ecdsa-sha2-nistp256 - ECDSA, 256 bits

  • ecdsa-sha2-nistp384 - ECDSA, 384 bits

  • ecdsa-sha2-nistp521 - ECDSA, 521 bits

  • ssh-ed2551

.This custom field can also be used if the current private key's algorithm cannot be detected.

To prevent private key rotation, a custom text field can be added to the PAM User record with the label Private Key Rotate. If the value of the field is TRUE, or the field doesn't exists, the private key will be rotated if it exists. If the value is FALSE, the private key will not be rotated.

For Linux user rotations, password-encrypted PEM files are not currently supported.

Last updated

Was this helpful?