Skip to content

Commit

Permalink
spread/google: add support for service accounts
Browse files Browse the repository at this point in the history
Add support for attaching service accounts to the instances created in GCP.

Signed-off-by: Maciej Borzecki <[email protected]>
  • Loading branch information
bboozzoo committed Jun 14, 2024
1 parent ded9133 commit a1696e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spread/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,17 @@ func (p *googleProvider) createMachine(ctx context.Context, system *System) (*go
},
}

if serviceAccount := p.backend.GoogleServiceAccount; serviceAccount != "" {
// XXX the service account could be set from google key
// credentials, but the account used in the context of the
// request may not have the permissions to attach a service
// account to the instance
params["serviceAccounts"] = []googleParams{{
"email": serviceAccount,
"scopes": []string{"https://www.googleapis.com/auth/cloud-platform"},
}}
}

if system.SecureBoot {
params["shieldedInstanceConfig"] = googleParams{
"enableSecureBoot": true,
Expand Down
9 changes: 9 additions & 0 deletions spread/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type Backend struct {

Priority OptionalInt
Manual bool

// Only relevant for the Google backend
GoogleServiceAccount string `yaml:"google-service-account"`
}

func (b *Backend) String() string { return fmt.Sprintf("backend %q", b.Name) }
Expand Down Expand Up @@ -1024,6 +1027,12 @@ func (p *Project) Jobs(options *Options) ([]*Job, error) {
}
backend.Key = strings.TrimSpace(value)

value, err = evalone(bname+" backend GCP service account", backend.GoogleServiceAccount, cmdcache, true, penv, benv)
if err != nil {
return nil, err
}
backend.GoogleServiceAccount = strings.TrimSpace(value)

for _, system := range backend.Systems {
if system.Username != "" {
value, err := evalone(system.String()+" username", system.Username, cmdcache, false, penv, benv)
Expand Down

0 comments on commit a1696e0

Please sign in to comment.