This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.18.5.2.2. 使用 Cloud Credential Operator 实用程序创建 AWS 资源
您可以使用 CCO 实用程序(ccoctl) 单独创建所需的 AWS 资源,或使用单个命令来创建。
18.5.2.2.1. 单独创建 AWS 资源 复制链接链接已复制到粘贴板!
如果您需要在修改 AWS 资源前查看 ccoctl 工具创建的 JSON 文件,或者 ccoctl 工具用于创建 AWS 资源的过程无法自动满足组织的要求,您可以单独创建 AWS 资源。例如,此选项对于在不同用户或部门之间共享创建这些资源的组织可能有用。
否则,您可以使用 ccoctl aws create-all 命令自动创建 AWS 资源。
默认情况下,ccoctl 在运行命令的目录中创建对象。要在其他目录中创建对象,请使用 --output-dir 标志。此流程使用 < ;path_to_ccoctl_output_dir > 来引用此目录。
有些 ccoctl 命令会发出 AWS API 调用来创建或修改 AWS 资源。您可以使用 --dry-run 标志来避免发出 API 调用。使用此标志在本地文件系统中创建 JSON 文件。您可以检查和修改 JSON 文件,然后使用 --cli-input-json 参数通过 AWS CLI 工具应用它们。
先决条件
-
提取并准备
ccoctl二进制文件。
流程
生成用于为集群设置 OpenID Connect 供应商的公共和私有 RSA 密钥文件:
ccoctl aws create-key-pair
$ ccoctl aws create-key-pairCopy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例:
2021/04/13 11:01:02 Generating RSA keypair 2021/04/13 11:01:03 Writing private key to /<path_to_ccoctl_output_dir>/serviceaccount-signer.private 2021/04/13 11:01:03 Writing public key to /<path_to_ccoctl_output_dir>/serviceaccount-signer.public 2021/04/13 11:01:03 Copying signing key for use by installer
2021/04/13 11:01:02 Generating RSA keypair 2021/04/13 11:01:03 Writing private key to /<path_to_ccoctl_output_dir>/serviceaccount-signer.private 2021/04/13 11:01:03 Writing public key to /<path_to_ccoctl_output_dir>/serviceaccount-signer.public 2021/04/13 11:01:03 Copying signing key for use by installerCopy to Clipboard Copied! Toggle word wrap Toggle overflow 其中
serviceaccount-signer.private和serviceaccount-signer.public是生成的密钥文件。此命令还会在 /<
path_to_ccoctl_output_dir>/tls/bound-service-account-signing-key.key中创建集群在安装过程中所需的私钥。在 AWS 上创建 OpenID Connect 身份提供程序和 S3 存储桶:
ccoctl aws create-identity-provider \ --name=<name> \ --region=<aws_region> \ --public-key-file=<path_to_ccoctl_output_dir>/serviceaccount-signer.public
$ ccoctl aws create-identity-provider \ --name=<name> \ --region=<aws_region> \ --public-key-file=<path_to_ccoctl_output_dir>/serviceaccount-signer.publicCopy to Clipboard Copied! Toggle word wrap Toggle overflow 其中:
-
<name>是用于标记为跟踪而创建的云资源的名称。 -
<aws-region>是将要在其中创建云资源的 AWS 区域。 -
<path_to_ccoctl_output_dir> 是ccoctl aws create-key-pair命令生成的公钥文件的路径。
输出示例:
2021/04/13 11:16:09 Bucket <name>-oidc created 2021/04/13 11:16:10 OpenID Connect discovery document in the S3 bucket <name>-oidc at .well-known/openid-configuration updated 2021/04/13 11:16:10 Reading public key 2021/04/13 11:16:10 JSON web key set (JWKS) in the S3 bucket <name>-oidc at keys.json updated 2021/04/13 11:16:18 Identity Provider created with ARN: arn:aws:iam::<aws_account_id>:oidc-provider/<name>-oidc.s3.<aws_region>.amazonaws.com
2021/04/13 11:16:09 Bucket <name>-oidc created 2021/04/13 11:16:10 OpenID Connect discovery document in the S3 bucket <name>-oidc at .well-known/openid-configuration updated 2021/04/13 11:16:10 Reading public key 2021/04/13 11:16:10 JSON web key set (JWKS) in the S3 bucket <name>-oidc at keys.json updated 2021/04/13 11:16:18 Identity Provider created with ARN: arn:aws:iam::<aws_account_id>:oidc-provider/<name>-oidc.s3.<aws_region>.amazonaws.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow 其中
02-openid-configuration是发现文档,,03-keys.json是 JSON Web 密钥集文件。此命令还会在 /<
path_to_ccoctl_output_dir>/manifests/cluster-authentication-02-config.yaml中创建 YAML 配置文件。此文件为集群生成的服务帐户令牌设置签发者 URL 字段,以便 AWS IAM 身份提供程序信任令牌。-
为集群中的每个组件创建 IAM 角色。
从 OpenShift Container Platform 发行镜像中提取
CredentialsRequest对象列表:oc adm release extract \ --credentials-requests \ --cloud=aws \ --to=<path_to_directory_with_list_of_credentials_requests>/credrequests
$ oc adm release extract \ --credentials-requests \ --cloud=aws \ --to=<path_to_directory_with_list_of_credentials_requests>/credrequests1 --from=quay.io/<path_to>/ocp-release:<version>Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
credrequests是存储CredentialsRequest对象列表的目录。如果该目录不存在,此命令就会创建该目录。
使用
ccoctl工具处理credrequests目录中的所有CredentialsRequest对象:ccoctl aws create-iam-roles \ --name=<name> \ --region=<aws_region> \ --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests \ --identity-provider-arn=arn:aws:iam::<aws_account_id>:oidc-provider/<name>-oidc.s3.<aws_region>.amazonaws.com
$ ccoctl aws create-iam-roles \ --name=<name> \ --region=<aws_region> \ --credentials-requests-dir=<path_to_directory_with_list_of_credentials_requests>/credrequests \ --identity-provider-arn=arn:aws:iam::<aws_account_id>:oidc-provider/<name>-oidc.s3.<aws_region>.amazonaws.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow 注意对于使用其他 IAM API 端点的 AWS 环境(如 GovCloud),还必须使用
--region参数指定您的区域。对于每个
CredentialsRequest对象,ccoctl创建一个带有信任策略的 IAM 角色,该角色与指定的 OIDC 身份提供程序相关联,以及来自 OpenShift Container Platform 发行镜像的每个CredentialsRequest对象中定义的权限策略。
验证
要验证 OpenShift Container Platform secret 是否已创建,列出
<path_to_ccoctl_output_dir>/manifests目录中的文件:ll <path_to_ccoctl_output_dir>/manifests
$ ll <path_to_ccoctl_output_dir>/manifestsCopy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
您可以通过查询 AWS 来验证是否已创建 IAM 角色。如需更多信息,请参阅有关列出 IAM 角色的 AWS 文档。