Skip to content

Commit d9b180d

Browse files
committed
fix(orgadm): add credentials-project flag and fix IAM policy version
- Add -credentials-project flag for cross-project Datastore access - Set IAM policy version to 3 (required for conditional bindings)
1 parent c5cbd83 commit d9b180d

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

cmd/orgadm/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ import (
2121
)
2222

2323
var (
24-
org string
25-
orgEmail string
26-
project string
27-
updateTables bool
24+
org string
25+
orgEmail string
26+
project string
27+
credentialsProject string
28+
updateTables bool
2829
)
2930

3031
func init() {
3132
flag.StringVar(&org, "org", "", "Organization name. Must match name assigned by M-Lab")
3233
flag.StringVar(&project, "project", "", "GCP project to create organization resources")
34+
flag.StringVar(&credentialsProject, "credentials-project", "", "GCP project for credentials Datastore (defaults to -project)")
3335
flag.BoolVar(&updateTables, "update-tables", false, "Allow this org's service account to update table schemas")
3436
flag.StringVar(&orgEmail, "org-email", "", "Organization contact email")
3537
}
@@ -57,13 +59,17 @@ func main() {
5759
rtx.Must(err, "failed to create new dns service")
5860
d := dnsx.NewManager(dnsiface.NewCloudDNSService(dnsService), project, dnsname.ProjectZone(project))
5961

60-
// Create Datastore client
61-
dsc, err := datastore.NewClient(ctx, project)
62+
// Setup Datastore client for credentials (may be in a different project)
63+
credProj := credentialsProject
64+
if credProj == "" {
65+
credProj = project
66+
}
67+
dsc, err := datastore.NewClient(ctx, credProj)
6268
rtx.Must(err, "failed to create datastore client")
6369
defer dsc.Close()
6470

6571
// Initialize AutojoinManager from token-exchange with the correct namespace.
66-
am := store.NewAutojoinManager(dsc, project, "platform-credentials")
72+
am := store.NewAutojoinManager(dsc, credProj, "platform-credentials")
6773

6874
o := adminx.NewOrg(project, crmiface.NewCRM(project, crm), sa, sm, d, am, updateTables)
6975
err = o.Setup(ctx, org, orgEmail)

internal/adminx/org.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ func (o *Org) ApplyPolicy(ctx context.Context, org string, account *iam.ServiceA
173173
newBindings, wasMissing := appendBindingIfMissing(curr.Bindings, bindings...)
174174

175175
// Apply bindings if any were missing.
176+
// Version 3 is required for policies with conditional role bindings.
176177
preq := &cloudresourcemanager.SetIamPolicyRequest{
177178
Policy: &cloudresourcemanager.Policy{
178179
AuditConfigs: curr.AuditConfigs,
179180
Bindings: newBindings,
180181
Etag: curr.Etag,
181-
Version: curr.Version,
182+
Version: 3,
182183
},
183184
}
184185

0 commit comments

Comments
 (0)