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

[Do not merge] PR for diff of DANDI vs. LINC #15

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2ec43eb
allow HEAD requests from different origins.
satra May 3, 2022
2e90074
Merge pull request #124 from dandi/enh/origin-head
waxlamp Feb 27, 2024
f0047e7
Add CI for terraform linting/validation
mvandenburgh Sep 19, 2023
b9b6ab2
Fix linting
mvandenburgh Feb 26, 2024
f7118e6
Update `hashicorp/setup-terraform` action
mvandenburgh Feb 27, 2024
feab017
Merge pull request #159 from dandi/linting-workflow
waxlamp Feb 27, 2024
2de08cd
Deploy `dandidav` service to Heroku
mvandenburgh Mar 5, 2024
bc9962d
Add import blocks
mvandenburgh Mar 6, 2024
e755306
Merge pull request #167 from dandi/webdav-deployment
mvandenburgh Mar 11, 2024
b5eca95
Remove import blocks in webdav.tf
mvandenburgh Mar 11, 2024
273ae94
Merge pull request #168 from dandi/rm-imports-webdav
mvandenburgh Mar 11, 2024
8701e23
Disable Rust buildpack and dyno-metadata feature
mvandenburgh Mar 12, 2024
b4bed84
Merge pull request #170 from dandi/disable-rust-buildpack
mvandenburgh Mar 12, 2024
e60c8b5
Increase quantity of web dynos to 3
jjnesbitt Mar 25, 2024
5257f5c
Merge pull request #171 from dandi/heroku-web-dyno-count
jjnesbitt Mar 25, 2024
ce5cbf8
Add bucket policy for embargoed objects
jjnesbitt Mar 15, 2024
64eaf18
Merge pull request #169 from dandi/embargoed-object-tags
jjnesbitt Apr 3, 2024
1072e88
Revert "Add embargoed tags bucket policy"
jjnesbitt Apr 3, 2024
791ff4e
Merge pull request #174 from dandi/revert-169-embargoed-object-tags
jjnesbitt Apr 3, 2024
6c4cad1
Add bucket policy statement for embargoed objects
jjnesbitt Apr 3, 2024
afb577d
Merge pull request #175 from dandi/embargoed-object-tags-2
jjnesbitt Apr 3, 2024
6e56e06
Use full URL for webdav buildpack
mvandenburgh Apr 4, 2024
a04c6a4
Merge pull request #177 from dandi/fix-webdav-buildpack
mvandenburgh Apr 4, 2024
2de0231
Put in a trailing dot
waxlamp Apr 4, 2024
fd7b818
Merge pull request #176 from dandi/fqdn-dot
waxlamp Apr 5, 2024
fe8f233
WIP - remove trailing dot
waxlamp Apr 5, 2024
796c1cd
Merge pull request #178 from dandi/fqdn-no-dot
waxlamp Apr 5, 2024
c37fd64
Revert "Remove trailing dot for ACM CNAME entry"
waxlamp Apr 5, 2024
ae22b54
Merge pull request #179 from dandi/revert-178-fqdn-no-dot
waxlamp Apr 5, 2024
9a81347
Give heroku user `s3:PutObjectTagging` permission
mvandenburgh Apr 17, 2024
c36c4e0
Merge pull request #180 from dandi/putobjecttagging
mvandenburgh Apr 17, 2024
798f52d
Add dev_email variable and supply as env var
jjnesbitt Apr 25, 2024
8f0cc56
Merge pull request #181 from dandi/dev-email-list
jjnesbitt Apr 26, 2024
5de5bf4
Allow PutObjectTagging for both production and staging buckets
jjnesbitt Apr 29, 2024
d12f963
Merge pull request #182 from dandi/prod-put-object-tagging
jjnesbitt Apr 29, 2024
ef71895
Add `s3:PutObjectTagging` permission to sponsored bucket
jjnesbitt Apr 29, 2024
f82de1a
Merge pull request #183 from dandi/prod-bucket-put-object-tagging
jjnesbitt Apr 29, 2024
abb13a0
Update terraform to reflect correct heroku state
danlamanna Jul 26, 2024
c177402
Add identity provider for terraform cloud
danlamanna Jul 26, 2024
0bc9a6d
Merge pull request #185 from dandi/update-heroku-resources
danlamanna Jul 29, 2024
b547159
Merge pull request #184 from dandi/add-tfcloud-oidc-auth
danlamanna Jul 30, 2024
de64322
Import new heroku postgres addon
mvandenburgh Sep 9, 2024
64f1cdb
Merge pull request #187 from dandi/reimport-heroku-postgres
mvandenburgh Sep 10, 2024
efdd8a8
Remove import block
mvandenburgh Sep 10, 2024
7e2bd38
Merge pull request #188 from dandi/remove-imports
mvandenburgh Oct 7, 2024
64fb493
Scope trailing delete policy to `blobs` prefix only
mvandenburgh Oct 22, 2024
7937110
Merge pull request #190 from dandi/scoped-lifecycle-policy
mvandenburgh Oct 28, 2024
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
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI
on:
push:
branches:
- master
pull_request:

