mirror of https://github.com/apache/cassandra
Merge branch 'cassandra-4.0' into cassandra-4.1
This commit is contained in:
commit
85647ceadb
|
|
@ -6,6 +6,7 @@
|
||||||
* Equality check for Paxos.Electorate should not depend on collection types (CASSANDRA-19935)
|
* Equality check for Paxos.Electorate should not depend on collection types (CASSANDRA-19935)
|
||||||
* Fix race condition in DecayingEstimatedHistogramReservoir during rescale (CASSANDRA-19365)
|
* Fix race condition in DecayingEstimatedHistogramReservoir during rescale (CASSANDRA-19365)
|
||||||
Merged from 4.0:
|
Merged from 4.0:
|
||||||
|
* Tighten up permissions in dc authorizers (CASSANDRA-20225)
|
||||||
* CBUtil serialization of UTF8 does not handle all UTF8 properly (CASSANDRA-20234)
|
* CBUtil serialization of UTF8 does not handle all UTF8 properly (CASSANDRA-20234)
|
||||||
* Make hint expiry use request start time rather than timeout time for TTL (CASSANDRA-20014)
|
* Make hint expiry use request start time rather than timeout time for TTL (CASSANDRA-20014)
|
||||||
* Do not attach rows and partitions to CheckForAbort when already attached (CASSANDRA-20135)
|
* Do not attach rows and partitions to CheckForAbort when already attached (CASSANDRA-20135)
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,9 @@ public class AlterRoleStatement extends AuthenticationStatement
|
||||||
if (opts.getSuperuser().isPresent() && !isSuper)
|
if (opts.getSuperuser().isPresent() && !isSuper)
|
||||||
throw new UnauthorizedException("Only superusers are allowed to alter superuser status");
|
throw new UnauthorizedException("Only superusers are allowed to alter superuser status");
|
||||||
|
|
||||||
|
if (dcPermissions != null && !isSuper)
|
||||||
|
throw new UnauthorizedException("Only superusers are allowed to alter access to datacenters.");
|
||||||
|
|
||||||
// superusers can do whatever else they like
|
// superusers can do whatever else they like
|
||||||
if (isSuper)
|
if (isSuper)
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,9 @@ import org.apache.cassandra.cql3.statements.DropRoleStatement;
|
||||||
import org.apache.cassandra.db.Keyspace;
|
import org.apache.cassandra.db.Keyspace;
|
||||||
import org.apache.cassandra.db.marshal.UTF8Type;
|
import org.apache.cassandra.db.marshal.UTF8Type;
|
||||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||||
|
import org.apache.cassandra.exceptions.UnauthorizedException;
|
||||||
import org.apache.cassandra.service.ClientState;
|
import org.apache.cassandra.service.ClientState;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
|
|
||||||
import static org.apache.cassandra.auth.AuthKeyspace.NETWORK_PERMISSIONS;
|
import static org.apache.cassandra.auth.AuthKeyspace.NETWORK_PERMISSIONS;
|
||||||
import static org.apache.cassandra.auth.AuthTestUtils.getRolesReadCount;
|
import static org.apache.cassandra.auth.AuthTestUtils.getRolesReadCount;
|
||||||
|
|
@ -111,7 +113,19 @@ public class CassandraNetworkAuthorizerTest
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ClientState getClientState(String role)
|
||||||
|
{
|
||||||
|
ClientState state = ClientState.forInternalCalls();
|
||||||
|
state.login(new AuthenticatedUser(role));
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
private static void auth(String query, Object... args)
|
private static void auth(String query, Object... args)
|
||||||
|
{
|
||||||
|
auth(query, getClientState(), args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void auth(String query, ClientState clientState, Object... args)
|
||||||
{
|
{
|
||||||
CQLStatement statement = QueryProcessor.parseStatement(String.format(query, args)).prepare(ClientState.forInternalCalls());
|
CQLStatement statement = QueryProcessor.parseStatement(String.format(query, args)).prepare(ClientState.forInternalCalls());
|
||||||
assert statement instanceof CreateRoleStatement
|
assert statement instanceof CreateRoleStatement
|
||||||
|
|
@ -121,7 +135,8 @@ public class CassandraNetworkAuthorizerTest
|
||||||
|
|
||||||
// invalidate roles cache so that any changes to the underlying roles are picked up
|
// invalidate roles cache so that any changes to the underlying roles are picked up
|
||||||
Roles.cache.invalidate();
|
Roles.cache.invalidate();
|
||||||
authStmt.execute(getClientState());
|
authStmt.authorize(clientState);
|
||||||
|
authStmt.execute(clientState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DCPermissions dcPerms(String username)
|
private static DCPermissions dcPerms(String username)
|
||||||
|
|
@ -168,6 +183,27 @@ public class CassandraNetworkAuthorizerTest
|
||||||
assertDcPermRow(username);
|
assertDcPermRow(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void alterAsUser()
|
||||||
|
{
|
||||||
|
String username = createName();
|
||||||
|
|
||||||
|
assertNoDcPermRow(username);
|
||||||
|
auth("CREATE ROLE %s WITH PASSWORD = 'password' AND LOGIN = true AND ACCESS TO DATACENTERS {'dc1'}", username);
|
||||||
|
Assert.assertEquals(DCPermissions.subset("dc1"), dcPerms(username));
|
||||||
|
assertDcPermRow(username, "dc1");
|
||||||
|
|
||||||
|
// try to alter as a user
|
||||||
|
ClientState userState = getClientState(username);
|
||||||
|
Assertions.assertThatThrownBy(() -> auth("ALTER ROLE %s WITH ACCESS TO DATACENTERS {'dc1', 'dc2'}", userState, username))
|
||||||
|
.hasMessage("Only superusers are allowed to alter access to datacenters.")
|
||||||
|
.isInstanceOf(UnauthorizedException.class);
|
||||||
|
|
||||||
|
// nothing changed
|
||||||
|
Assert.assertEquals(DCPermissions.subset("dc1"), dcPerms(username));
|
||||||
|
assertDcPermRow(username, "dc1");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void drop()
|
public void drop()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue