You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "Flaugh24 (via GitHub)" <gi...@apache.org> on 2023/12/15 14:58:16 UTC
[PR] IGNITE-21065 WIP [ignite-3]
Flaugh24 opened a new pull request, #2962:
URL: https://github.com/apache/ignite-3/pull/2962
https://issues.apache.org/jira/browse/IGNITE-21065
Thank you for submitting the pull request.
To streamline the review process of the patch and ensure better code quality
we ask both an author and a reviewer to verify the following:
### The Review Checklist
- [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:
\- There is a single JIRA ticket related to the pull request.
\- The web-link to the pull request is attached to the JIRA ticket.
\- The JIRA ticket has the Patch Available state.
\- The description of the JIRA ticket explains WHAT was made, WHY and HOW.
\- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
- [ ] **Design:** new code conforms with the design principles of the components it is added to.
- [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
- [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
- [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
### Notes
- [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-21065 Enhance granularity of authentication events [ignite-3]
Posted by "valepakh (via GitHub)" <gi...@apache.org>.
valepakh commented on code in PR #2962:
URL: https://github.com/apache/ignite-3/pull/2962#discussion_r1430349948
##########
modules/security/src/main/java/org/apache/ignite/internal/security/authentication/AuthenticationManagerImpl.java:
##########
@@ -47,17 +50,98 @@
/**
* Implementation of {@link Authenticator}.
*/
-public class AuthenticationManagerImpl implements AuthenticationManager {
+public class AuthenticationManagerImpl
+ extends AbstractEventProducer<AuthenticationEvent, AuthenticationEventParameters>
+ implements AuthenticationManager {
private static final IgniteLogger LOG = Loggers.forClass(AuthenticationManagerImpl.class);
- private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+ /**
+ * Security configuration.
+ */
+ private final SecurityConfiguration securityConfiguration;
+
+ /**
+ * Security configuration listener. Refreshes the list of authenticators when the configuration changes.
+ */
+ private final ConfigurationListener<SecurityView> securityConfigurationListener;
+
+ /**
+ * Security enabled/disabled event factory. Fires events when security is enabled/disabled.
+ */
+ private final SecurityEnabledDisabledEventFactory securityEnabledDisabledEventFactory;
+
+ /**
+ * User event factory. Fires events when a basic user is created/updated/deleted.
+ */
+ private final UserEventFactory userEventFactory;
- private final List<AuthenticationListener> listeners = new CopyOnWriteArrayList<>();
+ /**
+ * Authentication provider event factory. Fires events when an authentication provider is created/updated/deleted.
+ */
+ private final AuthenticationProviderEventFactory providerEventFactory;
+ /**
+ * Read-write lock for the list of authenticators and the authentication enabled flag.
+ */
+ private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+
+ /**
+ * List of authenticators.
+ */
private List<Authenticator> authenticators = new ArrayList<>();
+ /**
+ * Authentication enabled flag.
+ */
private boolean authEnabled = false;
+ /**
+ * Constructor.
+ *
+ * @param securityConfiguration Security configuration.
+ */
+ public AuthenticationManagerImpl(SecurityConfiguration securityConfiguration) {
+ this.securityConfiguration = securityConfiguration;
+
+ this.securityConfigurationListener = ctx -> {
Review Comment:
```suggestion
securityConfigurationListener = ctx -> {
```
##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -849,4 +852,60 @@ private NotificationSender notificationSender(long requestId) {
// This is fine, because the client registers a listener before sending the request.
return (writer, err) -> sendNotification(requestId, writer, err);
}
+
+ @Override
+ public CompletableFuture<Boolean> notify(AuthenticationEventParameters parameters, @Nullable Throwable exception) {
+ if (shouldCloseConnection(parameters)) {
+ LOG.warn("Closing connection due to authentication event [connectionId=" + connectionId + ", remoteAddress="
+ + channelHandlerContext.channel().remoteAddress() + ", event=" + parameters.type() + ']');
+ closeConnection();
+ }
+ return CompletableFuture.completedFuture(false);
Review Comment:
```suggestion
return falseCompletedFuture();
```
##########
modules/security/src/main/java/org/apache/ignite/internal/security/authentication/AuthenticationManagerImpl.java:
##########
@@ -47,17 +50,98 @@
/**
* Implementation of {@link Authenticator}.
*/
-public class AuthenticationManagerImpl implements AuthenticationManager {
+public class AuthenticationManagerImpl
+ extends AbstractEventProducer<AuthenticationEvent, AuthenticationEventParameters>
+ implements AuthenticationManager {
private static final IgniteLogger LOG = Loggers.forClass(AuthenticationManagerImpl.class);
- private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+ /**
+ * Security configuration.
+ */
+ private final SecurityConfiguration securityConfiguration;
+
+ /**
+ * Security configuration listener. Refreshes the list of authenticators when the configuration changes.
+ */
+ private final ConfigurationListener<SecurityView> securityConfigurationListener;
+
+ /**
+ * Security enabled/disabled event factory. Fires events when security is enabled/disabled.
+ */
+ private final SecurityEnabledDisabledEventFactory securityEnabledDisabledEventFactory;
+
+ /**
+ * User event factory. Fires events when a basic user is created/updated/deleted.
+ */
+ private final UserEventFactory userEventFactory;
- private final List<AuthenticationListener> listeners = new CopyOnWriteArrayList<>();
+ /**
+ * Authentication provider event factory. Fires events when an authentication provider is created/updated/deleted.
+ */
+ private final AuthenticationProviderEventFactory providerEventFactory;
+ /**
+ * Read-write lock for the list of authenticators and the authentication enabled flag.
+ */
+ private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+
+ /**
+ * List of authenticators.
+ */
private List<Authenticator> authenticators = new ArrayList<>();
+ /**
+ * Authentication enabled flag.
+ */
private boolean authEnabled = false;
+ /**
+ * Constructor.
+ *
+ * @param securityConfiguration Security configuration.
+ */
+ public AuthenticationManagerImpl(SecurityConfiguration securityConfiguration) {
+ this.securityConfiguration = securityConfiguration;
+
+ this.securityConfigurationListener = ctx -> {
+ refreshProviders(ctx.newValue());
+ return nullCompletedFuture();
+ };
+
+ this.securityEnabledDisabledEventFactory = new SecurityEnabledDisabledEventFactory(this::fireEvent);
Review Comment:
```suggestion
securityEnabledDisabledEventFactory = new SecurityEnabledDisabledEventFactory(this::fireEvent);
```
##########
modules/security/src/main/java/org/apache/ignite/internal/security/authentication/AuthenticationManagerImpl.java:
##########
@@ -47,17 +50,98 @@
/**
* Implementation of {@link Authenticator}.
*/
-public class AuthenticationManagerImpl implements AuthenticationManager {
+public class AuthenticationManagerImpl
+ extends AbstractEventProducer<AuthenticationEvent, AuthenticationEventParameters>
+ implements AuthenticationManager {
private static final IgniteLogger LOG = Loggers.forClass(AuthenticationManagerImpl.class);
- private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+ /**
+ * Security configuration.
+ */
+ private final SecurityConfiguration securityConfiguration;
+
+ /**
+ * Security configuration listener. Refreshes the list of authenticators when the configuration changes.
+ */
+ private final ConfigurationListener<SecurityView> securityConfigurationListener;
+
+ /**
+ * Security enabled/disabled event factory. Fires events when security is enabled/disabled.
+ */
+ private final SecurityEnabledDisabledEventFactory securityEnabledDisabledEventFactory;
+
+ /**
+ * User event factory. Fires events when a basic user is created/updated/deleted.
+ */
+ private final UserEventFactory userEventFactory;
- private final List<AuthenticationListener> listeners = new CopyOnWriteArrayList<>();
+ /**
+ * Authentication provider event factory. Fires events when an authentication provider is created/updated/deleted.
+ */
+ private final AuthenticationProviderEventFactory providerEventFactory;
+ /**
+ * Read-write lock for the list of authenticators and the authentication enabled flag.
+ */
+ private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+
+ /**
+ * List of authenticators.
+ */
private List<Authenticator> authenticators = new ArrayList<>();
+ /**
+ * Authentication enabled flag.
+ */
private boolean authEnabled = false;
+ /**
+ * Constructor.
+ *
+ * @param securityConfiguration Security configuration.
+ */
+ public AuthenticationManagerImpl(SecurityConfiguration securityConfiguration) {
+ this.securityConfiguration = securityConfiguration;
+
+ this.securityConfigurationListener = ctx -> {
+ refreshProviders(ctx.newValue());
+ return nullCompletedFuture();
+ };
+
+ this.securityEnabledDisabledEventFactory = new SecurityEnabledDisabledEventFactory(this::fireEvent);
+
+ this.userEventFactory = new UserEventFactory(this::fireEvent);
Review Comment:
```suggestion
userEventFactory = new UserEventFactory(this::fireEvent);
```
##########
modules/security/src/main/java/org/apache/ignite/internal/security/authentication/AuthenticationManagerImpl.java:
##########
@@ -47,17 +50,98 @@
/**
* Implementation of {@link Authenticator}.
*/
-public class AuthenticationManagerImpl implements AuthenticationManager {
+public class AuthenticationManagerImpl
+ extends AbstractEventProducer<AuthenticationEvent, AuthenticationEventParameters>
+ implements AuthenticationManager {
private static final IgniteLogger LOG = Loggers.forClass(AuthenticationManagerImpl.class);
- private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+ /**
+ * Security configuration.
+ */
+ private final SecurityConfiguration securityConfiguration;
+
+ /**
+ * Security configuration listener. Refreshes the list of authenticators when the configuration changes.
+ */
+ private final ConfigurationListener<SecurityView> securityConfigurationListener;
+
+ /**
+ * Security enabled/disabled event factory. Fires events when security is enabled/disabled.
+ */
+ private final SecurityEnabledDisabledEventFactory securityEnabledDisabledEventFactory;
+
+ /**
+ * User event factory. Fires events when a basic user is created/updated/deleted.
+ */
+ private final UserEventFactory userEventFactory;
- private final List<AuthenticationListener> listeners = new CopyOnWriteArrayList<>();
+ /**
+ * Authentication provider event factory. Fires events when an authentication provider is created/updated/deleted.
+ */
+ private final AuthenticationProviderEventFactory providerEventFactory;
+ /**
+ * Read-write lock for the list of authenticators and the authentication enabled flag.
+ */
+ private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
+
+ /**
+ * List of authenticators.
+ */
private List<Authenticator> authenticators = new ArrayList<>();
+ /**
+ * Authentication enabled flag.
+ */
private boolean authEnabled = false;
+ /**
+ * Constructor.
+ *
+ * @param securityConfiguration Security configuration.
+ */
+ public AuthenticationManagerImpl(SecurityConfiguration securityConfiguration) {
+ this.securityConfiguration = securityConfiguration;
+
+ this.securityConfigurationListener = ctx -> {
+ refreshProviders(ctx.newValue());
+ return nullCompletedFuture();
+ };
+
+ this.securityEnabledDisabledEventFactory = new SecurityEnabledDisabledEventFactory(this::fireEvent);
+
+ this.userEventFactory = new UserEventFactory(this::fireEvent);
+
+ this.providerEventFactory = new AuthenticationProviderEventFactory(
Review Comment:
```suggestion
providerEventFactory = new AuthenticationProviderEventFactory(
```
##########
modules/security/build.gradle:
##########
@@ -29,6 +29,7 @@ dependencies {
implementation project(':ignite-configuration-api')
implementation libs.jetbrains.annotations
implementation libs.auto.service.annotations
+ testImplementation project(path: ':ignite-security')
Review Comment:
Is this really needed?
##########
modules/security/src/main/java/org/apache/ignite/internal/security/authentication/event/EventFactory.java:
##########
@@ -17,12 +17,16 @@
package org.apache.ignite.internal.security.authentication.event;
+import java.util.List;
+import java.util.function.BiFunction;
+import org.apache.ignite.internal.security.configuration.SecurityView;
+import org.jetbrains.annotations.Nullable;
+
/**
- * Represents the authentication event type.
+ * Event producer for security configuration changes.
*/
-public enum EventType {
- AUTHENTICATION_ENABLED,
- AUTHENTICATION_DISABLED,
- AUTHENTICATION_PROVIDER_REMOVED,
- AUTHENTICATION_PROVIDER_UPDATED
+@FunctionalInterface
+public interface EventFactory extends BiFunction<SecurityView, SecurityView, List<? extends AuthenticationEventParameters>> {
Review Comment:
This interface is unused.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-21065 Enhance granularity of authentication events [ignite-3]
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander merged PR #2962:
URL: https://github.com/apache/ignite-3/pull/2962
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-21065 Enhance granularity of authentication events [ignite-3]
Posted by "PakhomovAlexander (via GitHub)" <gi...@apache.org>.
PakhomovAlexander commented on code in PR #2962:
URL: https://github.com/apache/ignite-3/pull/2962#discussion_r1431445328
##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java:
##########
@@ -849,4 +857,60 @@ private NotificationSender notificationSender(long requestId) {
// This is fine, because the client registers a listener before sending the request.
return (writer, err) -> sendNotification(requestId, writer, err);
}
+
+ @Override
+ public CompletableFuture<Boolean> notify(AuthenticationEventParameters parameters, @Nullable Throwable exception) {
+ if (shouldCloseConnection(parameters)) {
+ LOG.warn("Closing connection due to authentication event [connectionId=" + connectionId + ", remoteAddress="
+ + channelHandlerContext.channel().remoteAddress() + ", event=" + parameters.type() + ']');
+ closeConnection();
+ }
+ return falseCompletedFuture();
+ }
+
+ private boolean shouldCloseConnection(AuthenticationEventParameters parameters) {
+ readWriteLock.readLock().lock();
Review Comment:
I think it is better to get the lock in `currentUserAffected` method then `AUTHENTICATION_ENABELED` and `default` won't hold the lock they are not needed in.
##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientAuthenticationTest.java:
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.ignite.internal.runner.app.client;
+
+import static org.apache.ignite.internal.configuration.hocon.HoconConverter.hoconSource;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrowWithCauseOrSuppressed;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import com.typesafe.config.ConfigFactory;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.client.BasicAuthenticator;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import org.apache.ignite.internal.security.authentication.basic.BasicAuthenticationProviderChange;
+import org.apache.ignite.internal.security.configuration.SecurityConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.security.exception.InvalidCredentialsException;
+import org.apache.ignite.sql.Session;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Thin client authentication test.
+ */
+public class ItThinClientAuthenticationTest extends ItAbstractThinClientTest {
+ private static final String USERNAME = "admin";
+
+ private static final String PASSWORD = "password";
+
+ /** Client. */
+ private IgniteClient clientWithAuth;
+
+ private SecurityConfiguration securityConfiguration;
+
+ private final BasicAuthenticator basicAuthenticator = BasicAuthenticator.builder()
+ .username(USERNAME)
+ .password(PASSWORD)
+ .build();
+
+ @BeforeEach
+ void setUp() {
+ securityConfiguration = clusterConfigurationRegistry().getConfiguration(SecurityConfiguration.KEY);
+
+ CompletableFuture<Void> enableAuthentication = securityConfiguration.change(change -> {
+ change.changeEnabled(true);
+ change.changeAuthentication()
+ .changeProviders()
+ .update("default", provider -> {
+ provider.convert(BasicAuthenticationProviderChange.class)
+ .changeUsers()
+ .createOrUpdate(USERNAME, user -> user.changePassword(PASSWORD));
+ });
+ });
+
+ assertThat(enableAuthentication, willCompleteSuccessfully());
+
+ clientWithAuth = IgniteClient.builder()
+ .authenticator(basicAuthenticator)
+ .reconnectThrottlingRetries(0)
+ .addresses(getClientAddresses().toArray(new String[0]))
+ .build();
+
+ await().untilAsserted(() -> checkConnection(clientWithAuth));
+ }
+
+ @AfterEach
+ void tearDown() throws Exception {
+ IgniteUtils.closeAll(clientWithAuth);
+ }
+
+ @Test
+ void connectionIsClosedIfAuthenticationEnabled() {
+ await().until(() -> checkConnection(client()), willThrowWithCauseOrSuppressed(InvalidCredentialsException.class));
Review Comment:
Can you add a case when you change the configuration (add one more provider or user) and the connection is still be opened.
--
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: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org