Skip to content
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

[TOAZ-126] Add Sam API for pet managed identities #737

Merged
merged 9 commits into from
Jul 6, 2022
Merged

Conversation

rtitle
Copy link
Contributor

@rtitle rtitle commented May 24, 2022

JIRA: https://broadworkbench.atlassian.net/browse/TOAZ-126

Design doc: https://docs.google.com/document/d/1cyrRTibpvMbu0DtAjDsXeQp6-U2RftO66hHNb3nw_h4/edit#heading=h.focnnsveczp4

Demo recording: https://drive.google.com/file/d/1HiiAxQDVteaznwlRQLuFrXfm9PkSJDyU/view?usp=drive_web

Friends with: https://github.com/broadinstitute/firecloud-develop/pull/2991 (but the PRs are independent)

Overview:

  • Adds AzureRoutes and AzureService classes to Sam
    • Contains single POST /api/azure/v1/user/petManagedIdentity API which gets or creates a pet-UAMI
  • Adds CRL dependency to Sam
  • Adds SAM_PET_MANAGED_IDENTITY SQL table and associated queries
  • Updates StandardUserInfoDirectives to handle requests from pet UAMIs and switch back to the owning user
  • Add unit + connected tests for the above

PR checklist

@rtitle
Copy link
Contributor Author

rtitle commented Jun 17, 2022

jenkins retest

#!/bin/bash

# TODO: Add Janitor secrets here
# https://broadworkbench.atlassian.net/browse/ID-96
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fleshed out the https://broadworkbench.atlassian.net/browse/ID-96 description a bit more

