Skip to main content

2 posts tagged with "EC2 Instance"

View All Tags

Secure EC2 Private Subnet Access Without Bastion Hosts - Save Costs

· 5 min read

Introduction

This approach of using EC2 Endpoint compared to a Bastion host not only streamlines the connection process but also saves costs associated with maintaining a bastion host.

The Traditional Method

EC2 endpoint

Typically, to connect to an EC2 instance in a private subnet, you would use a bastion host. The process involves:

  1. Setting up a bastion host in a public subnet.
  2. Connecting to the bastion host from your local machine.
  3. Using the bastion host to access the EC2 instance in the private subnet.

While this method is effective, it can be cumbersome and costly.

The New Approach: EC2 Instance Connect Endpoint

AWS recently introduced a new service called EC2 Instance Connect Endpoint. This service allows you to connect directly to your EC2 instance in a private subnet without the need for a bastion host.

EC2 Traditional Method

Here's how to set it up:

Step-by-Step Guide

Set Up Your VPC and Subnets

EC2 setup VPC

First, create a Virtual Private Cloud (VPC) with both public and private subnets:

  1. Public Subnet: This is where you will create the EC2 Instance Connect Endpoint.
  2. Private Subnet: This is where your EC2 instance will reside.
  3. Delete Default VPC: Start by deleting the default VPC in your AWS region to avoid conflicts.
  4. Create a New VPC:
    1. Navigate to the VPC console.
    2. Choose “VPC and more” and give it a suitable name (e.g., "YouTubeDemoVPC").
    3. Create one public subnet and one private subnet.
    4. No need for an S3 gateway in this setup.

Step 2: Launching the EC2 Instance

EC2 launch instance

  1. Launch an EC2 Instance in the Private Subnet:

    1. Go to the EC2 console and launch a new instance.
    2. Choose the private subnet for your instance.
    3. Select an instance type (e.g., t-nano).
    4. Create a key pair or use an existing one for SSH access.
  2. Set Up Security Groups:

    1. Create a new security group allowing all traffic within the VPC.
    2. Ensure the security group is attached to your EC2 instance.

Step 3: Creating the EC2 Instance Endpoint

  1. Navigate to the VPC console and select “Endpoints.”

  2. Create a new endpoint and attach it to the VPC.

  3. Assign a security group to the endpoint that allows all traffic.

  4. Configure Security Groups:

    1. Ensure the public security group for the endpoint allows inbound traffic from your local IP.

Step 4: Connecting via AWS CLI

EC2 connecting

  1. Install and Configure AWS CLI:

    1. Ensure AWS CLI is installed on your local machine.
    2. Configure AWS CLI with your access keys.
  2. Connect to the EC2 Instance:

    1. Use the following command with the correct private key and endpoint details to connect to the EC2 instance.
    ssh -i <keyName>.pem <username>@<instance-id> -o ProxyCommand="aws ec2-instance-connect open-tunnel --instance-id <instance-id>" --profile <profile-name>

Step 5: Connecting via WinSCP

EC2 WinSCP

  1. Download and Install WinSCP:

    1. Install WinSCP for a graphical interface to manage files on your EC2 instance.
  2. Set Up WinSCP:

EC2 continue

  1. Open WinSCP and configure a new session.

    1. Enter the private IP of the EC2 instance.

    2. Use the private key for authentication.

    3. Set up a proxy command to use the EC2 endpoint.

      1. Click Advanced --> Connection --> Proxy --> Local and enter following command:
      aws ec2-instance-connect open-tunnel --instance-id <instance-id>
  2. Connect and Manage Files:

EC2 cont

  1. Save the session settings and connect.
    1. You should now be able to manage files on your EC2 instance via WinSCP.

Troubleshooting Common Issues

  1. Permission Denied Errors:

  2. Ensure your private key file has the correct permissions (chmod 400 your-key.pem).

  3. Verify the security group rules allow inbound traffic from your IP.

  4. Endpoint Initialization Issues:

  5. Check the VPC and subnet configurations.

  6. Ensure the endpoint is associated with the correct security group.

Benefits of Using EC2 Instance Endpoints

  1. Cost Savings: Avoid additional costs associated with running a bastion host.
  2. Simplicity: Simplify the connection process by eliminating the need for an intermediary host.
  3. Security: Maintain secure access to instances in private subnets without exposing a bastion host.

Conclusion

Using EC2 instance endpoints is a powerful and cost-effective way to manage instances in private subnets. This guide has provided a comprehensive walkthrough of setting up and connecting to an EC2 instance without a bastion host, utilizing both AWS CLI and WinSCP. Implementing this approach can streamline your workflow and reduce costs, making your cloud infrastructure more efficient and manageable.


