Creates a target using an address for boundary dev and when first
init-ing boundary (boundary database init).
It also makes this newly created target the default one
(ttcp_1234567890). The target using host sources is now a secondary
target (ttcp_0987654321).
returnnil,fmt.Errorf("unable to list existing roles in project: %w",err)
}
iflen(roles)!=2{
returnnil,fmt.Errorf("unexpected number of roles in default project, expected 2, got %d",len(roles))
}
varidxint=-1
fori,r:=rangeroles{
// Hacky, I know, but saves a DB trip to look up other
// characteristics like "if any principals are currently attached".
// No matter what we pick here it's a bit heuristical.
ifr.Name=="Default Grants"{
idx=i
break
}
}
ifidx==-1{
returnnil,fmt.Errorf("couldn't find default grants role in default project")
}
if_,err:=iamRepo.AddPrincipalRoles(ctx,
roles[idx].PublicId,
roles[idx].Version,
[]string{b.DevUnprivilegedUserId});err!=nil{
returnnil,fmt.Errorf("error adding unpriv user ID to project default role: %w",err)
}
pr,err:=iam.NewRole(b.DevProjectId,
iam.WithName("Unprivileged User Session Authorization"),
iam.WithDescription(`Provides grants within the dev project scope to allow the initial unprivileged user to authorize sessions against the dev target`),
returnfmt.Errorf("failed to add %q as principal for role id %q",userId,defaultRole.GetPublicId())
}
defaultRole.Version++// The above call increments the role version in the database, so we must also track that with our state.
}
// Create a new role for the "authorize-session" grant and add the
// unprivileged user as a principal.
asRole,err:=iam.NewRole(projectId,
iam.WithName(fmt.Sprintf("Session authorization for %s",targetId)),
iam.WithDescription(fmt.Sprintf("Provides grants within the dev project scope to allow the initial unprivileged user to authorize sessions against %s",targetId)),
)
iferr!=nil{
returnfmt.Errorf("failed to create role object: %w",err)
}
asRole,err=repo.CreateRole(ctx,asRole)
iferr!=nil{
returnfmt.Errorf("failed to create role for unprivileged user: %w",err)
Usage:`If set, auto-created resources will use this value for their identifier (along with their resource-specific prefix). Must be 10 alphanumeric characters. As an example, if this is set to "1234567890", the generated password auth method ID will be "ampw_1234567890", the generated TCP target ID will be "ttcp_1234567890", and so on.`,
Usage:`If set, auto-created resources will use this value for their identifier (along with their resource-specific prefix). Must be 10 alphanumeric characters. As an example, if this is set to "1234567890", the generated password auth method ID will be "ampw_1234567890", the generated TCP target ID will be "ttcp_1234567890", and so on. Must be different from -secondary-id-suffix (BOUNDARY_DEV_SECONDARY_ID_SUFFIX).`,
})
f.StringVar(&base.StringVar{
Name:"secondary-id-suffix",
Target:&c.flagSecondaryIdSuffix,
Default:"0987654321",
EnvVar:"BOUNDARY_DEV_SECONDARY_ID_SUFFIX",
Usage:`If set, secondary auto-created resources will use this value for their identifier (along with their resource-specific prefix). Must be 10 alphanumeric characters. Currently only used for the target resource. Must be different from -id-suffix (BOUNDARY_DEV_ID_SUFFIX).`,