Skip to content

Commit d23f641

Browse files
Merge pull request containers#6264 from flouthoc/passwd-test
buildah: move `passwd` command to tests
2 parents f67acf9 + 063ee76 commit d23f641

File tree

7 files changed

+67
-36
lines changed

7 files changed

+67
-36
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export GOLANGCI_LINT_VERSION := 2.1.0
5959
# Note: Uses the -N -l go compiler options to disable compiler optimizations
6060
# and inlining. Using these build options allows you to subsequently
6161
# use source debugging tools like delve.
62-
all: bin/buildah bin/imgtype bin/copy bin/inet bin/tutorial bin/dumpspec docs
62+
all: bin/buildah bin/imgtype bin/copy bin/inet bin/tutorial bin/dumpspec bin/passwd docs
6363

6464
bin/buildah: $(SOURCES) internal/mkcw/embed/entrypoint_amd64.gz
6565
$(GO_BUILD) $(BUILDAH_LDFLAGS) $(GO_GCFLAGS) "$(GOGCFLAGS)" -o $@ $(BUILDFLAGS) ./cmd/buildah
@@ -106,6 +106,9 @@ bin/tutorial: $(SOURCES)
106106
bin/inet: tests/inet/inet.go
107107
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/inet/inet.go
108108

109+
bin/passwd: tests/passwd/passwd.go
110+
$(GO_BUILD) $(BUILDAH_LDFLAGS) -o $@ $(BUILDFLAGS) ./tests/passwd/passwd.go
111+
109112
.PHONY: clean
110113
clean:
111114
$(RM) -r bin tests/testreport/testreport tests/conformance/testdata/mount-targets/true

cmd/buildah/passwd.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

rpm/buildah.spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export BUILDTAGS+=" libtrust_openssl"
138138
%gobuild -o bin/tutorial ./tests/tutorial
139139
%gobuild -o bin/inet ./tests/inet
140140
%gobuild -o bin/dumpspec ./tests/dumpspec
141+
%gobuild -o bin/passwd ./tests/passwd
141142
%{__make} docs
142143

143144
%install
@@ -150,6 +151,7 @@ cp bin/copy %{buildroot}/%{_bindir}/%{name}-copy
150151
cp bin/tutorial %{buildroot}/%{_bindir}/%{name}-tutorial
151152
cp bin/inet %{buildroot}/%{_bindir}/%{name}-inet
152153
cp bin/dumpspec %{buildroot}/%{_bindir}/%{name}-dumpspec
154+
cp bin/passwd %{buildroot}/%{_bindir}/%{name}-passwd
153155

154156
rm %{buildroot}%{_datadir}/%{name}/test/system/tools/build/*
155157

@@ -175,6 +177,7 @@ rm %{buildroot}%{_datadir}/%{name}/test/system/tools/build/*
175177
%{_bindir}/%{name}-tutorial
176178
%{_bindir}/%{name}-inet
177179
%{_bindir}/%{name}-dumpspec
180+
%{_bindir}/%{name}-passwd
178181
%{_datadir}/%{name}/test
179182

180183
%changelog

tests/helpers.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ COPY_BINARY=${COPY_BINARY:-$TEST_SOURCES/../bin/copy}
99
TUTORIAL_BINARY=${TUTORIAL_BINARY:-$TEST_SOURCES/../bin/tutorial}
1010
INET_BINARY=${INET_BINARY:-$TEST_SOURCES/../bin/inet}
1111
DUMPSPEC_BINARY=${DUMPSPEC_BINARY:-$TEST_SOURCES/../bin/dumpspec}
12+
PASSWD_BINARY=${PASSWD_BINARY:-$TEST_SOURCES/../bin/passwd}
1213
STORAGE_DRIVER=${STORAGE_DRIVER:-vfs}
1314
PATH=$(dirname ${BASH_SOURCE})/../bin:${PATH}
1415
OCI=${BUILDAH_RUNTIME:-$(${BUILDAH_BINARY} info --format '{{.host.OCIRuntime}}' || command -v runc || command -v crun)}
@@ -833,7 +834,7 @@ auth:
833834
'
834835
# roughly equivalent to "htpasswd -nbB testuser testpassword", the registry uses
835836
# the same package this does for verifying passwords against hashes in htpasswd files
836-
htpasswd=${testuser}:$(buildah passwd ${testpassword})
837+
htpasswd=${testuser}:$(${PASSWD_BINARY} ${testpassword})
837838

838839
# generate the htpasswd and config.yml files for the registry
839840
mkdir -p "${TEST_SCRATCH_DIR}"/registry/root "${TEST_SCRATCH_DIR}"/registry/run "${TEST_SCRATCH_DIR}"/registry/certs "${TEST_SCRATCH_DIR}"/registry/config

tests/passwd/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# passwd
2+
3+
A standalone password hashing tool for buildah tests.
4+
5+
## Purpose
6+
7+
This tool generates bcrypt password hashes and is used exclusively for testing purposes. It was previously part of the main buildah command as a hidden `passwd` subcommand but has been split out into a separate tool to:
8+
9+
- Keep the main buildah command clean of test-only functionality
10+
- Allow tests to use password hashing independently
11+
- Follow the same pattern as other test tools like `imgtype`
12+
13+
## Usage
14+
15+
```bash
16+
passwd <password>
17+
```
18+
19+
## Example
20+
21+
```bash
22+
$ passwd testpassword
23+
$2a$10$ZamosnV9dfpTJn4Uk.Xix.5nwbKNiLw8xpP/6g2z83jhY.WKZuRjG
24+
```
25+
26+
The tool outputs a bcrypt hash of the input password to stdout, which can be used in test scenarios that require password hashing (such as setting up test registries with HTTP basic authentication).
27+
28+
## Building
29+
30+
The tool is built automatically when running `make all` or can be built individually with:
31+
32+
```bash
33+
make bin/passwd
34+
```

tests/passwd/passwd.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"golang.org/x/crypto/bcrypt"
8+
)
9+
10+
func main() {
11+
if len(os.Args) != 2 {
12+
fmt.Fprintf(os.Stderr, "Usage: %s <password>\n", os.Args[0])
13+
fmt.Fprintf(os.Stderr, "Generate a password hash using golang.org/x/crypto/bcrypt.\n")
14+
os.Exit(1)
15+
}
16+
17+
passwd, err := bcrypt.GenerateFromPassword([]byte(os.Args[1]), bcrypt.DefaultCost)
18+
if err != nil {
19+
fmt.Fprintf(os.Stderr, "Error generating password hash: %v\n", err)
20+
os.Exit(1)
21+
}
22+
fmt.Println(string(passwd))
23+
}

tests/tmt/system.fmf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ environment:
1010
COPY_BINARY: /usr/bin/buildah-copy
1111
TUTORIAL_BINARY: /usr/bin/buildah-tutorial
1212
DUMPSPEC_BINARY: /usr/bin/buildah-dumpspec
13+
PASSWD_BINARY: /usr/bin/buildah-passwd
1314
TMPDIR: /var/tmp
1415

1516
adjust:

0 commit comments

Comments
 (0)