#Day39:Aws & IAM  Users, Groups and Roles

#Day39:Aws & IAM Users, Groups and Roles

ยท

9 min read

Exploring Amazon Web Services (AWS) - Your Gateway to Cloud Computing

Amazon Web Services (AWS) has revolutionized the way businesses and individuals access and manage their computing resources. As one of the leading cloud service providers in the world, AWS offers a wide range of services that empower users to build, deploy, and scale applications with ease. In this blog, we'll explore some key features of AWS, with a focus on user data and identity and access management (IAM).

Getting Started with AWS

One of the standout features of AWS is its Free Tier, which is a fantastic opportunity for students and cloud enthusiasts to get hands-on experience without incurring costs. By creating a free account, you can explore a multitude of AWS services and learn how to utilize them effectively.

User Data in AWS

Amazon Elastic Compute Cloud (EC2) is a fundamental service offered by AWS that allows you to launch virtual machines in the cloud. When you launch an EC2 instance, you have the option to pass user data to the instance. This user data can be in the form of shell scripts or cloud-init directives. The beauty of this feature lies in its automation capabilities. You can use user data to execute common configuration tasks and run scripts on the instance after it starts.

User data can be provided in various formats, including plain text, files, or base64-encoded text. This functionality is a huge time-saver when you need to install applications like Apache, Docker, or Jenkins on your instances, as you can automate these tasks during the launch process.

Unlocking the Power of AWS Securely with IAM ๐Ÿ›ก๏ธ

Imagine you have a treasure chest ๐Ÿ—๏ธ filled with precious jewels ๐Ÿ’Ž, and you want to make sure only the right people can access it. Amazon Web Services (AWS) Identity and Access Management (IAM) is like the guardian of your digital treasure chest.

What is IAM? ๐Ÿค–

IAM is a clever web service provided by AWS. Its main job is to help you keep your AWS resources safe from unwanted visitors. These resources could be anything from super-fast computers in the cloud โ˜๏ธ to data storage ๐Ÿ—„๏ธ and more.

How Does IAM Work? ๐Ÿšง

Think of IAM as a powerful gatekeeper ๐Ÿšช. It has two main tasks:

  1. Authentication: This is like checking your ID before you enter a secret club ๐ŸŽ‰. IAM makes sure you are who you say you are. In the digital world, this means confirming that someone is signed in with the right username and password.

  2. Authorization: After confirming your identity, IAM decides what you're allowed to do ๐Ÿ“œ. Can you read files ๐Ÿ“‚, write data ๐Ÿ“, or maybe even do both? IAM sets the rules to make sure only the right people can do the right things with AWS resources.

Central Control ๐ŸŒ

One of the coolest things about IAM is that it lets you control everything from one central place โ˜๏ธ. You can decide who can access what, and you can change the rules whenever you want. This is like having a magical remote control ๐Ÿ“บ for your digital kingdom ๐Ÿ‘‘.

Why is IAM Important? ๐Ÿ’ก

Imagine if anyone could just wander into your treasure chest room and grab your jewels ๐Ÿ˜ฑ. Chaos, right? IAM helps you avoid this chaos in the digital world by giving you the power to decide who gets to see ๐Ÿ‘€, touch โœ‹, or change your precious digital assets.

In a nutshell, AWS IAM is like your personal bouncer ๐Ÿ•บ for your digital world, ensuring that only the right people get access to your valuable AWS resources while keeping the digital riff-raff out ๐Ÿšซ.

Task1:

Launch EC2 instance with already installed Jenkins on it. Once server shows up in console, hit the IP address in browser and you Jenkins page should be visible.

