This repository provides a demonstration of IAM Roles Anywhere, a solution for using X.509 certificates to assume IAM roles in AWS environments. The demo showcases the process of creating a Certificate Authority (CA), generating credentials, and utilizing them to assume roles.
The following commands explain how to create a CA for testing purposes. Please note that this CA is not suitable for production use, where you should use ACM Private Certificate Authority or a fully-implemented, reliably secure private CA.
-
Generate the CA private key: Run the following command to generate a private key for your CA:
openssl ecparam -genkey -name secp384r1 -out ca.key
This command will generate a private key and save it in the file
ca.key
. -
Edit
root_ca_request.config
and customize: Make any necessary customizations to theroot_ca_request.config
file, which contains the configuration for the CA request. -
Generate the CA request: Execute the following command to generate the CA request using the private key and configuration:
openssl req -new -key ca.key -out ca.req -nodes -config root_ca_request.config
This will generate the CA request and save it in the file
ca.req
. -
Edit
root_cert.config
and customize: Customize theroot_cert.config
file according to your requirements. -
Generate the CA certificate: Use the following command to generate the CA certificate by self-signing the CA request:
openssl ca -out ca.pem -keyfile ca.key -selfsign -config root_cert.config -in ca.req
The CA certificate will be generated and saved in the file
ca.pem
. -
Create the client key: Generate a private key for the client using the following command:
openssl ecparam -genkey -name secp384r1 -out client.key
The client private key will be generated and saved in the file
client.key
. -
Edit and customize the basic CSR config file (
client_request.config
): Make any necessary modifications to theclient_request.config
file, which contains the configuration for the client's Certificate Signing Request (CSR). -
Generate the client CSR: Run the following command to generate the client's CSR using the client private key and CSR configuration:
openssl req -new -sha512 -nodes -key client.key -out client.csr -config client_request.config
The client CSR will be generated and saved in the file
client.csr
. -
Edit and customize
client_cert.config
: Customize theclient_cert.config
file based on your preferences and requirements. -
Generate the client certificate: Use the following command to generate the client certificate by signing the client CSR with the CA:
openssl x509 -req -sha512 -days 30 -in client.csr -CA ca.pem -CAkey ca.key -CAcreateserial -out client.pem -extfile client_cert.config
The client certificate will be generated and saved in the file
client.pem
.
To create a Roles Anywhere Trust Anchor, Role, and Profile in AWS, execute the following command:
aws cloudformation deploy --template template.yaml --stack-name roles-anywhere-demo --parameter-overrides OU=IT X509CertificateData="$(cat ca.pem)" --capabilities CAPABILITY_NAMED_IAM --disable-rollback
This command deploys an AWS Cloud
Formation stack using the template.yaml
file. The stack creates the necessary resources for the Roles Anywhere demo, including the Trust Anchor, IAM Role, and IAM Profile. The OU
parameter specifies the Organizational Unit for the role, and X509CertificateData
is the content of the CA certificate (ca.pem
).
Generate credentials using the certificate and the IAM Roles Anywhere Trust Anchor, Role, and Profile
To generate credentials using the client certificate and the IAM Roles Anywhere Trust Anchor, Role, and Profile, run the following command:
./get_creds.sh
This command executes the get_creds.sh
script, which performs the necessary steps to obtain temporary AWS credentials using the client certificate and the created IAM resources. The script facilitates the process of assuming the IAM role and setting the appropriate environment variables for subsequent AWS operations.
Feel free to explore and modify the provided scripts and configuration files to adapt the demo to your specific use cases and requirements.
This demo is provided under the MIT License. Feel free to use, modify, and distribute it according to the terms of the license.