列出证书授权机构

本页面介绍如何列出 Google Cloud 项目中的证书授权机构 (CA)。

列出根 CA

本部分介绍如何查看根 CA。

列出各 CA 池中的根 CA

如需列出各 CA 池中的所有根 CA,请执行以下操作:

控制台

  1. 在 Google Cloud 控制台中,前往 Certificate Authority Service 页面。

    转到 Certificate Authority Service

  2. 点击 CA 管理器标签页,转到证书授权机构页面。

  3. 过滤条件字段中,从列表中选择类型

  4. Type 的值设置为 Root

系统会列出类型设置为的所有 CA。

gcloud

运行以下命令:

gcloud privateca roots list --location LOCATION

LOCATION 替换为根 CA 的位置。如需查看完整的位置列表,请参阅位置

列出特定 CA 池中的根 CA

如需列出特定 CA 池中的所有根 CA,请按照以下说明操作:

控制台

  1. 转到 Certificate Authority Service 页面。

    转到 Certificate Authority Service

  2. 点击 CA 管理器标签页,转到证书授权机构页面。

  3. 过滤条件字段中,从列表中选择类型

  4. Type 的值设置为 Root

  5. 过滤条件字段中,选择列表中的

  6. 点击列表中 CA 池的名称。

gcloud

运行以下命令:

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

替换以下内容:

  • LOCATION:CA 池的位置。如需查看完整的位置列表,请参阅位置
  • POOL_ID:CA 池的名称。

如需列出所有 CA 池和位置的根 CA,请省略命令中的 --pool--location 标志。

如需详细了解 gcloud privateca roots list 命令,请参阅 gcloud privateca roots list

列出从属 CA

本部分介绍如何查看从属 CA。

列出多个 CA 池中的从属 CA

如需列出各 CA 池中的所有从属 CA,请执行以下操作:

控制台

  1. 转到 Certificate Authority Service 页面。

    转到 Certificate Authority Service

  2. 点击 CA 管理器标签页,转到证书授权机构页面。

  3. 过滤条件字段中,从列表中选择类型

  4. 类型的值设置为从属

系统会列出类型设置为从属的所有 CA。

gcloud

运行以下命令:

gcloud privateca subordinates list --location LOCATION

LOCATION 替换为从属 CA 的位置。如需查看完整的位置列表,请参阅位置

列出特定 CA 池中的从属 CA

如需列出特定 CA 池中的所有从属 CA,请执行以下操作:

控制台

  1. 转到 Certificate Authority Service 页面。

    转到 Certificate Authority Service

  2. 点击 CA 管理器标签页,转到证书授权机构页面。

  3. 过滤条件字段中,从列表中选择类型

  4. 类型的值设置为从属

  5. 过滤条件字段中,选择列表中的

  6. 点击列表中 CA 池的名称。

gcloud

运行以下命令:

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

替换以下内容:

  • LOCATION:CA 池的位置。如需查看完整的位置列表,请参阅位置
  • POOL_ID:CA 池的名称。

如需详细了解 gcloud privateca subordinates list 命令,请参阅 gcloud privateca subordinates list

列出所有 CA

如需列出 CA 池中的所有 CA,请按照以下说明操作:

控制台

  1. 转到 Certificate Authority Service 页面。

    转到 Certificate Authority Service

  2. 点击 CA 管理器标签页,转到证书授权机构页面。

  3. 过滤条件字段中,选择列表中的

  4. 点击列表中 CA 池的名称。

或者,您也可以执行以下操作,从 CA 池管理器页面查看特定 CA 池中的 CA:

  1. 点击 CA 池管理员标签页。
  2. CA 池页面上,点击要查看其 CA 的 CA 池的名称。

CA 池详情页面上,您可以看到池中的证书授权机构下列出的 CA。您可以根据类型、层级、位置、状态等过滤 CA。

Go

如需向 CA Service 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

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 Service 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证


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 Service 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

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)

后续步骤