Skip to content

Conversation

@scaps1
Copy link
Contributor

@scaps1 scaps1 commented Jan 21, 2025

Because of incorrect registry url of docker hub in imagePullSecret we receiving alerts that images are unavailable and 401 UNAUTHORIZED in app logs.
Example of incorrect creds:

{
  "auths": {
    "docker.io": {
      "username": "login",
      "password": "password",
      "auth": "auth_chain"
    }
  }
}

Correct way:

{
  "auths": {
    "https://index.docker.io/v1/": {
      "username": "login",
      "password": "pass",
      "auth": "chain"
    }
  }
}

@scaps1 scaps1 self-assigned this Jan 21, 2025
Signed-off-by: alexey.komyakov <[email protected]>
Signed-off-by: alexey.komyakov <[email protected]>
@scaps1 scaps1 requested a review from nabokihms January 21, 2025 09:23
@scaps1 scaps1 marked this pull request as ready for review January 21, 2025 09:23
@nabokihms nabokihms changed the title Add handling of incorrect dokcer hub URLs Add handling of incorrect docker hub URLs Jan 22, 2025
Comment on lines 28 to 35
if secret.Type != corev1.SecretTypeDockerConfigJson {
continue
}

data, exists := secret.Data[corev1.DockerConfigJsonKey]
if !exists {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There are two types of docker secrets. We have to cover both:

	// SecretTypeDockercfg contains a dockercfg file that follows the same format rules as ~/.dockercfg
	//
	// Required fields:
	// - Secret.Data[".dockercfg"] - a serialized ~/.dockercfg file
	SecretTypeDockercfg SecretType = "kubernetes.io/dockercfg"

	// DockerConfigKey is the key of the required data for SecretTypeDockercfg secrets
	DockerConfigKey = ".dockercfg"

	// SecretTypeDockerConfigJson contains a dockercfg file that follows the same format rules as ~/.docker/config.json
	//
	// Required fields:
	// - Secret.Data[".dockerconfigjson"] - a serialized ~/.docker/config.json file
	SecretTypeDockerConfigJson SecretType = "kubernetes.io/dockerconfigjson"

	// DockerConfigJsonKey is the key of the required data for SecretTypeDockerConfigJson secrets
	DockerConfigJsonKey = ".dockerconfigjson"

return secrets, nil
}

func parseDockerConfig(data []byte) (map[string]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave a comment with the example of data.

}

func updateDockerRegistryAuths(dockerConfig map[string]interface{}) error {
auths, ok := dockerConfig["auths"].(map[string]interface{})
Copy link
Contributor

Choose a reason for hiding this comment

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

In "kubernetes.io/dockercfg" there is no auth, we have to parse these two types differently.

}

func parseDockerConfig(data []byte) (map[string]interface{}, error) {
var dockerConfig map[string]interface{}
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: it is better to use map[string]json.RawMessage

Signed-off-by: alexey.komyakov <[email protected]>
Signed-off-by: alexey.komyakov <[email protected]>
@nabokihms nabokihms merged commit 05fd531 into master Jan 24, 2025
8 checks passed
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.

3 participants