Authentication & Authorization
Background
In ShardingSphere-Proxy, user authentication and authorization information is configured through authority.
Thanks to ShardingSphere’s pluggable architecture, Proxy provides two levels of privilege providers, namely:
ALL_PERMITTED: each user has all privileges without special authorization. (Will be removed in a future version)DATABASE_PERMITTED: grants the user privileges on the specified logical databases, defined byuser-database-mappings. (Recommended)
The administrator can choose which privilege provider to use as needed when configuring authority.
Parameters
authority:
users:
- user: # Specify the username, and authorized host for logging in to the compute node. Format: <username>@<hostname>. When the hostname is % or an empty string, it indicates that the authorized host is not limited, username and hostname are case-insensitive
password: # Password
admin: # Optional, administrator identity. If true, the user has the highest authority. The default value is false
authenticationMethodName: # Optional, used to specify the password authentication method for the user
authenticators: # Optional, not required by default, Proxy will automatically choose the authentication method according to the frontend protocol type
authenticatorName:
type: # Authentication method type
defaultAuthenticator: # Optional, specify an authenticator as the default password authentication method
privilege:
type: # Privilege provider type. The default value is ALL_PERMITTEDSample
Minimalist configuration
authority:
users:
- user: root@%
password: root
- user: sharding
password: shardingExplanation:
- Two users are defined:
root@%andsharding; authenticationMethodNameis not specified forroot@127.0.0.1, Proxy will automatically choose the authentication method according to the frontend protocol;- Privilege provider is not specified, the default
ALL_PERMITTEDwill be used;
Authentication configuration
The custom authentication configuration allows users to greater leeway to set their own custom configurations according to their scenarios.
Taking openGauss as the frontend protocol type as an example, its default authentication method is scram-sha-256.
If the user sharding needs to use an old version of the psql client (which does not support scram-sha-256) to connect to the Proxy, the administrator may allow sharding to use the md5 method for password authentication.
The configuration is as follows:
authority:
users:
- user: root@127.0.0.1
password: root
- user: sharding
password: sharding
authenticationMethodName: md5
authenticators:
md5:
type: MD5
privilege:
type: ALL_PERMITTEDExplanation:
- Two users are defined:
root@127.0.0.1andsharding; - Use
MD5method for password authentication forsharding; - Authentication method is not specified for
root@127.0.0.1, Proxy will automatically choose one according to the frontend protocol; - The privilege provider
ALL_PERMITTEDis specified.
Authorization configuration
ALL_PERMITTED (Will be removed in a future version)
authority:
users:
- user: root@127.0.0.1
password: root
- user: sharding
password: sharding
privilege:
type: ALL_PERMITTEDExplanation:
- Two users are defined:
root@127.0.0.1andsharding; authenticatorsandauthenticationMethodNameare not defined, Proxy will automatically choose the authentication method according to the frontend protocol;- The privilege provider
ALL_PERMITTEDis specified.
DATABASE_PERMITTED (Recommended)
authority:
users:
- user: root@127.0.0.1
password: root
admin: true
- user: sharding
password: sharding
- user: test
password: sharding
privilege:
type: DATABASE_PERMITTED
props:
user-database-mappings: sharding@%=*, test@%=test_db, test@%=sharding_dbExplanation:
- Three users are defined:
root@127.0.0.1,shardingandtest, whichroot@127.0.0.1is an admin user; authenticatorsandauthenticationMethodNameare not defined, Proxy will automatically choose the authentication method according to the frontend protocol;- The privilege provider
DATABASE_PERMITTEDis specified, authorizesharding@%to access all logical databases (*), and usertestcan only accesstest_dbandsharding_db.