Skip to content
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

Cassandra 20118 5.0 #3737

Draft
wants to merge 4 commits into
base: cassandra-5.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pylib/cassandra-cqlsh-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ TESTSUITE_NAME="${TESTSUITE_NAME}.$(uname -m)"
ccm remove test || true # in case an old ccm cluster is left behind
ccm create test -n 1 --install-dir=${CASSANDRA_DIR}
ccm updateconf "user_defined_functions_enabled: true"
ccm updateconf "storage_compatibility_mode: NONE"

version_from_build=$(ccm node1 versionfrombuild)
export pre_or_post_cdc=$(python -c """from distutils.version import LooseVersion
Expand Down
20 changes: 14 additions & 6 deletions src/java/org/apache/cassandra/auth/AuthKeyspace.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.cassandra.schema.KeyspaceMetadata;
import org.apache.cassandra.schema.KeyspaceParams;
import org.apache.cassandra.schema.Tables;
import org.apache.cassandra.utils.StorageCompatibilityMode;

import static java.lang.String.format;
import static org.apache.cassandra.config.CassandraRelevantProperties.SUPERUSER_SETUP_DELAY_MS;
Expand Down Expand Up @@ -154,11 +155,18 @@ private static TableMetadata parse(String name, String description, String cql)

public static KeyspaceMetadata metadata()
{
return KeyspaceMetadata.create(SchemaConstants.AUTH_KEYSPACE_NAME,
KeyspaceParams.simple(Math.max(DEFAULT_RF, DatabaseDescriptor.getDefaultKeyspaceRF())),
Tables.of(Roles, RoleMembers, RolePermissions,
ResourceRoleIndex, NetworkPermissions,
CIDRPermissions, CIDRGroups,
IdentityToRoles));
if (DatabaseDescriptor.getStorageCompatibilityMode() == StorageCompatibilityMode.CASSANDRA_4)
return KeyspaceMetadata.create(SchemaConstants.AUTH_KEYSPACE_NAME,
KeyspaceParams.simple(Math.max(DEFAULT_RF, DatabaseDescriptor.getDefaultKeyspaceRF())),
Tables.of(Roles, RoleMembers, RolePermissions,
ResourceRoleIndex, NetworkPermissions));
else
return KeyspaceMetadata.create(SchemaConstants.AUTH_KEYSPACE_NAME,
KeyspaceParams.simple(Math.max(DEFAULT_RF, DatabaseDescriptor.getDefaultKeyspaceRF())),
Tables.of(Roles, RoleMembers, RolePermissions,
ResourceRoleIndex, NetworkPermissions,
CIDRPermissions, CIDRGroups,
IdentityToRoles));

}
}
16 changes: 11 additions & 5 deletions src/java/org/apache/cassandra/auth/CassandraRoleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.NoSpamLogger;
import org.apache.cassandra.utils.StorageCompatibilityMode;
import org.mindrot.jbcrypt.BCrypt;

import static org.apache.cassandra.config.CassandraRelevantProperties.AUTH_BCRYPT_GENSALT_LOG2_ROUNDS;
Expand Down Expand Up @@ -147,7 +148,8 @@ public CassandraRoleManager()
public void setup()
{
loadRoleStatement();
loadIdentityStatement();
if (DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
loadIdentityStatement();
scheduleSetupTask(() -> {
setupDefaultRole();
return null;
Expand Down Expand Up @@ -241,10 +243,13 @@ public Set<Option> alterableOptions()
public void createRole(AuthenticatedUser performer, RoleResource role, RoleOptions options)
throws RequestValidationException, RequestExecutionException
{
List<String> identitiesOfRole = identitiesForRole(role.getRoleName());
if (!identitiesOfRole.isEmpty())
if (DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
{
throw new IllegalStateException(String.format("Cannot create a role '%s' when identities already exists for it", role.getRoleName()));
List<String> identitiesOfRole = identitiesForRole(role.getRoleName());
if (!identitiesOfRole.isEmpty())
{
throw new IllegalStateException(String.format("Cannot create a role '%s' when identities already exists for it", role.getRoleName()));
}
}
String insertCql = options.getPassword().isPresent() || options.getHashedPassword().isPresent()
? String.format("INSERT INTO %s.%s (role, is_superuser, can_login, salted_hash) VALUES ('%s', %s, %s, '%s')",
Expand All @@ -271,7 +276,8 @@ public void dropRole(AuthenticatedUser performer, RoleResource role) throws Requ
escape(role.getRoleName())),
consistencyForRoleWrite(role.getRoleName()));
removeAllMembers(role.getRoleName());
removeAllIdentitiesOfRole(role.getRoleName());
if (DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
removeAllIdentitiesOfRole(role.getRoleName());
}

public void alterRole(AuthenticatedUser performer, RoleResource role, RoleOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.utils.StorageCompatibilityMode;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

Expand All @@ -37,6 +39,11 @@ public class CreateRoleStatement extends AuthenticationStatement
final CIDRPermissions cidrPermissions;
private final boolean ifNotExists;

public CreateRoleStatement(RoleName name, RoleOptions options, DCPermissions dcPermissions, boolean ifNotExists)
{
this(name, options, dcPermissions, null, ifNotExists);
}

public CreateRoleStatement(RoleName name, RoleOptions options, DCPermissions dcPermissions,
CIDRPermissions cidrPermissions, boolean ifNotExists)
{
Expand Down Expand Up @@ -93,7 +100,7 @@ public ResultMessage execute(ClientState state) throws RequestExecutionException
DatabaseDescriptor.getNetworkAuthorizer().setRoleDatacenters(role, dcPermissions);
}

if (cidrPermissions != null)
if (cidrPermissions != null && DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
DatabaseDescriptor.getCIDRAuthorizer().setCidrGroupsForRole(role, cidrPermissions);

grantPermissionsToCreator(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.utils.StorageCompatibilityMode;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

Expand Down Expand Up @@ -75,7 +77,8 @@ public ResultMessage execute(ClientState state) throws RequestValidationExceptio
DatabaseDescriptor.getAuthorizer().revokeAllFrom(role);
DatabaseDescriptor.getAuthorizer().revokeAllOn(role);
DatabaseDescriptor.getNetworkAuthorizer().drop(role);
DatabaseDescriptor.getCIDRAuthorizer().dropCidrPermissionsForRole(role);
if (DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
DatabaseDescriptor.getCIDRAuthorizer().dropCidrPermissionsForRole(role);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.apache.cassandra.concurrent.ExecutorPlus;
import org.apache.cassandra.concurrent.FutureTask;
import org.apache.cassandra.concurrent.ScheduledExecutors;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Mutation;
import org.apache.cassandra.exceptions.RequestFailureReason;
import org.apache.cassandra.gms.ApplicationState;
Expand All @@ -69,6 +70,7 @@
import org.apache.cassandra.utils.NoSpamLogger;
import org.apache.cassandra.utils.Pair;
import org.apache.cassandra.utils.Simulate;
import org.apache.cassandra.utils.StorageCompatibilityMode;
import org.apache.cassandra.utils.concurrent.Future;
import org.apache.cassandra.utils.concurrent.ImmediateFuture;
import org.apache.cassandra.utils.concurrent.WaitQueue;
Expand Down Expand Up @@ -387,6 +389,11 @@ private boolean shouldPullFromEndpoint(InetAddressAndPort endpoint)

if (messagingService.versions.getRaw(endpoint) != MessagingService.current_version)
{
if (DatabaseDescriptor.getStorageCompatibilityMode() == StorageCompatibilityMode.CASSANDRA_4 && messagingService.versions.getRaw(endpoint) == MessagingService.VERSION_50)
{
logger.debug("Allowing schema pull from {} because we are in CASSANDRA_4 mode", endpoint);
return true;
}
logger.debug("Not pulling schema from {} because their schema format is incompatible", endpoint);
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/java/org/apache/cassandra/service/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
import org.apache.cassandra.utils.MD5Digest;
import org.apache.cassandra.utils.OutputHandler;
import org.apache.cassandra.utils.Pair;
import org.apache.cassandra.utils.StorageCompatibilityMode;
import org.apache.cassandra.utils.Throwables;
import org.apache.cassandra.utils.WrappedRunnable;
import org.apache.cassandra.utils.concurrent.Future;
Expand Down Expand Up @@ -1431,7 +1432,8 @@ public void doAuthSetup(boolean setUpSchema)
DatabaseDescriptor.getAuthenticator().setup();
DatabaseDescriptor.getAuthorizer().setup();
DatabaseDescriptor.getNetworkAuthorizer().setup();
DatabaseDescriptor.getCIDRAuthorizer().setup();
if (DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
DatabaseDescriptor.getCIDRAuthorizer().setup();
AuthCacheService.initializeAndRegisterCaches();
Schema.instance.registerListener(new AuthSchemaChangeListener());
authSetupComplete = true;
Expand Down
1 change: 1 addition & 0 deletions test/conf/cassandra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ local_read_size_warn_threshold: 4096KiB
local_read_size_fail_threshold: 8192KiB
row_index_read_size_warn_threshold: 4096KiB
row_index_read_size_fail_threshold: 8192KiB
storage_compatibility_mode: NONE

memtable:
configurations:
Expand Down