google-deployment-manager - 如何在 Cloud Deployment Manager 中指定阻止项目范围的 SSH 密钥?
问题描述
我想从 GCP Marketplace 创建一个 WURFL 微服务基础实例,但是我想以编程方式执行此操作,以便在需要时重现它。
并将其解压缩到我的机器上,所以这里有用于创建 WURFL 解决方案的代码:
文件test_config.yaml包含有关我的部署的相关信息,我将 serviceAccount、zone、network、subnetwork 和 externalIP 属性更改为我需要它们具有的值:
imports:
- path: wurfl-microservice-basic.jinja
resources:
- name: wurfl-microservice-basic
type: wurfl-microservice-basic.jinja
properties:
zone: europe-west2-a
network:
- sharedresources
subnetwork:
- eu-west2
externalIP:
- NONE
serviceAccount: wurflrunner@XXXXX.iam.gserviceaccount.com
我通过发布进行部署:
gcloud deployment-manager deployments create \
wurfl \
--project xxxxxxx \
--config test_config.yaml
为了允许指定 serviceAccount,我必须对部署包进行一些更改。
我在wurfl-microservice-basic.jinja.schema的属性中添加了一个 serviceAccount 属性
properties:
serviceAccount:
type: string
default: stop@gocreateaservieaccount.com
zone:
type: string
x-googleProperty:
type: GCE_ZONE
machineType:
type: string
default: e2-small
x-googleProperty:
type: GCE_MACHINE_TYPE
zoneProperty: zone
gceMachineType:
minCpu: 2
minRamGb: 1.9990234375
network:
type: array
default: [default]
minItems: 1
maxItems: 1
x-googleProperty:
type: GCE_NETWORK
gceNetwork:
allowSharedVpcs: True
machineTypeProperty: machineType
subnetwork:
type: array
minItems: 1
maxItems: 1
x-googleProperty:
type: GCE_SUBNETWORK
zoneProperty: zone
gceSubnetwork:
networkProperty: network
externalIP:
type: array
default: [EPHEMERAL]
minItems: 1
maxItems: 1
x-googleProperty:
type: GCE_EXTERNAL_IP
gceExternalIp:
networkProperty: network
notConfigurable: False
allowStaticIps: True
bootDiskType:
type: string
default: pd-ssd
x-googleProperty:
type: GCE_DISK_TYPE
zoneProperty: zone
bootDiskSizeGb:
type: integer
default: 20
minimum: 20
maximum: 10000
x-googleProperty:
type: GCE_DISK_SIZE
gceDiskSize:
diskTypeProperty: bootDiskType
在wurfl-microservice-basic.jinja我添加了:
{% set serviceAccount = properties["serviceAccount"] %}
并改变:
serviceAccounts:
- email: default
scopes:
- 'https://www.googleapis.com/auth/cloud.useraccounts.readonly'
- 'https://www.googleapis.com/auth/devstorage.read_only'
- 'https://www.googleapis.com/auth/logging.write'
- 'https://www.googleapis.com/auth/monitoring.write'
到
serviceAccounts:
- email: {{ serviceAccount }}
scopes:
- 'https://www.googleapis.com/auth/cloud.useraccounts.readonly'
- 'https://www.googleapis.com/auth/devstorage.read_only'
- 'https://www.googleapis.com/auth/logging.write'
- 'https://www.googleapis.com/auth/monitoring.write'
这导致包成功创建。创建的 VM 允许项目范围的 SSH 密钥:
我被告知这违反了公司政策,“阻止项目范围的 SSH 密钥”需要打开(即选中)。
当我进行更改以允许指定 serviceAccount 时,这相对容易,因为 serviceAccount 已经存在于wurfl-microservice-basic.jinja但是“阻止项目范围的 SSH 密钥”设置并非如此。
请有人告诉我需要对下载的部署包进行哪些更改才能打开“阻止项目范围的 SSH 密钥”?
解决方案
弄清楚了。它是实例元数据的一部分。我通过更改在vm_instance.py中的 Cloud Deployment Manager 包中对其进行了更改
def SetMetadataDefaults(metadata):
"""Set default metadata items."""
# Disable stackdriver monitoring by default.
items = metadata.setdefault('items', list())
if not [True for x in items
if x.get('key', None) == 'google-monitoring-enable']:
items.append({'key': 'google-monitoring-enable',
'value': '0'})
if not [True for x in items
if x.get('key', None) == 'google-logging-enable']:
items.append({'key': 'google-logging-enable',
'value': '0'})
到
def SetMetadataDefaults(metadata):
"""Set default metadata items."""
# Disable stackdriver monitoring by default.
items = metadata.setdefault('items', list())
if not [True for x in items
if x.get('key', None) == 'google-monitoring-enable']:
items.append({'key': 'google-monitoring-enable',
'value': '0'})
if not [True for x in items
if x.get('key', None) == 'google-logging-enable']:
items.append({'key': 'google-logging-enable',
'value': '0'})
if not [True for x in items
if x.get('key', None) == 'block-project-ssh-keys']:
items.append({'key': 'block-project-ssh-keys',
'value': 'TRUE'})
这是结果
推荐阅读
- reactjs - 在本机反应中点击活动选项卡时滚动到顶部
- list - 附加到列表行为不正常
- android - 带有自定义 PopupMenu 的窗口管理器
- matlab - 如何将 Y 定义为不同的 X 值(如直方图)
- java - GSON 在库模块中未序列化数据
- angular - 我怎么知道我已经在 Angular 应用程序中单点登录?
- python - 在 Python 中键入一个可变参数函数
- python - 我正在使用乌龟制作蛇游戏,但在制作程序功能时遇到问题,因为它没有移动
- python - 带有面部跟踪器的 python 运动面具
- r - 结合来自两个不同数据集的 glm 模型 (r/rpy2)