WIP: ✨ docker: public.ecr.aws support #66
Reference in New Issue
Block a user
Delete Branch "main"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
初步实现 public.ecr.aws 的认证逻辑
#65
因 public.ecr.aws 似乎不能通过 HEAD blobs 的方式获取 Layer 大小,因此暂时的解决方案是将 layer.Size() 的返回错误降级为 Warning,避免中断流程。此时下游拉取时将无法看到进度条。
一种解决方案是,使用 Range: bytes=0-0 的方式请求 bolb:
响应 206,响应头中包含 content-range:
只需解析 content-range 即可获取 Layer size,但这个破坏了现有获取 layer size 的流程,后续可以考虑实现或者研究一下 HEAD 401 的原因
Summary by CodeRabbit
New Features
Improvements
Chores
Walkthrough
Adds AWS ECR token-based auth support for upstream requests. Introduces conditional Bearer vs Anonymous auth selection at runtime. Adds a public ECR registry mapping in default config. Adjusts blob retrieval to proceed even if size fetch fails. Updates dependencies to include json-iterator directly and testify indirectly.
Changes
src/config/config.gosrc/go.modgithub.com/json-iterator/go v1.1.12to direct dependency; addsgithub.com/stretchr/testify v1.10.0as indirect.src/handlers/docker.goSequence Diagram(s)
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands and usage tips.Actionable comments posted: 1
🧹 Nitpick comments (2)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration.
📥 Commits
Reviewing files that changed from the base of the PR and between
0cd5a7334dand13f24c9d26.⛔ Files ignored due to path filters (1)
src/go.sumis excluded by!**/*.sum📒 Files selected for processing (3)
src/config/config.go(1 hunks)src/go.mod(2 hunks)src/handlers/docker.go(3 hunks)🧰 Additional context used
🧬 Code graph analysis (1)
src/handlers/docker.go (1)
🔇 Additional comments (1)
💡 Verification agent
❓ Verification inconclusive
AWS ECR token fetch: add status check, fix logging, type-safe JSON; consider scoping.
errwhen token is missing (nil at that point).serviceand reposcopequery params; currently the token may lack required scopes, leading to 401 loops when used as a static Bearer. This likely needs passing the repository name intocreateUpstreamOptionsto buildscope=repository:<repo>:pull. If that’s too large for this PR, at least keep anonymous so the standard challenge flow can obtain a scoped token.Apply minimal safety fixes now:
Scope suggestion (follow-up): change signature to accept repo name and build
authURL := fmt.Sprintf("https://%s?service=public.ecr.aws&scope=repository:%s:pull", mapping.AuthHost, repo); pass the repo from callers (handleUpstream*).Add status-code check, correct logging and JSON handling, and scope ECR tokens
resp.StatusCode != http.StatusOKbefore reading the body; fallback to anonymous on non-200.errfrom the missing-token log and unmarshal into a typed struct.serviceandscope=repository:<repo>:pullquery params (e.g.?service=public.ecr.aws&scope=repository:${repo}:pull); consider updatingcreateUpstreamOptionssignature to accept the repo name.📝 Committable suggestion
🤖 Prompt for AI Agents
考虑到使用 GET "Range: bytes=0-0" 的方式过于 hack,且会破坏当前处理流程和 google/go-containerregistry 的封装,考虑等到上游支持 HEAD blob 的时候(aws/containers-roadmap#2671)再合并。
Pull request closed