44
55package cloud .katta .cli .commands .storage ;
66
7+ import cloud .katta .cli .KattaSetupCli ;
8+ import io .minio .admin .MinioAdminClient ;
79import org .apache .commons .io .IOUtils ;
810import org .json .JSONArray ;
911import org .json .JSONObject ;
12+ import picocli .CommandLine ;
1013
14+ import java .net .URI ;
1115import java .nio .charset .Charset ;
1216import java .util .List ;
1317import java .util .Objects ;
1418import java .util .concurrent .Callable ;
1519
16- import cloud .katta .cli .KattaSetupCli ;
17- import io .minio .admin .MinioAdminClient ;
18- import picocli .CommandLine ;
19-
2020/**
2121 * Sets up MinIO for Katta in STS mode:
2222 * <ul>
@@ -36,6 +36,9 @@ public class MinioStsSetup implements Callable<Void> {
3636 @ CommandLine .Option (names = {"--endpointUrl" }, description = "MinIO URL. Example: \" http://localhost:9000\" " , required = true )
3737 String endpointUrl ;
3838
39+ @ CommandLine .Option (names = {"--hubUrl" }, description = "Hub URL. Example: \" https://testing.katta.cloud/tamarind\" " , required = true )
40+ String hubUrl ;
41+
3942 @ CommandLine .Option (names = {"--profileName" }, description = "AWS profile to load AWS credentials from. See ~/.aws/credentials." , required = false )
4043 String profileName ;
4144
@@ -59,10 +62,10 @@ public class MinioStsSetup implements Callable<Void> {
5962
6063 @ Override
6164 public Void call () throws Exception {
62- if (createbucketPolicyName == null ) {
65+ if (createbucketPolicyName == null ) {
6366 createbucketPolicyName = String .format ("%screatebucketpolicy" , bucketPrefix );
6467 }
65- if (accessbucketPolicyName == null ) {
68+ if (accessbucketPolicyName == null ) {
6669 accessbucketPolicyName = String .format ("%saccessbucketpolicy" , bucketPrefix );
6770 }
6871
@@ -74,7 +77,7 @@ public Void call() throws Exception {
7477 {
7578 final JSONObject miniocreatebucketpolicy = new JSONObject (IOUtils .toString (KattaSetupCli .class .getResourceAsStream ("/setup/minio_sts/createbucketpolicy.json" ), Charset .defaultCharset ()));
7679 final JSONArray statements = miniocreatebucketpolicy .getJSONArray ("Statement" );
77- for (int i = 0 ; i < statements .length (); i ++) {
80+ for (int i = 0 ; i < statements .length (); i ++) {
7881 final List <String > list = statements .getJSONObject (i ).getJSONArray ("Resource" ).toList ().stream ().map (Objects ::toString ).map (s -> s .replace ("katta" , bucketPrefix )).toList ();
7982 statements .getJSONObject (i ).put ("Resource" , list );
8083 }
@@ -85,34 +88,48 @@ public Void call() throws Exception {
8588 {
8689 final JSONObject minioaccessbucketpolicy = new JSONObject (IOUtils .toString (KattaSetupCli .class .getResourceAsStream ("/setup/minio_sts/accessbucketpolicy.json" ), Charset .defaultCharset ()));
8790 final JSONArray statements = minioaccessbucketpolicy .getJSONArray ("Statement" );
88- for (int i = 0 ; i < statements .length (); i ++) {
91+ for (int i = 0 ; i < statements .length (); i ++) {
8992 final List <String > list = statements .getJSONObject (i ).getJSONArray ("Resource" ).toList ().stream ().map (Objects ::toString ).map (s -> s .replace ("katta" , bucketPrefix )).toList ();
9093 statements .getJSONObject (i ).put ("Resource" , list );
9194 }
9295 minioAdminClient .addCannedPolicy (accessbucketPolicyName , minioaccessbucketpolicy .toString ());
9396 System .out .println (minioAdminClient .listCannedPolicies ().get (accessbucketPolicyName ));
9497 }
9598
96-
97- // /mc idp openid add myminio cryptomator \
98- // config_url="${HUB_KEYCLOAK_URL}${HUB_KEYCLOAK_BASEPATH}/realms/${HUB_KEYCLOAK_REALM}/.well-known/openid-configuration" \
99- // client_id="cryptomator" \
100- // client_secret="ignore-me" \
101- // role_policy="cipherduckcreatebucket"
102- // {
103- // minioClient.
104- // }
105- // /mc idp openid add myminio cryptomatorhub \
106- // config_url="${HUB_KEYCLOAK_URL}${HUB_KEYCLOAK_BASEPATH}/realms/${HUB_KEYCLOAK_REALM}/.well-known/openid-configuration" \
107- // client_id="cryptomatorhub" \
108- // client_secret="ignore-me" \
109- // role_policy="cipherduckcreatebucket"
110- // /mc idp openid add myminio cryptomatorvaults \
111- // config_url="${HUB_KEYCLOAK_URL}${HUB_KEYCLOAK_BASEPATH}/realms/${HUB_KEYCLOAK_REALM}/.well-known/openid-configuration" \
112- // client_id="cryptomatorvaults" \
113- // client_secret="ignore-me" \
114- // role_policy="cipherduckaccessbucket"
115-
99+ final String json = IOUtils .toString (URI .create (hubUrl + "/api/config" ), Charset .forName ("UTF-8" ));
100+ final JSONObject apiConfig = new JSONObject (json );
101+ final String wellKnown = String .format ("%s/realms/%s/.well-known/openid-configuration" , apiConfig .getString ("keycloakUrl" ), apiConfig .getString ("keycloakRealm" ));
102+
103+ String keycloakClientIdCryptomator = apiConfig .getString ("keycloakClientIdCryptomator" );
104+ String keycloakClientIdHub = apiConfig .getString ("keycloakClientIdHub" );
105+ String keycloakClientIdCryptomatorVaults = apiConfig .getString ("keycloakClientIdCryptomatorVaults" );
106+ System .out .println (String .format ("""
107+ # The MinIO Client API is incomplete (https://github.com/minio/minio/issues/16151).
108+ # Please execute the following commands on the command line.
109+ # Further info: https://github.com/shift7-ch/katta-docs/blob/main/SETUP_KATTA_SERVER.md#minio
110+
111+ mc alias set myminio %s %s %s
112+
113+ mc idp openid add myminio %s \\
114+ config_url="%s" \\
115+ client_id="%s" \\
116+ client_secret="ignore-me" \\
117+ role_policy="%s"
118+ mc idp openid add myminio %s \\
119+ config_url="%s" \\
120+ client_id="%s" \\
121+ client_secret="ignore-me" \\
122+ role_policy="%s" \s
123+ mc idp openid add myminio %s \\
124+ config_url="%s" \\
125+ client_id="%s" \\
126+ client_secret="ignore-me" \\
127+ role_policy="%s" \s
128+ mc admin service restart myminio
129+ """ , endpointUrl , accessKey , secretKey ,
130+ keycloakClientIdCryptomator , wellKnown , keycloakClientIdCryptomator , createbucketPolicyName ,
131+ keycloakClientIdHub , wellKnown , keycloakClientIdHub , accessbucketPolicyName ,
132+ keycloakClientIdCryptomatorVaults , wellKnown , keycloakClientIdCryptomatorVaults , accessbucketPolicyName ));
116133 return null ;
117134 }
118135}
0 commit comments