🔚 Call to Action

Choosing the right platform depends on your organizations needs. For more insights, subscribe to our newsletter for insights on cloud computing, tips, and the latest trends in technology. or follow our video series on cloud comparisons.

Interested in having your organization setup on cloud? If yes, please contact us and we'll be more than glad to help you embark on cloud journey.

💬 Comment below:
Which tool is your favorite? What do you want us to review next?

Your Data, Your Keys, Your Control: Bring your own keys to AWS CloudHSM - Part 3

· 4 min read

Introduction

Please refer HSM Part 1 & HSM Part 2 for additional details on HSM setup.

AWS Key Management Service (KMS) provides a secure, centralized platform for managing cryptographic keys. Multi-Region keys in AWS KMS allow you to use the same keys across multiple AWS Regions, making it easier to manage encrypted data and ensuring business continuity. In this guide, we'll explore how to set up and use Multi-Region

BYOK (Bring Your Own Key) in AWS KMS.



Step 1: Setting Up Your Environment

Before you start, ensure you have an AWS account with the necessary permissions, AWS CLI installed, and familiarity with AWS regions and KMS concepts.

Creating an Empty Directory on EC2 Instance:

Start by creating a new directory on your EC2 instance where you'll manage your keys:

mkdir /opt/vb-hsm/hsm-21
cd /opt/vb-hsm/hsm-21

Step 2: Creating a Multi-Region KMS Key


Multi-Region KMS Multi-Region KMS


Generate a new KMS key with no key material associated, indicating it's external and multi-region:

aws kms create-key --origin EXTERNAL --region us-east-1 --multi-region

You'll receive an output similar to this:

{
"KeyMetadata": {
"AWSAccountId": "<AccountID>",
"KeyId": "mrk-d58582b2563a40ef893d9181052130db",
"Arn": "arn:aws:kms:us-east-1:<AccountID>:key/mrk-d58582b2563a40ef893d9181052130db",
...
"MultiRegion": true,
...
}
}

Make sure to note down the KeyId as it will be used later.

Step 3: Preparing for Key Import

Create an alias for easier reference to your key:

aws kms create-alias --alias-name alias/byok-mrk --target-key-id mrk-d58582b2563a40ef893d9181052130db

Retrieve the parameters needed for importing your key:

aws kms get-parameters-for-import --key-id mrk-d58582b2563a40ef893d9181052130db --wrapping-algorithm RSAES_OAEP_SHA_256 --wrapping-key-spec RSA_2048 --region us-east-1 > ./WrappingParameters.json

Extract the import token and create a public key:

jq -r '.ImportToken' ./WrappingParameters.json > ./ImportToken.b64
echo -e "-----BEGIN PUBLIC KEY-----\n$(jq -r '.PublicKey' ./WrappingParameters.json)\n-----END PUBLIC KEY-----" > ./PublicKey.pem
openssl enc -d -base64 -A -in ./ImportToken.b64 -out ./ImportToken.bin

Step 4: Importing Key Material

Initialize your Crypto user and import settings:

export CLOUDHSM_ROLE=crypto-user
export CLOUDHSM_PIN=cu_user1:acord12345
/opt/cloudhsm/bin/cloudhsm-cli key import pem --path ./PublicKey.pem --label wrapping-key-example-21 --key-type-class rsa-public --attributes wrap=true

Step 5: Replicating Key to Another Region

Understand the mechanics of cross-Region replication, crucial for maintaining data consistency across geographical locations. Use AWS KMS's built-in replication features to copy key material securely between regions, adhering strictly to AWS security protocols.

Read about Key Management
Ready to take your cloud infrastructure to the next level? Please reach out to us Contact Us


Conclusion

Using AWS KMS Multi-Region keys with BYOK configurations adds a layer of flexibility and security to your cloud infrastructure, enabling seamless data encryption and decryption across different AWS Regions. By carefully following these steps and maintaining rigorous security standards, you can ensure the safety of your key material and uphold compliance across your organization.


🔚 Call to Action


Choosing the right platform depends on your organizations needs. For more insights, subscribe to our newsletter for insights on cloud computing, tips, and the latest trends in technology. or follow our video series on cloud comparisons.


Interested in having your organization setup on cloud? If yes, please contact us and we'll be more than glad to help you embark on cloud journey.


💬 Comment below:
How is your experience with Mac on EC2? What do you want us to review next?