Skip to content

Commit 5c28f8d

Browse files
authored
Add SSL docs and update authentication samples accordingly. (#443)
1 parent 38e4b76 commit 5c28f8d

File tree

4 files changed

+91
-65
lines changed

4 files changed

+91
-65
lines changed

spring-pulsar-docs/src/main/asciidoc/attributes-variables.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
:spring-cloud-stream-docs: https://docs.spring.io/spring-cloud-stream/docs/{spring-cloud-stream-version}/reference/html/
1616
:spring-cloud-function: https://spring.io/projects/spring-cloud-function
1717

18-
:apache-pulsar-docs: https://pulsar.apache.org/docs/3.0.x
18+
:apache-pulsar-docs: https://pulsar.apache.org/docs/3.1.x
1919
:apache-pulsar-cient-docs: {apache-pulsar-docs}/client-libraries-java
2020
:apache-pulsar-io-docs: {apache-pulsar-docs}/io-connectors
2121
:apache-pulsar-function-docs: {apache-pulsar-docs}/functions-overview
Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
11

22
include::attributes.adoc[]
33

4-
To connect to a Pulsar cluster that requires authentication, you need to set the `authPluginClassName` and any parameters required by the authentication plugin. You can set the parameters as a single JSON-encoded string or as map of parameter names to parameter values. The following listings show both approaches:
4+
To connect to a Pulsar cluster that requires authentication, you need to specify which authentication plugin to use and any parameters required by the specified plugin.
5+
When **using Spring Boot** auto-configuration, you can set the plugin and the plugin parameters via configuration properties (in most cases).
56

6-
[source,yaml,indent=0,role="primary"]
7-
.[.small]#Map#
8-
----
9-
spring:
10-
pulsar:
11-
client:
12-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.oauth2.AuthenticationOAuth2
13-
authentication:
14-
issuer-url: https://auth.server.cloud/
15-
private-key: file:///Users/some-key.json
16-
audience: urn:sn:acme:dev:my-instance
17-
----
7+
[NOTE]
8+
====
9+
You need to ensure that names defined under `+spring.pulsar.client.authentication.param.*+` exactly match those expected by your auth plugin (which is typically camel cased).
10+
Spring Boot will not attempt any kind of relaxed binding for these entries.
1811
19-
.[.small]#JSON encoded string#
20-
[source,yaml,indent=0,role="secondary"]
21-
----
22-
spring:
23-
pulsar:
24-
client:
25-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.oauth2.AuthenticationOAuth2
26-
auth-params: "{\"privateKey\":\"file:///Users/some-key.json\",\"issuerUrl\":\"https://auth.server.cloud/", \"audience\":\"urn:sn:acme:dev:my-instance"}"
27-
----
12+
For example, if you want to configure the issuer url for the `AuthenticationOAuth2` auth plugin you must use `+spring.pulsar.client.authentication.param.issuerUrl+`.
13+
If you use other forms, such as `issuerurl` or `issuer-url`, the setting will not be applied to the plugin.
14+
====
15+
16+
When **not using Spring Boot** auto-configuration, you can use the `org.apache.pulsar.client.api.AuthenticationFactory` to create the authentication and then set it directly on the Pulsar client builder in a client customizer that you provide to the client factory.
2817

29-
TIP: Using a map is the recommended approach as it is less error-prone and easier to read.
3018

3119
The following listings show how to configure each of the supported authentication mechanisms.
3220

@@ -39,15 +27,31 @@ The following listings show how to configure each of the supported authenticatio
3927
spring:
4028
pulsar:
4129
client:
42-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationAthenz
4330
authentication:
44-
tenant-domain: ...
45-
tenant-service: ...
46-
provider-domain: ...
47-
private-key: ...
48-
key-id: ...
49-
enable-tls: true
50-
tls-trust-certs-file: /path/to/cacert.pem
31+
plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationAthenz
32+
param:
33+
tenantDomain: ...
34+
tenantService: ...
35+
providerDomain: ...
36+
privateKey: ...
37+
keyId: ...
38+
----
39+
NOTE: This also requires TLS encryption as described in <<pulsar.adoc#tls-encryption>>.
40+
====
41+
42+
[[Token]]
43+
.[.underline]#Click ##here## for **Token**#
44+
[%collapsible]
45+
====
46+
[source, yaml]
47+
----
48+
spring:
49+
pulsar:
50+
client:
51+
authentication:
52+
plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationToken
53+
param:
54+
token: some-token-goes-here
5155
----
5256
====
5357
@@ -60,10 +64,11 @@ spring:
6064
spring:
6165
pulsar:
6266
client:
63-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationBasic
6467
authentication:
65-
user-id: ...
66-
password: ...
68+
plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationBasic
69+
param:
70+
userId: ...
71+
password: ...
6772
----
6873
====
6974
@@ -76,12 +81,13 @@ spring:
7681
spring:
7782
pulsar:
7883
client:
79-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.oauth2.AuthenticationFactoryOAuth2
8084
authentication:
81-
issuer-url: ...
82-
private-key: ...
83-
audience: ...
84-
scope: ...
85+
plugin-class-name: org.apache.pulsar.client.impl.auth.oauth2.AuthenticationFactoryOAuth2
86+
param:
87+
issuerUrl: ...
88+
privateKey: ...
89+
audience: ...
90+
scope: ...
8591
----
8692
====
8793
@@ -94,44 +100,40 @@ spring:
94100
spring:
95101
pulsar:
96102
client:
97-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationSasl
98103
authentication:
99-
sasl-jaas-client-section-name: ...
100-
server-type: ...
104+
plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationSasl
105+
param:
106+
saslJaasClientSectionName: ...
107+
serverType: ...
101108
----
102109
====
103110
104-
[[Tls]]
105-
.[.underline]#Click ##here## for **Tls**#
111+
[[mTlS-pem]]
112+
.[.underline]#Click ##here## for **mTLS (PEM)**#
106113
[%collapsible]
107114
====
108-
[source, yaml]
115+
NOTE: Because this option requires TLS encryption, which already requires you to <<pulsar.adoc#tls-encryption,provide a client builder customizer>>, it is recommended to simply add the authentication directly on the client builder in your provided TLS customizer.
116+
You can use the `org.apache.pulsar.client.api.AuthenticationFactory` to help create the authentication object as follows:
117+
[source,java]
109118
----
110-
spring:
111-
pulsar:
112-
client:
113-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationTls
114-
authentication:
115-
tls-cert-file: /path/to/my-role.cert.pem
116-
tls-key-file: /path/to/my-role.key-pk8.pem
117-
enable-tls: true
118-
tls-trust-certs-file: /path/to/cacert.pem
119+
Authentication auth = AuthenticationFactory.TLS("/path/to/my-role.cert.pem", "/path/to/my-role.key-pk8.pem");
119120
----
121+
See the official Pulsar documentation on {apache-pulsar-docs}/security-tls-authentication/#configure-mtls-authentication-in-pulsar-clients[mTLS (PEM)].
120122
====
121123

