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

Support for maven servers requiring authentication #215

Merged
merged 8 commits into from
Nov 1, 2018

Conversation

rdnetto4
Copy link
Contributor

@rdnetto4 rdnetto4 commented Oct 22, 2018

This PR contains three main changes:

It adds support for maven servers which require authentication in AetherResolver. (I haven't been able to figure out the correct place in CoursierResolver to hook this in - it looks like it needs to be done on the creation of every Artifact)

The second change is to improve the handling of import-scoped dependencies, so that users can opt-in to ignoring them instead of failing the conversion. This makes sense for a large project we're converting to Bazel, as all the usages of import-scoped dependencies in our transitive closure would be overridden by our direct dependencies anyway.

The third change is to compute the SHA256 checksum on the AetherResolver codepath, as this was previously not done and is relied upon by the generated workspace.bzl.

@rdnetto4
Copy link
Contributor Author

Bump :)

Copy link
Collaborator

@johnynek johnynek left a comment

Choose a reason for hiding this comment

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

Sorry for the latency.

Can we please split this into two PRs to make it easier for us to understand the change history?

Secondly, I will merge this PR, but I have a lot of anxiety about having two backends each with their own feature sets. We have seen bugs with aether and no longer use it at Stripe in favor of coursier, which is also much faster. It would be really nice to see if we can support everything in one backend.

private val m2Home = new File(new File(System.getProperty("user.home")), "/.m2/")
private val m2SecurityXml = new File(m2Home, "settings-security.xml")

private val settingsDecrypter: SettingsDecrypter = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems like a separate PR, can we please separate from the warning/error on imports?

logger.warn (s"unsupported import-scope dependency: $d")
false
case ImportScopeHandling.Error =>
sys.error (s"unsupported import-scope dependency: $d")
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you have any idea how much work it is to support this? I have not looked in detail, but I think it also coming up in #220

@johnynek
Copy link
Collaborator

sorry for the latency

@rdnetto4
Copy link
Contributor Author

Secondly, I will merge this PR, but I have a lot of anxiety about having two backends each with their own feature sets. We have seen bugs with aether and no longer use it at Stripe in favor of coursier, which is also much faster. It would be really nice to see if we can support everything in one backend.

After digging into it a bit, I believe I've gotten authentication working for the Coursier backend as well. Given that it's both more reliable and faster, I'm happy to drop the importScopeHandling change if we can just use Coursier instead. AFAICT, Coursier also handles import-scope dependencies if we don't filter JARs out in processArtifact()

@rdnetto4 rdnetto4 changed the title Server auth + importScopeHandling Support for maven servers requiring authentication Oct 31, 2018
Copy link
Collaborator

@johnynek johnynek left a comment

Choose a reason for hiding this comment

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

This looks great. Two minor nits and one question: can we have any simple test for this?

import org.slf4j.LoggerFactory
import scala.collection.JavaConversions._

class SettingsLoader {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be an object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that definitely makes more sense.

servers.map { case MavenServer(id, t, u) =>
var server = settings.getServer(id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use a val here and Option(settings.getServer(id)).getOrElse(new Server)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, will do so. 👍

@rdnetto4
Copy link
Contributor Author

rdnetto4 commented Nov 1, 2018

This looks great. Two minor nits and one question: can we have any simple test for this?

The tricky part of this what we test. In the resolvers, we're simply passing the credentials through to aether/coursier, and I'm not sure there's much value in testing that. Similarly, SettingsLoader is really just a wrapper around the maven-settings library.

The most likely cause of a regression in this functionality would be forgetting to pass the credentials through, like here, but that feels like the sort of problem best caught by an integration test that actually tries to fetch an artifact requiring authentication...

@johnynek johnynek merged commit 1af8921 into bazeltools:master Nov 1, 2018
@johnynek
Copy link
Collaborator

johnynek commented Nov 1, 2018

I’ve merged. It would be good to see if we can add an integration test to prevent future breaks.

Thanks for the PR!

@deadmoose
Copy link
Contributor

I'm late to the game, but finally gave this a whirl instead of my own in-house hackery to cope with our authed repos.

Resolution worked without a hitch, getting creds from my ~/.m2/settings.xml, but then my bazel build falls over because it's still trying to just ctx.download() the artifact without authentication.

What secret am I missing to getting that second part working, or is that still an issue?

(FWIW, my local hack I'm using currently is to identify the authenticated servers and have them use bazel-tools' maven_jar() instead of jar_artifact(). It shells out to maven which makes all the auth magically work, but is heavyweight enough I can only afford it on the things that need it)

@guw
Copy link
Contributor

guw commented Feb 19, 2019

@deadmoose You can't. Bazel repository_ctx.download doesn't support auth. I've opened bazelbuild/bazel#7469.

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.

4 participants