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

leap, m2lines: Bucket public access update #2751

Merged
merged 3 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions docs/howto/features/buckets.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,12 @@ on why users want this!
very helpful for 'scratch' buckets that are temporary. Set to
`null` to prevent this cleaning up process from happening, e.g., if users want a persistent bucket.

2. Enable access to these buckets from the hub by [editing `hub_cloud_permissions`](howto:features:cloud-access:access-perms)
2. Enable access to these buckets from the hub or make them publicly accessible from outside
by [editing `hub_cloud_permissions`](howto:features:cloud-access:access-perms)
in the same `.tfvars` file. Follow all the steps listed there - this
should create the storage buckets and provide all users access to them!

3. (If requested) Enable public read access to these buckets by editing the
`bucket_public_access` list in the same `.tfvars`:

```terraform
bucket_public_access = [
"public-persistent"
]
```

4. You can set the `SCRATCH_BUCKET` (and the deprecated `PANGEO_SCRATCH`)
3. You can set the `SCRATCH_BUCKET` (and the deprecated `PANGEO_SCRATCH`)
env vars on all user pods so users can use the created bucket without
having to hard-code the bucket name in their code. In the hub-specific
`.values.yaml` file in `config/clusters/<cluster-name>`,
Expand Down Expand Up @@ -79,7 +71,7 @@ on why users want this!

You can also add other env vars pointing to other buckets users requested.

5. Get this change deployed, and users should now be able to use the buckets!
4. Get this change deployed, and users should now be able to use the buckets!
Currently running users might have to restart their pods for the change to take effect.


Expand Down
5 changes: 4 additions & 1 deletion docs/howto/features/cloud-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This AWS IAM Role is managed via terraform.
"<hub-name-slug>": {
requestor_pays : true,
bucket_admin_access : ["bucket-1", "bucket-2"]
bucket_public_access : ["bucket-1"]
hub_namespace : "<hub-name>"
}
}
Expand All @@ -63,7 +64,9 @@ This AWS IAM Role is managed via terraform.
access to. Used along with the [user_buckets](howto:features:cloud-access:storage-buckets)
terraform variable to enable the [scratch buckets](topic:features:cloud:scratch-buckets)
feature.
4. (GCP only) `hub_namespace` is the full name of the hub, as hubs are put in Kubernetes
4. `bucket_public_access` lists bucket names (as specified in `user_buckets`
terraform variable) that should be publicly accessible.
5. (GCP only) `hub_namespace` is the full name of the hub, as hubs are put in Kubernetes
Namespaces that are the same as their names. This is explicitly specified here
because `<hub-name-slug>` could possibly be truncated on GCP.

Expand Down
15 changes: 12 additions & 3 deletions terraform/gcp/buckets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ locals {
}
]
]))

bucket_public_permissions = distinct(flatten([
for hub_name, permissions in var.hub_cloud_permissions : [
for bucket_name in permissions.bucket_public_access : {
hub_name = hub_name
bucket_name = bucket_name
}
]
]))
}

resource "google_storage_bucket_iam_member" "member" {
Expand All @@ -77,9 +86,9 @@ resource "google_storage_bucket_iam_member" "extra_admin_members" {
member = each.value.member
}

resource "google_storage_default_object_access_control" "public_rule" {
for_each = toset(var.bucket_public_access)
bucket = google_storage_bucket.user_buckets[each.key].name
resource "google_storage_bucket_access_control" "public_rule" {
for_each = { for bp in local.bucket_public_permissions : "${bp.hub_name}.${bp.bucket_name}" => bp }
bucket = google_storage_bucket.user_buckets[each.value.bucket_name].name
role = "READER"
entity = "allUsers"
}
Expand Down
5 changes: 1 addition & 4 deletions terraform/gcp/projects/leap.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ hub_cloud_permissions = {
requestor_pays : true,
bucket_admin_access : ["scratch", "persistent"],
bucket_readonly_access : ["persistent-ro"],
bucket_public_access : ["persistent-ro"],
hub_namespace : "prod"
}
}

bucket_public_access = [
"persistent-ro"
]

# Setup notebook node pools
notebook_nodes = {
"medium" : {
Expand Down
5 changes: 1 addition & 4 deletions terraform/gcp/projects/m2lines.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ hub_cloud_permissions = {
"prod" : {
requestor_pays : true,
bucket_admin_access : ["scratch", "persistent", "public-persistent"],
bucket_public_access : ["public-persistent"],
hub_namespace : "prod"
},
}

bucket_public_access = [
"public-persistent"
]
10 changes: 1 addition & 9 deletions terraform/gcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ variable "hub_cloud_permissions" {
requestor_pays : bool,
bucket_admin_access : set(string),
bucket_readonly_access : optional(set(string), []),
bucket_public_access : optional(set(string), []),
hub_namespace : string
})
)
Expand All @@ -373,15 +374,6 @@ variable "hub_cloud_permissions" {
EOT
}

variable "bucket_public_access" {
type = list(any)
default = []
description = <<-EOT
A list of GCS storage buckets defined in user_buckets that should be granted public read access.

EOT
}

variable "container_repos" {
type = list(any)
default = []
Expand Down