Skip to content

Commit 761fe46

Browse files
chenkinsdkocher
authored andcommitted
Fix creating bucket in requested region. Upload dir.uvf for root dir.
1 parent 0fdead4 commit 761fe46

File tree

10 files changed

+43
-40
lines changed

10 files changed

+43
-40
lines changed

hub/src/main/java/cloud/katta/crypto/uvf/UvfMetadataPayload.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ public byte[] computeRootDirUvf() throws JsonProcessingException {
132132
final Cryptor cryptor = provider.provide(masterKey, FastSecureRandomProvider.get().provide());
133133
DirectoryMetadata rootDirMetadata = cryptor.directoryContentCryptor().rootDirectoryMetadata();
134134
DirectoryContentCryptor dirContentCryptor = cryptor.directoryContentCryptor();
135-
byte[] rootDirUvfFileContents = dirContentCryptor.encryptDirectoryMetadata(rootDirMetadata);
136-
return rootDirUvfFileContents;
135+
return dirContentCryptor.encryptDirectoryMetadata(rootDirMetadata);
137136
}
138137

139138
public static final class UniversalVaultFormatJWKS {

hub/src/main/java/cloud/katta/workflows/CreateVaultService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.io.IOException;
2828
import java.nio.charset.Charset;
29+
import java.util.Base64;
2930
import java.util.Collections;
3031
import java.util.EnumSet;
3132
import java.util.UUID;
@@ -96,6 +97,7 @@ public void createVault(final UserKeys userKeys, final StorageProfileDtoWrapper
9697
.withStorage(new VaultMetadataJWEBackendDto()
9798
.provider(storageProfileWrapper.getId().toString())
9899
.defaultPath(storageProfileWrapper.getProtocol() == Protocol.S3_STS ? storageProfileWrapper.getBucketPrefix() + vaultModel.vaultId() : vaultModel.bucketName())
100+
.region(vaultModel.region())
99101
.nickname(vaultModel.vaultName())
100102
.username(vaultModel.accessKeyId())
101103
.password(vaultModel.secretKey()))
@@ -119,12 +121,12 @@ public void createVault(final UserKeys userKeys, final StorageProfileDtoWrapper
119121
.uvfKeySet(jwks.serializePublicRecoverykey());
120122

121123
final String hashedRootDirId = metadataPayload.computeRootDirIdHash();
122-
final byte[] rootDirUvf = metadataPayload.computeRootDirUvf();
123124
final CreateS3STSBucketDto storageDto = new CreateS3STSBucketDto()
124125
.vaultId(vaultModel.vaultId().toString())
125126
.storageConfigId(storageProfileWrapper.getId())
126127
.vaultUvf(uvfMetadataFile)
127128
.rootDirHash(hashedRootDirId)
129+
.dirUvf(Base64.getUrlEncoder().encodeToString(metadataPayload.computeRootDirUvf()))
128130
.region(metadataPayload.storage().getRegion());
129131
log.debug("Created storage dto {}", storageDto);
130132

@@ -135,7 +137,7 @@ public void createVault(final UserKeys userKeys, final StorageProfileDtoWrapper
135137
configResource.apiConfigGet(), vaultDto.getId(), metadataPayload.storage(), tokens);
136138
if(storageProfileWrapper.getProtocol() == Protocol.S3) {
137139
// permanent: template upload into existing bucket from client (not backend)
138-
templateUploadService.uploadTemplate(bookmark, metadataPayload, storageDto, hashedRootDirId, rootDirUvf);
140+
templateUploadService.uploadTemplate(bookmark, metadataPayload, storageDto, hashedRootDirId);
139141
}
140142
else {
141143
// non-permanent: pass STS tokens (restricted by inline policy) to hub backend and have bucket created from there
@@ -174,19 +176,19 @@ public void createVault(final UserKeys userKeys, final StorageProfileDtoWrapper
174176
static class TemplateUploadService {
175177
static TemplateUploadService disabled = new TemplateUploadService() {
176178
@Override
177-
void uploadTemplate(final Host bookmark, final UvfMetadataPayload metadataPayload, final CreateS3STSBucketDto storageDto, final String hashedRootDirId, final byte[] rootDirUvf) {
179+
void uploadTemplate(final Host bookmark, final UvfMetadataPayload metadataPayload, final CreateS3STSBucketDto storageDto, final String hashedRootDirId) {
178180
// do nothing
179181
}
180182
};
181183

182-
void uploadTemplate(final Host bookmark, final UvfMetadataPayload metadataPayload, final CreateS3STSBucketDto storageDto, final String hashedRootDirId, final byte[] rootDirUvf) throws BackgroundException {
184+
void uploadTemplate(final Host bookmark, final UvfMetadataPayload metadataPayload, final CreateS3STSBucketDto storageDto, final String hashedRootDirId) throws BackgroundException {
183185
final S3Session session = new S3Session(bookmark);
184186
session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
185187
session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
186188

187189
// upload vault template
188190
new HubUVFVault(session, new Path(metadataPayload.storage().getDefaultPath(), EnumSet.of(Path.Type.directory, Path.Type.vault)))
189-
.create(session, metadataPayload.storage().getRegion(), storageDto.getVaultUvf(), hashedRootDirId, rootDirUvf);
191+
.create(session, metadataPayload.storage().getRegion(), storageDto.getVaultUvf(), hashedRootDirId, Base64.getUrlDecoder().decode(storageDto.getDirUvf()));
190192
session.close();
191193
}
192194
}

hub/src/main/resources/sts_create_bucket_inline_policy_template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"s3:PutObject"
2020
],
2121
"Resource": [
22-
"arn:aws:s3:::{}/vault.uvf",
22+
"arn:aws:s3:::{}/*.uvf",
2323
"arn:aws:s3:::{}/*/"
2424
]
2525
}
2626
]
27-
}
27+
}

hub/src/test/resources/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KATTA_SERVER_IMAGE=ghcr.io/shift7-ch/katta-server:1.5.0-SNAPSHOT-ci
1+
KATTA_SERVER_IMAGE=ghcr.io/shift7-ch/katta-server:commit-940cd56264fc0a53619e1af995ef9b33bfe23015-ci
22
HUB_PORT=8080
33
HUB_KEYCLOAK_URL=http://localhost:8180
44
HUB_KEYCLOAK_BASEPATH=

hub/src/test/resources/.hybrid.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KATTA_SERVER_IMAGE=ghcr.io/shift7-ch/katta-server:1.5.0-SNAPSHOT-ci
1+
KATTA_SERVER_IMAGE=ghcr.io/shift7-ch/katta-server:commit-940cd56264fc0a53619e1af995ef9b33bfe23015-ci
22
HUB_PORT=8280
33
HUB_KEYCLOAK_URL=https://testing.katta.cloud
44
HUB_KEYCLOAK_BASEPATH=/kc

hub/src/test/resources/.local.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KATTA_SERVER_IMAGE=ghcr.io/shift7-ch/katta-server:1.5.0-SNAPSHOT-ci
1+
KATTA_SERVER_IMAGE=ghcr.io/shift7-ch/katta-server:commit-940cd56264fc0a53619e1af995ef9b33bfe23015-ci
22
HUB_PORT=8280
33
HUB_KEYCLOAK_URL=http://localhost:8380
44
HUB_KEYCLOAK_BASEPATH=

hub/src/test/resources/log4j-test.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<Logger name="testrunner" level="info"/>
3232
<Logger name="ch.cyberduck" level="warn"/>
3333
<Logger name="ch.cyberduck.core.cryptomator" level="debug"/>
34+
<Logger name="ch.cyberduck.core.s3" level="debug"/>
3435
<Logger name="ch.cyberduck.transcript" level="info"/>
3536
<Logger name="org.apache.http.wire" additivity="true" level="debug">
3637
<AppenderRef ref="rollingFile"/>
Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
2-
"Version": "2012-10-17",
3-
"Statement": [
4-
{
5-
"Effect": "Allow",
6-
"Action": [
7-
"s3:GetBucketLocation",
8-
"s3:ListBucket",
9-
"s3:ListBucketMultipartUploads",
10-
"s3:GetBucketVersioning"
11-
],
12-
"Resource": "arn:aws:s3:::cipherduck${aws:PrincipalTag/VaultRequested}"
13-
},
14-
{
15-
"Effect": "Allow",
16-
"Action": [
17-
"s3:GetObject",
18-
"s3:PutObject",
19-
"s3:DeleteObject",
20-
"s3:ListMultipartUploadParts",
21-
"s3:AbortMultipartUpload"
22-
],
23-
"Resource": "arn:aws:s3:::cipherduck${aws:PrincipalTag/VaultRequested}/*"
24-
}
25-
]
26-
}
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": [
7+
"s3:GetBucketLocation",
8+
"s3:ListBucket",
9+
"s3:ListBucketMultipartUploads",
10+
"s3:GetBucketVersioning",
11+
"s3:ListBucketVersions"
12+
],
13+
"Resource": "arn:aws:s3:::cipherduck${aws:PrincipalTag/VaultRequested}"
14+
},
15+
{
16+
"Effect": "Allow",
17+
"Action": [
18+
"s3:GetObject",
19+
"s3:PutObject",
20+
"s3:DeleteObject",
21+
"s3:ListMultipartUploadParts",
22+
"s3:AbortMultipartUpload"
23+
],
24+
"Resource": "arn:aws:s3:::cipherduck${aws:PrincipalTag/VaultRequested}/*"
25+
}
26+
]
27+
}

hub/src/test/resources/setup/aws_sts/createbucketpermissionpolicy.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"s3:PutObject"
2222
],
2323
"Resource": [
24-
"arn:aws:s3:::cipherduck*/vault.uvf",
24+
"arn:aws:s3:::cipherduck*/*.uvf",
2525
"arn:aws:s3:::cipherduck*/*/"
2626
]
2727
}
2828
]
29-
}
29+
}

hub/src/test/resources/setup/minio_sts/createbucketpolicy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"Resource": [
2222
"arn:aws:s3:::katta*/*/",
23-
"arn:aws:s3:::katta*/vault.uvf"
23+
"arn:aws:s3:::katta*/*.uvf"
2424
]
2525
}
2626
]

0 commit comments

Comments
 (0)