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

http_archive rule now has an ability to authenticate to github using .netrc file as storage for credentials #7978

Closed
wants to merge 2 commits into from

Conversation

genrym
Copy link

@genrym genrym commented Apr 8, 2019

Hi.

Need an opinion for the general direction.

It is still missing the default path for .netrc file to be set to home directory, which is now set as root directory

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@genrym genrym force-pushed the http-netrc-auth branch from 40652bb to 4eba284 Compare April 9, 2019 08:30
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Apr 9, 2019
Copy link
Contributor

@aehlig aehlig left a comment

Choose a reason for hiding this comment

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

Generally I like the idea of adding .netrc authentication, but please follow the procedure required by our design review process.

private static final Map<String, AuthorizationProtocol> TYPE_TO_PROTOCOL = new HashMap<>();

public AuthorizationHeaderProvider() {
TYPE_TO_PROTOCOL.put("github", new GithubAuthorizationProtocol());
Copy link
Contributor

Choose a reason for hiding this comment

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

So the "github" authentication protocol is just sticking "token " in front of the password? And that is only necessary because the .netrc format does not allow to quote spaces?

Is that something generic (so that changing the name would be appropriate) or something really used by github only? What I'm worried about is that, over time, we might accumulate special casing for each and every hosting site.

Copy link
Author

Choose a reason for hiding this comment

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

So the "github" authentication protocol is just sticking "token " in front of the password? And that is only necessary because the .netrc format does not allow to quote spaces?

That is right

Copy link
Author

Choose a reason for hiding this comment

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

Is that something generic (so that changing the name would be appropriate) or something really used by github only? What I'm worried about is that, over time, we might accumulate special casing for each and every hosting site.

Unfortunately, github uses a non-standard Authorization protocol, so this is specific for github.

OAuth2 states:
Authorization: Bearer <token>

Github states:
Authorization: token <token>

It is possible in future to add generic protocols, such as OAuth2, Basic authentication, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the "github" authentication protocol is just sticking "token " in front of the password? And that is only necessary because the .netrc format does not allow to quote spaces?

That is right

Thanks for clarifying. That does not improve my opinion on the .netrc format, but if it is popular, we'll have to support it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, github uses a non-standard Authorization protocol, so this is specific for github.

OAuth2 states:
Authorization: Bearer <token>

Github states:
Authorization: token <token>

OK, so we have to special case it, unless we define a parametric WithPrefixAuthenticationProtocol.

It is possible in future to add generic protocols, such as OAuth2, Basic authentication, etc.

I would appreciate if bazel wouldn't add authentication for GitHub only.

Copy link
Author

Choose a reason for hiding this comment

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

on it


Optional<Credentials> getCredentials(String host);

class Credentials {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are Credentials always user name and pasword? I.e., will a credential provide always be limited to essentially basic auth?

Copy link
Author

Choose a reason for hiding this comment

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

At the moment I am not aware of more information needed for authentication and authorization either than user/pass or api key (token - which we use password to state in netrc file).
However, if would be required, the interface can be evolved using default methods

@@ -27,6 +25,9 @@
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.util.Sleeper;

import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import java.io.IOException;
Copy link
Contributor

Choose a reason for hiding this comment

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

This rearrangement of imports seems unrelated (and will be changed back anyway upon import into the authoritative repository).

That's just FYI, there is nothing to do on your side.

@@ -459,6 +461,24 @@ public void extract(Object archive, Object output, String stripPrefix, Location
+ " <code>build_file</code>, this field can be used to strip it from extracted"
+ " files."),
@Param(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a change of a public Starlark build API interface, for which the bazel policy requires a design discussion; see https://github.com/bazelbuild/proposals/

Copy link
Author

Choose a reason for hiding this comment

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

Will post one, thanks :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Will post one, thanks :)

Thanks. So I'll wait for that design document being written and discussed before processing with this pull request.

Copy link
Author

Choose a reason for hiding this comment

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

@aehlig added the proposal: bazelbuild/proposals#115
Should I assign you as a reviewer?

@@ -459,6 +461,24 @@ public void extract(Object archive, Object output, String stripPrefix, Location
+ " <code>build_file</code>, this field can be used to strip it from extracted"
+ " files."),
@Param(
name = "is_netrc_auth_enabled",
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that flag implicit by whether or not the appropriate key is found in netrc_domain_auth_types?

Copy link
Author

Choose a reason for hiding this comment

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

You are right, we can remove it

Copy link
Author

Choose a reason for hiding this comment

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

removed

type = SkylarkDict.class,
defaultValue = "{}",
named = true,
doc = "the authorization type which is the host in netrc file for now support \"github\""),
Copy link
Contributor

Choose a reason for hiding this comment

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

What about true basic auth? Isn't that provided by the default authorization protocol anyway?

Copy link
Author

Choose a reason for hiding this comment

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

We can add a BasicAuthenticationProtocol implementation by type basic if needed. I might be missing, is there another implementation for basic authentication already?

private static final Map<String, AuthorizationProtocol> TYPE_TO_PROTOCOL = new HashMap<>();

public AuthorizationHeaderProvider() {
TYPE_TO_PROTOCOL.put("github", new GithubAuthorizationProtocol());
Copy link
Author

Choose a reason for hiding this comment

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

So the "github" authentication protocol is just sticking "token " in front of the password? And that is only necessary because the .netrc format does not allow to quote spaces?

That is right

private static final Map<String, AuthorizationProtocol> TYPE_TO_PROTOCOL = new HashMap<>();

public AuthorizationHeaderProvider() {
TYPE_TO_PROTOCOL.put("github", new GithubAuthorizationProtocol());
Copy link
Author

Choose a reason for hiding this comment

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

Is that something generic (so that changing the name would be appropriate) or something really used by github only? What I'm worried about is that, over time, we might accumulate special casing for each and every hosting site.

Unfortunately, github uses a non-standard Authorization protocol, so this is specific for github.

OAuth2 states:
Authorization: Bearer <token>

Github states:
Authorization: token <token>

It is possible in future to add generic protocols, such as OAuth2, Basic authentication, etc.


Optional<Credentials> getCredentials(String host);

class Credentials {
Copy link
Author

Choose a reason for hiding this comment

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

At the moment I am not aware of more information needed for authentication and authorization either than user/pass or api key (token - which we use password to state in netrc file).
However, if would be required, the interface can be evolved using default methods

@@ -459,6 +461,24 @@ public void extract(Object archive, Object output, String stripPrefix, Location
+ " <code>build_file</code>, this field can be used to strip it from extracted"
+ " files."),
@Param(
Copy link
Author

Choose a reason for hiding this comment

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

Will post one, thanks :)

@@ -459,6 +461,24 @@ public void extract(Object archive, Object output, String stripPrefix, Location
+ " <code>build_file</code>, this field can be used to strip it from extracted"
+ " files."),
@Param(
name = "is_netrc_auth_enabled",
Copy link
Author

Choose a reason for hiding this comment

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

You are right, we can remove it

type = SkylarkDict.class,
defaultValue = "{}",
named = true,
doc = "the authorization type which is the host in netrc file for now support \"github\""),
Copy link
Author

Choose a reason for hiding this comment

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

We can add a BasicAuthenticationProtocol implementation by type basic if needed. I might be missing, is there another implementation for basic authentication already?

@@ -78,6 +90,7 @@ public void setDistdir(List<Path> distdir) {
* @param clientEnv environment variables in shell issuing this command
* @param repo the name of the external repository for which the file was fetched; used only for
* reporting
* @param authorization TBD
Copy link
Author

Choose a reason for hiding this comment

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

will add description

Copy link
Author

Choose a reason for hiding this comment

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

done

@jin jin added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Apr 19, 2019
@jin
Copy link
Member

jin commented Apr 30, 2019

Is this blocked on a proposal?

@genrym
Copy link
Author

genrym commented Apr 30, 2019

I am changing the implementation according to comments, which seems like also changing the api a bit, then will send a proposal for api

@genrym
Copy link
Author

genrym commented May 1, 2019

proposal submitted: bazelbuild/proposals#115

@genrym
Copy link
Author

genrym commented May 1, 2019

only now saw that there is an issue for that already, which this PR tries to solve: #7770

@genrym
Copy link
Author

genrym commented Jul 26, 2019

@aehlig (thanks to you :) ) we have already a solution for http_archive rule will respect by default .netrc stored credentials and use HTTP basic authentication for the related domain/host which will be available at version 0.29.
Proposing to close this one.

@jin
Copy link
Member

jin commented Aug 1, 2019

Closing this PR as @aehlig has integrated netrc w/ http_* rules. Thanks @aehlig :)

@jin jin closed this Aug 1, 2019
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants