Commit 4eb9949
OCI registry support for Bicep extension publishing (#18956)
# OCI Registry Support for Bicep Extension Publishing
## Description
Adds support for publishing and restoring Bicep modules and extensions
to/from non-Azure OCI-compliant container registries (GHCR, Docker Hub,
etc.).
Previously, `publish`, `restore`, and `publish-extension` only worked
with Azure Container Registry (ACR) because the transport was hard-coded
to the Azure SDK's `ContainerRegistryContentClient`. This change
introduces an alternative transport built on [ORAS (OCI Registry As
Storage)](https://oras.land/), so Bicep artifacts can be stored in any
compliant registry.
Related to [#4884](#4884).
---
## User Experience
### Feature flag
The feature is gated behind an experimental flag called `ociEnabled`.
Either of the following enables it:
1. CLI flag — pass `--oci-enabled` before the subcommand:
```bash
bicep --oci-enabled publish myModule.bicep \
--target 'br:ghcr.io/myorg/bicep/modules/my-module:v1.0'
```
2. `bicepconfig.json`:
```json
{
"experimentalFeaturesEnabled": {
"ociEnabled": true
}
}
```
### Authentication
When the flag is enabled and the target host is not an Azure-managed
registry, Bicep authenticates using Docker credentials:
1. Docker credential helpers — reads `~/.docker/config.json` and invokes
the configured `credsStore` or per-registry `credHelpers` (e.g.
`docker-credential-desktop`, `docker-credential-ecr-login`).
2. Static `auth` entries — falls back to base64-encoded
`username:password` entries in the `auths` section of
`~/.docker/config.json`.
ACR (`*.azurecr.io`, `*.azurecr.cn`, `*.azurecr.us`, `*.azurecr.de`,
`*.azurecr.gov`) and `mcr.microsoft.com` continue to use the existing
Azure SDK auth path regardless of the flag.
### Example: publish a module to GHCR
```bash
# Log in to GHCR (one-time, stores creds in Docker config)
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin
# Publish
bicep --oci-enabled publish ./main.bicep \
--target 'br:ghcr.io/myorg/bicep/modules/network:v1.0'
# Reference in another file:
# module vnet 'br:ghcr.io/myorg/bicep/modules/network:v1.0' = { ... }
# Restore
bicep --oci-enabled restore ./consumer.bicep
```
### Example: publish an extension
```bash
bicep --oci-enabled publish-extension \
--target 'br:myregistry.example.com/bicep/extensions/my-ext:v1.0' \
--index-file ./out/index.json
```
---
## Design
### Session API
All push/pull/resolve operations go through a single `IRegistrySession`
interface:
- `PushAsync` — pushes config, layers, and manifest
- `PullAsync` — fetches manifest and layers, returns an
`OciArtifactResult`
- `ResolveAsync` — resolves a reference to `(digest, OciManifest)`
Two implementations:
| Session | Wraps | Used for |
|---|---|---|
| `AcrRegistrySession` | `AzureContainerRegistryManager` (Azure SDK) |
ACR / `mcr.microsoft.com` always; non-ACR hosts when `ociEnabled` is off
(preserves pre-flag behavior) |
| `OrasRegistrySession` |
[oras-dotnet](https://github.com/oras-project/oras-dotnet) | Non-ACR
hosts when `ociEnabled` is on |
Sessions are created by
`OciRegistryTransportFactory.CreateSession(reference, cloud)`, which
inspects the registry hostname (and the `ociEnabled` feature flag for
non-ACR hosts) to pick the implementation. There's no provider/strategy
plumbing — the routing is a single inline check.
### Transport vs. session
`IOciRegistryTransport` (singleton) is reserved for catalog enumeration
(`GetRepositoryNamesAsync`, `GetRepositoryTagsAsync`) used by
`PrivateAcrModuleMetadataProvider`. It always resolves to
`AzureContainerRegistryManager` because catalog APIs are ACR-specific
today.
`IRegistrySession` (per-call, scoped to a `(registry, repository,
credentials)` tuple) handles per-artifact push/pull/resolve. This split
keeps a clear separation between "list what's in the registry"
(singleton, ACR-only) and "act on a specific artifact" (per-reference,
transport-agnostic).
### Credentials
For non-ACR hosts, `DockerCredentialProvider` is injected directly into
`OrasRegistrySession`. It implements oras-dotnet's `ICredentialProvider`
and the [Docker credential helper
protocol](https://docs.docker.com/engine/reference/commandline/login/#credential-helpers)
— sends the registry hostname to `docker-credential-<helper> get` via
stdin and parses the JSON response. Supports username/password and
identity-token auth.
ACR credentials continue to flow through the Azure SDK's existing token
chain inside `AzureContainerRegistryManager`.
### Registry routing
Hosts matching `*.azurecr.{io,cn,us,de,gov}` or `mcr.microsoft.com` are
classified as Azure-SDK hosts
(`OciRegistryTransportFactory.IsAzureSdkHost`) and always route through
`AcrRegistrySession`. All other hosts route through
`OrasRegistrySession` when `ociEnabled` is on, and fall back to
`AcrRegistrySession` otherwise (preserving the pre-PR
anonymous-then-authenticated Azure SDK flow for non-ACR hosts).
ACR registries behind custom domains will fall through to the generic
ORAS path, which works via Docker credential helpers (e.g.
`docker-credential-acr-env`). A future improvement could use OCI auth
challenge detection to identify the backing provider regardless of
hostname.
### New dependency
Project reference to
[oras-dotnet](https://github.com/oras-project/oras-dotnet) for the
generic OCI transport.
---
## What's unchanged
- ACR workflows — still use the Azure SDK path, no behavioral changes.
- Module reference syntax — same `br:registry/path:tag` format for any
registry.
- Local artifact cache — non-Azure artifacts are cached the same way as
ACR artifacts.
---
## Checklist
- [x] I have read and adhere to the [contribution
guide](https://github.com/Azure/bicep/blob/main/CONTRIBUTING.md).
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/18956)
---------
Signed-off-by: willdavsmith <willdavsmith@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 4f6a7a1 commit 4eb9949
47 files changed
Lines changed: 1838 additions & 170 deletions
File tree
- docs
- src
- Bicep.Cli.IntegrationTests
- Bicep.Cli/Commands
- Bicep.Core.UnitTests
- Configuration
- Features
- Mock/Registry
- Registry
- Catalog
- Oci/Oras
- Utils
- Bicep.Core
- Configuration
- Features
- Registry
- Azure
- Catalog/Implementation
- PrivateRegistries
- Oci
- Oras
- Sessions
- Bicep.LangServer.UnitTests/Completions
- Bicep.Wasm
- vscode-bicep/schemas
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
101 | 104 | | |
102 | 105 | | |
103 | 106 | | |
| 107 | + | |
104 | 108 | | |
105 | 109 | | |
106 | 110 | | |
| |||
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
| 121 | + | |
117 | 122 | | |
| 123 | + | |
118 | 124 | | |
119 | 125 | | |
120 | 126 | | |
| |||
169 | 175 | | |
170 | 176 | | |
171 | 177 | | |
172 | | - | |
| 178 | + | |
173 | 179 | | |
174 | 180 | | |
175 | 181 | | |
| 182 | + | |
176 | 183 | | |
177 | 184 | | |
| 185 | + | |
178 | 186 | | |
179 | 187 | | |
180 | 188 | | |
| |||
188 | 196 | | |
189 | 197 | | |
190 | 198 | | |
| 199 | + | |
191 | 200 | | |
| 201 | + | |
192 | 202 | | |
193 | 203 | | |
194 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | | - | |
87 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
| 190 | + | |
189 | 191 | | |
190 | 192 | | |
191 | 193 | | |
| |||
292 | 294 | | |
293 | 295 | | |
294 | 296 | | |
| 297 | + | |
295 | 298 | | |
296 | 299 | | |
297 | 300 | | |
| |||
376 | 379 | | |
377 | 380 | | |
378 | 381 | | |
| 382 | + | |
379 | 383 | | |
380 | 384 | | |
381 | 385 | | |
| |||
461 | 465 | | |
462 | 466 | | |
463 | 467 | | |
| 468 | + | |
464 | 469 | | |
465 | 470 | | |
466 | 471 | | |
| |||
709 | 714 | | |
710 | 715 | | |
711 | 716 | | |
712 | | - | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
713 | 720 | | |
714 | 721 | | |
715 | 722 | | |
| |||
813 | 820 | | |
814 | 821 | | |
815 | 822 | | |
| 823 | + | |
816 | 824 | | |
817 | 825 | | |
818 | 826 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
Lines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
123 | | - | |
124 | | - | |
| 124 | + | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
130 | | - | |
| 131 | + | |
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
137 | | - | |
| 138 | + | |
138 | 139 | | |
139 | 140 | | |
140 | 141 | | |
| |||
0 commit comments