Skip to content

Commit b0ccced

Browse files
committed
Fixing up policy
1 parent 7c57051 commit b0ccced

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

aws-cs-assume-role/create-role/CreateRoleStack.cs

+35-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,32 @@ public CreateRoleStack()
2626
new CustomResourceOptions { AdditionalSecretOutputs = { "secret" } });
2727

2828
AssumeRolePolicyArgs policyArgs = new AssumeRolePolicyArgs(unprivilegedUser.Arn);
29-
var tempPolicy = Output.Create(policyArgs).Apply(args => JsonSerializer.Serialize(args));
29+
var tempPolicy = Output.Create(policyArgs).Apply(args => JsonSerializer.Serialize(args,
30+
new JsonSerializerOptions
31+
{
32+
WriteIndented = false,
33+
PropertyNamingPolicy = null // Remove camelCase policy
34+
}));
35+
36+
// Alternative approach using a direct string-based policy document
37+
var directPolicy = unprivilegedUser.Arn.Apply(arn => @$"{{
38+
""Version"": ""2012-10-17"",
39+
""Statement"": [
40+
{{
41+
""Sid"": ""AllowAssumeRole"",
42+
""Effect"": ""Allow"",
43+
""Principal"": {{
44+
""AWS"": ""{arn}""
45+
}},
46+
""Action"": ""sts:AssumeRole""
47+
}}
48+
]
49+
}}");
3050

3151
var allowS3ManagementRole = new Iam.Role("allow-s3-management", new Iam.RoleArgs
3252
{
3353
Description = "Allow management of S3 buckets",
34-
AssumeRolePolicy = tempPolicy
54+
AssumeRolePolicy = directPolicy // Use the direct string approach instead
3555
});
3656

3757
var rolePolicy = new Iam.RolePolicy("allow-s3-management-policy", new Iam.RolePolicyArgs
@@ -57,21 +77,30 @@ public CreateRoleStack()
5777

5878
public class AssumeRolePolicyArgs
5979
{
80+
[JsonPropertyName("Version")]
6081
public string Version => "2012-10-17";
61-
public StatementArgs Statement { get; private set; }
82+
83+
[JsonPropertyName("Statement")]
84+
public StatementArgs[] Statement { get; private set; }
6285

6386
public AssumeRolePolicyArgs(Input<string> arn)
6487
{
65-
Statement = new StatementArgs(arn);
88+
Statement = new StatementArgs[] { new StatementArgs(arn) };
6689
}
67-
6890
}
6991

7092
public class StatementArgs
7193
{
94+
[JsonPropertyName("Sid")]
7295
public string Sid => "AllowAssumeRole";
96+
97+
[JsonPropertyName("Effect")]
7398
public string Effect => "Allow";
99+
100+
[JsonPropertyName("Principal")]
74101
public PrincipalArgs Principal { get; private set; }
102+
103+
[JsonPropertyName("Action")]
75104
public string Action => "sts:AssumeRole";
76105

77106
public StatementArgs(Input<string> arn)
@@ -82,6 +111,7 @@ public StatementArgs(Input<string> arn)
82111

83112
public class PrincipalArgs
84113
{
114+
[JsonPropertyName("AWS")]
85115
public Input<string> AWS { get; private set; }
86116

87117
public PrincipalArgs(Input<string> arn)

0 commit comments

Comments
 (0)