You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/11 15:54:06 UTC
[GitHub] [pulsar] nodece opened a new pull request, #16526: [improve][authentication] Improve get the basic authentication config
nodece opened a new pull request, #16526:
URL: https://github.com/apache/pulsar/pull/16526
Signed-off-by: Zixuan Liu <no...@gmail.com>
### Motivation
Right now the Pulsar only supports getting the basic authentication config from the system properties, I suggest reading it from the Pulsar config file.
### Modifications
- Add the `basicAuthConf` to the config file for use in reading the basic authentication config
- Add Base64 support for basic authentication config
### Documentation
- [x] `doc-required`
Add `basicAuthConf` to Refrences page.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r936763979
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
Let me open a new PR to do that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r920269032
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
I think we can add a prefix so like:
```
basicAuthConf=data:;base64,YOUR-BASE64
basicAuthConf=file:///my/basic.conf
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r920269032
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
I think we can add a prefix so like:
```
basicAuthConf=data:;base64,YOUR-BASE64
basicAuthConf=file:///my/basic.conf
``
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#issuecomment-1205042983
Move `release/2.9.4` to #16944.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r919639074
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
I think we can use 2 different config/property names instead of checking isBase64, the isBase64(path) maybe return true?
##########
conf/broker.conf:
##########
@@ -751,6 +751,13 @@ athenzDomainNames=
# When this parameter is not empty, unauthenticated users perform as anonymousUserRole
anonymousUserRole=
+## Configure the datasource of basic authenticate, supports the file and Base64 format.
+# file:
+# basicAuthConf=/path/my/.htpasswd
+# use Base64 to encode the contents of .htpasswd:
+# basicAuthConf=YOUR-BASE64-DATA
+basicAuthConf=
Review Comment:
```suggestion
basicAuthInBase64=
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] Technoboy- merged pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
Technoboy- merged PR #16526:
URL: https://github.com/apache/pulsar/pull/16526
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r936762598
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
@codelipenghui This PR has been merged into master, this config still keep old style.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#issuecomment-1205093339
Move `release/2.7.5` to #16947.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r936921465
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
Link to #16935.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r928674445
##########
conf/broker.conf:
##########
@@ -751,6 +751,13 @@ athenzDomainNames=
# When this parameter is not empty, unauthenticated users perform as anonymousUserRole
anonymousUserRole=
+## Configure the datasource of basic authenticate, supports the file and Base64 format.
+# file:
+# basicAuthConf=/path/my/.htpasswd
+# use Base64 to encode the contents of .htpasswd:
+# basicAuthConf=YOUR-BASE64-DATA
+basicAuthConf=
Review Comment:
Do you want to add two config?
```
basicAuthInBase64=YOUR-BASE64-DATA
basicAuthInFile=/path/to/basic
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] nodece commented on pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
nodece commented on PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#issuecomment-1205042295
When cherry-picking this PR to branch-2.x, we also need to cherry-pick the https://github.com/apache/pulsar/pull/16935 to the same branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r936286872
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
@nodece Could you please update the PR as your description?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui commented on a diff in pull request #16526: [improve][authentication] Improve get the basic authentication config
Posted by GitBox <gi...@apache.org>.
codelipenghui commented on code in PR #16526:
URL: https://github.com/apache/pulsar/pull/16526#discussion_r936286319
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderBasic.java:
##########
@@ -48,14 +51,28 @@ public void close() throws IOException {
@Override
public void initialize(ServiceConfiguration config) throws IOException {
- File confFile = new File(System.getProperty(CONF_SYSTEM_PROPERTY_KEY));
- if (!confFile.exists()) {
- throw new IOException("The password auth conf file does not exist");
- } else if (!confFile.isFile()) {
- throw new IOException("The path is not a file");
+ String data = config.getProperties().getProperty(CONF_PULSAR_PROPERTY_KEY);
+ if (StringUtils.isEmpty(data)) {
+ data = System.getProperty(CONF_SYSTEM_PROPERTY_KEY);
+ }
+ if (StringUtils.isEmpty(data)) {
+ throw new IOException("No basic authentication config provided");
+ }
+
+ @Cleanup BufferedReader reader = null;
+ if (org.apache.commons.codec.binary.Base64.isBase64(data)) {
+ reader = new BufferedReader(new StringReader(new String(Base64.getDecoder().decode(data),
+ StandardCharsets.UTF_8)));
+ } else {
Review Comment:
Ok, looks good to me.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org