8000 feat: add login type 'none' to prevent password login by Emyrk · Pull Request #8009 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: add login type 'none' to prevent password login #8009

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 8 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
forgot to commit migration
  • Loading branch information
Emyrk committed Jun 13, 2023
commit f43212731487e410e2b68a19b453664b4289f493
23 changes: 18 additions & 5 deletions cli/usercreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (

func (r *RootCmd) userCreate() *clibase.Cmd {
var (
email string
username string
password string
email string
username string
password string
disableLogin bool
)
client := new(codersdk.Client)
cmd := &clibase.Cmd{
Expand Down Expand Up @@ -53,7 +54,7 @@ func (r *RootCmd) userCreate() *clibase.Cmd {
return err
}
}
if password == "" {
if password == "" && !disableLogin {
password, err = cryptorand.StringCharset(cryptorand.Human, 20)
if err != nil {
return err
Expand All @@ -65,10 +66,16 @@ func (r *RootCmd) userCreate() *clibase.Cmd {
Username: username,
Password: password,
OrganizationID: organization.ID,
DisableLogin: disableLogin,
})
if err != nil {
return err
}
authenticationMethod := `Your password is: ` + cliui.DefaultStyles.Field.Render(password)
if disableLogin {
authenticationMethod = "Login has been disabled for this user. Contact your administrator to authenticate."
}

_, _ = fmt.Fprintln(inv.Stderr, `A new user has been created!
Share the instructions below to get them started.
`+cliui.DefaultStyles.Placeholder.Render("—————————————————————————————————————————————————")+`
Expand All @@ -78,7 +85,7 @@ https://github.com/coder/coder/releases
Run `+cliui.DefaultStyles.Code.Render("coder login "+client.URL.String())+` to authenticate.

Your email is: `+cliui.DefaultStyles.Field.Render(email)+`
Your password is: `+cliui.DefaultStyles.Field.Render(password)+`
`+authenticationMethod+`

Create a workspace `+cliui.DefaultStyles.Code.Render("coder create")+`!`)
return nil
Expand All @@ -103,6 +110,12 @@ Create a workspace `+cliui.DefaultStyles.Code.Render("coder create")+`!`)
Description: "Specifies a password for the new user.",
Value: clibase.StringOf(&password),
},
{
Flag: "disable-login",
Description: "Disabling login for a user prevents the user from authenticating themselves via a login. Authentication would require an api keys/token. " +
"Be careful when using this flag as it can lock the user out of their account.",
Value: clibase.BoolOf(&disableLogin),
},
}
return cmd
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- It's not possible to drop enum values from enum types, so the UP has "IF NOT
-- EXISTS".
3 changes: 3 additions & 0 deletions coderd/database/migrations/000126_login_type_none.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TYPE login_type ADD VALUE IF NOT EXISTS 'none';

COMMENT ON TYPE login_type IS 'Specifies the method of authentication. "none" is a special case in which no authentication method is allowed.';
2 changes: 1 addition & 1 deletion codersdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type CreateFirstUserResponse struct {
type CreateUserRequest struct {
Email string `json:"email" validate:"required,email" format:"email"`
Username string `json:"username" validate:"required,username"`
Password string `json:"password" validate:"required"`
Password string `json:"password" validate:"required_if=DisableLogin false"`
// DisableLogin sets the user's login type to 'none'. This prevents the user
// from being able to use a password or any other authentication method to login.
DisableLogin bool `json:"disable_login"`
Expand Down
1 change: 1 addition & 0 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export interface CreateUserRequest {
readonly email: string
readonly username: string
readonly password: string
readonly disable_login: boolean
readonly organization_id: string
}

Expand Down
1 change: 1 addition & 0 deletions site/src/components/CreateUserForm/CreateUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const CreateUserForm: FC<
password: "",
username: "",
organization_id: myOrgId,
disable_login: false,
},
validationSchema,
onSubmit,
Expand Down
0