-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ID-1328 system resource access policy creation on boot #1482
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,3 +243,52 @@ janitor { | |
trackResourceTopicId = ${?JANITOR_TRACK_RESOURCE_TOPIC_ID} | ||
} | ||
|
||
terra.support.emails = [ | ||
// dynamically configuring lists is hard, so 10 slots are provided for support emails | ||
// add more if more than 10 are ever needed | ||
${?TERRA_SUPPORT_EMAIL_0} | ||
${?TERRA_SUPPORT_EMAIL_1} | ||
${?TERRA_SUPPORT_EMAIL_2} | ||
${?TERRA_SUPPORT_EMAIL_3} | ||
${?TERRA_SUPPORT_EMAIL_4} | ||
${?TERRA_SUPPORT_EMAIL_5} | ||
${?TERRA_SUPPORT_EMAIL_6} | ||
${?TERRA_SUPPORT_EMAIL_7} | ||
${?TERRA_SUPPORT_EMAIL_8} | ||
${?TERRA_SUPPORT_EMAIL_9} | ||
] | ||
|
||
resourceAccessPolicies { | ||
resource_type_admin { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's an example for doing this for services (Leo, Rawls)? Wondering if our existing roles will work, or if it would be better to create some new ones for service management of resources.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my intent was to create new roles with hand picked actions. The workspace application role is probably ok for Leo but every other resource type probably needs other roles. |
||
workspace { | ||
support { | ||
memberEmails = ${terra.support.emails} | ||
roles = ["support"] | ||
} | ||
} | ||
managed-group { | ||
support { | ||
memberEmails = ${terra.support.emails} | ||
roles = ["support"] | ||
} | ||
} | ||
billing-project { | ||
support { | ||
memberEmails = ${terra.support.emails} | ||
roles = ["support"] | ||
} | ||
} | ||
dataset { | ||
support { | ||
memberEmails = ${terra.support.emails} | ||
roles = ["support"] | ||
} | ||
} | ||
datasnapshot { | ||
support { | ||
memberEmails = ${terra.support.emails} | ||
roles = ["support"] | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ import org.broadinstitute.dsde.workbench.google.{ | |
HttpGoogleStorageDAO | ||
} | ||
import org.broadinstitute.dsde.workbench.google2.{GoogleStorageInterpreter, GoogleStorageService} | ||
import org.broadinstitute.dsde.workbench.model.WorkbenchEmail | ||
import org.broadinstitute.dsde.workbench.model.{WorkbenchEmail, WorkbenchException} | ||
import org.broadinstitute.dsde.workbench.oauth2.{ClientId, OpenIDConnectConfiguration} | ||
import org.broadinstitute.dsde.workbench.sam.api.{LivenessRoutes, SamRoutes, StandardSamUserDirectives} | ||
import org.broadinstitute.dsde.workbench.sam.azure.{AzureService, CrlService} | ||
|
@@ -44,6 +44,7 @@ import org.broadinstitute.dsde.workbench.sam.db.DbReference | |
import org.broadinstitute.dsde.workbench.sam.google._ | ||
import org.broadinstitute.dsde.workbench.sam.model._ | ||
import org.broadinstitute.dsde.workbench.sam.service._ | ||
import org.broadinstitute.dsde.workbench.sam.util.SamRequestContext | ||
import org.broadinstitute.dsde.workbench.sam.util.Sentry.initSentry | ||
import org.broadinstitute.dsde.workbench.util.DelegatePool | ||
import org.typelevel.log4cats.StructuredLogger | ||
|
@@ -80,6 +81,23 @@ object Boot extends IOApp with LazyLogging { | |
|
||
_ <- dependencies.policyEvaluatorService.initPolicy() | ||
|
||
// make sure all users referenced by resourceAccessPolicies exist | ||
_ <- appConfig.resourceAccessPolicies.flatMap { case (_, policy) => policy.memberEmails }.toList.traverse { email => | ||
dependencies.samApplication.userService.inviteUser(email, SamRequestContext()).attempt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure we want to silently do this? Since this is on-boot, I'm wondering if it would be better to hard-fail if the users don't exist, with some descriptive message saying there's a configuration error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a BEE, the user's probably won't exist because our services register their service account users on startup. Any new live environment will also have this issue. The accounts exist in our live environments because they were registered by the same process many moons ago. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point about BEEs! |
||
} | ||
|
||
// create resourceAccessPolicies | ||
policyTrials <- dependencies.samApplication.resourceService.upsertResourceAccessPolicies(appConfig.resourceAccessPolicies) | ||
_ = policyTrials.map { | ||
case (policyId, Left(t)) => | ||
logger.error(s"FATAL - failure creating configured policy [$policyId] on startup", t) | ||
case (policyId, Right(_)) => | ||
logger.info(s"Upserted configured policy [$policyId] at startup") | ||
} | ||
_ <- IO.raiseWhen(policyTrials.values.exists(_.isLeft))( | ||
new WorkbenchException("FATAL - failure creating configured policy on startup, see above errors") | ||
) | ||
|
||
_ <- dependencies.cloudExtensionsInitializer.onBoot(dependencies.samApplication) | ||
|
||
binding <- IO.fromFuture(IO(Http().newServerAt("0.0.0.0", 8080).bind(dependencies.samRoutes.route))).onError { case t: Throwable => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,26 @@ prometheus { | |
|
||
admin { | ||
serviceAccountAdmins = ${?SERVICE_ACCOUNT_ADMINS} | ||
} | ||
|
||
resourceAccessPolicies { | ||
resource_type_admin { | ||
workspace { | ||
rawls-policy { | ||
memberEmails = ["[email protected]"] | ||
descendantPermissions = [ | ||
{ | ||
resourceTypeName = "workspace", | ||
roles = ["owner"] | ||
} | ||
] | ||
} | ||
} | ||
kubernetes-app { | ||
leo-policy { | ||
memberEmails = ["[email protected]"] | ||
roles = ["support"] | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
package org.broadinstitute.dsde.workbench.sam.config | ||
|
||
import com.typesafe.config.{ConfigException, ConfigFactory, ConfigValueFactory} | ||
import org.broadinstitute.dsde.workbench.model.WorkbenchEmail | ||
import org.broadinstitute.dsde.workbench.sam.model.api.AccessPolicyMembershipRequest | ||
import org.broadinstitute.dsde.workbench.sam.model.{ | ||
AccessPolicyDescendantPermissions, | ||
AccessPolicyName, | ||
FullyQualifiedPolicyId, | ||
FullyQualifiedResourceId, | ||
ResourceId, | ||
ResourceRoleName, | ||
ResourceTypeName, | ||
SamResourceTypes | ||
} | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
|
@@ -36,4 +48,28 @@ class AppConfigSpec extends AnyFlatSpec with Matchers { | |
AppConfig.readConfig(combinedConfig.withoutPath("googleServices.appName")) | ||
} | ||
} | ||
|
||
it should "load resourceAccessPolicies" in { | ||
val appConfig = AppConfig.load | ||
appConfig.resourceAccessPolicies should contain allElementsOf Map( | ||
FullyQualifiedPolicyId(FullyQualifiedResourceId(SamResourceTypes.resourceTypeAdminName, ResourceId("workspace")), AccessPolicyName("rawls-policy")) -> | ||
AccessPolicyMembershipRequest( | ||
Set(WorkbenchEmail("[email protected]")), | ||
Set.empty, | ||
Set.empty, | ||
Some( | ||
Set( | ||
AccessPolicyDescendantPermissions( | ||
ResourceTypeName("workspace"), | ||
Set.empty, | ||
Set(ResourceRoleName("owner")) | ||
) | ||
) | ||
), | ||
None | ||
), | ||
FullyQualifiedPolicyId(FullyQualifiedResourceId(SamResourceTypes.resourceTypeAdminName, ResourceId("kubernetes-app")), AccessPolicyName("leo-policy")) -> | ||
AccessPolicyMembershipRequest(Set(WorkbenchEmail("[email protected]")), Set.empty, Set(ResourceRoleName("support")), None, None) | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new config should replace this script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see also https://github.com/broadinstitute/terra-helmfile/pull/5706