jobs:
lint-terraform:
name: Lint Terraform code
runs-on: ubuntu-latest
defaults:
run:
working-directory: terraform
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Terraform
uses: hashicorp/setup-terraform@v3

- name: Lint Terraform code
run: terraform fmt -check -diff -recursive

- name: Initialize Terraform (offline only)
run: terraform init -backend=false

- name: Validate Terraform code
run: terraform validate
3 changes: 2 additions & 1 deletion terraform/api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module "api" {
heroku_cloudamqp_plan = "squirrel-1"
heroku_papertrail_plan = "liatorp"

heroku_web_dyno_quantity = 1
heroku_web_dyno_quantity = 3
heroku_worker_dyno_quantity = 1

django_default_from_email = "[email protected]"
Expand All @@ -42,6 +42,7 @@ module "api" {
DJANGO_DANDI_WEB_APP_URL = "https://dandiarchive.org"
DJANGO_DANDI_API_URL = "https://api.dandiarchive.org"
DJANGO_DANDI_JUPYTERHUB_URL = "https://hub.dandiarchive.org/"
DJANGO_DANDI_DEV_EMAIL = var.dev_email
}
additional_sensitive_django_vars = {
DJANGO_DANDI_DOI_API_PASSWORD = var.doi_api_password
Expand Down
43 changes: 43 additions & 0 deletions terraform/aws_oidc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
data "tls_certificate" "tfc_certificate" {
url = "https://app.terraform.io"
}

resource "aws_iam_openid_connect_provider" "tfc_provider" {
url = data.tls_certificate.tfc_certificate.url
client_id_list = ["aws.workload.identity"]
thumbprint_list = [data.tls_certificate.tfc_certificate.certificates[0].sha1_fingerprint]
}

resource "aws_iam_role" "tfc_role" {
name = "terraform-cloud-role"

assume_role_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Federated" : "${aws_iam_openid_connect_provider.tfc_provider.arn}"
},
"Action" : "sts:AssumeRoleWithWebIdentity",
"Condition" : {
"StringEquals" : {
"app.terraform.io:aud" : "${one(aws_iam_openid_connect_provider.tfc_provider.client_id_list)}"
},
"StringLike" : {
"app.terraform.io:sub" : "organization:dandi:project:Default Project:workspace:dandi-prod:run_phase:*"
}
}
}
]
})
}

data "aws_iam_policy" "administrator_access" {
arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}

resource "aws_iam_role_policy_attachment" "tfc_policy_attachment" {
role = aws_iam_role.tfc_role.name
policy_arn = data.aws_iam_policy.administrator_access.arn
}
2 changes: 1 addition & 1 deletion terraform/domain.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "aws_route53_record" "acm_validation" {
name = "_cbe41dfe1888c2bb5c157cacc35e1722"
type = "CNAME"
ttl = "300"
records = ["_46df7ee9a9c17698aedbb737f220c63a.mzlfeqexyx.acm-validations.aws"]
records = ["_46df7ee9a9c17698aedbb737f220c63a.mzlfeqexyx.acm-validations.aws."]
}

