Skip to main content

Lab 010: Set Up and Manage a Secure Azure DevOps Repository


Requirements

The Nautilus DevOps Team has received a request from the Development Team to set up a new repository for better code management. They need a secure way to access the repository using SSH.

Create an Azure DevOps repository named datacenter-repo in the project name datacenter-project. Add the root user's SSH public key from azure-client host to the Azure DevOps SSH keys. Create an SSH config under /root/.ssh/config on azure-client host and make changes to authenticate with the created repository. Clone the new repository on azure-client host under /root. Add the contents of /root/pyapp directory to this repository, then add, commit, and push the changes to the repository. You might need to set the git user and email to commit your code; you can use any email ID and user name for that. Please use the same credentials provided for logging into the Azure portal to log in to the Azure DevOps portal.

Use below given Azure DevOps Credentials: (You can run the showcreds command on azure-client host to retrieve these credentials)

Portal URLAzure Devops
Organizationdevops_org

Note

This task combines Azure DevOps portal actions and CLI/Git commands. If your environment does not have Azure DevOps extension configured for Azure CLI, create the repository and SSH key entry from the portal, then use the CLI/Git steps below on the client host.

Prerequisites

  • git is installed on the azure-client host.
  • Azure DevOps credentials are available from showcreds.
  • /root/pyapp exists on the host.
  • Root SSH public key exists at /root/.ssh/id_rsa.pub.

Steps

ORG_URL="https://dev.azure.com/devops_org"
PROJECT_NAME="datacenter-project"
REPO_NAME="datacenter-repo"
WORKDIR="/root"

# Create SSH key if needed
if [ ! -f /root/.ssh/id_rsa.pub ]; then
ssh-keygen -t rsa -b 2048 -f /root/.ssh/id_rsa -q -N ""
fi

# Configure Azure DevOps defaults (requires az devops extension and login)
az devops configure --defaults organization="$ORG_URL" project="$PROJECT_NAME"

# Create repository
az repos create --name "$REPO_NAME"

# Build SSH clone URL
REPO_SSH_URL="git@ssh.dev.azure.com:v3/devops_org/$PROJECT_NAME/$REPO_NAME"

# Add SSH config entry
cat >> /root/.ssh/config <<EOF
Host azure-devops
HostName ssh.dev.azure.com
User git
IdentityFile /root/.ssh/id_rsa
EOF
chmod 600 /root/.ssh/config

# Clone, copy app content, commit, and push
cd "$WORKDIR"
rm -rf "$REPO_NAME"
git clone "$REPO_SSH_URL"
cp -R /root/pyapp/. "/root/$REPO_NAME/"

cd "/root/$REPO_NAME"
git config user.name "devops-user"
git config user.email "devops-user@example.com"
git add .
git commit -m "Initial commit from pyapp"
git push origin main || git push origin master

Verification

  • Confirm repository datacenter-repo exists under project datacenter-project.
  • Confirm latest commit is pushed to remote branch.
  • Confirm cloned repository under /root/datacenter-repo contains files from /root/pyapp.

Resources

Azure CLI Docs