Skip to content

[gitpod-protocol] handle host:port:token for getGitpodImageAuth #20806

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kylos101
Copy link
Contributor

@kylos101 kylos101 commented May 9, 2025

Description

Be able to consume GITPOD_IMAGE_AUTH, where it is host:<token> or host:port:<token>.

Related Issue(s)

Fixes #16237
Fixes CLC-1364

How to test

See unit tests

Documentation

Preview status

gitpod:summary

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment / Integration Tests
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • /werft preemptible
    Saves cost. Untick this only if you're really sure you need a non-preemtible machine.
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh. If enabled, with-preview and with-large-vm will be enabled.
  • with-monitoring

/hold

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 improves the parsing of the Gitpod image authentication environment variable by supporting both "host:token" and "host:port:token" formats. In addition to updating the splitting logic in getGitpodImageAuth, comprehensive unit tests have been added to cover various scenarios including malformed inputs and entries with extra spaces.

Reviewed Changes

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

File Description
components/gitpod-protocol/src/protocol.ts Updated getGitpodImageAuth to correctly handle host:token and host:port:token formats.
components/gitpod-protocol/src/protocol.spec.ts Added tests for the new parsing logic and ensured various cases (empty, malformed, multiple entries) are covered.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

@kylos101 We have at least two other places where we parse this forward, which we need to adjust as well.

IIRC it was in proxy.go (image-builder-bob), and maybe even somewhere else - maybe around docker-up? 🤔

I can pull out the references on Monday - or you try to ask cline 😉

@kylos101 kylos101 marked this pull request as draft May 9, 2025 16:15
.map((e) => e.trim().split(":"))
.filter((e) => e.length == 2)
.forEach((e) => res.set(e[0], e[1]));
(imageAuth.value || "").split(",").forEach((entry) => {
Copy link
Member

Choose a reason for hiding this comment

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

Somehow it's very hard for me to understand the new implementation, while the old I could grok in an instant.

Does it really need that many lines? And if the answer is really yes: We should probably have a separate (in-function?) "parse" method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I introduced an inline function and reduced lines of code in c0be79f.

You'll notice a truthiness check on all parts, this is to ensure we're not working with junk. I could remove it, but that'll cause tests to fail like so:

image

LMKWYT? I'll move onto checking other components now.

@kylos101
Copy link
Contributor Author

kylos101 commented May 9, 2025

@kylos101 We have at least two other places where we parse this forward, which we need to adjust as well.

IIRC it was in proxy.go (image-builder-bob), and maybe even somewhere else - maybe around docker-up? 🤔

I can pull out the references on Monday - or you try to ask cline 😉

Thanks again for the tip, @geropl!

It seems supervisor is impacted here,image-builder-bob here and here, and perhaps image-builder-mk3 here are impacted (I'll start with supervisor).

@kylos101 kylos101 requested a review from Copilot May 9, 2025 18:43
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 enhances the Gitpod image authentication mechanism by supporting both "host:" and "host:port:" formats. Key changes include:

  • Introducing a helper function getHost to determine the host (with optional port) from the token.
  • Updating the image authentication parsing logic accordingly.
  • Adding extensive unit tests to cover various input scenarios for image authentication.

Reviewed Changes

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

File Description
components/gitpod-protocol/src/protocol.ts Added helper function and updated parsing logic for handling host with optional port
components/gitpod-protocol/src/protocol.spec.ts Added new tests to verify correct handling of image auth entries, including edge cases

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please support private Docker registries with a non-default port
4 participants