-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kerberos: authentication between client and broker #3821
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
|
||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you 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. | ||
|
||
--> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.pulsar</groupId> | ||
<artifactId>pulsar</artifactId> | ||
<version>2.4.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pulsar-broker-auth-sasl</artifactId> | ||
<packaging>jar</packaging> | ||
<description>SASL authentication plugin for broker</description> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>pulsar-broker</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.kerby</groupId> | ||
<artifactId>kerby-config</artifactId> | ||
<version>${kerby.version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.kerby</groupId> | ||
<artifactId>kerb-simplekdc</artifactId> | ||
<version>${kerby.version}</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>pulsar-broker</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<type>test-jar</type> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>managed-ledger-original</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>pulsar-zookeeper-utils</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>pulsar-client-auth-sasl</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
113 changes: 113 additions & 0 deletions
113
...asl/src/main/java/org/apache/pulsar/broker/authentication/AuthenticationProviderSasl.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,113 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.apache.pulsar.broker.authentication; | ||
|
||
import static org.apache.pulsar.common.sasl.SaslConstants.JAAS_BROKER_SECTION_NAME; | ||
import static org.apache.pulsar.common.sasl.SaslConstants.JAAS_CLIENT_ALLOWED_IDS; | ||
import static org.apache.pulsar.common.sasl.SaslConstants.KINIT_COMMAND; | ||
|
||
import java.io.IOException; | ||
import java.net.SocketAddress; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
import java.util.regex.PatternSyntaxException; | ||
|
||
import javax.naming.AuthenticationException; | ||
import javax.net.ssl.SSLSession; | ||
import javax.security.auth.login.LoginException; | ||
|
||
import com.google.common.collect.Maps; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.broker.ServiceConfiguration; | ||
import org.apache.pulsar.common.api.AuthData; | ||
import org.apache.pulsar.common.sasl.JAASCredentialsContainer; | ||
import org.apache.pulsar.common.sasl.SaslConstants; | ||
|
||
@Slf4j | ||
public class AuthenticationProviderSasl implements AuthenticationProvider { | ||
|
||
private Pattern allowedIdsPattern; | ||
private Map<String, String> configuration; | ||
|
||
private JAASCredentialsContainer jaasCredentialsContainer; | ||
private String loginContextName; | ||
|
||
@Override | ||
public void initialize(ServiceConfiguration config) throws IOException { | ||
this.configuration = Maps.newHashMap(); | ||
final String allowedIdsPatternRegExp = config.getSaslJaasClientAllowedIds(); | ||
configuration.put(JAAS_CLIENT_ALLOWED_IDS, allowedIdsPatternRegExp); | ||
configuration.put(JAAS_BROKER_SECTION_NAME, config.getSaslJaasBrokerSectionName()); | ||
configuration.put(KINIT_COMMAND, config.getKinitCommand()); | ||
|
||
try { | ||
this.allowedIdsPattern = Pattern.compile(allowedIdsPatternRegExp); | ||
} catch (PatternSyntaxException error) { | ||
log.error("Invalid regular expression for id " + allowedIdsPatternRegExp, error); | ||
throw new IOException(error); | ||
} | ||
|
||
loginContextName = config.getSaslJaasBrokerSectionName(); | ||
if (jaasCredentialsContainer == null) { | ||
log.info("JAAS loginContext is: {}." , loginContextName); | ||
try { | ||
jaasCredentialsContainer = new JAASCredentialsContainer( | ||
loginContextName, | ||
new PulsarSaslServer.SaslServerCallbackHandler(allowedIdsPattern), | ||
configuration); | ||
} catch (LoginException e) { | ||
log.error("JAAS login in broker failed: {}" , e); | ||
throw new IOException(e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String authenticate(AuthenticationDataSource authData) throws AuthenticationException { | ||
if (authData instanceof SaslAuthenticationDataSource) { | ||
return ((SaslAuthenticationDataSource)authData).getAuthorizationID(); | ||
} else { | ||
throw new AuthenticationException("Not support authDataSource type, expect sasl."); | ||
} | ||
} | ||
|
||
@Override | ||
public String getAuthMethodName() { | ||
return SaslConstants.AUTH_METHOD_NAME; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
} | ||
|
||
@Override | ||
public AuthenticationState newAuthState(AuthData authData, | ||
SocketAddress remoteAddress, | ||
SSLSession sslSession) throws AuthenticationException { | ||
try { | ||
new PulsarSaslServer(jaasCredentialsContainer.getSubject(), allowedIdsPattern); | ||
return new SaslAuthenticationState( | ||
new SaslAuthenticationDataSource( | ||
new PulsarSaslServer(jaasCredentialsContainer.getSubject(), allowedIdsPattern))); | ||
} catch (Throwable t) { | ||
log.error("Failed create sasl auth state: {}" , t); | ||
throw new AuthenticationException(t.getMessage()); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @eolivelli , yes, there is a planed work.
current step is for client <-> broker. will add the web-resource/http support in the TODO issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by this parameter we could bypass the web-resource/http checking temporary.