To launch an Amazon EC2 instance with Jenkins and Java installed through a user data script, follow these steps:

  1. Log in to AWS Console: Go to the AWS Management Console (https://aws.amazon.com/console/) and sign in to your AWS account.

  2. Navigate to EC2: Click on the "Services" dropdown in the top left corner and select "EC2" under the "Compute" section.

  3. Launch an EC2 Instance:

    • Click on the "Instances" link in the EC2 Dashboard.

    • Click the "Launch Instances" button.

  4. Choose an Amazon Machine Image (AMI):

    • In the "Choose an Amazon Machine Image (AMI)" step, select a base Amazon Linux 2 AMI or any other AMI that suits your needs. Make sure it's compatible with Jenkins and Java installation.
  5. Choose an Instance Type:

    • Select the instance type based on your requirements. For a basic setup, you can use a t2.micro instance. Click "Next: Configure Instance Details" when ready.
  6. Configure Instance Details:

    • In the "Configure Instance Details" section:

      • Choose the number of instances you want to launch.

      • Optionally, configure other settings like network, IAM role, and shutdown behavior.

      • In the "User data" section, input your user data script to install Jenkins and Java during instance launch. The script should look something like this:

         #!/bin/bash
           sudo apt update
           sudo apt install openjdk-11-jre -y

           curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
             /usr/share/keyrings/jenkins-keyring.asc > /dev/null
           echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
             https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
             /etc/apt/sources.list.d/jenkins.list > /dev/null
           sudo apt-get update
           sudo apt-get install jenkins -y

            sudo systemctl enable jenkins
            sudo systemctl start jenkins

This script updates the system, installs Java , sets up the Jenkins repository, installs Jenkins, starts Jenkins, and enables it to start on boot.

  1. Configure Security Group:

    • Create or select a security group that allows inbound traffic to ports 22 (SSH), 8080 (Jenkins), and any other ports you might need.

    • Ensure that port 8080 is open for Jenkins to be accessible from your IP address.

    • Click "Review and Launch" when ready.

  2. Review and Launch:

    • Review your instance configuration, and if everything looks good, click "Launch."
  3. Select Key Pair: If you have an existing key pair, select it. If not, you can create a new key pair. This key pair is used to access your instance securely. Click "Launch Instances" after selecting the key pair.

  4. View Instances:

    • After launching the instance, you can go back to the EC2 Dashboard and view your instance. Wait until it shows a status of "running" and has a green checkmark.
  5. Access Jenkins:

    • Note the public IP address or public DNS name of your instance.

    • Open a web browser and enter the public IP address or DNS name followed by port 8080 (e.g., http://your-instance-ip:8080).

  6. Set up Jenkins:

    • Follow the Jenkins setup process, including retrieving the initial admin password, and complete the configuration.

You've now launched an EC2 instance with Jenkins and Java installed through a user data script. Make sure to configure Jenkins and access it as needed for your tasks.

IAM Users, Groups, and Roles: Building Blocks of AWS Security

In the realm of Amazon Web Services (AWS), security is paramount. AWS Identity and Access Management (IAM) is the guardian of this security, providing you with the tools to control access to your AWS resources. To understand IAM fully, let's break down its core components: Users, Groups, and Roles.

IAM Users

Imagine IAM Users as the individuals who need access to your AWS kingdom. These users can be actual humans or applications, and each user gets their own set of credentials (like a username and password) to access AWS services. Users are like the people in your organization who have different roles and responsibilities.

For example, you might have an IAM User named "DevOps-User" who can manage EC2 instances, while another named "Data-User" can access S3 buckets for data analysis.

IAM Groups

Now, think of IAM Groups as a way to organize your users. Instead of managing permissions for each user individually, you can group them together based on their responsibilities or access needs. This makes it easier to assign and manage permissions because you can apply them to a whole group at once.

For instance, you can create a group called "Developers" and add IAM Users who are responsible for coding. Then, you assign permissions to the "Developers" group, and all users within that group inherit those permissions. If a new developer joins, you simply add them to the group, and they automatically gain the appropriate access.

IAM Roles

Roles are a bit different; they're like special passes that IAM Users and even AWS services can temporarily assume when needed. Roles are not associated with individuals or applications permanently; instead, they are assumed temporarily when specific conditions are met.

Roles are incredibly handy in situations where, for example, an EC2 instance needs to access an S3 bucket securely. Instead of hard-coding credentials into the instance, you can assign a role to it, granting it temporary permissions to access the bucket. This way, you don't need to manage credentials directly, making your environment more secure and manageable.

In a nutshell:

  • IAM Users are for individuals or applications, each with their own permanent credentials.

  • IAM Groups help organize users, making it efficient to manage permissions for groups of users with similar responsibilities.

  • IAM Roles are temporary permissions that can be assumed by users or AWS services, reducing the need for hardcoded credentials.

IAM is your AWS security powerhouse, enabling you to finely control who gets access to your AWS resources and what they can do with them. By strategically using IAM Users, Groups, and Roles, you can build a robust security framework that keeps your AWS kingdom safe and sound.

Task2: Create three Roles named: DevOps-User, Test-User and Admin.

  1. Log in to AWS Console: Go to the AWS Management Console (https://aws.amazon.com/console/) and sign in to your AWS account.

  2. Navigate to IAM: Click on the "Services" dropdown in the top left corner and select "IAM" under the "Security, Identity, & Compliance" section.

  3. Create the "DevOps-User" Role:

    a. In the IAM dashboard, click on "Roles" in the left-hand navigation pane.

    b. Click the "Create role" button.

    c. For "Select type of trusted entity," choose "AWS service."

    d. In the "Use case" section, find and select "EC2" as the service that will use this role. Click "Next: Permissions."

    e. In the "Permissions" step, you can attach policies that define what actions the "DevOps-User" role can perform. You can attach existing policies or create custom policies according to your requirements. After attaching the desired policies, click "Next: Tags."

    f. (Optional) You can add tags to the role for better organization and tracking. Click "Next: Review."

    g. Provide a meaningful name for the role, such as "DevOps-User," and add an optional description. Then, click "Create role."

  4. Create the "Test-User" Role:

    Repeat the same steps as above (steps 3a to 3g), but name the role "Test-User" and assign appropriate policies based on the permissions required for your test users.

  5. Create the "Admin" Role:

    Repeat the same steps as above (steps 3a to 3g), but name the role "Admin" and assign policies that grant administrative-level permissions.

Once you've created these roles, you can assign them to IAM users, groups, or AWS resources (like EC2 instances) as needed. These roles will help you manage and delegate permissions effectively within your AWS environment, ensuring that users and resources have the appropriate access to AWS services and resources based on their roles and responsibilities.

ย