forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remote: Add support for HTTP Basic Auth
Closes bazelbuild#4609. PiperOrigin-RevId: 185032751
- Loading branch information
Showing
5 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ make builds significantly faster. | |
* [Bazel Remote Cache](#bazel-remote-cache) | ||
* [Google Cloud Storage](#google-cloud-storage) | ||
* [Other servers](#other-servers) | ||
* [Authentication](#authentication) | ||
* [HTTP Caching Protocol](#http-caching-protocol) | ||
* [Run Bazel using the remote cache](#run-bazel-using-the-remote-cache) | ||
* [Read from and write to the remote cache](#read-from-and-write-to-the-remote-cache) | ||
|
@@ -174,6 +175,14 @@ You can set up any HTTP/1.1 server that supports PUT and GET as the cache's | |
backend. Users have reported success with caching backends such as [Hazelcast], | ||
[Apache httpd], and [AWS S3]. | ||
|
||
## Authentication | ||
|
||
As of version 0.11.0 support for HTTP Basic Authentication was added to Bazel. | ||
You can pass a username and password to Bazel via the remote cache URL. The | ||
syntax is `https://username:[email protected]:port/path`. Please note that | ||
HTTP Basic Authentication transmits username and password in plaintext over the | ||
network and it's thus critical to always use it with HTTPS. | ||
|
||
## HTTP Caching Protocol | ||
|
||
Bazel supports remote caching via HTTP/1.1. The protocol is conceptually simple: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...est/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2018 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.remote.blobstore.http; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import io.netty.channel.ChannelPromise; | ||
import io.netty.channel.embedded.EmbeddedChannel; | ||
import io.netty.handler.codec.http.HttpHeaderNames; | ||
import io.netty.handler.codec.http.HttpRequest; | ||
import java.io.ByteArrayOutputStream; | ||
import java.net.URI; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
import org.mockito.Mockito; | ||
|
||
/** Tests for {@link AbstractHttpHandlerTest}. */ | ||
@RunWith(JUnit4.class) | ||
public abstract class AbstractHttpHandlerTest { | ||
|
||
@Test | ||
public void basicAuthShouldWork() throws Exception { | ||
URI uri = new URI("http://user:[email protected]/foo"); | ||
EmbeddedChannel ch = new EmbeddedChannel(new HttpDownloadHandler(null)); | ||
ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream()); | ||
DownloadCommand cmd = new DownloadCommand(uri, true, "abcdef", new ByteArrayOutputStream()); | ||
ChannelPromise writePromise = ch.newPromise(); | ||
ch.writeOneOutbound(cmd, writePromise); | ||
|
||
HttpRequest request = ch.readOutbound(); | ||
assertThat(request.headers().get(HttpHeaderNames.AUTHORIZATION)) | ||
.isEqualTo("Basic dXNlcjpwYXNzd29yZA=="); | ||
} | ||
|
||
@Test | ||
public void basicAuthShouldNotEnabled() throws Exception { | ||
URI uri = new URI("http://does.not.exist/foo"); | ||
EmbeddedChannel ch = new EmbeddedChannel(new HttpDownloadHandler(null)); | ||
ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream()); | ||
DownloadCommand cmd = new DownloadCommand(uri, true, "abcdef", new ByteArrayOutputStream()); | ||
ChannelPromise writePromise = ch.newPromise(); | ||
ch.writeOneOutbound(cmd, writePromise); | ||
|
||
HttpRequest request = ch.readOutbound(); | ||
assertThat(request.headers().contains(HttpHeaderNames.AUTHORIZATION)).isFalse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters