Skip to content

Commit a7d371c

Browse files
author
Jill Grant
authored
Merge pull request #246290 from vvenug/vvenug
How to - document for hardening the linux image by removing the sudo users.
2 parents 656e63b + 37869ee commit a7d371c

File tree

3 files changed

+96
-2
lines changed

3 files changed

+96
-2
lines changed

articles/confidential-computing/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
href: guest-attestation-example.md
137137
- name: Create a custom image for a confidential VM
138138
href: how-to-create-custom-image-confidential-vm.md
139+
- name: Image hardening techniques for deployment
140+
items:
141+
- name: Remove sudo users from Linux image
142+
href: harden-the-linux-image-to-remove-sudo-users.md
139143
- name: Secure Key Release (SKR) with Azure Key Vault
140144
items:
141145
- name: SKR with Azure Confidential Computing Concept
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
title: Harden the Linux image to remove sudo users
3+
description: Learn how to use the Azure CLI to harden the linux image to remove sudo users.
4+
author: vvenug
5+
ms.service: virtual-machines
6+
mms.subservice: confidential-computing
7+
ms.topic: how-to
8+
ms.workload: infrastructure
9+
ms.date: 7/21/2023
10+
ms.author: vvenugopal
11+
ms.custom: devx-track-azurecli
12+
---
13+
14+
# Harden the Linux image to remove sudo users
15+
16+
**Applies to:** :heavy_check_mark: Linux Images
17+
18+
This "how to" shows you steps to remove sudo users from the Linux image and deploy a confidential virtual machine (confidential VM) in Azure.
19+
20+
The objective of this article is to create an admin-less Linux image for confidential VM deployments. Removing the guest admin has immense security value, it reduces admin privileges across OS.
21+
22+
Understanding different types of users in Unix/Linux systems:
23+
- Admin user (sudoer): Regular users with extra permissions. These users can perform certain tasks that modify system configurations.
24+
25+
- Regular user: Regular users are nonadministrative users. They don't have permission to modify system configurations or install system-wide software.
26+
27+
In the context of admin-less Linux images, the aim is to deploy systems without sudo users.
28+
29+
> [!NOTE]
30+
> The configuration alone does not ensure prevention of users from being added to the sudo group. Any service with root or sudo privileges has the potential to escalate privileges.
31+
32+
## Prerequisites
33+
34+
- If you don't have an Azure subscription, [create a free Azure account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
35+
- An Ubuntu image - you can choose one from the [Azure Marketplace](/azure/virtual-machines/linux/cli-ps-findimage).
36+
37+
### Remove sudo users and prepare a generalized Linux image
38+
39+
The proposed solution results in a Linux image without sudo users.
40+
41+
Steps to create a generalized image that removes the sudo users are as follows:
42+
43+
1. Download an Ubuntu image.
44+
[Create a custom image for Azure confidential VM](/azure/confidential-computing/how-to-create-custom-image-confidential-vm)
45+
46+
2. Mount the image.
47+
48+
There are several ways to do this [Attach the disk](/azure/virtual-machines/linux/attach-disk-portal?tabs=ubuntu#mount-the-disk:~:text=new%20filesystem%20immediately.-,Mount%20the%20disk,-Create%20a%20directory), the example uses the loop device to mount the image. It can either be a disk attached or a loop device [Mount the image](https://manpages.ubuntu.com/manpages/jammy/man8/mount.8.html).
49+
50+
$imagedevice is the root filesystem's partition on the device that contains the image.
51+
```
52+
mount /dev/$imagedevice /mnt/dev/$imagedevice
53+
```
54+
55+
This process is commonly used to access and work with disk images. Here, it is used to remove the sudo users on the Ubuntu image.
56+
57+
3. Chroot into the vhd filesystem to run the following command, which lists users under the sudo group.
58+
```
59+
sudo chroot /mnt/dev/$imagedevice/ getent group sudo
60+
```
61+
62+
4. Validate step 3 by listing out the users in the sudoers.d home directory and in /etc/passwd, /etc/shadow files.
63+
If there are any users with sudo privileges, they are listed here,
64+
65+
```
66+
sudo ls /mnt/dev/$imagedevice/etc/sudoers.d
67+
68+
sudo cat /mnt/dev/$imagedevice/etc/passwd
69+
70+
sudo cat /mnt/dev/$imagedevice/etc/shadow
71+
```
72+
73+
5. Remove sudo privileges: Use the deluser command to remove sudo privilege for the user,
74+
```
75+
sudo chroot /mnt/dev/$imagedevice/ deluser -r [sudo_username]
76+
```
77+
78+
6. Repeat step 4 to validate that the user has no sudo privilege on the vhd.
79+
80+
7. Unmount the image.
81+
```
82+
umount /mnt/dev/$imagedevice
83+
```
84+
85+
The image prepared does not include any sudo users that can be used for creating the confidential VMs.
86+
87+
Follow the steps [Create a custom image for Azure confidential VM](/azure/confidential-computing/how-to-create-custom-image-confidential-vm) to create an Azure confidential VM.
88+
Use the admin-less image in step 4 of [Create a custom image for Azure confidential VM](/azure/confidential-computing/how-to-create-custom-image-confidential-vm) while doing azcopy and the rest of the steps remains the same.

articles/confidential-computing/index.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ landingContent:
9090
url: guest-attestation-example.md
9191
- text: Create a custom image for a confidential VM
9292
url: how-to-create-custom-image-confidential-vm.md
93+
- text: Harden the Linux image to remove sudo users
94+
url: harden-the-linux-image-to-remove-sudo-users.md
9395
- linkListType: reference
9496
links:
9597
- text: AMD confidential VMs FAQ
@@ -109,14 +111,14 @@ landingContent:
109111
- title: Container compute
110112
linkLists:
111113
- linkListType: overview
112-
links:
114+
links:
113115
- text: Confidential containers on Azure overview
114116
url: confidential-containers.md
115117
- text: Confidential VM with AMD SEV-SNP node pools in AKS
116118
url: confidential-node-pool-aks.md
117119
- text: App enclave nodes with Intel SGX in AKS
118120
url: confidential-nodes-aks-overview.md
119-
121+
120122
- linkListType: quickstart
121123
links:
122124
- text: Hello world with Confidential containers with Azure Container Instances (ACI)

0 commit comments

Comments
 (0)