1818import java .security .cert .Certificate ;
1919import java .security .cert .CertificateEncodingException ;
2020import java .util .Collections ;
21+ import java .util .List ;
2122import java .util .Optional ;
2223import java .util .concurrent .Callable ;
2324
@@ -67,6 +68,9 @@ public class AwsStsSetup implements Callable<Void> {
6768 @ CommandLine .Option (names = {"--maxSessionDuration" }, description = "Bucket Prefix for STS vaults." , required = false )
6869 Integer maxSessionDuration ;
6970
71+ @ CommandLine .Option (names = {"--clientId" }, description = "ClientIds for the OIDC provider." , required = true )
72+ List <String > clientId ;
73+
7074 @ Override
7175 public Void call () throws Exception {
7276 // remove trailing slash
@@ -79,24 +83,24 @@ public Void call() throws Exception {
7983
8084 final String sha = getThumbprint (url );
8185 System .out .println (sha );
82- final Region region = Region .AWS_GLOBAL ;
8386
8487 try (final IamClient iam = IamClient .builder ()
85- .region (region )
88+ .region (Region . AWS_GLOBAL )
8689 .credentialsProvider (ProfileCredentialsProvider .create (profileName ))
8790 .build ()) {
8891 final ListOpenIdConnectProvidersResponse existingOpenIdConnectProviders = iam .listOpenIDConnectProviders ();
8992 System .out .println (existingOpenIdConnectProviders );
9093
9194
9295 final Optional <OpenIDConnectProviderListEntry > existingOIDCProvider = existingOpenIdConnectProviders .openIDConnectProviderList ().stream ().filter (idp -> idp .arn ().endsWith (arnPostfix )).findFirst ();
93-
96+ //
9497 // aws iam create-open-id-connect-provider --url https://testing.hub.cryptomator.org/kc/realms/cipherduck --client-id-list cryptomator cryptomatorhub --thumbprint-list BE21B29075BF9F3265353F8B85208A8981DAEC2A
98+ //
9599 final String oidcProviderArn ;
96100 if (existingOIDCProvider .isEmpty ()) {
97101 final CreateOpenIdConnectProviderResponse openIDConnectProvider = iam .createOpenIDConnectProvider (CreateOpenIdConnectProviderRequest .builder ()
98102 .url (realmUrl )
99- .clientIDList ("cryptomator" , "cryptomatorhub" , "cryptomatorvaults" )
103+ .clientIDList (clientId )
100104 .thumbprintList (sha )
101105 .build ());
102106 oidcProviderArn = openIDConnectProvider .openIDConnectProviderArn ();
@@ -112,19 +116,18 @@ public Void call() throws Exception {
112116 System .out .println (oidcProviderArn );
113117 final String arnPrefix = oidcProviderArn .replace (":oidc-provider" + "/" + arnPostfix , "" );
114118
115-
119+ //
116120 // aws iam create-role --role-name cipherduck-createbucket --assume-role-policy-document file://src/main/resources/cipherduck/setup/aws_stscreatebuckettrustpolicy.json
117121 // aws iam put-role-policy --role-name cipherduck-createbucket --policy-name cipherduck-createbucket --policy-document file://src/main/resources/cipherduck/setup/aws_stscreatebucketpermissionpolicy.json
122+ //
118123 final String awsSTSCreateBucketRoleName = String .format ("%s-createbucket" , arnPostfixSanitized );
119124 final JSONObject awsSTSCreateBuckeTrustPolicyTemplate = new JSONObject (IOUtils .toString (KattaSetupCli .class .getResourceAsStream ("/setup/aws_sts/createbuckettrustpolicy.json" ), Charset .defaultCharset ()));
120125 final JSONObject awsSTSCreateBuckePermissionPolicyTemplate = new JSONObject (IOUtils .toString (KattaSetupCli .class .getResourceAsStream ("/setup/aws_sts/createbucketpermissionpolicy.json" ), Charset .defaultCharset ()));
121126 injectFederated (awsSTSCreateBuckeTrustPolicyTemplate , oidcProviderArn );
122127 injectBucketPrefixIntoResources (awsSTSCreateBuckePermissionPolicyTemplate , bucketPrefix );
123128 uploadAssumeRolePolicyAndPermissionPolicy (iam , awsSTSCreateBucketRoleName , awsSTSCreateBuckeTrustPolicyTemplate , awsSTSCreateBuckePermissionPolicyTemplate , maxSessionDuration );
124129
125- // TODO inject MaxSessionDuration
126-
127-
130+ //
128131 // aws iam create-role --role-name cipherduck_chain_01 --assume-role-policy-document file://src/main/resources/cipherduck/setup/aws_stscipherduck_chain_01_trustpolicy.json
129132 // aws iam put-role-policy --role-name cipherduck_chain_01 --policy-name cipherduck_chain_01 --policy-document file://src/main/resources/cipherduck/setup/aws_stscipherduck_chain_01_permissionpolicy.json
130133 //
@@ -136,8 +139,11 @@ public Void call() throws Exception {
136139 awsSTSChain01RoleNamePermissionPolicyTemplate .getJSONArray ("Statement" ).getJSONObject (0 ).put ("Resource" , arnPrefix + ":role/" + awsSTSChain02RoleName );
137140 uploadAssumeRolePolicyAndPermissionPolicy (iam , awsSTSChain01RoleName , awsSTSChain01RoleNameTrustPolicyTemplate , awsSTSChain01RoleNamePermissionPolicyTemplate , maxSessionDuration );
138141
139- Thread . sleep ( 10000 );
142+ //
140143 // sleep 10;
144+ //
145+ Thread .sleep (10000 );
146+
141147 //
142148 // aws iam create-role --role-name cipherduck_chain_02 --assume-role-policy-document file://src/main/resources/cipherduck/setup/aws_stscipherduck_chain_02_trustpolicy.json
143149 // aws iam put-role-policy --role-name cipherduck_chain_02 --policy-name cipherduck_chain_02 --policy-document file://src/main/resources/cipherduck/setup/aws_stscipherduck_chain_02_permissionpolicy.json
0 commit comments