1
0
Fork 0
mirror of https://github.com/imjasonh/krust synced 2026-07-08 14:55:35 +00:00

implement auth

Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
Jason Hall 2025-10-15 08:51:46 -04:00
parent 9d788792ca
commit 5d730a36da
8 changed files with 410 additions and 27 deletions

34
tests/testdata/auth_base64.txt vendored Normal file
View file

@ -0,0 +1,34 @@
# Test base64 encoded auth from Docker config
# Create a test project
-- Cargo.toml --
[package]
name = "auth-b64-test"
version = "0.1.0"
edition = "2021"
[dependencies]
-- src/main.rs --
fn main() {
println!("Testing base64 auth");
}
# Create Docker config with base64 auth (testuser:testpass = dGVzdHVzZXI6dGVzdHBhc3M=)
mkdir .docker
-- .docker/config.json --
{
"auths": {
"ghcr.io": {
"auth": "dGVzdHVzZXI6dGVzdHBhc3M="
}
}
}
# Set HOME to use our config
env HOME=$WORK
env RUST_LOG=debug
# Try to build (will fail at registry, but auth should be resolved)
! exec ./krust build --platform linux/amd64 --image ghcr.io/user/app:latest .
stderr 'Resolving auth'
stderr 'ghcr.io'

View file

@ -0,0 +1,62 @@
# Test credential helper execution
# Create a mock credential helper that logs when it's called
-- docker-credential-mock --
#!/bin/sh
# Mock credential helper that logs execution and returns test credentials
# Log that we were called
echo "MOCK_HELPER_CALLED" >&2
case "$1" in
get)
# Read registry from stdin
read registry
echo "MOCK_HELPER_REGISTRY=$registry" >&2
# Return credentials
cat <<EOF
{
"Username": "helper-user",
"Secret": "helper-pass"
}
EOF
;;
*)
exit 1
;;
esac
-- Cargo.toml --
[package]
name = "cred-helper-test"
version = "0.1.0"
edition = "2021"
[dependencies]
-- src/main.rs --
fn main() {
println!("Testing credential helper");
}
# Make the helper executable
chmod +x docker-credential-mock
# Create Docker config that uses our mock helper
mkdir .docker
-- .docker/config.json --
{
"credHelpers": {
"mock.registry.io": "mock"
}
}
# Add current dir to PATH and set HOME
env HOME=$WORK
env PATH=$WORK:$PATH
env RUST_LOG=debug
# Try to push to mock.registry.io (will fail at network level, but should call helper)
# Using --no-push to avoid actual network call
! exec ./krust build --platform linux/amd64 --image mock.registry.io/test:latest .
# Should see the helper being attempted
stderr 'credential helper'

View file

@ -0,0 +1,36 @@
# Test basic auth from Docker config
# Create a test project
-- Cargo.toml --
[package]
name = "auth-basic-test"
version = "0.1.0"
edition = "2021"
[dependencies]
-- src/main.rs --
fn main() {
println!("Testing basic auth");
}
# Create Docker config with username/password
mkdir .docker
-- .docker/config.json --
{
"auths": {
"test.example.com": {
"username": "myuser",
"password": "mypass"
}
}
}
# Set HOME to use our config
env HOME=$WORK
env RUST_LOG=debug
# Try to build and push (will fail at registry level, but auth should be resolved)
# We can verify auth was read from config in debug logs
! exec ./krust build --platform linux/amd64 --image test.example.com/app:latest .
stderr 'Resolving auth'
stderr 'test.example.com'