-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#27): Enable SSL transport options on sources
- Adds SSL transport support when configured - Enables SSL support on AWS S3 source
- Loading branch information
1 parent
856be2b
commit f9d1b86
Showing
15 changed files
with
350 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
aws-s3-source/src/main/java/dev/knative/eventing/KnativeClientOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package dev.knative.eventing; | ||
|
||
import io.quarkus.tls.runtime.keystores.TrustAllOptions; | ||
import io.vertx.core.net.JksOptions; | ||
import io.vertx.core.net.PemKeyCertOptions; | ||
import io.vertx.core.net.PfxOptions; | ||
import io.vertx.ext.web.client.WebClientOptions; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Named; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.spi.PropertiesComponent; | ||
|
||
/** | ||
* Knative client options able to configure secure Http transport options. | ||
* SSL options are added automatically when enabled via | ||
*/ | ||
@ApplicationScoped | ||
public class KnativeClientOptions { | ||
|
||
private static final String PROPERTY_PREFIX = "camel.knative.client.ssl."; | ||
|
||
@Named("knativeClientOptions") | ||
public WebClientOptions knativeClientOptions(CamelContext camelContext) { | ||
PropertiesComponent propertiesComponent = camelContext.getPropertiesComponent(); | ||
|
||
boolean sslEnabled = Boolean.parseBoolean( | ||
propertiesComponent.resolveProperty(PROPERTY_PREFIX + "enabled").orElse("false")); | ||
|
||
WebClientOptions options = new WebClientOptions(); | ||
if (sslEnabled) { | ||
options.setSsl(true); | ||
|
||
boolean verifyHostname = Boolean.parseBoolean( | ||
propertiesComponent.resolveProperty(PROPERTY_PREFIX + "verify.hostname").orElse("false")); | ||
options.setVerifyHost(verifyHostname); | ||
|
||
String keystorePath = propertiesComponent.resolveProperty(PROPERTY_PREFIX + "keystore.path").orElse(""); | ||
String keystorePassword = propertiesComponent.resolveProperty(PROPERTY_PREFIX + "keystore.password").orElse(""); | ||
|
||
if (!keystorePath.isEmpty()) { | ||
if (keystorePath.endsWith(".p12")) { | ||
options.setKeyCertOptions(new PfxOptions().setPath(keystorePath).setPassword(keystorePassword)); | ||
} else { | ||
options.setKeyCertOptions(new JksOptions().setPath(keystorePath).setPassword(keystorePassword)); | ||
} | ||
} | ||
|
||
String keyPath = propertiesComponent.resolveProperty(PROPERTY_PREFIX + "key.path").orElse(""); | ||
String certPath = propertiesComponent.resolveProperty(PROPERTY_PREFIX + "cert.path").orElse(keyPath); | ||
|
||
if (!keyPath.isEmpty()) { | ||
options.setKeyCertOptions(new PemKeyCertOptions().setKeyPath(keyPath).setCertPath(certPath)); | ||
} | ||
|
||
options.setTrustOptions(TrustAllOptions.INSTANCE); | ||
} | ||
return options; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
aws-s3-source/src/test/java/dev/knative/eventing/connector/ssl/AwsS3SourceSSLTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package dev.knative.eventing.connector.ssl; | ||
|
||
import java.util.Collections; | ||
|
||
import dev.knative.eventing.connector.LocalstackTestResource; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.common.ResourceArg; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.citrusframework.GherkinTestActionRunner; | ||
import org.citrusframework.annotations.CitrusResource; | ||
import org.citrusframework.context.TestContext; | ||
import org.citrusframework.http.endpoint.builder.HttpEndpoints; | ||
import org.citrusframework.http.security.HttpSecureConnection; | ||
import org.citrusframework.http.server.HttpServer; | ||
import org.citrusframework.quarkus.CitrusSupport; | ||
import org.citrusframework.spi.BindToRegistry; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
import software.amazon.awssdk.core.sync.RequestBody; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.CompletedMultipartUpload; | ||
import software.amazon.awssdk.services.s3.model.CompletedPart; | ||
import software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse; | ||
|
||
import static org.citrusframework.http.actions.HttpActionBuilder.http; | ||
|
||
@QuarkusTest | ||
@CitrusSupport | ||
@QuarkusTestResource(value = LocalstackTestResource.class, restrictToAnnotatedClass = true, initArgs = { | ||
@ResourceArg(name = "bucketNameOrArn", value = "mybucket"), | ||
@ResourceArg(name = "k.sink", value = "https://localhost:8443"), | ||
@ResourceArg(name = "camel.knative.client.ssl.enabled", value = "true"), | ||
@ResourceArg(name = "camel.knative.client.ssl.key.path", value = "keystore/client.pem"), | ||
@ResourceArg(name = "camel.knative.client.ssl.cert.path", value = "keystore/client.crt") | ||
//@ResourceArg(name = "camel.knative.client.ssl.keystore.path", value = "keystore/client.jks") | ||
//@ResourceArg(name = "camel.knative.client.ssl.keystore.path", value = "keystore/client.p12") | ||
//@ResourceArg(name = "camel.knative.client.ssl.keystore.password", value = "secr3t") | ||
}) | ||
public class AwsS3SourceSSLTest { | ||
|
||
@CitrusResource | ||
private GherkinTestActionRunner tc; | ||
|
||
private final String s3Key = "message.txt"; | ||
private final String s3Data = "Hello from secured AWS S3!"; | ||
private final String s3BucketName = "mybucket"; | ||
|
||
@LocalstackTestResource.Injected | ||
public S3Client s3Client; | ||
|
||
@BindToRegistry | ||
public HttpServer knativeBroker = HttpEndpoints.http() | ||
.server() | ||
.port(8080) | ||
.securePort(8443) | ||
.secured(HttpSecureConnection.ssl() | ||
.keyStore("classpath:keystore/server.jks", "secr3t") | ||
.trustStore("classpath:keystore/truststore.jks", "secr3t")) | ||
.autoStart(true) | ||
.build(); | ||
|
||
@Test | ||
public void shouldProduceSecureEvents() { | ||
tc.given(this::uploadS3File); | ||
|
||
tc.when( | ||
http().server(knativeBroker) | ||
.receive() | ||
.post() | ||
.message() | ||
.body(s3Data) | ||
.header("ce-id", "@matches([0-9A-Z]{15}-[0-9]{16})@") | ||
.header("ce-type", "dev.knative.connector.event.aws-s3") | ||
.header("ce-source", "dev.knative.eventing.aws-s3-source") | ||
.header("ce-subject", "aws-s3-source") | ||
); | ||
|
||
tc.then( | ||
http().server(knativeBroker) | ||
.send() | ||
.response(HttpStatus.OK) | ||
); | ||
} | ||
|
||
private void uploadS3File(TestContext context) { | ||
CreateMultipartUploadResponse initResponse = s3Client.createMultipartUpload(b -> b.bucket(s3BucketName).key(s3Key)); | ||
String etag = s3Client.uploadPart(b -> b.bucket(s3BucketName) | ||
.key(s3Key) | ||
.uploadId(initResponse.uploadId()) | ||
.partNumber(1), | ||
RequestBody.fromString(s3Data)).eTag(); | ||
s3Client.completeMultipartUpload(b -> b.bucket(s3BucketName) | ||
.multipartUpload(CompletedMultipartUpload.builder() | ||
.parts(Collections.singletonList(CompletedPart.builder() | ||
.partNumber(1) | ||
.eTag(etag).build())).build()) | ||
.key(s3Key) | ||
.uploadId(initResponse.uploadId())); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIFuTCCA6GgAwIBAgIBZTANBgkqhkiG9w0BAQsFADB+MQswCQYDVQQGEwJERTET | ||
MBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ | ||
dHkgTHRkMQ0wCwYDVQQDDARZQUtTMSgwJgYJKoZIhvcNAQkBFhl5YWtzLWRldkBn | ||
b29nbGVncm91cHMuY29tMB4XDTI0MDYxODA3MDM1OFoXDTI1MDYwOTA3MDM1OFow | ||
fjELMAkGA1UEBhMCREUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGElu | ||
dGVybmV0IFdpZGdpdHMgUHR5IEx0ZDENMAsGA1UEAwwEWUFLUzEoMCYGCSqGSIb3 | ||
DQEJARYZeWFrcy1kZXZAZ29vZ2xlZ3JvdXBzLmNvbTCCAiIwDQYJKoZIhvcNAQEB | ||
BQADggIPADCCAgoCggIBANvrpZbRRbUmngCvZKKdqCsyoAtlrGtXy8zpUlyMwFcI | ||
RR1UZgxVNNuqjA3mQ5HdaPHYCqQdsDD8SpIreNuTjdnlmxA5vxGuW0Aq+lX1SKq+ | ||
CjsycurX50uUPsiR/znQhkhVkbjYGOASbZ0MJ4u0jumKk/z1SSm8qpfnLsdGxEFj | ||
Tg+H7N7C/HJ3ZOVBbFZBLHCgIzXsVhIgz8uv/hP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5Eaf0J6Fd2Qpk2FQg7xw/5UzAV97lhDNRr6yN2GxBs5gcPcK | ||
tGcvay7coUkG4ZSmhUVRcqoXmNT3u1KxTMjUQDiWJpXtAGq4MHTSp37nW7fTnPKj | ||
PS9vNPCNoUDVj5IpWM7a7T/9mbrhsubreye7hy2qF85w/UWL8V+E797t0WQIdFRy | ||
eb+3EXcFenRnyVCDX81uz84Xmo7EeNawbucJKyY8Nx2XwJGzn5o5Wm7Z5xqE2rsc | ||
boqQ3Gqp84ATr6EnjueDKfcdfjI/XdzR8ZZQtkg= | ||
-----END CERTIFICATE----- |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.