Skip to content

cli/demo: provision an initial non-root "demo" user #54749

Merged
craig[bot] merged 5 commits intocockroachdb:masterfrom
knz:20200924-demo-pwd
Sep 24, 2020
Merged

cli/demo: provision an initial non-root "demo" user #54749
craig[bot] merged 5 commits intocockroachdb:masterfrom
knz:20200924-demo-pwd

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Sep 24, 2020

Fixes #54557.
Requested by @jseldess

First 2 commits from #54741 (can be ignored during review)

Release note (cli change): cockroach demo now pre-creates a demo
user account with a random password, instead of letting (and
encouraging) the user to use the root account directly.
The demo account is currently granted the admin role.

This makes it easier to process a file other than the standard input.

Release note: None
@knz knz requested review from irfansharif and otan September 24, 2020 13:58
@knz knz requested a review from a team as a code owner September 24, 2020 13:58
@knz knz changed the title 20200924 demo pwd cli/demo: provision an initial non-root "demo" user Sep 24, 2020
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@knz knz requested a review from arulajmani September 24, 2020 14:00
@knz knz force-pushed the 20200924-demo-pwd branch 3 times, most recently from 1b286b4 to cf81313 Compare September 24, 2020 14:22
// a cluster is started for the first time.
//
// The "startSingleNode" argument is true for `start-single-node`
// and `cockroach demo` with 2 nodes or less.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] rephrase to use "fewer" instead?

func runInitialSQL(ctx context.Context, s *server.Server, startSingleNode bool) error {
if startSingleNode && s.InitialStart() {
// For start-single-node, set the default replication factor to
// 1 so as to avoid warning message and unnecessary rebalance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"1 to avoid the warning message..."?

const symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var result strings.Builder
for i := 0; i < length; i++ {
r := rand.Intn(len(symbols))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐶 🔍 isn't math/rand in appropriate here? I thought that was what we had crypto/rand for.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize it doesn't matter now, it's just used for cockroach demo, but GenerateRandomPassword within pkg/security seems too enticing for use elsewhere. If the intent here is to have it only used in cockroach demo, should we rename/add a caveat somewhere? Again, 🐶 🔍

Release note (cli change): `cockroach sql` and `cockroach demo` now
support the command-line parameter `--input-file` (shorthand `-f`) to
read commands from a named file. The behavior is the same as if the
file was redirected on the standard input; in particular, the
processing stops at the first error encountered (which is different
from interactive usage with a prompt).

Note that it is not (yet) possible to combine `-f` with `-e`.
@knz knz force-pushed the 20200924-demo-pwd branch from cf81313 to 9884177 Compare September 24, 2020 16:24
Copy link
Copy Markdown
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @arulajmani, @irfansharif, and @otan)


pkg/security/password.go, line 102 at r4 (raw file):

Previously, irfansharif (irfan sharif) wrote…

I realize it doesn't matter now, it's just used for cockroach demo, but GenerateRandomPassword within pkg/security seems too enticing for use elsewhere. If the intent here is to have it only used in cockroach demo, should we rename/add a caveat somewhere? Again, 🐶 🔍

Done.


pkg/cli/initial_sql.go, line 27 at r3 (raw file):

Previously, irfansharif (irfan sharif) wrote…

[nit] rephrase to use "fewer" instead?

Done.


pkg/cli/initial_sql.go, line 31 at r3 (raw file):

Previously, irfansharif (irfan sharif) wrote…

"1 to avoid the warning message..."?

Done.

knz added 3 commits September 24, 2020 18:26
This also makes `cockroach demo` and `cockroach start` share the same
initialization function.

Release note (cli change): The large banner message "Replication has
been disabled for this cluster ..." that was unconditionally emitted
on the standard error stream for `cockroach start-single-node` has now
become a simple log message at severity INFO.
This implements an alphanumeric password generator.

Release note: None
Release note (cli change): `cockroach demo` now pre-creates a `demo`
user account with a random password, instead of letting (and
encouraging) the user to use the `root` account directly.
The `demo` account is currently granted the `admin` role.
@knz knz force-pushed the 20200924-demo-pwd branch from 9884177 to aff9c7c Compare September 24, 2020 16:32
@knz
Copy link
Copy Markdown
Contributor Author

knz commented Sep 24, 2020

bors r=irfansharif

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 24, 2020

Build succeeded:

@craig craig bot merged commit 3c81612 into cockroachdb:master Sep 24, 2020
@knz knz deleted the 20200924-demo-pwd branch September 25, 2020 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a non-root user for cockroach demo

3 participants