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

security policy change for private python index for ddat data science #163

Merged
88 changes: 79 additions & 9 deletions infra/ecs_main_gitlab.tf
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ resource "aws_launch_configuration" "gitlab_runner_data_science" {
# types of infrastructure
image_id = "ami-0749bd3fac17dc2cc"
instance_type = var.gitlab_runner_data_science_instance_type
iam_instance_profile = aws_iam_instance_profile.gitlab_runner[count.index].name
iam_instance_profile = aws_iam_instance_profile.gitlab_runner_data_science[count.index].name
security_groups = ["${aws_security_group.gitlab_runner[count.index].id}"]
key_name = aws_key_pair.shared.key_name

Expand Down Expand Up @@ -936,6 +936,69 @@ data "aws_iam_policy_document" "gitlab_runner" {
]
}

}

resource "aws_iam_policy_attachment" "gitlab_runner" {
count = var.gitlab_on ? 1 : 0
name = "${var.prefix}-gitlab-runner"
roles = ["${aws_iam_role.gitlab_runner[count.index].name}"]
policy_arn = aws_iam_policy.gitlab_runner[count.index].arn
}

resource "aws_iam_instance_profile" "gitlab_runner_data_science" {
count = var.gitlab_on ? 1 : 0
name = "${var.prefix}-gitlab-runner-data-science"
role = aws_iam_role.gitlab_runner_data_science[count.index].name
}

resource "aws_iam_role" "gitlab_runner_data_science" {
count = var.gitlab_on ? 1 : 0
name = "${var.prefix}-gitlab-runner"
path = "/"
assume_role_policy = data.aws_iam_policy_document.gitlab_runner_data_science_assume_role[count.index].json
}

data "aws_iam_policy_document" "gitlab_runner_data_science_assume_role" {
count = var.gitlab_on ? 1 : 0
statement {
actions = ["sts:AssumeRole"]

principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}

resource "aws_iam_policy" "gitlab_runner_data_science" {
count = var.gitlab_on ? 1 : 0
name = "${var.prefix}-gitlab-runner-data-science"
policy = data.aws_iam_policy_document.gitlab_runner_data_science[count.index].json
}

data "aws_iam_policy_document" "gitlab_runner_data_science" {
count = var.gitlab_on ? 1 : 0

statement {
actions = [
"ecr:GetAuthorizationToken",
]

resources = [
"*"
]
}

# Read only for the base images
statement {
actions = [
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
]

resources = aws_ecr_repository.theia.arn
}

# All for user-provided
statement {
actions = [
Expand All @@ -946,20 +1009,27 @@ data "aws_iam_policy_document" "gitlab_runner" {
"ecr:ListImages",
"ecr:DescribeImages",
"ecr:BatchGetImage",
"ecr:InitiateLayerUpload",
"ecr:UploadLayerPart",
"ecr:CompleteLayerUpload",
"ecr:PutImage",
]
resources = [
"${aws_ecr_repository.user_provided.arn}",
]
}

# Allow list and put object for Gitlab private package index
statement {
actions = [
"s3:ListBucket",
"s3:PutObject"
]
resources = [
"arn:aws:s3:::${aws_s3_bucket.notebooks.id}/shared/ddat_packages/*"
]
}
}

resource "aws_iam_policy_attachment" "gitlab_runner" {
resource "aws_iam_policy_attachment" "gitlab_runner_data_science" {
count = var.gitlab_on ? 1 : 0
name = "${var.prefix}-gitlab-runner"
roles = ["${aws_iam_role.gitlab_runner[count.index].name}"]
policy_arn = aws_iam_policy.gitlab_runner[count.index].arn
name = "${var.prefix}-gitlab-runner-data-science"
roles = ["${aws_iam_role.gitlab_runner_data_science[count.index].name}"]
policy_arn = aws_iam_policy.gitlab_runner_data_science[count.index].arn
}
Loading