@@ -336,18 +337,22 @@ object Boot extends IOApp with LazyLogging {
val managedGroupService =
new ManagedGroupService(resourceService, policyEvaluatorService, resourceTypeMap, accessPolicyDAO, directoryDAO, cloudExtensionsInitializer.cloudExtensions, config.emailDomain)
val samApplication = SamApplication(userService, resourceService, statusService, tosService)

val azureRoutes = config.azureServicesConfig.map { config =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the azureServicesConfig is optional. We won't add the AzureRoutes if it's not present.

This is NOT using the existing CloudExtensionRoutes pattern in Sam. CloudExtensionRoutes doesn't really fit this use case -- Sam code is structured to only have 1 cloud extension, and it mostly deals with Google group stuff which is not relevant on Azure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a renaming/refactoring opportunity to make sure other people don't get confused in the future.

https://broadworkbench.atlassian.net/browse/ID-109

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its disappointing that it's structured this way, but I think it makes sense to do it like this for the sake of expediency.

content:
application/json:
schema:
type: string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this just returns the managed identity objectId as a String. This fits the Leo/WSM use case. I debated returning more information in a JSON object but keeping it simple for now.

@@ -116,6 +116,12 @@ testStuff = {
reuseIds = false
}
}
# Test MRG in which to create managed identities
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We commonly use this MRG for testing in WSM, Leo, etc

"AzureService" should "create a pet managed identity" taggedAs ConnectedTest in {
val azureServicesConfig = appConfig.azureServicesConfig

assume(azureServicesConfig.isDefined, "-- skipping Azure test")
Copy link
Contributor Author

@rtitle rtitle Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note these tests only run if render-test-config.sh was run. This doesn't happen in CI/CD, so these tests are skipped. Part of https://broadworkbench.atlassian.net/browse/ID-96 should be enabling these tests in CI/CD.


import scala.jdk.CollectionConverters._

object MockCrlService extends MockitoSugar {
Copy link
Contributor Author

@rtitle rtitle Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this mockito usage isn't too horrible. 😂 Azure SDKs are mock-able, but create a lot of intermediate classes which need to be mocked. (FWIW WSM tests Azure SDK the same way with mocks.)

* 4. Get the managed app "plan" id
* 4. Validate the plan id matches the configured value
*/
private def validateManagedResourceGroup(request: GetOrCreatePetManagedIdentityRequest): IO[Unit] = {
Copy link
Contributor Author

@rtitle rtitle Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a separate check than user access control -- it essentially validates the MRG was created from the Terra managed app.

@rtitle rtitle marked this pull request as ready for review June 17, 2022 20:44
@rtitle rtitle requested a review from tlangs June 17, 2022 20:44
@rtitle
Copy link
Contributor Author

rtitle commented Jun 17, 2022

@tlangs I cleaned this up and added tests -- I think it's working well. I moved out of draft mode and requested review. Feel free to assign others too as needed.

I tried to annotate the PR a bit above. Happy to answer any further questions. And I punted on Janitor integration as we discussed -- added some context to https://broadworkbench.atlassian.net/browse/ID-96 as a follow-on task.

Thanks!

(And I know it's Friday 4:45pm before a long weekend -- I don't expect you to see this until next week 😄 )

@rtitle rtitle changed the title [draft] [TOAZ-126] Add Sam API for pet managed identities [TOAZ-126] Add Sam API for pet managed identities Jun 17, 2022
@rtitle
Copy link
Contributor Author

rtitle commented Jun 21, 2022

jenkins retest

@rtitle
Copy link
Contributor Author

rtitle commented Jun 22, 2022

jenkins retest

@rtitle
Copy link
Contributor Author

rtitle commented Jun 22, 2022

seems like a spurious rawls failure, jenkins retest

@rtitle
Copy link
Contributor Author

rtitle commented Jun 22, 2022

jenkins retest

render-test-config.sh Show resolved Hide resolved
render-test-config.sh Outdated Show resolved Hide resolved
render-test-config.sh Show resolved Hide resolved
src/main/resources/swagger/api-docs.yaml Show resolved Hide resolved
@@ -336,18 +337,22 @@ object Boot extends IOApp with LazyLogging {
val managedGroupService =
new ManagedGroupService(resourceService, policyEvaluatorService, resourceTypeMap, accessPolicyDAO, directoryDAO, cloudExtensionsInitializer.cloudExtensions, config.emailDomain)
val samApplication = SamApplication(userService, resourceService, statusService, tosService)

val azureRoutes = config.azureServicesConfig.map { config =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a renaming/refactoring opportunity to make sure other people don't get confused in the future.

https://broadworkbench.atlassian.net/browse/ID-109

xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

<changeSet logicalFilePath="dummy" author="rtitle" id="pet_user_assigned_managed_identity">
<createTable tableName="SAM_PET_MANAGED_IDENTITY">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make this named SAM_AZURE_MANAGED_IDENTITY_PET for clarity?

Copy link
Contributor Author

@rtitle rtitle Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the pattern of the pre-existing SAM_PET_SERVICE_ACCOUNT table.

We could throw "azure" in there: SAM_PET_AZURE_MANAGED_IDENTITY. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehhh, I'll leave it. MANAGED_IDENTITY and SERVICE_ACCOUNT are Microsoft & Google concepts respectively, so it just requires that knowledge.

@@ -336,18 +337,22 @@ object Boot extends IOApp with LazyLogging {
val managedGroupService =
new ManagedGroupService(resourceService, policyEvaluatorService, resourceTypeMap, accessPolicyDAO, directoryDAO, cloudExtensionsInitializer.cloudExtensions, config.emailDomain)
val samApplication = SamApplication(userService, resourceService, statusService, tosService)

val azureRoutes = config.azureServicesConfig.map { config =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its disappointing that it's structured this way, but I think it makes sense to do it like this for the sake of expediency.

@rtitle
Copy link
Contributor Author

rtitle commented Jun 27, 2022

Thanks for the reviews @gpolumbo-broad and @tlangs!

Some good comments above -- will do another pass and ping you when ready for another look.

@sonarcloud
Copy link

sonarcloud bot commented Jul 5, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -73,6 +73,11 @@ paths:
required: true
schema:
type: string
requestBody:
Copy link
Contributor Author

@rtitle rtitle Jul 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are to work around an OpenAPI codegen bug which surfaced in Workspace Manager: OpenAPITools/openapi-generator#11833

Basically if PUT/POST requests don't have a request body and thus have a null content-type, the generated client throws a NPE. It used to default to application/json but this changed when we upgraded openapi in this PR.

To work around I simply set the content-type for each affected PUT/POST method in swagger. This doesn't affect the actual backend routes -- it's just a client fix.

An alternative fix would be to patch the codegen logic in the mustache code, but I don't know all the implications of that, and this change seems reasonable enough.

Let me know if you have other thoughts..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this.

@rtitle
Copy link
Contributor Author

rtitle commented Jul 5, 2022

jenkins retest

@rtitle
Copy link
Contributor Author

rtitle commented Jul 5, 2022

Hey @tlangs @gpolumbo-broad, sorry for the delay -- I think I addressed all comments, can you take another look at this? Thanks.

@rtitle rtitle requested review from tlangs and gpolumbo-broad July 5, 2022 18:39
@rtitle rtitle requested a review from zykonda July 6, 2022 17:25
@rtitle rtitle merged commit 3081228 into develop Jul 6, 2022
@rtitle rtitle deleted the rt-uami branch July 6, 2022 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants