|
| 1 | +--- |
| 2 | +severity: Important |
| 3 | +pillar: Security |
| 4 | +category: SE:10 Monitoring and threat detection |
| 5 | +resource: Container Registry |
| 6 | +resourceType: Microsoft.ContainerRegistry/registries,Microsoft.Insights/diagnosticSettings |
| 7 | +online version: https://azure.github.io/PSRule.Rules.Azure/en/rules/Azure.ACR.Logs/ |
| 8 | +--- |
| 9 | + |
| 10 | +# Audit Container Registry access |
| 11 | + |
| 12 | +## SYNOPSIS |
| 13 | + |
| 14 | +Ensure container registry audit diagnostic logs are enabled. |
| 15 | + |
| 16 | +## DESCRIPTION |
| 17 | + |
| 18 | +Azure Container Registry (ACR) provides diagnostic logs that can be used to monitor and audit access to container images. |
| 19 | +Enabling audit logs helps you track who accesses your registry and when, which is important for security and compliance. |
| 20 | + |
| 21 | +The following log categories should be enabled: |
| 22 | + |
| 23 | +- `ContainerRegistryLoginEvents` - Captures authentication events to the registry. |
| 24 | +- `ContainerRegistryRepositoryEvents` - Captures push and pull operations for container images. |
| 25 | + |
| 26 | +Alternatively, you can enable the `audit` or `allLogs` category group to capture these and other audit events. |
| 27 | + |
| 28 | +## RECOMMENDATION |
| 29 | + |
| 30 | +Consider configuring diagnostic settings to capture container registry audit logs for security investigation. |
| 31 | + |
| 32 | +## EXAMPLES |
| 33 | + |
| 34 | +### Configure with Azure template |
| 35 | + |
| 36 | +To deploy container registries that pass this rule: |
| 37 | + |
| 38 | +- Deploy a diagnostic settings sub-resource (extension resource). |
| 39 | +- Enable `ContainerRegistryLoginEvents` and `ContainerRegistryRepositoryEvents` categories or `audit` category group or `allLogs` category group. |
| 40 | + |
| 41 | +For example: |
| 42 | + |
| 43 | +```json |
| 44 | +{ |
| 45 | + "type": "Microsoft.ContainerRegistry/registries", |
| 46 | + "apiVersion": "2023-11-01-preview", |
| 47 | + "name": "[parameters('name')]", |
| 48 | + "location": "[parameters('location')]", |
| 49 | + "sku": { |
| 50 | + "name": "Premium" |
| 51 | + }, |
| 52 | + "properties": { |
| 53 | + "adminUserEnabled": false, |
| 54 | + "policies": { |
| 55 | + "quarantinePolicy": { |
| 56 | + "status": "enabled" |
| 57 | + } |
| 58 | + } |
| 59 | + }, |
| 60 | + "resources": [ |
| 61 | + { |
| 62 | + "type": "Microsoft.Insights/diagnosticSettings", |
| 63 | + "apiVersion": "2021-05-01-preview", |
| 64 | + "scope": "[format('Microsoft.ContainerRegistry/registries/{0}', parameters('name'))]", |
| 65 | + "name": "logs", |
| 66 | + "properties": { |
| 67 | + "workspaceId": "[parameters('workspaceId')]", |
| 68 | + "logs": [ |
| 69 | + { |
| 70 | + "category": "ContainerRegistryLoginEvents", |
| 71 | + "enabled": true |
| 72 | + }, |
| 73 | + { |
| 74 | + "category": "ContainerRegistryRepositoryEvents", |
| 75 | + "enabled": true |
| 76 | + } |
| 77 | + ] |
| 78 | + }, |
| 79 | + "dependsOn": [ |
| 80 | + "[parameters('name')]" |
| 81 | + ] |
| 82 | + } |
| 83 | + ] |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +### Configure with Bicep |
| 88 | + |
| 89 | +To deploy container registries that pass this rule: |
| 90 | + |
| 91 | +- Deploy a diagnostic settings sub-resource (extension resource). |
| 92 | +- Enable `ContainerRegistryLoginEvents` and `ContainerRegistryRepositoryEvents` categories or `audit` category group or `allLogs` category group. |
| 93 | + |
| 94 | +For example: |
| 95 | + |
| 96 | +```bicep |
| 97 | +resource registry 'Microsoft.ContainerRegistry/registries@2023-11-01-preview' = { |
| 98 | + name: name |
| 99 | + location: location |
| 100 | + sku: { |
| 101 | + name: 'Premium' |
| 102 | + } |
| 103 | + properties: { |
| 104 | + adminUserEnabled: false |
| 105 | + policies: { |
| 106 | + quarantinePolicy: { |
| 107 | + status: 'enabled' |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | +} |
| 112 | +
|
| 113 | +resource logs 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = { |
| 114 | + name: 'logs' |
| 115 | + scope: registry |
| 116 | + properties: { |
| 117 | + workspaceId: workspaceId |
| 118 | + logs: [ |
| 119 | + { |
| 120 | + category: 'ContainerRegistryLoginEvents' |
| 121 | + enabled: true |
| 122 | + } |
| 123 | + { |
| 124 | + category: 'ContainerRegistryRepositoryEvents' |
| 125 | + enabled: true |
| 126 | + } |
| 127 | + ] |
| 128 | + } |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +Alternatively, you can use category groups: |
| 133 | + |
| 134 | +```bicep |
| 135 | +resource logs 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = { |
| 136 | + name: 'logs' |
| 137 | + scope: registry |
| 138 | + properties: { |
| 139 | + workspaceId: workspaceId |
| 140 | + logs: [ |
| 141 | + { |
| 142 | + categoryGroup: 'audit' |
| 143 | + enabled: true |
| 144 | + } |
| 145 | + ] |
| 146 | + } |
| 147 | +} |
| 148 | +``` |
| 149 | + |
| 150 | +## LINKS |
| 151 | + |
| 152 | +- [SE:10 Monitoring and threat detection](https://learn.microsoft.com/azure/well-architected/security/monitor-threats) |
| 153 | +- [LT-4: Enable logging for security investigation](https://learn.microsoft.com/security/benchmark/azure/baselines/container-registry-security-baseline#lt-4-enable-logging-for-security-investigation) |
| 154 | +- [Monitor Azure Container Registry](https://learn.microsoft.com/azure/container-registry/monitor-container-registry) |
| 155 | +- [Container Registry resource logs](https://learn.microsoft.com/azure/container-registry/monitor-container-registry-reference#resource-logs) |
| 156 | +- [Azure deployment reference](https://learn.microsoft.com/azure/templates/microsoft.containerregistry/registries) |
0 commit comments