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

Create pytorch-ci-artifacts s3 bucket #33

Merged
merged 1 commit into from
Feb 22, 2024
Merged
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
97 changes: 97 additions & 0 deletions aws/391835788720/us-east-1/ci-artifacts.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
resource "aws_s3_bucket" "pytorch_ci_artifacts" {
bucket = "pytorch-ci-artifacts"
}

resource "aws_s3_bucket_public_access_block" "pytorch_ci_artifacts_access_block" {
bucket = aws_s3_bucket.pytorch_ci_artifacts.id

block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}

resource "aws_s3_bucket_policy" "allow_public_read" {
bucket = aws_s3_bucket.pytorch_ci_artifacts.id
policy = data.aws_iam_policy_document.allow_public_read.json
}

data "aws_iam_policy_document" "allow_public_read" {
statement {
principals {
type = "*"
identifiers = ["*"]
}

actions = [
"s3:GetObject",
]

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

resource "aws_s3_bucket_website_configuration" "pytorch_ci_artifacts_website" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This makes a publicly available web URL for the S3 bucket to download artifacts from. We purposely disallow navigating the website to prevent snooping so users will need to know the direct URL for the artifacts they want to access.

What typically I've seen other projects do is create a index.html to list all of the artifacts for the build and store the build URL for the S3 bucket to that index file so that there's only 1 URL per build to remember and download the rest of the artifacts from.

bucket = aws_s3_bucket.pytorch_ci_artifacts.id

index_document {
suffix = "index.html"
}

error_document {
key = "error.html"
}
}

resource "aws_iam_policy" "pytorch_ci_artifacts_access" {
name = "pytorch-ci-artifacts-access"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::pytorch-ci-artifacts/*"]
}
]
}
EOF
}

resource "aws_iam_role" "gha_pytorch_ci_artifacts_role" {
name = "gha-pytorch-ci-artifacts-role"

max_session_duration = 18000
description = "Used by PyTorch CI to upload artifacts to S3 bucket pytorch-ci-artifacts"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Principal = {
Federated = "arn:aws:iam::${local.aws_account_id}:oidc-provider/token.actions.githubusercontent.com"
}
Action = "sts:AssumeRoleWithWebIdentity"
Condition = {
StringEquals = {
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
}
StringLike = {
"token.actions.githubusercontent.com:sub" = "repo:pytorch/*",
}
}
}
]
})
}

resource "aws_iam_role_policy_attachment" "pytorch_ci_artifacts_attach" {
role = aws_iam_role.gha_pytorch_ci_artifacts_role.name
policy_arn = aws_iam_policy.pytorch_ci_artifacts_access.arn
}
Loading