122-
[[Token]]
123-
.[.underline]#Click ##here## for **Token**#
124+
[[mTLS-jks]]
125+
.[.underline]#Click ##here## for **mTLS (JKS)**#
124126
[%collapsible]
125127
====
126-
[source, yaml]
128+
NOTE: Because this option requires TLS encryption, which already requires you to <<pulsar.adoc#tls-encryption,provide a client builder customizer>>, it is recommended to simply add the authentication directly on the client builder in your provided TLS customizer.
129+
You can use the `org.apache.pulsar.client.api.AuthenticationFactory` to help create the authentication object as follows:
130+
[source,java]
127131
----
128-
spring:
129-
pulsar:
130-
client:
131-
auth-plugin-class-name: org.apache.pulsar.client.impl.auth.AuthenticationToken
132-
authentication:
133-
token: some-token-goes-here
132+
Authentication auth = AuthenticationFactory.create(
133+
"org.apache.pulsar.client.impl.auth.AuthenticationKeyStoreTls",
134+
Map.of("keyStoreType", "JKS", "keyStorePath", "/path/to/my/keystore.jks", "keyStorePassword", "clientpw"));
134135
----
136+
See the official Pulsar documentation on {apache-pulsar-docs}/security-tls-authentication/#configure-clients[mTLS (JKS)].
135137
====
136138

137-
NOTE: You can find more information on each of the schemes and their required properties in the official {apache-pulsar-docs}/security-overview#authentication-providers[Pulsar security] documentation.
139+
You can find more information on each of the support plugins and their required properties in the official {apache-pulsar-docs}/security-overview#authentication-providers[Pulsar security] documentation.

spring-pulsar-docs/src/main/asciidoc/pulsar.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ You can further configure the client by specifying any of the {spring-boot-pulsa
2727
NOTE: If you are not using the starter, you will need to configure and register the `PulsarClient` yourself.
2828
There is a `DefaultPulsarClientFactory` that accepts a builder customizer that can be used to help with this.
2929

30+
[[tls-encryption]]
31+
=== TLS Encryption (SSL)
32+
include::tls-encryption.adoc[]
33+
3034
[[client-authentication]]
3135
=== Authentication
3236
include::authentication.adoc[]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
include::attributes.adoc[]
3+
4+
By default, Pulsar clients communicate with Pulsar services in plain text.
5+
The following section describes how to configure Pulsar clients to use TLS encryption (SSL).
6+
A pre-requisite is that the Broker has also been configured to use TLS encryption.
7+
8+
The Spring Boot auto-configuration does not currently support any TLS/SSL configuration properties.
9+
You can instead provide a `PulsarClientBuilderCustomizer` that sets the necessary properties on the Pulsar client builder.
10+
Pulsar supports both Privacy Enhanced Mail (PEM) and Java KeyStore (JKS) certificate formats.
11+
12+
Follow these steps to configure TLS:
13+
14+
1. Adjust the Pulsar client service url to use the `pulsar+ssl://` scheme and TLS port (typically `6651`).
15+
2. Adjust the admin client service url to use the `https://` scheme and TLS web port (typically `8443`).
16+
3. Provide client builder customizer(s) that sets the relevant properties on the builder.
17+
- {github}/blob/02730275e8d0291525eed9db5babe880c555a7bd/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/SamplePemBasedSslConfig.java#L30-L49[PEM based sample]
18+
- {github}/blob/02730275e8d0291525eed9db5babe880c555a7bd/integration-tests/src/intTest/java/org/springframework/pulsar/inttest/app/SampleJksBasedSslConfig.java#L30-L57[JKS based sample]
19+
20+
You can find more information on the above in the official {apache-pulsar-docs}/security-tls-transport/[Pulsar TLS Encryption] documentation.

0 commit comments

Comments
 (0)