Gaurav Negi
Gaurav Negi

Reputation: 21

How to use authenticated repo in bazel for thirdparty dependant artifacts

My code depends on some thirdparty artifacts, that are put in some authenticated repo. WORKSPACE file is like this

http_archive(
  name = "glog_archive",
  build_file = "@//:third_party/BUILD.glog",
  sha256 = "SOME SHA ID",
  url = "https://artifactory/thirdparty/glog.<version>.tar.gz",
)

But repo https://artifactory/thirdparty/ is authenticated.

How can I put user/password or API key so that download of thirdparty archives works well?

Went through this doc https://docs.bazel.build/versions/master/repo/http.html#http_archive-auth_patterns

But couldnot get it correctly.

If there any example I can get?

Upvotes: 2

Views: 5398

Answers (1)

Ondrej K.
Ondrej K.

Reputation: 9664

This depends on how (can) are you trying to authenticate to your artifactory instance. If you rely on HTTP basic authentication scheme either using a username and paswword (or username and API key; or username and access token), you need to add those to corresponding machine entry in .netrc file, e.g.:

machine your.artifactory.host
        login YOUR_ARTIFACTORY_USERNAME
        password YOUR_PASSWORD_OR_KEY_OR_TOKEN

You can either add path to the netrc file in eponymous attribute of the http_* repository rules. Or bazel will look for it as ${HOME}/.netrc for non Windows system and very recently (in master, but not yet in 3.0.0 release) as %USERPROFILE%/.netrc.

Using API alone (with X-JFrog-Art-Api) is not supported by http_* rules.

You only needs to use auth_patterns if you were not using basic authentication scheme. I.e. you wanted to use the Artifactory access token as a bearer token. In which case you would add:

auth_patterns = {
    "your.artifactory.host": "Bearer <password>"
}

You then add the token into your netrc (see above if it needs to be explicitly added to the rule or not):

machine your.artifactory.host
        password YOUR_TOKEN

How this works is for given host it takes string of the corresponding auth_patterns value, replaces <login> and <password> (if used) with those obtained for given host from netrc and passes that as value for Authorization header. I.e. in the above example:

Authorization: Bearer YOUR_TOKEN

Upvotes: 2

Related Questions