Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update Azure Container Registry cache-rule to support unauthenticated repositories and wildcards #3764

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f5cef3e
Make `credentialSetResourceId` optional
seesharprun Nov 11, 2024
7ffc7ba
Fix `name` parameter to replace wildcard (asterisk) symbol
seesharprun Nov 11, 2024
b05f277
Make `credentialSetResourceId` nullable
seesharprun Nov 11, 2024
1a8dbef
Add unit tests
seesharprun Nov 11, 2024
89d0db2
Run generation of readme and JSON files
seesharprun Nov 11, 2024
cc0a93b
Run `Set-AVMModule` on all sub-modules
seesharprun Nov 11, 2024
6574d66
Use a unique string for the cache-rule name instead of fragile `repla…
seesharprun Nov 11, 2024
23abaca
Fixed `replace` logic
seesharprun Nov 12, 2024
9646b1b
Try not setting `credentialSetResourceId`
seesharprun Nov 12, 2024
cb5e18d
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 12, 2024
2397f9c
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 14, 2024
697ae65
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 15, 2024
5d36196
Push to Bicep `0.31.92.45157`
seesharprun Nov 18, 2024
b854404
Remove credential set conflict
seesharprun Nov 18, 2024
1ad088c
Rework tests
seesharprun Nov 20, 2024
0007f7f
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 20, 2024
37fe901
Fix bug with unique key vault names in test
seesharprun Nov 20, 2024
c49924e
Fix credential set deployment
seesharprun Nov 21, 2024
69dcd66
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 21, 2024
ce9774e
Merge branch 'main' into fix-container-registry-cache-rules-params
seesharprun Nov 21, 2024
6dc2aa3
Merge branch 'Azure:main' into fix-container-registry-cache-rules-params
seesharprun Nov 25, 2024
ed897fd
Merge branch 'main' into fix-container-registry-cache-rules-params
AlexanderSehr Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions avm/res/container-registry/registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,22 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
name: 'registryDeployment'
params: {
// Required parameters
name: '<name>'
name: 'crrcach001'
// Non-required parameters
acrAdminUserEnabled: false
acrSku: 'Standard'
cacheRules: [
{
credentialSetResourceId: '<credentialSetResourceId>'
name: 'customRule'
name: 'docker-rule-with-credentials'
sourceRepository: 'docker.io/library/hello-world'
targetRepository: 'cached-docker-hub/hello-world'
}
{
name: 'mcr-rule-anonymous'
sourceRepository: 'mcr.microsoft.com/*'
targetRepository: 'cached-mcr/*'
}
]
credentialSets: [
{
Expand All @@ -81,10 +86,22 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
managedIdentities: {
systemAssigned: true
}
name: 'default'
name: 'docker-credential-set'
}
]
location: '<location>'
managedIdentities: {
userAssignedResourceIds: [
'<managedIdentityResourceId>'
]
}
roleAssignments: [
{
principalId: '<principalId>'
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: '4633458b-17de-408a-b874-0445c86b69e6'
}
]
}
}
```
Expand All @@ -103,7 +120,7 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
"parameters": {
// Required parameters
"name": {
"value": "<name>"
"value": "crrcach001"
},
// Non-required parameters
"acrAdminUserEnabled": {
Expand All @@ -116,9 +133,14 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
"value": [
{
"credentialSetResourceId": "<credentialSetResourceId>",
"name": "customRule",
"name": "docker-rule-with-credentials",
"sourceRepository": "docker.io/library/hello-world",
"targetRepository": "cached-docker-hub/hello-world"
},
{
"name": "mcr-rule-anonymous",
"sourceRepository": "mcr.microsoft.com/*",
"targetRepository": "cached-mcr/*"
}
]
},
Expand All @@ -136,12 +158,28 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
"managedIdentities": {
"systemAssigned": true
},
"name": "default"
"name": "docker-credential-set"
}
]
},
"location": {
"value": "<location>"
},
"managedIdentities": {
"value": {
"userAssignedResourceIds": [
"<managedIdentityResourceId>"
]
}
},
"roleAssignments": {
"value": [
{
"principalId": "<principalId>",
"principalType": "ServicePrincipal",
"roleDefinitionIdOrName": "4633458b-17de-408a-b874-0445c86b69e6"
}
]
}
}
}
Expand All @@ -158,17 +196,22 @@ module registry 'br/public:avm/res/container-registry/registry:<version>' = {
using 'br/public:avm/res/container-registry/registry:<version>'

// Required parameters
param name = '<name>'
param name = 'crrcach001'
// Non-required parameters
param acrAdminUserEnabled = false
param acrSku = 'Standard'
param cacheRules = [
{
credentialSetResourceId: '<credentialSetResourceId>'
name: 'customRule'
name: 'docker-rule-with-credentials'
sourceRepository: 'docker.io/library/hello-world'
targetRepository: 'cached-docker-hub/hello-world'
}
{
name: 'mcr-rule-anonymous'
sourceRepository: 'mcr.microsoft.com/*'
targetRepository: 'cached-mcr/*'
}
]
param credentialSets = [
{
Expand All @@ -183,10 +226,22 @@ param credentialSets = [
managedIdentities: {
systemAssigned: true
}
name: 'default'
name: 'docker-credential-set'
}
]
param location = '<location>'
param managedIdentities = {
userAssignedResourceIds: [
'<managedIdentityResourceId>'
]
}
param roleAssignments = [
{
principalId: '<principalId>'
principalType: 'ServicePrincipal'
roleDefinitionIdOrName: '4633458b-17de-408a-b874-0445c86b69e6'
}
]
```

</details>
Expand Down
18 changes: 9 additions & 9 deletions avm/res/container-registry/registry/cache-rule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,17 @@ Cache for Azure Container Registry (Preview) feature allows users to cache conta

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`credentialSetResourceId`](#parameter-credentialsetresourceid) | string | The resource ID of the credential store which is associated with the cache rule. |
| [`registryName`](#parameter-registryname) | string | The name of the parent registry. Required if the template is used in a standalone deployment. |
| [`sourceRepository`](#parameter-sourcerepository) | string | Source repository pulled from upstream. |

**Optional parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`credentialSetResourceId`](#parameter-credentialsetresourceid) | string | The resource ID of the credential store which is associated with the cache rule. |
| [`name`](#parameter-name) | string | The name of the cache rule. Will be derived from the source repository name if not defined. |
| [`targetRepository`](#parameter-targetrepository) | string | Target repository specified in docker pull command. E.g.: docker pull myregistry.azurecr.io/{targetRepository}:{tag}. |

### Parameter: `credentialSetResourceId`

The resource ID of the credential store which is associated with the cache rule.

- Required: Yes
- Type: string

### Parameter: `registryName`

The name of the parent registry. Required if the template is used in a standalone deployment.
Expand All @@ -52,13 +45,20 @@ Source repository pulled from upstream.
- Required: Yes
- Type: string

### Parameter: `credentialSetResourceId`

The resource ID of the credential store which is associated with the cache rule.

- Required: No
- Type: string

### Parameter: `name`

The name of the cache rule. Will be derived from the source repository name if not defined.

- Required: No
- Type: string
- Default: `[replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-')]`
- Default: `[replace(replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-'), '*', '')]`

### Parameter: `targetRepository`

Expand Down
6 changes: 3 additions & 3 deletions avm/res/container-registry/registry/cache-rule/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ metadata owner = 'Azure/module-maintainers'
param registryName string

@description('Optional. The name of the cache rule. Will be derived from the source repository name if not defined.')
param name string = replace(replace(sourceRepository, '/', '-'), '.', '-')
param name string = replace(replace(replace(sourceRepository, '/', '-'), '.', '-'), '*', '')

@description('Required. Source repository pulled from upstream.')
param sourceRepository string

@description('Optional. Target repository specified in docker pull command. E.g.: docker pull myregistry.azurecr.io/{targetRepository}:{tag}.')
param targetRepository string = sourceRepository

@description('Required. The resource ID of the credential store which is associated with the cache rule.')
param credentialSetResourceId string
@description('Optional. The resource ID of the credential store which is associated with the cache rule.')
param credentialSetResourceId string?

resource registry 'Microsoft.ContainerRegistry/registries@2023-06-01-preview' existing = {
name: registryName
Expand Down
27 changes: 19 additions & 8 deletions avm/res/container-registry/registry/cache-rule/main.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"languageVersion": "2.0",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.3.12046",
"templateHash": "17205938486061573561"
"version": "0.31.92.45157",
"templateHash": "17904436773568970815"
},
"name": "Container Registries Cache",
"description": "Cache for Azure Container Registry (Preview) feature allows users to cache container images in a private container registry. Cache for ACR, is a preview feature available in Basic, Standard, and Premium service tiers ([ref](https://learn.microsoft.com/en-us/azure/container-registry/tutorial-registry-cache)).",
Expand All @@ -20,7 +21,7 @@
},
"name": {
"type": "string",
"defaultValue": "[replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-')]",
"defaultValue": "[replace(replace(replace(parameters('sourceRepository'), '/', '-'), '.', '-'), '*', '')]",
"metadata": {
"description": "Optional. The name of the cache rule. Will be derived from the source repository name if not defined."
}
Expand All @@ -40,23 +41,33 @@
},
"credentialSetResourceId": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Required. The resource ID of the credential store which is associated with the cache rule."
"description": "Optional. The resource ID of the credential store which is associated with the cache rule."
}
}
},
"resources": [
{
"resources": {
"registry": {
"existing": true,
"type": "Microsoft.ContainerRegistry/registries",
"apiVersion": "2023-06-01-preview",
"name": "[parameters('registryName')]"
},
"cacheRule": {
"type": "Microsoft.ContainerRegistry/registries/cacheRules",
"apiVersion": "2023-06-01-preview",
"name": "[format('{0}/{1}', parameters('registryName'), parameters('name'))]",
"properties": {
"sourceRepository": "[parameters('sourceRepository')]",
"targetRepository": "[parameters('targetRepository')]",
"credentialSetResourceId": "[parameters('credentialSetResourceId')]"
}
},
"dependsOn": [
"registry"
]
}
],
},
"outputs": {
"name": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.30.3.12046",
"templateHash": "13281764602355848660"
"version": "0.31.92.45157",
"templateHash": "6279725946439884689"
},
"name": "Container Registries Credential Sets",
"description": "This module deploys an ACR Credential Set.",
Expand Down
4 changes: 2 additions & 2 deletions avm/res/container-registry/registry/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ module registry_cacheRules 'cache-rule/main.bicep' = [
params: {
registryName: registry.name
sourceRepository: cacheRule.sourceRepository
name: cacheRule.?name ?? replace(replace(cacheRule.sourceRepository, '/', '-'), '.', '-')
name: cacheRule.?name ?? replace(replace(replace(cacheRule.sourceRepository, '/', '-'), '.', '-'), '*', '')
targetRepository: cacheRule.?targetRepository ?? cacheRule.sourceRepository
credentialSetResourceId: cacheRule.?credentialSetResourceId
credentialSetResourceId: !empty(cacheRule.?credentialSetResourceId) ? cacheRule.?credentialSetResourceId : null // Must only be set if condition is set
}
dependsOn: [
registry_credentialSets
Expand Down
Loading