Skip to content

Implement #4 - fix password via CLI #5

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 1 commit into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/self-hosted/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ OPTIONS
-v, --version show CLI version
--cert=cert
--cert-key=cert-key
--password=password
--help show CLI help
```

Expand Down
17 changes: 11 additions & 6 deletions packages/server/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Entry extends Command {
version: flags.version({ char: "v" }),
"no-auth": flags.boolean({ default: false }),
"allow-http": flags.boolean({ default: false }),
password: flags.string(),
Copy link
Member

Choose a reason for hiding this comment

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

We could generate the password here and add it as a default. What do you think?

Copy link

Choose a reason for hiding this comment

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

@kylecarbs for non interactive env's a flag should be provided I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kylecarbs Maybe, but in this case, code-server --help will print always a random password as a default value for --password argument, won't it?

Copy link
Member

Choose a reason for hiding this comment

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

Ah thats correct. I agree.


// Dev flags
"bootstrap-fork": flags.string({ hidden: true }),
Expand Down Expand Up @@ -132,13 +133,17 @@ export class Entry extends Command {
}
});

const passwordLength = 12;
const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const chars = [];
for (let i = 0; i < passwordLength; i++) {
chars.push(possible[Math.floor(Math.random() * possible.length)]);
let password = flags["password"];
if (!password) {
// Generate a random password
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated issue but this needs to be changed. The password should generated from a CPRNG.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is only related to adding a static password feature, not changing original password generation method.

Copy link
Contributor

Choose a reason for hiding this comment

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

For those reading this thread, aforementioned issue is located at #26

const passwordLength = 12;
const possible = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const chars = [];
for (let i = 0; i < passwordLength; i++) {
chars.push(possible[Math.floor(Math.random() * possible.length)]);
}
password = chars.join("");
}
const password = chars.join("");

const hasCustomHttps = certData && certKeyData;
const app = await createApp({
Expand Down