{"id":994,"library":"keyrings-google-artifactregistry-auth","title":"Keyring Backend for Google Artifact Registry Authentication","description":"keyrings.google-artifactregistry-auth is a Python package that allows you to configure keyring to interact with Python repositories stored in Google Artifact Registry. The backend automatically searches for credentials from the environment and authenticates to Artifact Registry using Google Application Default Credentials or gcloud SDK credentials. The current version is 1.1.2.","status":"active","version":"1.1.2","language":"python","source_language":"en","source_url":"https://github.com/GoogleCloudPlatform/artifact-registry-python-tools","tags":["keyring","google","artifact-registry","authentication","pypi","gcloud"],"install":[{"cmd":"pip install keyrings.google-artifactregistry-auth","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"This package is a backend for the `keyring` library, which provides OS-level credential storage.","package":"keyring","optional":false},{"reason":"Used for authenticating with Google Cloud, often via Application Default Credentials or gcloud SDK.","package":"google-auth","optional":false}],"imports":[{"note":"The backend registers itself with the `keyring` library; direct imports from `keyrings.gauth` are uncommon for end-user application logic. The backend's class name is `GooglePythonAuth` within the `keyrings.gauth` module.","symbol":"GooglePythonAuth","correct":"import keyring\n# The backend is automatically discovered by `keyring` once installed.\n# You typically don't import from keyrings.gauth directly for runtime usage.\n# To verify installation:\n# assert 'keyrings.gauth.GooglePythonAuth' in [k.name for k in keyring.get_keyring().backends]"}],"quickstart":{"code":"import os\nimport subprocess\n\n# 1. Ensure gcloud CLI is authenticated\n# Option A: Login as an end user\n# print(\"Please run: gcloud auth login\")\n# Option B: Login as a service account (recommended for CI/CD)\n# print(\"Please run: gcloud auth application-default login\")\n# Or set GOOGLE_APPLICATION_CREDENTIALS env var\n# os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/key.json'\n\n# 2. Install the backend (if not already installed)\n# For this quickstart, assume it's installed as per 'install' section.\n\n# 3. Verify the backend is listed by keyring\ntry:\n    # Using subprocess to run keyring CLI, as direct Python API usage is complex for listing backends\n    result = subprocess.run(['keyring', '--list-backends'], capture_output=True, text=True, check=True)\n    if 'keyrings.gauth.GooglePythonAuth' in result.stdout:\n        print(\"keyrings.google-artifactregistry-auth backend is successfully installed and recognized.\")\n    else:\n        print(\"Warning: keyrings.google-artifactregistry-auth backend not found in keyring --list-backends output.\")\n        print(\"Output: \", result.stdout)\nexcept FileNotFoundError:\n    print(\"Error: 'keyring' command not found. Please ensure `keyring` is installed and in your PATH.\")\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error running keyring --list-backends: {e.stderr}\")\n\n# 4. Configure pip/twine to use Artifact Registry (example for pip.conf)\n# You would typically run 'gcloud artifacts print-settings python' and copy the output.\n# Example values (replace with your own):\n# project_id = os.environ.get('GCP_PROJECT_ID', 'your-gcp-project-id')\n# repository_id = os.environ.get('AR_REPOSITORY_ID', 'your-repo-id')\n# location = os.environ.get('GCP_REGION', 'us-central1')\n# \n# print(f\"\\nTo configure pip, run: \")\n# print(f\"gcloud artifacts print-settings python --project={project_id} --repository={repository_id} --location={location}\")\n# print(\"Then add the extra-index-url to your pip.conf or requirements.txt\")","lang":"python","description":"The quickstart involves three main steps: authenticating your `gcloud` CLI (which the keyring backend uses), installing the `keyrings.google-artifactregistry-auth` package, and then configuring your Python tools (like `pip` or `twine`) to use your Artifact Registry repository. The backend automatically leverages your active `gcloud` credentials."},"warnings":[{"fix":"Upgrade `keyrings.google-artifactregistry-auth` to a newer version that addresses this, or pin `keyring<=23.8.2` as a temporary workaround.","message":"Installing `keyring` version 23.9.0 caused `keyrings.google-artifactregistry-auth` to fail due to a missing `keyring.util.properties` module.","severity":"breaking","affected_versions":"keyring==23.9.0"},{"fix":"Roll back `google-auth` to version 2.40.3 or earlier (`google-auth==2.40.3`).","message":"Using `google-auth` version 2.41.1 with this keyring backend can lead to 'No credentials could be found' errors when fetching credentials from GCP Artifact Registry.","severity":"breaking","affected_versions":"google-auth==2.41.1"},{"fix":"Ensure only one primary authentication method is active. If encountering issues, try `gcloud auth revoke --all` to clear conflicting credentials.","message":"Mixing user credentials (`gcloud auth login`) and service account credentials (via `GOOGLE_APPLICATION_CREDENTIALS` or `gcloud auth application-default login`) simultaneously can cause authentication conflicts.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use Docker's secret volume mounts (`--secret`) to securely pass credentials during the build process.","message":"When building Docker images, passing sensitive information like `ARTIFACT_REGISTRY_TOKEN` via `--build-arg` is insecure as it remains in the image metadata.","severity":"gotcha","affected_versions":"All versions (Docker build practices)"},{"fix":"Investigate Databricks-specific configuration or environment issues. It may require direct intervention to ensure the keyring backend is properly registered and accessible by the Python environment.","message":"On Databricks runtimes greater than 10.4, the `GooglePythonAuth` keyring backend may not be correctly set up or recognized, even if the package is installed.","severity":"gotcha","affected_versions":"Databricks Runtimes > 10.4"},{"fix":"Migrate to Python 3. If Python 2 is unavoidable, use `keyrings.google-artifactregistry-auth-py2` and be aware it might not receive the same level of updates or support.","message":"A separate package, `keyrings.google-artifactregistry-auth-py2`, exists for Python 2 compatibility. The main `keyrings.google-artifactregistry-auth` package is for Python 3.","severity":"deprecated","affected_versions":"Python 2 projects"}],"env_vars":null,"last_verified":"2026-05-12T22:26:41.998Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Upgrade `pip` to a recent version: `pip install -U pip`.","cause":"An outdated `pip` version is trying to build the `cryptography` dependency from source instead of using a pre-built wheel, and the system lacks a Rust compiler.","error":"error: can't find Rust compiler\nIf you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler. To update pip, run: pip install --upgrade pip and then retry package installation. If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain. This package requires Rust >=1.41.0."},{"fix":"Authenticate using `gcloud auth application-default login` or set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to a service account key file path. Ensure the authenticated identity has necessary Artifact Registry permissions.","cause":"The `keyrings.google-artifactregistry-auth` backend could not locate valid Google Cloud credentials via Application Default Credentials (ADC) or the `gcloud` CLI.","error":"Artifact Registry PyPI Keyring: No credentials could be found.\nFailed to find credentials, Please run: `gcloud auth application-default login or export GOOGLE_APPLICATION_CREDENTIALS=<path/to/service/account/key>`"},{"fix":"Ensure `keyring` and `keyrings.google-artifactregistry-auth` are installed (`pip install keyring keyrings.google-artifactregistry-auth`) and verify the backend is active using `keyring --list-backends`. For Python 3.12+, explicitly verify the backend with `python -m keyrings.google_artifactregistry_auth`.","cause":"The `keyrings.google-artifactregistry-auth` backend is installed but not correctly configured or activated, leading pip/twine to default to basic authentication prompts.","error":"User for <artifact-registry-url>: (prompt for username/password by pip or twine)"},{"fix":"Consolidate to a single authentication method. If using a service account, rely on `GOOGLE_APPLICATION_CREDENTIALS`. If using user credentials, ensure only `gcloud auth application-default login` (or `gcloud auth login` for interactive use) is used, and revoke conflicting credentials if necessary (`gcloud auth revoke --all`).","cause":"The user might have configured conflicting authentication methods (e.g., `GOOGLE_APPLICATION_CREDENTIALS` and `gcloud auth login`), causing the keyring to use unintended or insufficient credentials.","error":"Keyring authentication to Artifact Repository not working (GCP)"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.1.2","cli_name":"","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.17,"mem_mb":7,"disk_size":"45.0M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.2,"mem_mb":7,"disk_size":"43.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4.5,"import_time_s":0.12,"mem_mb":7,"disk_size":"45M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.12,"mem_mb":7,"disk_size":"44M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.26,"mem_mb":8,"disk_size":"48.5M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.3,"mem_mb":8,"disk_size":"47.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":4.4,"import_time_s":0.25,"mem_mb":8,"disk_size":"49M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.22,"mem_mb":8,"disk_size":"48M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":8,"disk_size":"39.4M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":8,"disk_size":"38.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.6,"import_time_s":0.22,"mem_mb":8,"disk_size":"40M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.23,"mem_mb":8,"disk_size":"39M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.21,"mem_mb":8.3,"disk_size":"39.1M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.22,"mem_mb":8.3,"disk_size":"37.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":3.5,"import_time_s":0.21,"mem_mb":8.3,"disk_size":"40M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.22,"mem_mb":8.3,"disk_size":"38M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.15,"mem_mb":6.7,"disk_size":"45.0M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.16,"mem_mb":6.7,"disk_size":"43.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":5.4,"import_time_s":0.15,"mem_mb":6.7,"disk_size":"45M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.14,"mem_mb":6.7,"disk_size":"44M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}