GitHub Copilot Agent Mode in Action

GitHub Copilot Agent Mode in Action

GitHub Copilot has significantly shifted the landscape of software development, moving beyond smart code completion to become a more integrated AI partner. One of the most exciting advancements is GitHub Copilot Agent Mode, where Copilot aims to understand and execute more complex tasks based on natural language prompts. But how does this work in a real scenario? To cut through the abstract descriptions, this article dives into a concrete example: I'll share a specific prompt given to GitHub Copilot Agent Mode and analyze the response it generated, offering a practical look at its capabilities and potential impact on developer workflows.

Example: Add Managed Identity Support

Developer: As security enhancement, update Azure deployment, where backend container app authenticates to Azure Postgres using Managed Identity. For local docker deployment, continue to use password based authentication. Ensure necessary changes are applied to code, infra and config.

GitHub Copilot: I'll help you enhance the security of your Azure deployment by configuring the backend container app to authenticate to Azure PostgreSQL using Managed Identity, while preserving password-based authentication for local Docker deployment. Let's start by exploring the codebase to understand the current setup.I'll help you implement secure authentication from your backend container app to Azure PostgreSQL using Managed Identity. Let me explain what I've found and the changes we need to make.

Current Setup

Based on my analysis of your codebase:

  1. You have a finance tracking application with a frontend and backend, both deployed to Azure Container Apps
  2. Your database is Azure PostgreSQL Flexible Server
  3. Currently, your app uses password-based authentication for database access (stored in environment variables)
  4. You're deploying with Azure Developer CLI (AZD) and Bicep templates

Implementation Plan

Here's what we'll need to update:

  1. Modify the connection.ts file to support Managed Identity authentication
  2. Update the Bicep templates to assign and configure the Managed Identity
  3. Ensure local development still works with password authentication
  4. Update environment configuration to support both scenarios

Let's make these changes one by one.

1. First, let's update the database connection class to support Managed Identity:

## Didn't include the changes to `connection.ts` for brevity.        

Made changes.

Now that we've updated the database connection class to support Managed Identity authentication, let's update the environment configuration to support this new authentication mode:

## Didn't include the changes to `env.ts` for brevity.        

Made changes.

Now let's update the .env.local file to include the new environment variable:

## Didn't include the changes to `.env.local` for brevity.        

Made changes.

Now let's modify the backend.bicep file to assign a managed identity to the backend container app and grant it access to PostgreSQL:

## Didn't include the changes to `bakcend.bicep` for brevity.        

Made changes.

Now that we've updated the backend container app to use a managed identity, we need to make sure the PostgreSQL server can accept this type of authentication. Let's update the PostgreSQL server configuration in the main Bicep file to properly support Azure AD authentication.

## Didn't include the changes to `database.bicep` for brevity.        

Made changes.

I'll now make sure the docker-compose.yml file for local development is updated to maintain compatibility with the password-based authentication approach. Let's continue implementing our solution for using Managed Identity in Azure and password-based authentication for local Docker development.

The docker-compose.yml looks good as is, since it's already set up for password-based authentication for local development. Now, let's add a new health endpoint to the backend app to make sure our container health checks work properly: I see that the app has a health check endpoint in app.ts but we'll need to expand it to include a separate /api/health endpoint for the container health probes we've configured in our Bicep file. Let's add that endpoint now:

## Didn't include the changes to `database.bicep` for brevity.        

Made changes.

Now let's continue enhancing the security of your Finance Tracker application by implementing support for Azure Managed Identity authentication to PostgreSQL.

We've already made several key changes:

  1. Updated the database connection class to support Managed Identity authentication
  2. Modified the configuration to handle this new authentication method
  3. Updated the Bicep template to assign a Managed Identity to the backend container app
  4. Added proper health check endpoints for container probes
  5. Configured PostgreSQL to accept Azure AD authentication

Let's now update the deployment script in azure.yaml to ensure our managed identity configurations are properly set up:

## Didn't include the changes to `azure.yaml` for brevity.        

Made changes.

Now that we've completed the implementation of Managed Identity authentication for Azure PostgreSQL, let's finalize our solution by updating the container app environment settings in the Azure YAML configuration:

## Didn't include the changes to `azure.yaml` for brevity.        

Made changes.

I've implemented all the necessary changes to enhance the security of your Finance Tracker application by enabling Managed Identity authentication for the backend container app to connect to Azure PostgreSQL. Here's a summary of the changes made:

Security Enhancement Implementation

  1. Database Connection Logic: Modified connection.ts to support both password-based authentication (for local Docker development) and Managed Identity authentication (for Azure deployment). The connection code now detects the authentication method based on environment variables.
  2. Environment Configuration: Updated env.ts and .env.example to include the new USE_MANAGED_IDENTITY configuration flag, which determines the authentication method to use.
  3. Azure PostgreSQL Configuration: Updated the PostgreSQL server configuration in main.bicep to enable Azure AD authentication alongside password authentication, which is required for Managed Identity support.
  4. Managed Identity Assignment: Modified the backend container app configuration in backend.bicep to:
  5. Deployment Scripts: Enhanced the post-deployment scripts in azure.yaml to create the necessary database roles and permissions for the Managed Identity.
  6. Health Checks: Added a dedicated /api/health endpoint to ensure the container health probes work correctly with the new authentication method.
  7. Local Docker Compatibility: Maintained password-based authentication for local Docker deployment as requested.

How It Works

  • In Azure: The backend container app uses its system-assigned Managed Identity to authenticate with PostgreSQL, eliminating the need for passwords in environment variables.
  • In Local Development: The application continues to use password-based authentication with credentials from environment variables.

Benefits

  1. Enhanced Security: No database passwords stored in container app configuration or exposed in environment variables
  2. Simplified Management: No need to rotate database passwords for Azure deployments
  3. Secure Access Control: Azure's Managed Identity provides fine-grained control over database access
  4. Local Development Compatibility: Developers can still use the familiar password-based authentication locally

The next time you deploy using azd up command, the application will use Managed Identity authentication in Azure while continuing to support password authentication for local Docker deployment.

Summary:

In a significant demonstration of its capabilities, the GitHub Copilot Agent operated autonomously to implement changes, showcasing a powerful new paradigm for automated development workflows. Without needing manual intervention, it successfully modified application code, adjusted related configuration files, and updated infrastructure-as-code templates. This highlights its potential to act as a unified coding agent, handling tasks typically requiring both Fullstack and DevOps expertise.


To view or add a comment, sign in

More articles by Sathish Krishnan

Others also viewed

Explore content categories