我正在使用Gcloud来运行Prow (Continous Integration server)。我的一项工作是创建一个虚拟机,执行一些测试,然后删除该实例。我使用服务帐户创建虚拟机,运行测试。
#!/bin/bash
set -o errexit
cleanup() {
gcloud compute instances delete kyma-integration-test-${RANDOM_ID}
}
gcloud config set project ...
gcloud auth activate-service-account --key-file ...
gcloud compute instances create <vm_name> \
--metadata enable-oslogin=TRUE \
--image debian-9-stretch-v20181009 \
--image-project debian-cloud --machine-type n1-standard-4 --boot-disk-size 20 \
trap cleanup exit
gcloud compute scp --strict-host-key-checking=no --quiet <script.sh> <vm_name>:~/<script.sh>
gcloud compute ssh --quiet <vm_name> -- ./<script.sh>一段时间后,我得到了以下错误:
ERROR: (gcloud.compute.scp) INVALID_ARGUMENT: Login profile size exceeds 32 KiB. Delete profile values to make additional space.实际上,对于服务帐户,describe命令会返回大量数据,例如sshPublicKeys部分中大约70个条目。
gcloud auth activate-service-account --key-file ... gcloud compute os-login describe-profile
这些公钥中的大多数都是指已经删除的VM实例。如何清理此列表?或者有没有可能根本不存储这些公钥?
发布于 2019-01-25 00:37:33
上面一种非常粗糙的方法对我来说很有效,那就是:
for i in $(gcloud compute os-login ssh-keys list); do echo $i; gcloud compute os-login ssh-keys remove --key $i; done我在删除了几十个键之后停止了这个操作(使用Control-C组合键),然后它又开始工作了。
实际上,在GUI的项目元数据中,我没有看到很多键。仅限:
公钥密钥: network-name...
发布于 2021-05-27 04:32:14
永久的解决方案是使用--ssh-key-expire-after 30s。您仍然需要使用上面的解决方案来清理现有的密钥,或者像这样使用更多的命令功夫(没有grep)。
for i in $(gcloud compute os-login ssh-keys list --format="table[no-heading](value.fingerprint)"); do
echo $i;
gcloud compute os-login ssh-keys remove --key $i || true;
done注意:您必须使用违规帐户。gcloud config account activate ACCOUNT和/或gcloud auth activate-service-account --key-file=FILE或gcloud auth login
在脚本中需要一个新的ssh密钥:
# KEYNAME should be something like $HOME/.ssh/google_compute_engine
ssh-keygen -t rsa -N "" -f "${KEYNAME}" -C "${USERNAME}" || true
chmod 400 ${KEYNAME}*
cat > ssh-keys <<EOF
${USERNAME}:$(cat ${KEYNAME}.pub)
EOF测试此解决方案:
while :; do
USERNAME=testing@test-project.iam.gserviceaccount.com
KEYNAME=~/.ssh/google_compute_engine
rm -f ~/.ssh/google_compute_engine*
ssh-keygen -t rsa -N "" -f "${KEYNAME}" -C "${USERNAME}" || true
chmod 400 ${KEYNAME}*
cat > ssh-keys <<EOF
${USERNAME}:$(cat ${KEYNAME}.pub)
EOF
gcloud --project=test-project compute ssh --ssh-key-expire-after 30s one-bastion-to-rule-them-all -- date
gcloud --project=test-project compute os-login ssh-keys list --format="table[no-heading](value.fingerprint)" \
|wc -l
done发布于 2018-11-12 03:19:21
这些密钥存储在您的Project Metadata中,您可以通过谷歌控制台UI删除它们
https://stackoverflow.com/questions/53180624
复制相似问题