Skip to content

feat: Generate random admin user password in dev mode #1207

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 9 commits into from
Apr 28, 2022

Conversation

mafredri
Copy link
Member

This PR replaces the static dev mode admin password with a randomly generated one. It allows both email and password to be set either via environment or command line flags.

Normally passwords as cli flags is suboptimal, but considering the use case I think it's acceptable and may be nicer for the developer.

This PR also fixes a flake in the TestServer/Development test.

Closes #825

@mafredri mafredri self-assigned this Apr 28, 2022
@mafredri mafredri requested review from ammario, coadler, johnstcn and a team April 28, 2022 14:17
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

LGTM!

@codecov
Copy link

codecov bot commented Apr 28, 2022

Codecov Report

Merging #1207 (0026a12) into main (a7fb018) will decrease coverage by 0.15%.
The diff coverage is 71.87%.

@@            Coverage Diff             @@
##             main    #1207      +/-   ##
==========================================
- Coverage   66.25%   66.09%   -0.16%     
==========================================
  Files         265      265              
  Lines       16681    16771      +90     
  Branches      157      157              
==========================================
+ Hits        11052    11085      +33     
- Misses       4484     4527      +43     
- Partials     1145     1159      +14     
Flag Coverage Δ
unittest-go-macos-latest 53.39% <71.87%> (-0.32%) ⬇️
unittest-go-postgres- 65.45% <71.87%> (-0.09%) ⬇️
unittest-go-ubuntu-latest 55.91% <71.87%> (-0.17%) ⬇️
unittest-go-windows-2022 53.07% <71.87%> (-0.08%) ⬇️
unittest-js 66.50% <ø> (ø)
Impacted Files Coverage Δ
cli/server.go 58.77% <71.87%> (-0.15%) ⬇️
pty/start_other.go 64.70% <0.00%> (-23.53%) ⬇️
codersdk/provisionerdaemons.go 61.97% <0.00%> (-5.64%) ⬇️
coderd/users.go 61.27% <0.00%> (-2.01%) ⬇️
provisionerd/provisionerd.go 76.84% <0.00%> (-0.67%) ⬇️
coderd/database/queries.sql.go 81.12% <0.00%> (-0.54%) ⬇️
coderd/provisionerdaemons.go 63.29% <0.00%> (-0.51%) ⬇️
peer/conn.go 79.44% <0.00%> (ø)
codersdk/users.go 64.20% <0.00%> (ø)
peerbroker/proxy.go 58.72% <0.00%> (+0.58%) ⬆️
... and 3 more

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 a7fb018...0026a12. Read the comment docs.


wantEmail := "myadmin@coder.com"
wantPassword := "testpass42"
os.Setenv("CODER_DEV_ADMIN_EMAIL", wantEmail)
Copy link
Member

Choose a reason for hiding this comment

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

t.Setenv handles this for you :-)

root.SetOutput(&stdoutBuf)
var buf strings.Builder
root.SetOutput(&buf)
done := make(chan struct{})
Copy link
Member

Choose a reason for hiding this comment

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

minor: another way to do this is to use sync.WaitGroup:

var wg sync.WaitGroup
go myFunc() {
    ... stuff happens
   wg.Done()
}()
wg.Add(1)
wg.Wait()

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.

Nice work!

@mafredri mafredri requested a review from a team as a code owner April 28, 2022 14:53
Copy link
Contributor

@presleyp presleyp left a comment

Choose a reason for hiding this comment

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

The frontend change looks fine to me!

@mafredri mafredri merged commit afc43fe into main Apr 28, 2022
@mafredri mafredri deleted the mafredri/feat-generate-random-dev-user-password branch April 28, 2022 16:13
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
* feat: Generate random admin user password in dev mode

* Add dev mode test with email/pass from env

* Set email/pass for playwright e2e test via cli flags
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
7 participants