# Google Artifact Registry - プライベートパッケージ

Google Artifact Registry に保存されたプライベートパッケージは、**Poetry、UV、NPM、PNPM、Yarn、Bun および Go の AutoFix** において AutoFix が取得できます。Google Artifact Registry への認証は、[Workload Identity Federation](https://help.aikidogov.us/docs/docs-ja/autofix-and-remediation/connect-private-packages/google-artifact-registry-private-packages#using-workload-identity-federation) または [Service Account](https://help.aikidogov.us/docs/docs-ja/autofix-and-remediation/connect-private-packages/google-artifact-registry-private-packages#using-a-service-account) を使用して行えます。

## Workload Identity Federation の使用

Workload Identity Federation を使用すると、認証情報を Aikido と共有することなく、Google Artifact Registry への読み取りロールのアクセスを Aikido に付与できます。これは、Google Artifact Registry でホストされているプライベートパッケージを設定する際の**推奨される方法**です。

### Google Cloud Console での設定

#### ステップ 1: Workload Identity Pool と AWS プロバイダーを作成する

1. Google Cloud Console を開き、[**IAM と管理** > **Workload Identity 連携**](https://console.cloud.google.com/iam-admin/workload-identity-pools)**に移動します。**
2. **+ Get Started**(すでにプールを設定済みの場合は **+ Create Pool**)をクリックします。
3. **プールに名前を付ける:** 名前として `aikido-identity-pool` を入力し、**Continue** をクリックします。
4. **プールにプロバイダーを追加する:**
   * _Select a provider_ ドロップダウンリストから **AWS** を選択します
   * **Provider name** に `aws-provider` を入力します
   * Aikido の **AWS Account ID** として `881830977366` を入力します
   * **Continue** をクリックします。
5. **プロバイダー属性を設定する:**
   * **Attribute mapping** では、Google が自動的に `google.subject` を `aws.arn` にマッピングします。デフォルトのままにするか、特定の属性を抽出したい場合は変更してください。
   * **Save** をクリックして、プールとプロバイダーを作成します。

#### ステップ 2: フェデレーション ID の JSON をダウンロードする

1. [aikido-identity-pool](http://console.cloud.google.com/iam-admin/workload-identity-pools/pool/aikido-identity-pool) の詳細に移動します
2. **+ Grant access** をクリックします
3. 「Grant access using federated identities」を使用します
4. `Download config` をクリックして、構成 JSON を取得します

#### ステップ 3: Artifact Registry でアクセスを付与する

1. [Artifact Registry](https://console.cloud.google.com/artifacts) に移動します
2. Aikido にアクセスを提供するリポジトリを選択します
3. 上部メニューの **Permissions** をクリックします(これはリポジトリを選択している場合にのみ表示されます)
4. **Add principal** をクリックします
5. **New principals** テキストボックスに次のプリンシパルを入力し、`<project-id>` を 12 桁のプロジェクト ID に置き換えます:

```
principalSet://iam.googleapis.com/projects/<project-id>/locations/global/workloadIdentityPools/aikido-identity-pool/attribute.aws_role/arn:aws:sts::881830977366:assumed-role/autofix-codeartifact-readonly-role
```

6. `Artifact Registry Reader` ロールを**割り当て**ます
7. **Save** をクリックします

### **Aikido UI での設定**

Google Artifact Registry は現在、Poetry、UV、NPM、PNPM、Yarn、Bun および Go の AutoFix でのみサポートされています。GCP の認証情報は、プライベートパッケージ設定の Google Artifact Registry セクションで設定できます。

GCP コンソールでの手順が完了したら、以下の手順に従って、プライベートレジストリで認証するように AutoFix を設定できます:

1. Aikido UI の [AutoFix > Settings](https://app.aikido.dev/issues/fix/settings) ページに移動します
2.  **+ Connect Registry** をクリックすると、設定モーダルが表示されます

    <figure><img src="https://help.aikidogov.us/_assets/96ffdad4fe3d/image-426.png" alt=""><figcaption></figcaption></figure>
3. Google Artifact Registry を選択します:\
   ![](https://help.aikidogov.us/_assets/eff330131b43/image-427.png)
4. 上記ステップ 3 で保存した **JSON config** の内容を **GCP credentials** フィールドに貼り付けます
5. **Save** をクリックして設定を保存します。

## Service Account の使用

### Google Cloud Console での設定

#### ステップ 1: Service Account を作成する

まず、Google Cloud プロジェクトで Service Account を作成します:

1. Google Cloud Console に移動します。
2. [**IAM と管理** > **サービス アカウント**](https://console.cloud.google.com/iam-admin/serviceaccounts)に移動します。
3. **Create Service Account** をクリックします。
4. `Aikido Artifact Registry Reader` などの **Service account name** を入力し、**Create And Continue** をクリックします。
5. Service Account に **Artifact Registry Reader** ロールを付与します。
6. **Continue** をクリックし、**Done** をクリックします。

#### ステップ 2: Service Account のキーを作成する <a href="#id-2-create-a-key-for-the-service-account" id="id-2-create-a-key-for-the-service-account"></a>

1. **Service Accounts** ページで、先ほど作成した Service Account を見つけます。
2. 右側の三点リーダーをクリックし、**Manage Keys** を選択します。
3. **Add Key** > **Create New Key** をクリックします。
4. **JSON** を選択し、**Create** をクリックします。
5. **JSON キーファイル**を安全な場所に保存します。

### **Aikido UI での設定**

Google Artifact Registry は現在、Poetry、UV、NPM、PNPM、Yarn、Bun および Go の AutoFix でのみサポートされています。GCP の認証情報は、プライベートパッケージ設定の Google Artifact Registry セクションで設定できます。

GCP コンソールでの手順が完了したら、以下の手順に従って、プライベートレジストリで認証するように AutoFix を設定できます:

1. Aikido UI の [AutoFix > Settings](https://app.aikido.dev/issues/fix/settings) ページに移動します
2.  **+ Connect Registry** をクリックすると、設定モーダルが表示されます

    <figure><img src="https://help.aikidogov.us/_assets/96ffdad4fe3d/image-426.png" alt=""><figcaption></figcaption></figure>
3. Google Artifact Registry を選択します:\
   ![](https://help.aikidogov.us/_assets/eff330131b43/image-427.png)
4. 上記ステップ 2 で保存した **Service Account Key** の内容を **GCP credentials** フィールドに貼り付けます
5. **Save** をクリックして設定を保存します。

### Go 向けの追加設定

Go のモジュールパスからは、どのレジストリがモジュールをホストしているかがわからないため、Go では **2 つの環境変数**が必要です。

AutoFix → Settings → Connect Registry → [Set Environment Variables](https://help.aikidogov.us/docs/docs-ja/autofix-and-remediation/connect-private-packages/custom-config-private-packages) で設定してください:

* `GOPROXY`: まず Artifact Registry の Go リポジトリを指定し、その後に公開 Go プロキシを指定します。例: `https://<location>-go.pkg.dev/<project-id>/<repository>,https://proxy.golang.org,direct`
* `GONOSUMDB`: プライベートモジュールのモジュールパス。これにより、Go が公開チェックサムデータベースに照合しないようにします。例: `github.com/<your-org>/*`&#x20;

<figure><img src="https://help.aikidogov.us/_assets/948ea8bbf512/image-448.png" alt=""><figcaption></figcaption></figure>

AutoFix は、`GOPROXY` 内のすべての `go.pkg.dev` ホストへの認証に GCP の認証情報を使用します。
