Skip to content

Commit bcbe164

Browse files
committed
Add IAM federation to test artifacts
We already have this configured in prod artifacts.
1 parent 18597b6 commit bcbe164

File tree

1 file changed

+89
-0
lines changed
  • infra/aws/terraform/test-artifacts.k8s.io

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
# Recognize federated identities from the prow trusted cluster
18+
resource "aws_iam_openid_connect_provider" "k8s-infra-trusted-cluster" {
19+
url = "https://container.googleapis.com/v1/projects/k8s-infra-prow-build-trusted/locations/us-central1/clusters/prow-build-trusted"
20+
client_id_list = ["sts.amazonaws.com"]
21+
thumbprint_list = ["08745487e891c19e3078c1f2a07e452950ef36f6"]
22+
}
23+
24+
# s3writer iam role for artifacts management
25+
# We allow the kubernetes service account to assume this role
26+
resource "aws_iam_role" "artifacts-k8s-io-s3writer" {
27+
name = "${var.prefix}artifacts.k8s.io_s3writer"
28+
assume_role_policy = jsonencode({
29+
Version = "2012-10-17"
30+
Statement = [
31+
{
32+
"Effect" : "Allow",
33+
"Principal" : {
34+
"Federated" : aws_iam_openid_connect_provider.k8s-infra-trusted-cluster.arn
35+
},
36+
"Action" : "sts:AssumeRoleWithWebIdentity",
37+
"Condition" : {
38+
"StringEquals" : {
39+
"container.googleapis.com/v1/projects/k8s-infra-prow-build-trusted/locations/us-central1/clusters/prow-build-trusted:sub" : "system:serviceaccount:test-pods:k8s-infra-promoter"
40+
}
41+
}
42+
}
43+
]
44+
})
45+
46+
max_session_duration = 43200
47+
48+
tags = {
49+
project = "${var.prefix}artifacts.k8s.io"
50+
}
51+
}
52+
53+
# Grant the s3writer IAM role permissions to write to buckets
54+
resource "aws_iam_role_policy" "artifacts-k8s-io-s3writer-policy" {
55+
name = "${var.prefix}artifacts.k8s.io_s3writer_policy"
56+
role = aws_iam_role.artifacts-k8s-io-s3writer.id
57+
58+
policy = jsonencode({
59+
Version = "2012-10-17"
60+
Statement = [
61+
{
62+
Action = [
63+
# Object permissions
64+
"s3:GetObject",
65+
"s3:GetObjectAcl",
66+
"s3:GetObjectAttributes",
67+
"s3:GetObjectRetention",
68+
"s3:GetObjectTagging",
69+
"s3:GetObjectVersion",
70+
"s3:GetObjectVersionAcl",
71+
"s3:GetObjectVersionAttributes",
72+
"s3:GetObjectVersionForReplication",
73+
"s3:GetObjectVersionTagging",
74+
"s3:PutObject",
75+
76+
# Bucket permissions
77+
"s3:GetBucketAcl",
78+
"s3:GetBucketLocation",
79+
"s3:GetReplicationConfiguration",
80+
"s3:ListAllMyBuckets",
81+
"s3:ListBucket",
82+
"s3:ListBucketVersions",
83+
]
84+
Effect = "Allow"
85+
Resource = "*"
86+
},
87+
]
88+
})
89+
}

0 commit comments

Comments
 (0)