Skip to content

feat: Output username and password for code server --dev #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2022

Conversation

mafredri
Copy link
Member

This PR allows the dev mode credentials (email and password) to be output to the terminal.

Fixes #825

@mafredri mafredri requested review from johnstcn and a team April 27, 2022 13:08
@codecov
Copy link

codecov bot commented Apr 27, 2022

Codecov Report

Merging #1193 (e94fdaf) into main (a769e86) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1193      +/-   ##
==========================================
+ Coverage   66.26%   66.28%   +0.02%     
==========================================
  Files         265      265              
  Lines       16682    16681       -1     
  Branches      157      157              
==========================================
+ Hits        11054    11057       +3     
+ Misses       4483     4481       -2     
+ Partials     1145     1143       -2     
Flag Coverage Δ
unittest-go-macos-latest 53.61% <100.00%> (-0.07%) ⬇️
unittest-go-postgres- 65.62% <100.00%> (+<0.01%) ⬆️
unittest-go-ubuntu-latest 56.22% <100.00%> (+0.05%) ⬆️
unittest-go-windows-2022 53.20% <100.00%> (+0.02%) ⬆️
unittest-js 66.50% <ø> (ø)
Impacted Files Coverage Δ
cli/server.go 58.91% <100.00%> (-0.08%) ⬇️
provisionerd/provisionerd.go 76.17% <0.00%> (-0.54%) ⬇️
peer/conn.go 81.21% <0.00%> (ø)
peer/channel.go 84.97% <0.00%> (+1.15%) ⬆️
provisioner/echo/serve.go 59.20% <0.00%> (+4.80%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a769e86...e94fdaf. Read the comment docs.

@mafredri mafredri force-pushed the mafredri/dev-mode-credentials branch from 563b060 to d6410d9 Compare April 27, 2022 13:11
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

🎉 Two in one day! Just a couple of minor things.

@@ -88,6 +92,9 @@ func TestServer(t *testing.T) {
require.NoError(t, err)
parsed, err := url.Parse(accessURL)
require.NoError(t, err)
// Verify that credentials were output to the terminal.
assert.Contains(t, stdoutBuf.String(), "email: admin@coder.com", "unexpected output")
assert.Contains(t, stdoutBuf.String(), "password: password", "unexpected output")
Copy link
Member

Choose a reason for hiding this comment

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

nit: change msgAndArgs to be different for both asserts

@@ -88,6 +92,9 @@ func TestServer(t *testing.T) {
require.NoError(t, err)
parsed, err := url.Parse(accessURL)
require.NoError(t, err)
// Verify that credentials were output to the terminal.
assert.Contains(t, stdoutBuf.String(), "email: admin@coder.com", "unexpected output")
Copy link
Member

Choose a reason for hiding this comment

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

minor: should we use the values from defaultDevUser instead of hard-coding? This would mean exporting it, but I don't see a huge issue there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, we can do that. I think hard-coding would be acceptable here too, as changes to the defaults may require rethinking some things, but either works for me.

Copy link
Member

Choose a reason for hiding this comment

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

I'm a fan of hard coding here too. Customers that use the product will likely depend on the credentials, so having tests fail if they change seems reasonable.

@johnstcn
Copy link
Member

I don't think the test/go failure on ubuntu-latest is related to anything we're doing. You can just retry that for now.

@mafredri mafredri force-pushed the mafredri/dev-mode-credentials branch from e343748 to 3cd7460 Compare April 27, 2022 14:10
@mafredri mafredri merged commit 8661f92 into main Apr 27, 2022
@mafredri mafredri deleted the mafredri/dev-mode-credentials branch April 27, 2022 14:59

// Verify that credentials were output to the terminal.
wantEmail := "email: admin@coder.com"
wantPassword := "password: password"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could export defaultDevUser so we could assert the output in tests

Copy link
Member Author

Choose a reason for hiding this comment

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

That's definitely an option, we discussed it a bit and I added a commit that this this but ultimately dropped it before the merge.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, I should've read back before I commented!

Comment on lines +78 to +79
var stdoutBuf bytes.Buffer
root.SetOutput(&stdoutBuf)
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit: if you're only ever calling buffer.String() you can use strings.Builder to avoid a copy on each call to String()

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I didn't consider strings.Builder in this scenario although I did note the multiple calls to String() but thought it would be acceptable for a test. Would you like me to do a follow-up PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope! Not important at all, just thought I'd mention.

@ammario
Copy link
Member

ammario commented Apr 27, 2022

@mafredri I think the constant password + the external access URL option poses a security risk. I suggest we randomly generate the password to be safe.

Screen Shot 2022-04-27 at 12 31 43 PM

@mafredri
Copy link
Member Author

@ammario I'd be happy to look at fixing that. Should we move this to a new issue to narrow down the specs a bit? For instance, a user might want to override the random password with a self-defined one (thinking about the convenience of logging in). A way to achieve that could be an env variable, or perhaps storing the generated password in a dotfile or similar.

@ammario
Copy link
Member

ammario commented Apr 27, 2022

It's a highly relevant one line fix so I don't think a new issue is necessary.

I'm not sure what the best solution is... Writing to a dotfile makes sense as it achieves both stability and security.

@coadler
Copy link
Contributor

coadler commented Apr 27, 2022

I'd probably be against a dotfile approach. Getting the initial login would be harder in ephemeral environments, plus we can't always assume we have a writable fs.

@ammario
Copy link
Member

ammario commented Apr 27, 2022

That's fine... then we could default to a randomly generated one and let an environment variable override. Secure by default, stable if configured.

@coadler
Copy link
Contributor

coadler commented Apr 27, 2022

Seems reasonable to me

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.

dev mode launches with no credentials printed to console
6 participants