Skip to content

Commit aebba88

Browse files
authored
Merge pull request #1856 from dolthub/macneale4/ipv6-authen
Support IPV6 loopback address for looking up user credentials
2 parents a76f7eb + 7ff74d6 commit aebba88

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sql/mysql_db/mysql_db.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (db *MySQLDb) AddSuperUser(username string, host string, password string) {
263263
// roles, roleSearch changes whether the search matches against user or role rules.
264264
func (db *MySQLDb) GetUser(user string, host string, roleSearch bool) *User {
265265
//TODO: Determine what the localhost is on the machine, then handle the conversion between IP and localhost.
266-
// For now, this just treats localhost and 127.0.0.1 as the same.
266+
// For now, loopback addresses are treated as localhost.
267267
//TODO: Determine how to match anonymous roles (roles with an empty user string), which differs from users
268268
//TODO: Treat '%' as a proper wildcard for hostnames, allowing for regex-like matches.
269269
// Hostnames representing an IP address that have a wildcard have additional restrictions on what may match
@@ -274,6 +274,11 @@ func (db *MySQLDb) GetUser(user string, host string, roleSearch bool) *User {
274274
//TODO: Hostnames representing IPs can use masks, such as 'abc'@'54.244.85.0/255.255.255.0'
275275
//TODO: Allow for CIDR notation in hostnames
276276
//TODO: Which user do we choose when multiple host names match (e.g. host name with most characters matched, etc.)
277+
278+
if "127.0.0.1" == host || "::1" == host {
279+
host = "localhost"
280+
}
281+
277282
userEntries := db.user.data.Get(UserPrimaryKey{
278283
Host: host,
279284
User: user,
@@ -292,7 +297,7 @@ func (db *MySQLDb) GetUser(user string, host string, roleSearch bool) *User {
292297
readUserEntry := readUserEntry.(*User)
293298
//TODO: use the most specific match first, using "%" only if there isn't a more specific match
294299
if host == readUserEntry.Host ||
295-
(host == "127.0.0.1" && readUserEntry.Host == "localhost") ||
300+
(host == "localhost" && readUserEntry.Host == "::1") ||
296301
(host == "localhost" && readUserEntry.Host == "127.0.0.1") ||
297302
(readUserEntry.Host == "%" && (!roleSearch || host == "")) {
298303
return readUserEntry

0 commit comments

Comments
 (0)