En este documento, se describe cómo autenticarte en fuentes ascendentes para tu Repositorios remotos de Artifact Registry
En este documento, se supone que ya creaste un repositorio de Artifact Registry repositorio remoto y tener una cuenta con el fuente.
Para obtener más información sobre repositorios remotos, consulta el Descripción general de los repositorios remotos.
Roles obligatorios
Para obtener los permisos que necesitas a la hora de configurar la autenticación de fuentes ascendentes para repositorios remotos, solicita a tu administrador que te otorgue el los siguientes roles de IAM en el proyecto:
-
Administrador de Artifact Registry (
roles/artifactregistry.admin
) -
Administrador de Secret Manager (
roles/secretmanager.admin
)
Si quieres obtener más información para otorgar roles, consulta Administra el acceso.
También puedes obtener los permisos necesarios mediante roles personalizados o cualquier otro rol predefinido.
Fuentes upstream predeterminadas
Para configurar la autenticación de fuentes ascendentes predeterminadas, consulta el documento de una guía para cada upstream que sigue:
Fuentes upstream definidas por el usuario
Para configurar la autenticación de las fuentes ascendentes definidas por el usuario, completa los los siguientes pasos.
Guarda tu token de acceso en un Secret
- Crea un token de acceso en el registro privado.
- Crea un secreto en Secret Manager.
- Guarda tu token de acceso personal como una versión del secreto.
Otorga a la cuenta de servicio de Artifact Registry acceso a tu secreto.
El agente de servicio de Artifact Registry actúa en nombre de Artifact Registry cuando interactúa con los servicios de Google Cloud. Para permitir que el agente de servicio use Secrets de Cloud Storage en Secret Manager, debes otorgarle al agente de servicio para ver tu versión del Secret.
El identificador del agente de servicio es el siguiente:
service-PROJECT-NUMBER@gcp-sa-artifactregistry.iam.gserviceaccount.com
PROJECT-NUMBER es el número de proyecto del proyecto de Google Cloud en el que se ejecuta Artifact Registry.
Para otorgar al agente de servicio de Artifact Registry el Acceso a secretos de Secret Manager rol:
Console
-
Ve a la página Secret Manager en la consola de Google Cloud.
-
En la página Secret Manager, haz clic en la casilla de verificación junto al nombre del secreto.
-
Si aún no está abierto, haz clic en Mostrar panel de información para abrir el panel.
-
En el panel de información, haz clic en Agregar principal.
-
En el área de texto Principales nuevas, ingresa las direcciones de correo electrónico de los miembros que quieres agregar.
-
En el menú desplegable Selecciona una función, selecciona Secret Manager y, luego, Administrador y descriptor de acceso a Secretos.
gcloud
$ gcloud secrets add-iam-policy-binding secret-id \
--member="member" \
--role="roles/secretmanager.secretAccessor"
En el ejemplo anterior, member es un miembro de IAM, como un usuario, un grupo o una cuenta de servicio.
C#
Para autenticarte en Artifact Registry, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.
Go
Para autenticarte en Artifact Registry, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.
Java
Para autenticarte en Artifact Registry, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.
Node.js
Para autenticarte en Artifact Registry, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.
PHP
Para autenticarte en Artifact Registry, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.
Python
Para autenticarte en Artifact Registry, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.
Ruby
Para autenticarte en Artifact Registry, configura las credenciales predeterminadas de la aplicación. Si deseas obtener más información, consulta Configura la autenticación para un entorno de desarrollo local.
API
Nota: A diferencia de los otros ejemplos, esto reemplaza la política de IAM completa.
$ curl "https://secretmanager.googleapis.com/v1/projects/project-id/secrets/secret-id:setIamPolicy" \
--request "POST" \
--header "authorization: Bearer $(gcloud auth print-access-token)" \
--header "content-type: application/json" \
--data "{\"policy\": {\"bindings\": [{\"members\": [\"member\"], \"role\": \"roles/secretmanager.secretAccessor\"}]}}"
Para obtener más información sobre cómo otorgar o revocar el acceso a los Secrets, consulta Administra el acceso a los secretos.
Agrega credenciales upstream a tu repositorio remoto
Para actualizar tu repositorio remoto con tus credenciales de origen upstream:
Console
Abre la página Repositorios en la consola de Google Cloud.
En la lista de repositorios, selecciona el repositorio y haz clic en Edita el repositorio.
En la sección Modo de autenticación de repositorio remoto, actualiza o agrega tu nombre de usuario de origen upstream y el secreto que contiene tu token de acceso.
gcloud CLI
Para actualizar tu repositorio remoto con tus credenciales de origen upstream, ejecuta lo siguiente: el siguiente comando:
gcloud artifacts repositories update REPOSITORY \
--project=PROJECT_ID \
--location=LOCATION \
--remote-username=USERNAME \
--remote-password-secret-version=projects/SECRET_PROJECT_ID/secrets/SECRET_ID/versions/SECRET_VERSION
Reemplaza lo siguiente:
REPOSITORY
por el nombre del recurso remoto de Artifact Registry en un repositorio de confianza.PROJECT_ID
por el ID del proyecto de Google CloudLOCATION
por la configuración regional o multirregional location para el repositorio. Puedes omitir esta marca si estableces un valor predeterminado. Cómo ver una lista de ubicaciones compatibles, ejecuta el comandogcloud artifacts locations list
.USERNAME
por tu nombre de usuario de origen upstreamSECRET_PROJECT_ID
por el ID del proyecto en la que creaste el Secret.SECRET_ID
por el nombre que le asignaste a tu secreto.SECRET_VERSION
por la versión del secreto que guardaste para ingresar el token de acceso.
Tus credenciales se usarán la próxima vez que el repositorio remoto envíe una solicitud para un artefacto de la fuente upstream.
¿Qué sigue?
- Crea políticas de limpieza para borrar artefactos innecesarios.