因此,我需要能够将我的打包程序构建器移动到私有 VPC 中,并添加一个锁定的安全组,该安全组只允许来自受限 IP 范围的 ssh,因此:
"builders": [{
"type": "amazon-ebs",
"associate_public_ip_address": false,
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "{{user `aws_region`}}",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"name": "{{user `ami_source_name`}}",
"root-device-type": "ebs"
},
"owners": ["{{user `ami_source_owner_id`}}"],
"most_recent": true
},
"instance_type": "t3.small",
"iam_instance_profile": "{{user `iam_instance_profile`}}",
"ssh_username": "{{user `ssh_username`}}",
"ami_name": "{{user `ami_name_prefix`}}_{{user `ami_creation_date`}}",
"ami_users": "{{user `share_amis_with_account`}}",
"ebs_optimized": true,
"vpc_id": "vpc-123456",
"subnet_id": "subnet-123456",
"security_group_id": "sg-123456",
"user_data_file": "scripts/disable_tty.sh",
"launch_block_device_mappings": [{
"device_name": "{{user `root_device_name`}}",
"volume_size": 10,
"volume_type": "gp2",
"delete_on_termination": true
}],
"tags": {
"packer": "true",
"ansible_role": "{{user `ansible_role`}}",
"builtby": "{{user `builtby`}}",
"ami_name": "{{user `ami_name_prefix`}}_{{user `ami_creation_date`}}",
"ami_name_prefix": "{{user `ami_name_prefix`}}",
"project": "{{user `project`}}"
}
}]
首先,我添加了“associate_public_ip_address:false”(默认也是false),因为每次我运行packer时,主机都被分配了一个公共IP地址,但即使添加它仍然会获取一个公共IP??????? ?
我使用了一个分配给 Jenkins 构建从站的安全组,该从站也通过端口 22 进行通信,并且从我的基础架构的任何部分访问它们都没有任何问题。
我收到此错误:
1562344256,,ui,error,Build 'amazon-ebs' errored: Timeout waiting for SSH.
1562344256,,error-count,1
1562344256,,ui,error,\n==> Some builds didn't complete successfully and had errors:
1562344256,amazon-ebs,error,Timeout waiting for SSH.
1562344256,,ui,error,--> amazon-ebs: Timeout waiting for SSH.
在 SSH 响应的等待期间,我能够nc -v 1.2.3.5 22并获得连接,因此安全组允许从我的 IP 地址在端口 22 上进行通信。
如果我将安全组更改为0.0.0.0/0它会立即连接,但是为什么当我可以使用受限安全组nc连接到端口 22 时,packer 不能启动 SSH 连接?Packer 是否试图使用我终生无法关闭的公共 IP 地址?
我认为tcpdump端口 22 上的流量以查看发生了什么可能会很有帮助,但我有一台锁定的笔记本电脑,不允许安装那个特别方便的项目。
我也可以从我的笔记本电脑通过 ssh 连接到构建器,但是会出现身份验证失败太多错误,并且无法登录以查看发生了什么。