-
Notifications
You must be signed in to change notification settings - Fork 4.1k
CASSANDRA-21546: Support pluggable default role initialization #4990
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
Open
aparna0522
wants to merge
14
commits into
apache:trunk
Choose a base branch
from
aparna0522:anaik-hardcoded-creds-fix
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
998fcd7
Add MutualTLS strategy for Cluster Startup
1e7e210
rewrite
smiklosovic 9d7b7ee
redact values of ParameterizedClass parameters map which contain a pa…
smiklosovic 06a3726
support password hash
smiklosovic cd04177
my review
frankgh e05c56c
my review with default_role_initializer config changes
frankgh aa2b83d
fix checkstyle
frankgh 00e9243
defaultRoleInitializer should not be part of the IRoleManager interface
frankgh 16cc98f
revert 00e92434731cefde6aba401882b7bdf2c6bd3acf
frankgh a6ed8bb
Review fixes
cdf8332
added supportsRoleManager method
smiklosovic d5e790f
Revert "added supportsRoleManager method"
ab5f5e8
Create AbstractDefaultRoleInitializer class
57fad7a
review fixes
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
63 changes: 63 additions & 0 deletions
63
src/java/org/apache/cassandra/auth/AbstractDefaultRoleInitializer.java
This file contains hidden or 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,63 @@ | ||
| /* | ||
| * 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.cassandra.auth; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.cassandra.cql3.QueryProcessor; | ||
| import org.apache.cassandra.db.ConsistencyLevel; | ||
| import org.apache.cassandra.exceptions.RequestExecutionException; | ||
| import org.apache.cassandra.schema.SchemaConstants; | ||
| import org.apache.cassandra.tcm.ClusterMetadata; | ||
|
|
||
| import static org.apache.cassandra.auth.AuthUtils.escape; | ||
|
|
||
| public abstract class AbstractDefaultRoleInitializer implements IDefaultRoleInitializer | ||
| { | ||
| private static final Logger logger = LoggerFactory.getLogger(AbstractDefaultRoleInitializer.class); | ||
|
|
||
| @Override | ||
| public final void initializeDefaultRoleIfNeeded() | ||
| { | ||
| if (ClusterMetadata.current().tokenMap.tokens().isEmpty()) | ||
| throw new IllegalStateException(getClass().getSimpleName() + " skipped role setup: no known tokens in the ring"); | ||
|
|
||
| try { | ||
| if (!hasExistingRoles()) | ||
| createDefaultRole(); | ||
|
|
||
| } catch (RequestExecutionException e) | ||
| { | ||
| logger.warn(getClass().getSimpleName() + " skipped default role setup: some nodes were not ready"); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public final boolean hasExistingRoles() | ||
| { | ||
| // Try looking up the configured default role first, to avoid the range query if possible. | ||
| String defaultRoleQuery = String.format("SELECT * FROM %s.%s WHERE role = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLES, escape(defaultRoleName())); | ||
| String allUsersQuery = String.format("SELECT * FROM %s.%s LIMIT 1", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLES); | ||
| return !QueryProcessor.process(defaultRoleQuery, ConsistencyLevel.ONE).isEmpty() | ||
| || !QueryProcessor.process(defaultRoleQuery, ConsistencyLevel.QUORUM).isEmpty() | ||
| || !QueryProcessor.process(allUsersQuery, ConsistencyLevel.QUORUM).isEmpty(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,53 @@ | ||
| /* | ||
| * 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.cassandra.auth; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.mindrot.jbcrypt.BCrypt; | ||
|
|
||
| import org.apache.cassandra.config.DatabaseDescriptor; | ||
| import org.apache.cassandra.db.ConsistencyLevel; | ||
|
|
||
| public class AuthUtils | ||
| { | ||
| static final ConsistencyLevel DEFAULT_SUPERUSER_CONSISTENCY_LEVEL = ConsistencyLevel.QUORUM; | ||
|
|
||
| private AuthUtils() {} | ||
|
|
||
| public static String hashpw(String password) | ||
| { | ||
| return BCrypt.hashpw(password, PasswordSaltSupplier.get()); | ||
| } | ||
|
|
||
| public static String escape(String name) | ||
| { | ||
| return StringUtils.replace(name, "", "''"); | ||
| } | ||
|
|
||
| /** Allows selective overriding of the consistency level for specific roles. */ | ||
| public static ConsistencyLevel consistencyForRoleWrite(String role) | ||
| { | ||
| return role.equals(DatabaseDescriptor.getRoleManager().defaultRoleInitializer().defaultRoleName()) ? DEFAULT_SUPERUSER_CONSISTENCY_LEVEL : CassandraAuthorizer.authWriteConsistencyLevel(); | ||
| } | ||
|
|
||
| public static ConsistencyLevel consistencyForRoleRead(String role) | ||
| { | ||
| return role.equals(DatabaseDescriptor.getRoleManager().defaultRoleInitializer().defaultRoleName()) ? DEFAULT_SUPERUSER_CONSISTENCY_LEVEL : CassandraAuthorizer.authReadConsistencyLevel(); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.