Skip to content

Commit 4dd8525

Browse files
pufitnikitamikhaylov
authored andcommitted
Add enable_user_name_access_type setting for compatibility.
1 parent 9d83d9f commit 4dd8525

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

src/Access/AccessControl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ void AccessControl::setupFromMainConfig(const Poco::Util::AbstractConfiguration
306306
setSettingsConstraintsReplacePrevious(config_.getBool("access_control_improvements.settings_constraints_replace_previous", true));
307307
setTableEnginesRequireGrant(config_.getBool("access_control_improvements.table_engines_require_grant", false));
308308

309+
/// Set `true` by default because the feature is backward incompatible only when older version replicas are in the same cluster.
310+
setEnableUserNameAccessType(config_.getBool("access_control_improvements.enable_user_name_access_type", true));
311+
309312
addStoragesFromMainConfig(config_, config_path_, get_zookeeper_function_);
310313

311314
role_cache = std::make_unique<RoleCache>(*this, config_.getInt("access_control_improvements.role_cache_expiration_time_seconds", 600));
@@ -771,6 +774,15 @@ int AccessControl::getBcryptWorkfactor() const
771774
return bcrypt_workfactor;
772775
}
773776

777+
void AccessControl::setEnableUserNameAccessType(bool enable_user_name_access_type_)
778+
{
779+
enable_user_name_access_type = enable_user_name_access_type_;
780+
}
781+
782+
bool AccessControl::isEnabledUserNameAccessType() const
783+
{
784+
return enable_user_name_access_type;
785+
}
774786

775787
std::shared_ptr<const ContextAccess> AccessControl::getContextAccess(const ContextAccessParams & params) const
776788
{

src/Access/AccessControl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ class AccessControl : public MultipleAccessStorage
173173
void setBcryptWorkfactor(int workfactor_);
174174
int getBcryptWorkfactor() const;
175175

176+
/// Compatability setting
177+
void setEnableUserNameAccessType(bool enable_user_name_access_type_);
178+
bool isEnabledUserNameAccessType() const;
179+
176180
/// Enables logic that users without permissive row policies can still read rows using a SELECT query.
177181
/// For example, if there are two users A, B and a row policy is defined only for A, then
178182
/// if this setting is true the user B will see all rows, and if this setting is false the user B will see no rows.
@@ -284,6 +288,7 @@ class AccessControl : public MultipleAccessStorage
284288
std::atomic<AuthenticationType> default_password_type = AuthenticationType::SHA256_PASSWORD;
285289
std::atomic_bool allow_experimental_tier_settings = true;
286290
std::atomic_bool allow_beta_tier_settings = true;
291+
std::atomic_bool enable_user_name_access_type = true;
287292
};
288293

289294
}

src/Access/Common/AccessRightsElement.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#include <Access/AccessControl.h>
12
#include <Access/Common/AccessRightsElement.h>
23
#include <Common/quoteString.h>
34
#include <IO/Operators.h>
45
#include <IO/WriteBufferFromString.h>
6+
#include <Interpreters/Context.h>
57
#include <Parsers/IAST.h>
68

79

@@ -139,16 +141,36 @@ void AccessRightsElement::formatColumnNames(WriteBuffer & buffer) const
139141

140142
void AccessRightsElement::formatONClause(WriteBuffer & buffer, bool hilite) const
141143
{
144+
const auto context = Context::getGlobalContextInstance();
145+
const auto & access_control = context->getAccessControl();
146+
142147
buffer << (hilite ? IAST::hilite_keyword : "") << "ON " << (hilite ? IAST::hilite_none : "");
143148
if (isGlobalWithParameter())
144149
{
145-
if (anyParameter())
146-
buffer << "*";
150+
/// Special check for backward compatibility.
151+
/// If `enable_user_name_access_type` is set to false, we will dump `GRANT CREATE USER ON *` as `GRANT CREATE USER ON *.*`.
152+
/// This will allow us to run old replicas in the same cluster.
153+
if (access_flags.getParameterType() == AccessFlags::USER_NAME
154+
&& !access_control.isEnabledUserNameAccessType())
155+
{
156+
if (!anyParameter())
157+
getLogger("AccessRightsElement")->warning(
158+
"Converting {} to *.* because the setting `enable_user_name_access_type` is `false`. "
159+
"Consider turning this setting on, if your cluster contains no replicas older than 25.1",
160+
parameter);
161+
162+
buffer << "*.*";
163+
}
147164
else
148165
{
149-
buffer << backQuoteIfNeed(parameter);
150-
if (wildcard)
166+
if (anyParameter())
151167
buffer << "*";
168+
else
169+
{
170+
buffer << backQuoteIfNeed(parameter);
171+
if (wildcard)
172+
buffer << "*";
173+
}
152174
}
153175
}
154176
else if (anyDatabase())

0 commit comments

Comments
 (0)