Access a private GitHub repository from a Cloud Build step (glide install fails)

A Go project (A) depended on another private GitHub repository (B), and the Cloud Build pipeline could not fetch it. glide install failed with: [WARN] Unable to checkout github.com/avi/api, [ERROR] Update failed for github.com/avi/api: Unable to get repository. Cloning directly with the git builder failed too: SSH clone failed with "Host key verification failed / Could not read from remote repository", and HTTPS clone failed with "could not read Username for 'https://github.com': No such device or address". The build service account had no credentials for GitHub.

Cloud Build steps have no GitHub credentials by default, so private repos are unreachable until you inject them. The recommended approach is to store a deploy key or token encrypted and pull it into the build: keep the SSH key in Cloud Storage, fetch it in an early build step, then use it for git operations (add GitHub to known_hosts to avoid the host-key verification failure). Google published a tutorial on using encrypted files in builds covering exactly this pattern. This resolved the reporter's glide/private-repo failures.

Source: https://github.com/GoogleCloudPlatform/cloud-builders/issues/44