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

Programmatically generate htpasswd file #2539

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions jib-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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}"
testImplementation "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.7.0", // TODO: correctly fix this when using latest
"-Bbn",
username,
password)
.run();
// since registry:2 no longer contains htpasswd, generate the htpasswd file manually
loosebazooka marked this conversation as resolved.
Show resolved Hide resolved
// 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