-
-
Notifications
You must be signed in to change notification settings - Fork 12
Add Platform Support for Docker Image Downloads #191
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
base: master
Are you sure you want to change the base?
Add Platform Support for Docker Image Downloads #191
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds platform-specific Docker image download support, allowing users to explicitly request images for specific OS/architecture combinations (e.g., linux/amd64, linux/arm64) via a new platform query parameter. Previously, images defaulted to the server's architecture.
Key changes:
- Added
Platformstruct and related functions (ParsePlatform,DefaultPlatform) to handle platform specification - Modified image download flow to accept and use platform parameter throughout the stack
- Updated cache filename format to include platform information to prevent conflicts
- Enhanced error messages to show available platforms when requested platform is unavailable
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| registry.go | Adds Platform struct with parsing/serialization functions; updates ImageReference to include Platform field; modifies manifest selection to use requested platform instead of hardcoded linux/amd64 |
| server.go | Adds platform query parameter parsing and validation; updates cache key generation to include platform; modifies all image serving functions to accept platform parameter |
| image.go | Updates DownloadImage signature to accept platform parameter; modifies output filename format to include platform information |
| main.go | Improves config file handling to make it optional with automatic detection of config.yaml |
| registry_test.go | Adds comprehensive tests for Platform parsing, serialization, and default values |
| server_test.go | Adds tests for platform parameter handling, validation, URL encoding, and cache filename generation |
| image_test.go | Adds integration tests for downloading with different platforms and handling unsupported platforms |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…re correct format for filename suffix
| platform = DefaultPlatform().String() | ||
| } | ||
|
|
||
| // Create a unique cache key combining image name and platform |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
server.go
Outdated
| safeImageName := strings.ReplaceAll(ref.Repository, "/", "_") | ||
| return fmt.Sprintf("%s_%s.tar.gz", safeImageName, ref.Tag) | ||
| safePlatform := strings.ReplaceAll(ref.Platform.String(), "/", "_") | ||
| return fmt.Sprintf("%s_%s_%s.tar.gz", safeImageName, ref.Tag, safePlatform) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
user-provided value
…traversal attacks
… prevent path traversal vulnerabilities
|
Please document how to download images in the README (using wget) and (optional) update the website so users can download images without curl/wget |
jadolg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with using AI. Most of this new code is AI generated. But please review before requesting changes.
…ate README notes.
…mproved error parsing.
…and directly sanitizing image repository names.
…placement for filename generation.
…parators with underscores.
|
Mind fixing the problems found by CodeQL? |
Description
This PR implements the ability to specify a target platform when downloading Docker images. Previously, images were downloaded for ARM64 architecture by default based on the server's architecture. Now users can explicitly request images for specific platforms like
linux/amd64,linux/arm64, etc.Usage
Changes by File
registry.goAdded new types and functions for platform support:
Modified
ImageReferencestruct:Modified
ParseImageReference():Platformfield with default value (linux/amd64)Modified
selectManifestDigest():linux/amd64preference to usingref.Platformimage.goModified
DownloadImage()signature:Modified
createOutputTar():{image}_{tag}_{os}_{arch}.tar.gzlibrary_alpine_latest_linux_amd64.tar.gzserver.goModified
imageHandler():platformquery parametervalidatePlatform()linux/amd64to ensure consistent cache keys and proper deduplication of concurrent requestsAdded
validatePlatform()function:linux,windows,darwinamd64,arm64,arm,386,ppc64le,s390x,riscv64Added security functions to prevent path traversal (CodeQL fix):
sanitizePathComponent()- Removes dangerous characters (/,\,..) from path componentsvalidatePathContainment()- Ensures generated paths stay within the expected directorysanitizePlatform()- Returns sanitized platform reconstructed from validated whitelist valuesModified
getCacheFilename():Modified
serveImageFile():platformparameter to generate correct filenamemain.goFixed config file handling:
config.yamldoesn't exist)config.yamlif present in current directoryNew Unit Tests
registry_test.goTestParsePlatformTestPlatformStringPlatform.String()serializationTestDefaultPlatformlinux/amd64TestParseImageReference_IncludesPlatformserver_test.goTestImageHandler_WithPlatformTestImageHandler_WithURLEncodedPlatformlinux%2Famd64)TestImageHandler_InvalidPlatformTestValidatePlatformTestGetCacheFilename_WithPlatformTestImageHandler_PlatformNormalizationTestSanitizePathComponentTestValidatePathContainmentTestSanitizePlatformimage_test.goTestDownloadImage_WithPlatformTestDownloadImage_UnsupportedPlatformTestCreateOutputTar_IncludesPlatformInFilenameTesting
All 59 tests pass ✅
Security Enhancements
This PR includes security hardening to address CodeQL's "Uncontrolled data used in path expression" warning:
Path Traversal Protection
sanitizePathComponent(component string)- Removes dangerous characters:/,\)..).hidden)sanitizeForPath(s string)- Cleans strings for safe path usage::with-/with_\and other unsafe charactersvalidatePathContainment(basePath, targetPath string)- Ensures paths stay within bounds:sanitizePlatform(platform string)- Reconstructs platform from validated values:linux,windows,darwinamd64,arm64,arm,386,ppc64le,s390x,riscv64Defense in Depth
Even though platform values are validated against a whitelist, we apply multiple layers of protection:
validatePlatform()rejects invalid platforms with 400 errorsanitizePlatform()reconstructs from whitelist values onlyvalidatePathContainment()verifies final path stays within expected directoryChecklist
%2F)linux/amd64)