Skip to content
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

No support for hostnames with a hypen #2

Closed
StephanePaulus opened this issue Oct 28, 2022 · 3 comments · Fixed by #3
Closed

No support for hostnames with a hypen #2

StephanePaulus opened this issue Oct 28, 2022 · 3 comments · Fixed by #3

Comments

@StephanePaulus
Copy link

I am trying this credential helper with a docker repo like: mr-artifactory.data.internal
I think the issue is because hypens are not allowed in env variables.

So when I do EXPORT DOCKER_mr_artifactory_data_internal_USR, it cannot find the credentials as it doesn't match
mr.artifactory.data.internal

@StephanePaulus
Copy link
Author

After looking at the code:

func getEnvCredentials(hostname string) (username, password string, found bool) {
	labels := strings.Split(hostname, ".")

	for i := 0; i <= len(labels); i++ {
		envUsername, envPassword := getEnvVariables(labels, i)

		if username, found = os.LookupEnv(envUsername); found {
			if password, found = os.LookupEnv(envPassword); found {
				break
			}
		}
	}
	return
}

The hostname is just split based on the . char. So in the case of the host also having a - it will try to find env variables with the - in it. In my case DOCKER_mr-artifactory_USR, which is not valid. I don't want to use the catch all `DOCKER__USR' variable as this limit my choices.

@isometry
Copy link
Owner

@StephanePaulus - thanks for the bug report! What do you think would be the cleanest label transformation here? s/-/_/g (i.e. DOCKER_mr_artifactory_data_internal_USR) or s/-//g (i.e. DOCKER_mrartifactory_data_internal_USR)? I lean toward the first.

To unblock you, the workaround would be DOCKER_data_internal_USR to scope to all Docker registries within the data.internal zone.

@StephanePaulus
Copy link
Author

@isometry I would also think the first 1 makes the most sense.

isometry added a commit that referenced this issue Nov 3, 2022
isometry added a commit that referenced this issue Nov 3, 2022
fix(#2): normalize DNS label hyphens to underscores during environment variable lookup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants