11import { CustomResource } from "@aws-cdk/aws-cloudformation" ;
22import { FederatedPrincipal , PolicyStatement , Role } from "@aws-cdk/aws-iam" ;
3- import { Construct , Lazy } from "@aws-cdk/core" ;
3+ import { Construct } from "@aws-cdk/core" ;
44import { Cluster } from "./cluster" ;
55import { OPENIDCONNECT_PROVIDER_RESOURCE_TYPE } from "./cluster-resource-handler/consts" ;
66import { ClusterResourceProvider } from "./cluster-resource-provider" ;
77
8+ /**
9+ * Service Account
10+ */
811export interface ServiceAccountOptions {
12+ /**
13+ * The cluster to apply the patch to.
14+ */
915 readonly name : string ;
16+ /**
17+ * The cluster to apply the patch to.
18+ */
1019 readonly namespace : string ;
20+ /**
21+ * The cluster to apply the patch to.
22+ * @default No additional policies are applied
23+ */
1124 readonly policyStatements ?: PolicyStatement [ ] ;
1225}
1326
27+ /**
28+ * Service Account
29+ */
1430export interface ServiceAccountProps extends ServiceAccountOptions {
31+ /**
32+ * The cluster to apply the patch to.
33+ * [disable-awslint:ref-via-interface]
34+ */
1535 readonly cluster : Cluster ;
1636}
1737
38+ /**
39+ * Service Account
40+ */
1841export class ServiceAccount extends Construct {
19-
42+ /**
43+ * The cluster to apply the patch to.
44+ */
2045 public readonly serviceAccountName : string ;
2146
2247 private readonly role : Role ;
2348
24- private openIDConnectSubject : string | undefined ;
2549 private openIdConnectProviderArn : string | undefined ;
2650
2751 constructor ( scope : Construct , id : string , props : ServiceAccountProps ) {
@@ -31,11 +55,9 @@ export class ServiceAccount extends Construct {
3155 // Ensure OpenIDConnect association
3256 this . enableOpenIDConnectIAMProvider ( cluster ) ;
3357 // Create IAM Role
34- const condition : { [ id : string ] : any ; } = { } ;
35- condition [ Lazy . stringValue ( { produce : ( ) => this . openIDConnectSubject } ) ] = `system:serviceaccount:${ namespace } :${ name } ` ;
3658 this . role = new Role ( this , "Role" , {
3759 assumedBy : new FederatedPrincipal (
38- this . openIdConnectProviderArn ! , { StringEquals : condition } , "sts:AssumeRoleWithWebIdentity"
60+ this . openIdConnectProviderArn ! , { } , "sts:AssumeRoleWithWebIdentity"
3961 )
4062 } ) ;
4163 policyStatements ?. forEach ( this . role . addToPolicy ) ;
@@ -58,6 +80,9 @@ export class ServiceAccount extends Construct {
5880 this . serviceAccountName = name ;
5981 }
6082
83+ /**
84+ * The cluster to apply the patch to.
85+ */
6186 public addToPolicy ( statements : PolicyStatement ) {
6287 this . role . addToPolicy ( statements ) ;
6388 }
@@ -79,7 +104,7 @@ export class ServiceAccount extends Construct {
79104 }
80105 } ) ;
81106 }
82- this . openIDConnectSubject = resource . getAtt ( "openIDConnectSubject" ) . toString ( ) ;
107+ // this.openIDConnectSubject = resource.getAtt("openIDConnectSubject").toString();
83108 this . openIdConnectProviderArn = resource . ref ;
84109 }
85110}
0 commit comments