ministryofjustice / analytical-platform

Analytical Platform • This repository is defined and managed in Terraform
https://docs.analytical-platform.service.justice.gov.uk
MIT License
9 stars 4 forks source link

🔧 QuickSight Terraform #3881

Closed julialawrence closed 3 months ago

julialawrence commented 5 months ago

User Story

As an Ap Engineer I would like to deploy QuickSight into Modernisation Platform Compute account via Terraform

Value / Purpose

This is the first step to deploying a new solution for QuickSight

Proposal

Deploy QuickSight via Terraform

  1. MP Compute Dev account
  2. London region
  3. Public sharing option enabled
  4. Federated + Internal identity solution Identity Center integration
  5. QuickSight-managed role
  6. Access to the following services: S3, Athena, Glue

Additionally: Provision sandbox/developer role as an administrator Configure logging Onboard the account to Observability Platform

Definition of Done

Gary-H9 commented 4 months ago

Notes - 7th May

Are the final two bullet points related? Does this mean 'the QuickSight Managed Role should have access to the following services: S3, Athena, Glue' or are these distinct and the final point means that we want QuickSight Data Sources for S3, Athena, Glue? I suspect that the QuickSight Managed Role, may be created when the account has a QuickSight Subscription added, this is not noted in the terraform plan output.

The code works on the assumption that these are data sources. S3 and Athena can be defined in Terraform but Glue is not a parameter option.

📹 I found out that you can enable introductory videos for users.

julialawrence commented 4 months ago

I believe the region is selected not as a specific configurable attribute but by the region of the provider used to create the resource. So if you're using a provider set to London, I think it should create a QuickSight account with London being the main region.

The story has been updated and we now want to provision QS with identity center as the desired identity option. This is part of our effort to shift to IC and should make integration with lake formation simpler.

The final two points are related. We don't want to be managing the role manually. A managed role created by QS will update itself with the needed permissions when it is enabled for a specific service. The manual representation of this is logging into QS, going to manage QuickSight, and the click on service integration on the left side. Selecting or deselecting a checkbox updates the role under the hood. So this isn't calling for creation of data sources, just configuring the role.

Gary-H9 commented 4 months ago

Notes 8th May

Minor amounts of work done on this today.

Logging - there is no mention of logging in the Terraform resources for QuickSight and from the docs "CloudTrail is enabled on your AWS account when you create the account."

Gary-H9 commented 4 months ago

PR here but this ultimately boils down to this:

resource "aws_quicksight_account_subscription" "subscription" {
  account_name          = "analytical-platform-development"
  authentication_method = "IAM_IDENTITY_CENTER"
  edition               = "ENTERPRISE"
  admin_group           = ["analytical-platform"]
  author_group          = ["analytical-platform"] 
  notification_email    = local.notification_email
}

This then provides this option:

Image

Additionally we checked that we can consume the author_group as well and we can.

Glue is not an option we can enable in the Security & permissions settings in QS

Image

Image

We will complete the EKS Cluster work in Ingestion then deploy to that account in MPE.

jacobwoffenden commented 4 months ago

Analytical Platform Compute environment is now unblocked

jacobwoffenden commented 4 months ago

QuickSight is not deploying via @Gary-H9's pull request, it times out.

When trying it manually in analytical-platform-compute-development, it fails with:

User: arn:aws:sts::381491960855:assumed-role/AWSReservedSSO_modernisation-platform-sandbox_d0899345ec1769be/jacobwoffenden@digital.justice.gov.uk is not authorized to perform: sso:CreateApplication on resource: arn:aws:sso:::instance/ssoins-7535d9af4f41fb26 because no identity-based policy allows the sso:CreateApplication action (Service: SsoAdmin, Status Code: 400, Request ID: 3b8af00b-7aaf-4f6a-8506-d6aaa6e7fc1f)

Assumption is that arn:aws:iam::381491960855:role/MemberInfrastructureAccess isn't able to do sso:CreateApplication on arn:aws:sso:::instance/ssoins-7535d9af4f41fb26 either

Will raise with @ministryofjustice/modernisation-platform

jacobwoffenden commented 3 months ago

QuickSight is deployed into analytical-platform-compute-development 🎉

The following permissions need adding to MemberInfrastructureAccess to deploy to test and production

"sso:CreateApplication",
"sso:ListInstances",
"sso:DeleteApplication",
"sso:PutApplicationGrant",
"sso:PutApplicationAuthenticationMethod",
jacobwoffenden commented 3 months ago

Moving back to blocked while permissions are updated

jacobwoffenden commented 3 months ago

Pull request merged, but member-bootstrap failed so permissions not deployed 😭 being addressed by @ewastempel

jacobwoffenden commented 3 months ago

@ewastempel has fixed the role in test and prod ❤, and QuickSight has successfully deployed to all compute environments 🎉

Image

jacobwoffenden commented 3 months ago

Moving issue into review as the DoD items we can do have been done, does this need expanding or something spinning out into another ticket @julialawrence @Ed-Bajo

jacobwoffenden commented 3 months ago

QuickSight logs out to CloudTrail, and we can see CloudTrail's CloudWatch log group in Observability Platform - https://g-e937f84aea.grafana-workspace.eu-west-2.amazonaws.com/explore?orgId=1&left=%7B%22datasource%22:%220sEx8qYSz%22,%22queries%22:%5B%7B%22id%22:%22%22,%22region%22:%22default%22,%22logGroups%22:%5B%7B%22arn%22:%22arn:aws:logs:eu-west-2:381491960855:log-group:cloudtrail:%2A%22,%22name%22:%22cloudtrail%22,%22accountId%22:%22381491960855%22%7D%5D,%22queryMode%22:%22Logs%22,%22namespace%22:%22%22,%22metricName%22:%22%22,%22expression%22:%22fields%20@timestamp,%20@message%20%7C%5Cn%20filter%20eventSource%20%3D%3D%20%5C%22quicksight.amazonaws.com%5C%22%20%7C%5Cn%20filter%20sourceIPAddress%20%21%3D%20%5C%22config.amazonaws.com%5C%22%20%7C%5Cn%20sort%20@timestamp%20desc%20%7C%5Cn%20limit%2020%22,%22dimensions%22:%7B%7D,%22statistic%22:%22Average%22,%22period%22:%22%22,%22metricQueryType%22:0,%22metricEditorMode%22:0,%22sqlExpression%22:%22%22,%22matchExact%22:true,%22refId%22:%22A%22,%22datasource%22:%7B%22type%22:%22cloudwatch%22,%22uid%22:%220sEx8qYSz%22%7D,%22label%22:%22%22,%22statsGroups%22:%5B%5D%7D%5D,%22range%22:%7B%22from%22:%22now-7d%22,%22to%22:%22now%22%7D%7D