Skip to content

feat: add support for mounting OCI credentials as a Docker config vol…#33

Merged
iasthc merged 1 commit intomainfrom
docker-config
Mar 11, 2026
Merged

feat: add support for mounting OCI credentials as a Docker config vol…#33
iasthc merged 1 commit intomainfrom
docker-config

Conversation

@iasthc
Copy link
Copy Markdown
Member

@iasthc iasthc commented Mar 11, 2026

…ume in Job

Copilot AI review requested due to automatic review settings March 11, 2026 09:59
@iasthc iasthc merged commit aaec7dd into main Mar 11, 2026
13 checks passed
@iasthc iasthc deleted the docker-config branch March 11, 2026 10:00
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

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

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 login usage.
  • 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.

Comment on lines 208 to 212
envs := []corev1.EnvVar{
{Name: "OCI_TARGET", Value: OCIReference(artifact)},
{Name: "FORMAT", Value: string(artifact.Spec.Format)},
{Name: "DOCKER_CONFIG", Value: DockerConfigMountPath},
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
HaveField("Name", modelartifact.DockerConfigVolumeName),
HaveField("VolumeSource.Secret.SecretName", "oci-creds"),
HaveField("VolumeSource.Secret.Items", ConsistOf(
corev1.KeyToPath{Key: ".dockerconfigjson", Path: "config.json"},
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
corev1.KeyToPath{Key: ".dockerconfigjson", Path: "config.json"},
corev1.KeyToPath{Key: corev1.DockerConfigJsonKey, Path: "config.json"},

Copilot uses AI. Check for mistakes.
Comment on lines +211 to 213
{Name: "DOCKER_CONFIG", Value: DockerConfigMountPath},
}

Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
{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})
}

Copilot uses AI. Check for mistakes.
SecretName: cred.Name,
Items: []corev1.KeyToPath{
{
Key: ".dockerconfigjson",
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
Key: ".dockerconfigjson",
Key: corev1.DockerConfigJsonKey,

Copilot uses AI. Check for mistakes.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • OCI Credentials: Adds support for mounting OCI credentials as a Docker config volume in the Job pod.
  • Authentication: Handles registry authentication by mounting a kubernetes.io/dockerconfigjson Secret at /.docker/config.json.
  • Configuration: kit (and the underlying OCI libraries) now read this file automatically, so no explicit "kit login" step is required.
Activity
  • Constants defined for Docker config volume name and mount path.
  • Documentation added to explain registry authentication process.
  • OCI login step removed from the job script.
  • Volume and VolumeMount added to the Job spec to mount the Docker config.
  • Environment variable added to specify the Docker config mount path.
  • OCI_USER and OCI_PASS environment variables removed.
  • Test case added to verify the Docker config volume mount.
  • Test case updated to ensure no Docker config volume is mounted when no secret ref is provided.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 208 to 212
envs := []corev1.EnvVar{
{Name: "OCI_TARGET", Value: OCIReference(artifact)},
{Name: "FORMAT", Value: string(artifact.Spec.Format)},
{Name: "DOCKER_CONFIG", Value: DockerConfigMountPath},
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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})
    }

Comment on lines +276 to 281
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))
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
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"))
}

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.

2 participants