列出憑證授權單位

本頁說明如何列出Google Cloud 專案中的憑證授權單位 (CA)。

列出根 CA

本節說明如何查看根 CA。

列出各 CA 集區的根 CA

如要列出所有 CA 集區中的所有根 CA,請按照下列步驟操作:

控制台

  1. 前往 Google Cloud 控制台的「憑證授權單位」頁面。

    前往「憑證授權單位」

  2. 在「Filter」(篩選器) 欄位中,選取清單中的「Type」(類型)

  3. 將「Type」(類型) 的值設為「Root」(根)

系統會列出「類型」設為「根」的所有 CA。

gcloud

執行下列指令:

gcloud privateca roots list --location LOCATION

LOCATION 替換為根 CA 的位置。如需完整的位置清單,請參閱「位置」。

列出特定 CA 集區中的根 CA

如要列出特定 CA 集區中的所有根 CA,請按照下列指示操作:

控制台

  1. 前往「憑證授權單位」頁面。

    前往「憑證授權單位」

  2. 在「Filter」(篩選器) 欄位中,選取清單中的「Type」(類型)

  3. 將「Type」(類型) 的值設為「Root」(根)

  4. 在「Filter」(篩選器) 欄位中,從清單選取「Pool」(集區)

  5. 在清單中按一下 CA 集區名稱。

gcloud

執行下列指令:

gcloud privateca roots list --pool POOL_ID --location LOCATION

更改下列內容:

  • POOL_ID:CA 集區的名稱。
  • LOCATION:CA 集區的位置。如需完整的位置清單,請參閱「位置」。

如要列出所有 CA 集區和位置的根 CA,請從指令中省略 --pool--location 標記。

如要進一步瞭解 gcloud privateca roots list 指令,請參閱 gcloud privateca roots list

列出從屬 CA

本節說明如何查看下層 CA。

列出 CA 集區中的從屬 CA

如要列出 CA 集區中的所有從屬 CA,請執行下列步驟:

控制台

  1. 前往「憑證授權單位」頁面。

    前往「憑證授權單位」

  2. 在「Filter」(篩選器) 欄位中,選取清單中的「Type」(類型)

  3. 將「類型」的值設為「下屬」

系統會列出「類型」設為「從屬」的所有 CA。

gcloud

執行下列指令:

gcloud privateca subordinates list --location LOCATION

LOCATION 替換為下層 CA 的位置。如需完整地點清單,請參閱「地點」。

列出特定 CA 集區中的從屬 CA

如要列出特定 CA 集區中的所有下層 CA,請執行下列步驟:

控制台

  1. 前往「憑證授權單位」頁面。

    前往「憑證授權單位」

  2. 在「Filter」(篩選器) 欄位中,選取清單中的「Type」(類型)

  3. 將「類型」的值設為「下屬」

  4. 在「Filter」(篩選器) 欄位中,選取清單中的「Pool」(集區)

  5. 在清單中按一下 CA 集區名稱。

gcloud

執行下列指令:

gcloud privateca subordinates list --pool POOL_ID --location LOCATION 

更改下列內容:

  • POOL_ID:CA 集區的名稱。
  • LOCATION:CA 集區的位置。如需完整的位置清單,請參閱「位置」。

如要進一步瞭解 gcloud privateca subordinates list 指令,請參閱 gcloud privateca subordinates list

列出所有 CA

如要列出 CA 集區中的所有 CA,請按照下列指示操作:

控制台

  1. 前往「憑證授權單位」頁面。

    前往「憑證授權單位」

  2. 在「Filter」(篩選器) 欄位中,選取清單中的「Pool」(集區)

  3. 在清單中按一下 CA 集區名稱。

此外,您也可以在「CA pool manager」(CA 集區管理員) 頁面中查看特定 CA 集區中的 CA,步驟如下:

  1. 按一下「CA pool manager」(CA 集區管理員) 分頁標籤。
  2. 在「CA pools」(CA 集區) 頁面中,按一下要查看 CA 的 CA 集區名稱。

在「CA pool」(CA 集區) 詳細資料頁面中,您可以在「Certificate authorities in pool」(集區中的憑證授權單位) 下方看到列出的 CA。您可以依據類型、層級、位置、狀態等條件篩選 CA。

Go

如要向 CA 服務進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

import (
	"context"
	"fmt"
	"io"

	privateca "cloud.google.com/go/security/privateca/apiv1"
	"cloud.google.com/go/security/privateca/apiv1/privatecapb"
	"google.golang.org/api/iterator"
)

// List all Certificate Authorities present in the given CA Pool.
func listCas(w io.Writer, projectId string, location string, caPoolId string) error {
	// projectId := "your_project_id"
	// location := "us-central1"	// For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.
	// caPoolId := "ca-pool-id"		// The id of the CA pool under which the CAs to be listed are present.

	ctx := context.Background()
	caClient, err := privateca.NewCertificateAuthorityClient(ctx)
	if err != nil {
		return fmt.Errorf("NewCertificateAuthorityClient creation failed: %w", err)
	}
	defer caClient.Close()

	fullCaPoolName := fmt.Sprintf("projects/%s/locations/%s/caPools/%s", projectId, location, caPoolId)

	// Create the ListCertificateAuthorities.
	// See https://pkg.go.dev/cloud.google.com/go/security/privateca/apiv1/privatecapb#ListCertificateAuthoritiesRequest.
	req := &privatecapb.ListCertificateAuthoritiesRequest{Parent: fullCaPoolName}

	it := caClient.ListCertificateAuthorities(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("unable to get the list of cerficate authorities: %w", err)
		}

		fmt.Fprintf(w, " - %s (state: %s)", resp.Name, resp.State.String())
	}

	return nil
}

Java

如要向 CA 服務進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。


import com.google.cloud.security.privateca.v1.CaPoolName;
import com.google.cloud.security.privateca.v1.CertificateAuthority;
import com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient;
import java.io.IOException;

public class ListCertificateAuthorities {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    // location: For a list of locations, see:
    // https://cloud.google.com/certificate-authority-service/docs/locations
    // poolId: The id of the CA pool under which the CAs to be listed are present.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    listCertificateAuthority(project, location, poolId);
  }

  // List all Certificate authorities present in the given CA Pool.
  public static void listCertificateAuthority(String project, String location, String poolId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `certificateAuthorityServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient =
        CertificateAuthorityServiceClient.create()) {

      // Create CA pool name comprising of project, location and the pool name.
      CaPoolName parent =
          CaPoolName.newBuilder()
              .setProject(project)
              .setLocation(location)
              .setCaPool(poolId)
              .build();

      // List the CA name and its corresponding state.
      for (CertificateAuthority certificateAuthority :
          certificateAuthorityServiceClient.listCertificateAuthorities(parent).iterateAll()) {
        System.out.println(
            certificateAuthority.getName() + " is " + certificateAuthority.getState());
      }
    }
  }
}

Python

如要向 CA 服務進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

import google.cloud.security.privateca_v1 as privateca_v1


def list_certificate_authorities(
    project_id: str, location: str, ca_pool_name: str
) -> None:
    """
    List all Certificate authorities present in the given CA Pool.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        location: location you want to use. For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.
        ca_pool_name: the name of the CA pool under which the CAs to be listed are present.
    """

    caServiceClient = privateca_v1.CertificateAuthorityServiceClient()

    ca_pool_path = caServiceClient.ca_pool_path(project_id, location, ca_pool_name)

    # List the CA name and its corresponding state.
    for ca in caServiceClient.list_certificate_authorities(parent=ca_pool_path):
        print(ca.name, "is", ca.state)

後續步驟