Skip to content

Conversation

bluestealth
Copy link

What

Enables pulling of images that require authentication using the k3d docker client

Why

Enables usage of credentials when pulling from registries which allows access to private images, and bypass unauthenticated rate limits

Implications

  • If users have bad credentials in ${HOME}/docker/config.json pulls could fail with 401 instead of trying anonymous pull to indexes like docker.io

Copy link

@Copilot Copilot AI left a 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 enables authenticated image pulls in k3d by integrating Docker CLI authentication mechanisms. This allows users to pull private images and avoid rate limits on public registries by leveraging existing Docker credentials stored in ${HOME}/.docker/config.json.

Key Changes

  • Added authentication resolution logic to extract Docker credentials for image registries
  • Integrated authentication into the image pull process with proper error handling
  • Updated dependencies to expose the github.com/distribution/reference package

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/runtimes/docker/container.go Added resolveAuth function and integrated authentication into pullImage function
go.mod Changed github.com/distribution/reference from indirect to direct dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +138 to +142
l.Log().Warnf("Failed to get auth: %v", err)
}
encoded, err := registrytypes.EncodeAuthConfig(authConfig)
if err != nil {
l.Log().Warnf("Failed to encode auth: %v", err)
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When resolveAuth fails, the code continues with a potentially invalid authConfig struct. Similarly, when EncodeAuthConfig fails, the code continues with a potentially invalid encoded value. Consider using empty/default values or returning early on critical authentication failures to ensure predictable behavior.

Suggested change
l.Log().Warnf("Failed to get auth: %v", err)
}
encoded, err := registrytypes.EncodeAuthConfig(authConfig)
if err != nil {
l.Log().Warnf("Failed to encode auth: %v", err)
return fmt.Errorf("failed to get auth: %w", err)
}
encoded, err := registrytypes.EncodeAuthConfig(authConfig)
if err != nil {
return fmt.Errorf("failed to encode auth: %w", err)

Copilot uses AI. Check for mistakes.

Comment on lines +121 to +123
if authKey == "docker.io" || authKey == "index.docker.io" {
authKey = "https://index.docker.io/v1/"
}
Copy link
Preview

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The hardcoded registry URL transformation should be extracted into a constant or helper function for better maintainability. Consider defining const DockerHubAuthKey = \"https://index.docker.io/v1/\" at the package level.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant