Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GoogleContainerTools/jib
Browse files Browse the repository at this point in the history
…into louis-fixnpeexception

Merging #2537 fix
  • Loading branch information
Louis Murerwa committed Jun 29, 2020
2 parents 090d655 + 34a757b commit 6473b42
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ subprojects {
MOCKITO_CORE: '3.2.4',
SLF4J_API: '1.7.25',
SYSTEM_RULES: '1.19.0',
JBCRYPT: '0.4',
]

// Use this to ensure we correctly override transitive dependencies
Expand Down
2 changes: 2 additions & 0 deletions jib-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.

### Fixed

- Fixed `NullPointerException` when the `"auths":` section in `~/.docker/config.json` has an entry with no `"auth":` field. ([#2535](https://github.com/GoogleContainerTools/jib/issues/2535))

## 0.15.0

### Added
Expand Down
2 changes: 2 additions & 0 deletions jib-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dependencies {
testImplementation "org.mockito:mockito-core:${dependencyVersions.MOCKITO_CORE}"
testImplementation "org.slf4j:slf4j-api:${dependencyVersions.SLF4J_API}"
testImplementation "com.github.stefanbirkner:system-rules:${dependencyVersions.SYSTEM_RULES}"

integrationTestImplementation "org.mindrot:jbcrypt:${dependencyVersions.JBCRYPT}"
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.UUID;
import javax.annotation.Nullable;
import org.junit.rules.ExternalResource;
import org.mindrot.jbcrypt.BCrypt;

/** Runs a local registry. */
public class LocalRegistry extends ExternalResource {
Expand Down Expand Up @@ -68,19 +69,11 @@ public void start() throws IOException, InterruptedException {
Arrays.asList(
"docker", "run", "--rm", "-d", "-p", port + ":5000", "--name", containerName));
if (username != null && password != null) {
// Generate the htpasswd file to store credentials
String credentialString =
new Command(
"docker",
"run",
"--rm",
"--entrypoint",
"htpasswd",
"registry:2",
"-Bbn",
username,
password)
.run();
// Equivalent of "$ htpasswd -nbB username password".
// https://httpd.apache.org/docs/2.4/misc/password_encryptions.html
// BCrypt generates hashes using $2a$ algorithm (instead of $2y$ from docs), but this seems
// to work okay
String credentialString = username + ":" + BCrypt.hashpw(password, BCrypt.gensalt());
// Creates the temporary directory in /tmp since that is one of the default directories
// mounted into Docker.
// See: https://docs.docker.com/docker-for-mac/osxfs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Optional<Credential> retrieve(DockerConfig dockerConfig, Consumer<LogEvent> logg

// Lastly, find defined auth.
AuthTemplate auth = dockerConfig.getAuthFor(registryAlias);
if (auth != null) {
if (auth != null && auth.getAuth() != null) {
// 'auth' is a basic authentication token that should be parsed back into credentials
String usernameColonPassword =
new String(Base64.decodeBase64(auth.getAuth()), StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,15 @@ public void testRetrieve_azureIdentityToken() throws IOException, URISyntaxExcep
Assert.assertEquals("<token>", credentials.get().getUsername());
Assert.assertEquals("cool identity token", credentials.get().getPassword());
}

@Test
public void testRetrieve_noErrorWhenMissingAuthField() throws IOException, URISyntaxException {
Path dockerConfigFile = Paths.get(Resources.getResource("core/json/dockerconfig.json").toURI());

DockerConfigCredentialRetriever dockerConfigCredentialRetriever =
DockerConfigCredentialRetriever.create("no auth field", dockerConfigFile);

Optional<Credential> credentials = dockerConfigCredentialRetriever.retrieve(mockLogger);
Assert.assertFalse(credentials.isPresent());
}
}
3 changes: 2 additions & 1 deletion jib-core/src/test/resources/core/json/dockerconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"some registry":{"auth":"c29tZTphdXRo","password":"ignored"},
"https://registry":{"auth":"dG9rZW4="},

"example.com":{"auth":"should not match example"}
"example.com":{"auth":"should not match example"},
"no auth field":{}
},
"credsStore":"some credential store",
"credHelpers":{
Expand Down
1 change: 1 addition & 0 deletions jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Fixed

- Fixed reporting a wrong credential helper name when the helper does not exist on Windows. ([#2527](https://github.com/GoogleContainerTools/jib/issues/2527))
- Fixed `NullPointerException` when the `"auths":` section in `~/.docker/config.json` has an entry with no `"auth":` field. ([#2535](https://github.com/GoogleContainerTools/jib/issues/2535))

## 2.4.0

Expand Down
3 changes: 3 additions & 0 deletions jib-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ dependencies {
testImplementation "org.slf4j:slf4j-api:${dependencyVersions.SLF4J_API}"
testImplementation "com.github.stefanbirkner:system-rules:${dependencyVersions.SYSTEM_RULES}"


testImplementation project(path:':jib-plugins-common', configuration:'tests')
integrationTestImplementation project(path:':jib-core', configuration:'integrationTests')

integrationTestImplementation "org.mindrot:jbcrypt:${dependencyVersions.JBCRYPT}"

// only for testing a concrete Spring Boot example in a test (not for test infrastructure)
testImplementation 'org.springframework.boot:spring-boot-gradle-plugin:2.1.6.RELEASE'
}
Expand Down
1 change: 1 addition & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
### Fixed

- Fixed reporting a wrong credential helper name when the helper does not exist on Windows. ([#2527](https://github.com/GoogleContainerTools/jib/issues/2527))
- Fixed `NullPointerException` when the `"auths":` section in `~/.docker/config.json` has an entry with no `"auth":` field. ([#2535](https://github.com/GoogleContainerTools/jib/issues/2535))

## 2.4.0

Expand Down
2 changes: 2 additions & 0 deletions jib-maven-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ dependencies {
testImplementation 'org.slf4j:slf4j-api:1.7.30'
testImplementation 'org.slf4j:slf4j-simple:1.7.30'

integrationTestImplementation "org.mindrot:jbcrypt:${dependencyVersions.JBCRYPT}"

testImplementation project(path:':jib-plugins-common', configuration:'tests')
integrationTestImplementation project(path:':jib-core', configuration:'integrationTests')
}
Expand Down

0 comments on commit 6473b42

Please sign in to comment.