Support auth_patterns in source.json for Private Dependencies in Bazel Registry
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the feature request:
Bazel currently supports private repositories in `http_archive()` using the `auth_patterns` attribute, which allows authentication for URLs that require credentials. However, source.json in the Bazel registry does not support `auth_patterns,` making it difficult to use private repositories when fetching dependencies via bazel module.
This feature request proposes adding `auth_patterns` support in source.json, ensuring that authentication details can be properly forwarded to `http_archive()` when using private dependencies in private Bazel Central Registries.
### Which category does this issue belong to?
Core
### What underlying problem are you trying to solve with this feature?
Currently, when fetching dependencies from a private Bitbucket, GitHub, or other repository, users must manually override the module resolution by using `archive_override()` in MODULE.bazel. However, this defeats the purpose of the Bazel Central Registry, which is meant to provide a declarative way to manage dependencies.
For example, a public module in the Bazel registry looks like this:
```
{
"url": "https://github.com/example/example-repo/archive/refs/tags/v1.0.0.zip",
"integrity": "sha256-xyz...",
"strip_prefix": "example-repo-1.0.0"
}
````
However, if this URL requires authentication, users currently have no way to specify it within source.json. Instead, they must manually redefine the repository in MODULE.bazel with auth_patterns, like this:
````
bazel_dep(name = "example_repo", version = "1.0.0")
archive_override(
module_name = "example_repo",
urls = ["https://api.bitbucket.org/2.0/repositories/com/private-repo/downloads/example.zip"],
auth_patterns = {
"api.bitbucket.org": ["PRIVATE"]
}
)
````
This approach breaks modular dependency resolution and requires manual intervention. I also didn't find a way to reuse the MODULE.bazel and BUILD.bazel from the registry (defined in the overlay folder) in case archive_override was used.
### Which operating system are you running Bazel on?
Windows/Linux/macOS
### What is the output of `bazel info release`?
release 8.0.1
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
```
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
### Proposed Solution
Enable `auth_patterns` support in source.json, allowing private repositories to be defined directly in the Bazel Central Registry.
Example of the proposed enhanced source.json format:
````
{
"url": "https://api.bitbucket.org/2.0/repositories/com/private-repo/downloads/example.zip",
"integrity": "sha256-xyz...",
"strip_prefix": "example",
"auth_patterns": {
"api.bitbucket.org": ["PRIVATE"]
}
}
````
Contributor guide
Research direction
The request concerns source.json and its forwarding to http_archive(), with archive_override() currently used from MODULE.bazel. Start by tracing how source.json is consumed for Bazel registry dependencies; done means auth_patterns can be declared there and reach private fetches without the manual override, with coverage for the format and behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100