-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbucket-oidc-template.yaml
99 lines (91 loc) · 3.07 KB
/
bitbucket-oidc-template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
AWSTemplateFormatVersion: '2010-09-09'
Description: Bitbucket OIDC configuration for communication between Bitbucket and AWS.
Parameters:
WorkspaceName:
Type: String
Default: pjv93
Description: "Bitbucket workspace name (e.g., pjv93)."
RepositoryUUID:
Type: String
Default: "*"
Description: "Bitbucket repository UUID (e.g., {123e4567-e89b-12d3-a456-426614174000}) or * for all repositories."
Audience:
Type: String
Description: "The audience (aud) retrieved from Bitbucket repository settings."
BucketName:
Type: String
Default: iampjv.co
Description: "S3 bucket name (e.g., iampjv.co)."
IAMRoleName:
Type: String
Default: Bitbucket_OIDC_Role
Description: "IAM role name for Bitbucket OIDC (default: Bitbucket_OIDC_Role)."
Resources:
# OIDC Provider
BitbucketOidcProvider:
Type: AWS::IAM::OIDCProvider
Properties:
ClientIdList:
- !Ref Audience
ThumbprintList:
- a031c46782e6e6c661cd4bd10397f7fdc7df0afe
Url: !Sub "https://api.bitbucket.org/2.0/workspaces/${WorkspaceName}/pipelines-config/identity/oidc"
# IAM Role
BitbucketOidcRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref IAMRoleName
AssumeRolePolicyDocument: !Sub
- |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "${IamOidcProviderArn}"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"${OidcProviderEndpoint}:aud": "${Audience}"
},
"StringLike": {
"${OidcProviderEndpoint}:sub": "${RepositoryUUID}:*"
}
}
}
]
}
- {
"IamOidcProviderArn": !Sub "arn:aws:iam::${AWS::AccountId}:oidc-provider/api.bitbucket.org/2.0/workspaces/${WorkspaceName}/pipelines-config/identity/oidc",
"OidcProviderEndpoint": !Sub "api.bitbucket.org/2.0/workspaces/${WorkspaceName}/pipelines-config/identity/oidc",
"Audience": !Ref Audience,
"RepositoryUUID": !Ref RepositoryUUID
}
Policies:
- PolicyName: BitbucketOIDCPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: S3Access
Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:DeleteObject
Resource:
- !Sub "arn:aws:s3:::${BucketName}/*"
- Sid: CloudWatchLogsAccess
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
Outputs:
RoleArn:
Description: "The ARN of the IAM Role for Bitbucket OIDC."
Value: !GetAtt BitbucketOidcRole.Arn
Export:
Name: BitbucketOidcRoleArn