Managing Enterprise Credentials
Some companies get stuck on the treadmill of rotating keys to defend against old or exposed credentials or to satisfy a security checkbox. Worse, some assume no “bad actors” are in their systems - even though the mean time to discover a data breach is around 200-300 days (depending on your source). Fortunately there’s a solution that eliminates the need for key rotation.
Replace or supplant static credentials with machine identities, attribute-based access control (ABAC), and multi-factor authentication (MFA). We illustrate the benefits of this approach with Amazon Web Service (AWS) command-line interfaces (CLI), outlining the threat model, solution controls, and implementation details for two use cases: remote control and Infrastructure as Code (IaC).
Threat Model and a Control Solution
The threat model we’re using to guide our defenses includes:
Some controls that? assist this defense:
Controls Explained
With ABAC, one or more properties of the actor (person, instance, or “principal”) must match a property of the target (instance or “resource”). This can be implemented by assigning tags to every principle and resource, along with policies that check for matching tags. Once implemented, only “dev”-tagged users can access “dev” instances (for example). This enables easy scaling of principals and resources with no policy changes.
When machines are the principal, the use of machine attributes for authorization is sometimes called “machine identity” - and can include tags, names, IPs, or other attributes. When a person is the principal, the AWS Identity and Access Manager (IAM) can enforce MFA authentication for both GUI and CLI functions. Although credentials are used in our model, they are not preserved unencrypted on disk, decrypted only when needed, require MFA, and are used just long enough to get short-term, self-expiring tokens in memory.?
The Security Token Service (STS) issues those short-term user tokens. Those tokens should allow no permissions other than role assumption. When users try to assume a role with those tokens, policy checks occur to confirm authorization, then STS issues new role tokens.
Users can assume a remote access role using these controls. To start, a user would decrypt static credentials into memory and combine them with an MFA code to get STS user tokens. He would then request the remote control role. After an authorization check, he would get new STS role tokens. Then he would request remote access to an instance. AWS would use ABAC checks to confirm that the user and instance tags match, and would verify that the role tokens are valid. Then the AWS Systems Manager (SSM) would open a remote control session. No private keys (“pem” files) or internet-exposed ports are required.
Remote Access Commands
Here’s the 5 commands to remotely access an AWS instance using the controls described above. Replace $variables as needed. Additional details follow.
c=/tmp/creds;pass aws/creds > $c;chmod +x $c;. $c;shred -uvz $c 2>/dev/null; rm -f $c # decrypt keys into memory
aws sts get-session-token --serial-number $arnMfa --token-code $mfa --duration-seconds 900 # get user STS token
aws sts assume-role --role-arn $arnRole --duration-seconds 3600 --role-session-name jane.ssm # get role token
id=$(aws ec2 describe-instances --region $region --filter "Name=tag:Name,Values=$instanceName” --query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" $* --output text) # get id of instanceName to control
aws ssm start-session --target $id --region $region # start remote control of instanceName
Controls for Infrastructure as Code (IaC)
This methodology applies to other use cases. For example, IaC staff can avoid hard coding keys into terraform.tfvars files. Instead, they can:
领英推荐
If a machine rather than a person is doing the terraforming, no MFA is likely available, so adjust the IaC role’s ABAC checks to check metadata of the terraforming principal machine (tag, name, source IP, etc.).
For Ansible (another common IaC tool), export the tokens as “-e name=value” on the ansible-playbook call. Do this for all the name/value pairs from the IaC STS role tokens. Reference those names in the Ansible files as needed.
Implementation Detail
This section provides more hints towards working code.
Pass:
Policies:
Aliases:
More:
Implementation Summary:
The work described above functions correctly if all of these are true:
Conclusion
Additional advantages to using the controls above include:
This justifies, explains, and demonstrates a model for securing access to resources - without the usual vulnerabilities of static credentials - using encryption, MFA, ABAC policies, least-privilege roles, and short-term tokens.
About the author: DavidEason.com does cyber and many things security related, including reading and writing about it and training others, full-time and for fun.