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

[release-ocm-2.10] OCPBUGS-36504: Allow auth in docker credentials to be empty #6524

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 43 additions & 32 deletions internal/cluster/validations/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (e *PullSecretError) Unwrap() error {
return e.Cause
}

// ParsePullSecret validates the format of a pull secret and converts the secret string into individual credentail entries
// ParsePullSecret validates the format of a pull secret and converts the secret string into individual credential entries
func ParsePullSecret(secret string) (map[string]PullSecretCreds, error) {
result := make(map[string]PullSecretCreds)
var s imagePullSecret
Expand All @@ -111,44 +111,55 @@ func ParsePullSecret(secret string) (map[string]PullSecretCreds, error) {
}

for d, a := range s.Auths {

_, authPresent := a["auth"]
_, credsStorePresent := a["credsStore"]
if !authPresent && !credsStorePresent {
return nil, &PullSecretError{Msg: fmt.Sprintf("invalid pull secret: %q JSON-object requires either 'auth' or 'credsStore' field", d)}
}

var authRaw string
if auth, ok := a["auth"].(string); authPresent && !ok {
return nil, &PullSecretError{Msg: fmt.Sprintf("invalid pull secret: 'auth' field of %q is %v but should be a string", d, a["auth"])}
} else {
authRaw = auth
}
data, err := base64.StdEncoding.DecodeString(authRaw)
pullSecretCreds, err := parseAuthConfig(d, a)
if err != nil {
return nil, &PullSecretError{Msg: fmt.Sprintf("invalid pull secret: 'auth' field of %q is not base64-encoded", d)}
return nil, err
}

res := bytes.Split(data, []byte(":"))
if len(res) != 2 {
return nil, &PullSecretError{Msg: fmt.Sprintf("invalid pull secret: 'auth' for %s is not in 'user:password' format", d)}
}
result[d] = pullSecretCreds
}

var email string
if emailString, ok := a["email"].(string); ok {
email = emailString
}
return result, nil
}

result[d] = PullSecretCreds{
Password: string(res[1]),
Username: string(res[0]),
AuthRaw: authRaw,
Registry: d,
Email: email,
}
func parseAuthConfig(registry string, authConfig map[string]interface{}) (PullSecretCreds, error) {
email, _ := authConfig["email"].(string)

ret := PullSecretCreds{
Registry: registry,
Email: email,
}
return result, nil

auth, authPresent := authConfig["auth"]
if !authPresent {
return ret, nil
}

authRaw, ok := auth.(string)
if !ok {
return ret, &PullSecretError{Msg: fmt.Sprintf("invalid pull secret: 'auth' field of %q is %v but should be a string", registry, authConfig["auth"])}
}

if len(authRaw) == 0 {
return ret, nil
}

ret.AuthRaw = authRaw

data, err := base64.StdEncoding.DecodeString(authRaw)
if err != nil {
return ret, &PullSecretError{Msg: fmt.Sprintf("invalid pull secret: 'auth' field of %q is not base64-encoded", registry)}
}

res := strings.SplitN(string(data), ":", 2)
if len(res) != 2 {
return ret, &PullSecretError{Msg: fmt.Sprintf("invalid pull secret: 'auth' for %s is not in 'user:password' format", registry)}
}

ret.Username = res[0]
ret.Password = res[1]

return ret, nil
}

func AddRHRegPullSecret(secret, rhCred string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/uploader/auth_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getPullSecret(clusterPullSecret string, k8sclient k8sclient.K8SClient, key
if err != nil {
return nil, errors.Wrapf(err, "failed to parse pull secret")
}
if auth, ok := pullSecret[key]; ok {
if auth, ok := pullSecret[key]; ok && auth.AuthRaw != "" {
return &auth, nil
}
return nil, errors.Errorf("pull secret doesn't contain authentication information for %s", key)
Expand Down