🌐 Как ΡΠΎΡΡ‚Π°Π²ΠΈΡ‚ΡŒ список ΠΎΠ±Ρ€Π°Π·ΠΎΠ² Docker Π² рСдТСстри GitLab

Как ΠΏΠ΅Ρ€Π΅Ρ‡ΠΈΡΠ»ΠΈΡ‚ΡŒ список ΠΎΠ±Ρ€Π°Π·ΠΎΠ² Docker Π² рССстрС GitLab

by itisgood
Бписок ΠΎΠ±Ρ€Π°Π·ΠΎΠ² Docker Π² рСдТСстри GitLab.
Π­Ρ‚ΠΎΡ‚ ΠΌΠ΅Ρ‚ΠΎΠ΄ Π½Π°ΠΏΡ€ΡΠΌΡƒΡŽ обращаСтся ΠΊ рСдТСстри GitLab.
Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ ΠΏΠ΅Ρ€ΡΠΎΠ½Π°Π»ΡŒΠ½Ρ‹ΠΉ Ρ‚ΠΎΠΊΠ΅Π½ доступа с ΠΎΠ±Π»Π°ΡΡ‚ΡŒΡŽ read_registry.
Π‘ΠΎΠ·Π΄Π°ΠΉΡ‚Π΅ shell скрипт, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π±ΡƒΠ΄Π΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ для доступа ΠΊ рССстру GitLab.
Для этого ΠΏΠΎΡ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ΡΡ ΡƒΡ‚ΠΈΠ»ΠΈΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строки curl ΠΈ jq.
#!/usr/bin/env bash
# Display GitLab registry containers
#
# Create Personal Access Token with read_registry scope
#
# Define shell variables:
#   export GITLAB_USERNAME=milosz
#   export GITLAB_TOKEN="glpat-qhP3QBpSMXLUysvserXY"
#   export GITLAB_ADDRESS="https://gitlab.example.org"
#   export GITLAB_REGISTRY_ADDRESS="https://registry.example.org"

# Check required shell variables
if [ -n "$GITLAB_USERNAME" ] && [ -n "$GITLAB_TOKEN" ] && [ -n "$GITLAB_ADDRESS" ]; then
  # Check GitLab and its registry addresses
  curl --output /dev/null --silent --head --fail "$GITLAB_ADDRESS" || { echo "GitLab is not responding"; exit 1; }
  curl --output /dev/null --silent --head --fail "$GITLAB_REGISTRY_ADDRESS" || { echo "Registry is not responding"; exit 1; }

  # Get JWT token that grants access to registry catalog
  token="$(curl --silent --request GET --user "${GITLAB_USERNAME}:${GITLAB_TOKEN}" \
                "${GITLAB_ADDRESS}/jwt/auth?service=container_registry&scope=registry:catalog:*" | \
           jq --raw-output .token)"

  if [ -n "$token" ] && [ "$token" != "null" ]; then
    # Get repositories
    repositories="$(curl --silent --header "Authorization: Bearer $token" \
                         "${GITLAB_REGISTRY_ADDRESS}/v2/_catalog" | \
                    jq --raw-output ".repositories[]")"

    for repository in $repositories; do
      echo "Repository: $repository"

      # Get JWT token that grants pull access to the specific repository
      token="$(curl --silent --request GET --user "${GITLAB_USERNAME}:${GITLAB_TOKEN}" \
                    "${GITLAB_ADDRESS}/jwt/auth?service=container_registry&scope=repository:{$repository}:pull" | \
               jq --raw-output .token)"

      if [ -n "$token" ] && [ "$token" != "null" ]; then
        # Get tags
        tags="$(curl --silent --header "Authorization: Bearer $token" \
                     "https://registry.awesomebeastie.eu/v2/${repository}/tags/list" | \
                jq --raw-output .tags[])"

          echo "Tagged:"
        for tag in $tags; do
            echo "  - $tag"
        done
        echo
      else
        echo "Unable to retrieve the JWT token. Please verify your credentials and try again."
      fi
    done
  else
    echo "Unable to retrieve the JWT token. Please verify your credentials and try again."
  fi
fi
ЭкспортируйтС Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹Π΅ ΠΏΠ΅Ρ€Π΅ΠΌΠ΅Π½Π½Ρ‹Π΅ ΠΎΠ±ΠΎΠ»ΠΎΡ‡ΠΊΠΈ.
export GITLAB_USERNAME=milosz
export GITLAB_TOKEN="glpat-qhP3QBpSMXLUysvserXY"
export GITLAB_ADDRESS="https://gitlab.example.org"
export GITLAB_REGISTRY_ADDRESS="https://registry.example.org"

Π’Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚Π΅ Π΅Π³ΠΎ.

$ inspect_registry.sh 
Repository: containers/ansible
Tagged:
  - 9.3.0

Repository: containers/hugo
Tagged:
  - 0.122.0-r0
  - latest

Repository: containers/rust
Tagged:
  - 1.76.0-alpine

Repository: sandbox/alpine-cache-nexus
Tagged:
  - utilities

Repository: sandbox/alpine-cache
Tagged:
  - basic
  - utilities

API GitLab ΠΏΡ€Π΅Π΄Π»Π°Π³Π°Π΅Ρ‚ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ подробности, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΡ‹ рассмотрим ΠΏΠΎΠ·ΠΆΠ΅.

см. Ρ‚Π°ΠΊΠΆΠ΅:

🦊 GitLab настройка 2FA для всСх ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ

 

 

Loading

You may also like

Leave a Comment