Assignment: Permissions and Identity Management

Objective

This assignment is designed to introduce you to Identity Managament and IAM Roles, covering the setup of a WebApp and a Container Registry (ACR), configuration, and basic management of apps' identity and roles to connect both services. By the end of this assignment, you will understand how to connect at least two Azure services to allow them to communicate.


Task 1: Deploy a simple WebApp from Docker image

1. Log in to Azure

Navigate to your Azure portal and login.

2. Create a resource group

Name your resource group simpleAppRG

3. Create a WebApp

Go to App Services and create a new Web app. Set the following configurations:

Go to the Next step, configure the container:

Question: Wait few minutes then visit the URL of your WebApp, what do you see? Check the logs in the Deployment center to inspect what happened.

4. Create a Container Registry

Look for Container Registries service and create a new Registry.

alt text

Use the following configuration:

Question: What's a container registry?

5. Create a simple app

First, let's create a simple app. On your computer:

mkdir ~/simple-app
cd ~/simple-app
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello, Azure!"}

Feel free to update this app! Show me your creativity :)

# Use an official Python runtime as a parent image
FROM python:3.9

# Set the working directory
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install FastAPI and Uvicorn
RUN pip install fastapi uvicorn

# Make port 8080 available to the world outside this container
EXPOSE 8080

# Run app with Uvicorn on container startup
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
docker build -t fastapi-app .
docker run -d -p 8080:8080 fastapi-app

6. Push the image to the registry

Navigate to your appsRegistry resource. In "Overview", look for "Get Started" -> "Push an image". Follow the steps to understand the example. After the step 4, navigate to "Repositories", what do you see?

Now using the same steps to push your local Docker image to your ACR registry. Push the image to simpleApp repository.

Questions: Why did you have to run az acr login command? What does the step 3 do? What about step 4?

7. Create an Identity for your WebApp

You need to allow your WebApp to pull images from ACR in order to deploy it.

Questions:

8. Assign roles to your WebApp

Your WebApp doesn't have any role assignment for the moment, so technically, it can't access anything.

The WebApp needs access to ACR to pull the latest image of the app you pushed and deploy it. Let's grant it the permission:

Note: A rule to always have in mind when you use the cloud: always give users and applications the least privileges. It is for security reasons, the less you open your gates the safer it is.

Questions: Go back to your WebApp and check "Azure role assignments" again, what do you see?

9. Make the Webapp deploy the image from the registry

All permissions granted, now make the WebApp deploy the image you just pushed to the registry.

Wait few minutes and visit the URL of your WebApp, you may need to restrat the app.

Question: What did you understand from this assignment?

Task 2: Deploy your Website using Containers

Use the website you developed in previous assignments to create a Docker image and push it to ACR. Then, deploy the app to a WebApp (as in Task 1).

Try to give a unique name for yoru WebAppp anddeactivate the Unique default hostname (preview) on option (e.g., you can try: <name_oo_your_app>_your_name).

Once deployed, ask your classmate to visit your website!

Troubleshooting: