feat: add support for mounting OCI credentials as a Docker config vol…#33
feat: add support for mounting OCI credentials as a Docker config vol…#33
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds support for authenticating to OCI registries by mounting a kubernetes.io/dockerconfigjson Secret into the ModelArtifact build Job, replacing the previous username/password env-based login approach.
Changes:
- Mounts a docker config Secret as a volume in the build Job and removes
kit loginusage. - Introduces shared constants for the docker config volume name and mount path.
- Updates BuildJob tests to assert the new volume/volumeMount behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| internal/modelartifact/job.go | Switches OCI registry auth to dockerconfigjson Secret volume + removes env-based credentials/login. |
| internal/modelartifact/helpers.go | Adds constants for docker config volume name and mount path. |
| internal/modelartifact/job_test.go | Updates tests from env assertions to volume/volumeMount assertions for OCI credentials. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| envs := []corev1.EnvVar{ | ||
| {Name: "OCI_TARGET", Value: OCIReference(artifact)}, | ||
| {Name: "FORMAT", Value: string(artifact.Spec.Format)}, | ||
| {Name: "DOCKER_CONFIG", Value: DockerConfigMountPath}, | ||
| } |
There was a problem hiding this comment.
New behavior introduces DOCKER_CONFIG and changes registry auth flow, but the tests only assert the volume/volumeMount and don't assert the DOCKER_CONFIG env var behavior. Add assertions to cover whether DOCKER_CONFIG is set (and to what value) in both the credentials-present and credentials-absent cases, especially if you decide to conditionally set it.
| HaveField("Name", modelartifact.DockerConfigVolumeName), | ||
| HaveField("VolumeSource.Secret.SecretName", "oci-creds"), | ||
| HaveField("VolumeSource.Secret.Items", ConsistOf( | ||
| corev1.KeyToPath{Key: ".dockerconfigjson", Path: "config.json"}, |
There was a problem hiding this comment.
This test hard-codes the dockerconfigjson key as ".dockerconfigjson". Prefer using corev1.DockerConfigJsonKey (same constant suggested in BuildJob) so the test stays aligned with Kubernetes API conventions and avoids duplicated magic strings.
| corev1.KeyToPath{Key: ".dockerconfigjson", Path: "config.json"}, | |
| corev1.KeyToPath{Key: corev1.DockerConfigJsonKey, Path: "config.json"}, |
| {Name: "DOCKER_CONFIG", Value: DockerConfigMountPath}, | ||
| } | ||
|
|
There was a problem hiding this comment.
DOCKER_CONFIG is set unconditionally to "/.docker" even when no CredentialsSecretRef is provided. This overrides the default docker config lookup path (e.g., $HOME/.docker) and can break scenarios where the kit image already provides credentials or config at the default location. Consider only setting DOCKER_CONFIG (and mounting /.docker) when CredentialsSecretRef is present, or otherwise leaving DOCKER_CONFIG unset so default behavior is preserved.
| {Name: "DOCKER_CONFIG", Value: DockerConfigMountPath}, | |
| } | |
| } | |
| // Only override DOCKER_CONFIG when a registry credentials Secret is configured. | |
| // Otherwise, allow Docker/kit to use the default config resolution (e.g., $HOME/.docker). | |
| if artifact.Spec.Target.CredentialsSecretRef != nil { | |
| envs = append(envs, corev1.EnvVar{Name: "DOCKER_CONFIG", Value: DockerConfigMountPath}) | |
| } |
| SecretName: cred.Name, | ||
| Items: []corev1.KeyToPath{ | ||
| { | ||
| Key: ".dockerconfigjson", |
There was a problem hiding this comment.
The Secret item key is hard-coded as ".dockerconfigjson". Kubernetes defines a constant for this (corev1.DockerConfigJsonKey); using it reduces the chance of typos and makes the intent clearer. Update both the volume Items and the corresponding test expectation to use the constant.
| Key: ".dockerconfigjson", | |
| Key: corev1.DockerConfigJsonKey, |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new feature that allows mounting OCI credentials as a Docker config volume within the Job pod. This enhancement simplifies registry authentication by leveraging a Kubernetes secret to store the credentials and automatically configure the 'kit' tool to use them, eliminating the need for an explicit login step. Highlights
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors OCI credential handling to use a mounted Docker config volume instead of environment variables, which is a good security and standards improvement. I've found one issue where an environment variable is set unconditionally, which could lead to failures when no credentials are provided. I've also suggested an improvement to the tests to cover this case.
| envs := []corev1.EnvVar{ | ||
| {Name: "OCI_TARGET", Value: OCIReference(artifact)}, | ||
| {Name: "FORMAT", Value: string(artifact.Spec.Format)}, | ||
| {Name: "DOCKER_CONFIG", Value: DockerConfigMountPath}, | ||
| } |
There was a problem hiding this comment.
The DOCKER_CONFIG environment variable is set unconditionally, but the corresponding volume and volume mount are only added if CredentialsSecretRef is present. If no credentials are provided, DOCKER_CONFIG will point to a non-existent directory (/.docker), which could cause the kit command to fail when it tries to access the path for credentials. This environment variable should only be set when credentials are provided.
envs := []corev1.EnvVar{
{Name: "OCI_TARGET", Value: OCIReference(artifact)},
{Name: "FORMAT", Value: string(artifact.Spec.Format)},
}
if artifact.Spec.Target.CredentialsSecretRef != nil {
envs = append(envs, corev1.EnvVar{Name: "DOCKER_CONFIG", Value: DockerConfigMountPath})
}| for _, vm := range container.VolumeMounts { | ||
| Expect(vm.Name).NotTo(Equal(modelartifact.DockerConfigVolumeName)) | ||
| } | ||
| for _, v := range job.Spec.Template.Spec.Volumes { | ||
| Expect(v.Name).NotTo(Equal(modelartifact.DockerConfigVolumeName)) | ||
| } |
There was a problem hiding this comment.
This test correctly verifies that the docker config volume is not mounted when no secret is referenced. To ensure the fix for the unconditionally set DOCKER_CONFIG environment variable is covered, this test should also assert that the environment variable is not set in this scenario.
| for _, vm := range container.VolumeMounts { | |
| Expect(vm.Name).NotTo(Equal(modelartifact.DockerConfigVolumeName)) | |
| } | |
| for _, v := range job.Spec.Template.Spec.Volumes { | |
| Expect(v.Name).NotTo(Equal(modelartifact.DockerConfigVolumeName)) | |
| } | |
| for _, vm := range container.VolumeMounts { | |
| Expect(vm.Name).NotTo(Equal(modelartifact.DockerConfigVolumeName)) | |
| } | |
| for _, v := range job.Spec.Template.Spec.Volumes { | |
| Expect(v.Name).NotTo(Equal(modelartifact.DockerConfigVolumeName)) | |
| } | |
| for _, e := range container.Env { | |
| Expect(e.Name).NotTo(Equal("DOCKER_CONFIG")) | |
| } |
…ume in Job