resource "aws_route53_record" "gui" {
Expand Down
57 changes: 53 additions & 4 deletions terraform/modules/dandiset_bucket/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ resource "aws_s3_bucket_cors_configuration" "dandiset_bucket" {
"PUT",
"POST",
"GET",
"HEAD",
"DELETE",
]
allowed_headers = [
Expand Down Expand Up @@ -107,15 +108,15 @@ data "aws_iam_policy_document" "dandiset_bucket_owner" {
}

dynamic "statement" {
for_each = var.allow_heroku_put_object ? [1] : []
for_each = (var.allow_cross_account_heroku_put_object || var.allow_heroku_put_object) ? [1] : []
content {

resources = [
"${aws_s3_bucket.dandiset_bucket.arn}",
"${aws_s3_bucket.dandiset_bucket.arn}/*",
]

actions = ["s3:PutObject"]
actions = ["s3:PutObject", "s3:PutObjectTagging"]
}
}

Expand Down Expand Up @@ -166,6 +167,33 @@ data "aws_iam_policy_document" "dandiset_bucket_policy" {
}
}

# Disallow access to embargoed objects, unless using the heroku user arn
dynamic "statement" {
for_each = var.public ? [1] : []

content {
effect = "Deny"
principals {
identifiers = ["*"]
type = "*"
}
actions = ["s3:*"]
resources = [
"${aws_s3_bucket.dandiset_bucket.arn}/*",
]
condition {
test = "StringEquals"
variable = "s3:ExistingObjectTag/embargoed"
values = ["true"]
}
condition {
test = "ArnNotEquals"
variable = "aws:PrincipalArn"
values = [var.heroku_user.arn]
}
}
}

dynamic "statement" {
for_each = var.allow_cross_account_heroku_put_object ? [1] : []

Expand Down Expand Up @@ -237,6 +265,23 @@ data "aws_iam_policy_document" "dandiset_bucket_policy" {
}
}

dynamic "statement" {
for_each = var.allow_cross_account_heroku_put_object ? [1] : []
content {
resources = [
"${aws_s3_bucket.dandiset_bucket.arn}",
"${aws_s3_bucket.dandiset_bucket.arn}/*",
]

actions = ["s3:PutObjectTagging"]

principals {
type = "AWS"
identifiers = [var.heroku_user.arn]
}
}
}

dynamic "statement" {
for_each = var.trailing_delete ? [1] : []

Expand All @@ -263,7 +308,7 @@ data "aws_iam_policy_document" "dandiset_bucket_policy" {


# S3 lifecycle policy that permanently deletes objects with delete markers
# after 30 days.
# after 30 days. Note, this only applies to objects with the `blobs/` prefix.
resource "aws_s3_bucket_lifecycle_configuration" "expire_deleted_objects" {
# Must have bucket versioning enabled first
depends_on = [aws_s3_bucket_versioning.dandiset_bucket]
Expand All @@ -275,7 +320,11 @@ resource "aws_s3_bucket_lifecycle_configuration" "expire_deleted_objects" {
# Based on https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-configuration-examples.html#lifecycle-config-conceptual-ex7
rule {
id = "ExpireOldDeleteMarkers"
filter {}
filter {
# We only want to expire objects with the `blobs/` prefix, i.e. Asset Blobs.
# Other objects in this bucket are not subject to this lifecycle policy.
prefix = "blobs/"
}

# Expire objects with delete markers after 30 days
noncurrent_version_expiration {
Expand Down
2 changes: 1 addition & 1 deletion terraform/modules/dandiset_bucket/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ variable "log_bucket_name" {
# TODO: this can be inferred from the "versioning" variable once we're ready
# to deploy this to the production bucket as well.
variable "trailing_delete" {
type = bool
type = bool
description = "Whether or not trailing delete should be enabled on the bucket."
}
3 changes: 2 additions & 1 deletion terraform/staging_pipeline.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module "api_staging" {

heroku_web_dyno_size = "basic"
heroku_worker_dyno_size = "basic"
heroku_postgresql_plan = "basic"
heroku_postgresql_plan = "essential-1"
heroku_cloudamqp_plan = "tiger"
heroku_papertrail_plan = "fixa"

Expand Down Expand Up @@ -41,6 +41,7 @@ module "api_staging" {
DJANGO_DANDI_WEB_APP_URL = "https://gui-staging.dandiarchive.org"
DJANGO_DANDI_API_URL = "https://api-staging.dandiarchive.org"
DJANGO_DANDI_JUPYTERHUB_URL = "https://hub.dandiarchive.org/"
DJANGO_DANDI_DEV_EMAIL = var.dev_email
}
additional_sensitive_django_vars = {
DJANGO_DANDI_DOI_API_PASSWORD = var.test_doi_api_password
Expand Down
5 changes: 5 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ variable "test_doi_api_password" {
type = string
description = "The password for the Datacite Test API, used to mint new DOIs on staging during publish."
}

variable "dev_email" {
type = string
description = "The core developer email list."
}
36 changes: 36 additions & 0 deletions terraform/webdav.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "heroku_app" "webdav" {
name = "dandidav"
region = "us"
acm = true

organization {
name = data.heroku_team.dandi.name
}

buildpacks = [
# The Rust application is compiled and pushed to Heroku via a GitHub Action, so
# we don't need to specify a specific buildpack here. So, we just fall back to
# the Heroku CLI buildpack as a default.
"https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku-community/cli.tgz"
]
}

resource "heroku_formation" "webdav_heroku_web" {
app_id = heroku_app.webdav.id
type = "web"
size = "standard-2x"
quantity = 1
}

resource "heroku_domain" "webdav" {
app_id = heroku_app.webdav.id
hostname = "webdav.dandiarchive.org"
}

resource "aws_route53_record" "heroku" {
zone_id = aws_route53_zone.dandi.zone_id
name = "webdav"
type = "CNAME"
ttl = "300"
records = [heroku_domain.webdav.cname]
}