Skip to content

Commit

Permalink
cli: stop ignoring user arg in insecure mode
Browse files Browse the repository at this point in the history
Release note (bug fix): The --user argument is no longer ignored when
using `cockroach sql` in --insecure mode.
  • Loading branch information
rafiss committed Jan 20, 2022
1 parent 96779a6 commit 9b3efa2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/cli/democluster/demo_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ func (c *transientCluster) getNetworkURLForServer(
host, port, _ := addr.SplitHostPort(sqlAddr, "")
u.
WithNet(pgurl.NetTCP(host, port)).
WithDatabase(database)
WithDatabase(database).
WithUsername(c.adminUser.Normalized())

// For a demo cluster we don't use client TLS certs and instead use
// password-based authentication with the password pre-filled in the
Expand All @@ -1156,7 +1157,6 @@ func (c *transientCluster) getNetworkURLForServer(
u.WithInsecure()
} else {
u.
WithUsername(c.adminUser.Normalized()).
WithAuthn(pgurl.AuthnPassword(true, c.adminPassword)).
WithTransport(pgurl.TransportTLS(pgurl.TLSRequire, ""))
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/interactive_tests/test_style_enabled.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ eexpect eof

# Try connect and check the session variables match.

spawn $argv sql --url "postgresql://test@localhost:26257?options=-cintervalstyle%3Diso_8601"
spawn $argv sql --url "postgresql://root@localhost:26257?options=-cintervalstyle%3Diso_8601"
eexpect root@
send "SHOW intervalstyle;\r"
eexpect "iso_8601"
Expand All @@ -28,7 +28,7 @@ interrupt
eexpect eof

# TODO(#72065): uncomment
#spawn $argv sql --url "postgresql://test@localhost:26257?options=-cdatestyle%3Dymd"
#spawn $argv sql --url "postgresql://root@localhost:26257?options=-cdatestyle%3Dymd"
#eexpect root@
#send "SHOW datestyle;\r"
#eexpect "ISO, YMD"
Expand Down
5 changes: 5 additions & 0 deletions pkg/cli/interactive_tests/test_url_db_override.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ spawn $argv sql --url "postgresql://test@localhost:26257" --insecure -e "select
eexpect "1 row"
eexpect eof

# Make sure --insecure does not override --user
spawn $argv sql --user=test --insecure -e "select 'user=' || current_user()"
eexpect "user=test"
eexpect eof

set ::env(COCKROACH_INSECURE) "true"
end_test

Expand Down
1 change: 0 additions & 1 deletion pkg/server/pgurl/pgurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func (u *URL) GetOption(opt string) string {
// all security controls disabled.
func (u *URL) WithInsecure() *URL {
return u.
WithUsername("root").
WithAuthn(AuthnNone()).
WithTransport(TransportNone())
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/server/pgurl/testdata/url
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ JDBC: jdbc:postgresql://somehost:26257/somedb?application_name=myapp&password=

insecure
----
pq URL: postgresql://root@/?sslmode=disable
DSN: user=root sslmode=disable
JDBC: jdbc:postgresql:///?sslmode=disable&user=root
pq URL: postgresql:///?sslmode=disable
DSN: sslmode=disable
JDBC: jdbc:postgresql:///?sslmode=disable
--defaults filled--
pq URL: postgresql://root@defaulthost:26257/defaultdb?sslmode=disable
DSN: database=defaultdb user=root host=defaulthost port=26257 sslmode=disable
JDBC: jdbc:postgresql://defaulthost:26257/defaultdb?sslmode=disable&user=root
pq URL: postgresql://defaultuser@defaulthost:26257/defaultdb?sslmode=disable
DSN: database=defaultdb user=defaultuser host=defaulthost port=26257 sslmode=disable
JDBC: jdbc:postgresql://defaulthost:26257/defaultdb?sslmode=disable&user=defaultuser

subtest redundant

Expand Down

0 comments on commit 9b3efa2

Please sign in to comment.