Skip to content

Commit 1b51e9a

Browse files
pkg/gce: vm/gce: allow specifying instance tags in manager config
GCE instance tags can be used for various purposes, such as applying network firewall rules or filtering VMs for scheduling onto specific hosts. To support these use cases, syzkaller needs the ability to set instance tags during VM creation. This patch introduces a new tags field to the gce VM configuration that allows users to specify a list of tags to be attached to GCE instances created by syz-manager.
1 parent b223fd7 commit 1b51e9a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pkg/gce/gce.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func NewContext(customZoneID string) (*Context, error) {
118118
}
119119

120120
func (ctx *Context) CreateInstance(name, machineType, image, sshkey string,
121-
preemptible, displayDevice bool) (string, error) {
121+
tags []string, preemptible, displayDevice bool) (string, error) {
122122
prefix := "https://www.googleapis.com/compute/v1/projects/" + ctx.ProjectID
123123
sshkeyAttr := "syzkaller:" + sshkey
124124
oneAttr := "1"
@@ -165,6 +165,7 @@ func (ctx *Context) CreateInstance(name, machineType, image, sshkey string,
165165
DisplayDevice: &compute.DisplayDevice{
166166
EnableDisplay: displayDevice,
167167
},
168+
Tags: &compute.Tags{Items: tags},
168169
}
169170
retry:
170171
if !instance.Scheduling.Preemptible && strings.HasPrefix(machineType, "e2-") {

vm/gce/gce.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ type Config struct {
5959
// Leave empty for non-OS Login GCP projects.
6060
// Otherwise generate one and upload it:
6161
// `gcloud compute os-login ssh-keys add --key-file some-key.pub`.
62-
SerialPortKey string `json:"serial_port_key"`
62+
SerialPortKey string `json:"serial_port_key"`
63+
Tags []string `json:"tags"` // GCE instance tags
6364
}
6465

6566
type Pool struct {
@@ -195,7 +196,7 @@ func (pool *Pool) Create(_ context.Context, workdir string, index int) (vmimpl.I
195196
}
196197
log.Logf(0, "creating instance: %v", name)
197198
ip, err := pool.GCE.CreateInstance(name, pool.cfg.MachineType, pool.cfg.GCEImage,
198-
string(gceKeyPub), pool.cfg.Preemptible, pool.cfg.DisplayDevice)
199+
string(gceKeyPub), pool.cfg.Tags, pool.cfg.Preemptible, pool.cfg.DisplayDevice)
199200
if err != nil {
200201
return nil, err
201202
}

0 commit comments

Comments
 (0)