-
Notifications
You must be signed in to change notification settings - Fork 175
WIP: Fallback to running system's auth.json #1934
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,3 +23,88 @@ export def have_hostexports [] { | |
| export def parse_cmdline [] { | ||
| open /proc/cmdline | str trim | split row " " | ||
| } | ||
|
|
||
| # cstor-dist configuration for authenticated registry testing | ||
| # cstor-dist serves images from containers-storage via an authenticated OCI registry endpoint | ||
| # https://github.com/ckyrouac/cstor-dist | ||
| const CSTOR_DIST_IMAGE = "ghcr.io/ckyrouac/cstor-dist:latest" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably be good moving cstor-dist into the bootc-dev org |
||
| const CSTOR_DIST_USER = "testuser" | ||
| const CSTOR_DIST_PASS = "testpass" | ||
| const CSTOR_DIST_PORT = 8000 | ||
|
|
||
| # The registry address for cstor-dist | ||
| export const CSTOR_DIST_REGISTRY = $"localhost:($CSTOR_DIST_PORT)" | ||
|
|
||
| # Start cstor-dist with basic auth on localhost | ||
| # Fails if cstor-dist cannot be started | ||
| export def start_cstor_dist [] { | ||
| print "Starting cstor-dist with basic auth..." | ||
|
|
||
| # Pull test images that cstor-dist will serve | ||
| print "Pulling test images for cstor-dist to serve..." | ||
| podman pull docker.io/library/alpine:latest | ||
| podman pull docker.io/library/busybox:latest | ||
|
|
||
| # Run cstor-dist container with auth enabled | ||
| # Mount the local containers storage so cstor-dist can serve images from it | ||
| let storage_path = if ("/var/lib/containers/storage" | path exists) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be done by querying the |
||
| "/var/lib/containers/storage" | ||
| } else { | ||
| $"($env.HOME)/.local/share/containers/storage" | ||
| } | ||
|
|
||
| (podman run --privileged --rm -d --name cstor-dist-auth | ||
| -p $"($CSTOR_DIST_PORT):8000" | ||
| -v $"($storage_path):/var/lib/containers/storage" | ||
| $CSTOR_DIST_IMAGE --username $CSTOR_DIST_USER --password $CSTOR_DIST_PASS) | ||
|
|
||
| # Wait for cstor-dist to be ready by testing HTTP connection | ||
| # Loop for up to 20 seconds | ||
| print "Waiting for cstor-dist to be ready..." | ||
| let auth_header = $"($CSTOR_DIST_USER):($CSTOR_DIST_PASS)" | encode base64 | ||
| mut ready = false | ||
| for i in 1..20 { | ||
| let result = do { curl -sf -H $"Authorization: Basic ($auth_header)" $"http://($CSTOR_DIST_REGISTRY)/v2/" } | complete | ||
| if $result.exit_code == 0 { | ||
| $ready = true | ||
| break | ||
| } | ||
| print $"Attempt ($i)/20: cstor-dist not ready yet..." | ||
| sleep 1sec | ||
| } | ||
|
|
||
| if not $ready { | ||
| # Show container logs for debugging | ||
| print "cstor-dist failed to start. Container logs:" | ||
| podman logs cstor-dist-auth | ||
| error make { msg: "cstor-dist failed to become ready within 20 seconds" } | ||
| } | ||
|
|
||
| print $"cstor-dist running on ($CSTOR_DIST_REGISTRY)" | ||
| } | ||
|
|
||
| # Get cstor-dist auth config | ||
| export def get_cstor_auth [] { | ||
| # Base64 encode the credentials for auth.json | ||
| let auth_b64 = $"($CSTOR_DIST_USER):($CSTOR_DIST_PASS)" | encode base64 | ||
| { | ||
| registry: $CSTOR_DIST_REGISTRY, | ||
| auth_b64: $auth_b64 | ||
| } | ||
| } | ||
|
|
||
| # Configure insecure registry for cstor-dist (no TLS) | ||
| export def setup_insecure_registry [] { | ||
| mkdir /etc/containers/registries.conf.d | ||
| (echo $"[[registry]]\nlocation=\"($CSTOR_DIST_REGISTRY)\"\ninsecure=true" | ||
| | save -f /etc/containers/registries.conf.d/99-cstor-dist.conf) | ||
| } | ||
|
|
||
| # Set up auth.json on the running system with cstor-dist credentials | ||
| export def setup_system_auth [] { | ||
| mkdir /run/ostree | ||
| let cstor = get_cstor_auth | ||
| print $"Setting up system auth for cstor-dist at ($cstor.registry)" | ||
| let auth_json = $'{"auths": {"($cstor.registry)": {"auth": "($cstor.auth_b64)"}}}' | ||
| echo $auth_json | save -f /run/ostree/auth.json | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
if let ... else if let ...chain can be simplified by combining the fallback logic into a singleelseblock, which makes the code slightly more concise.