Skip to content

Commit 6f28a0f

Browse files
committed
make linode-root-pass optional, autogenerated
Closes #11
1 parent c10287a commit 6f28a0f

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ docker-machine create -d linode --linode-token=<linode-token> --linode-root-pass
5151
| Argument | Env | Default | Description
5252
| --- | --- | --- | ---
5353
| `linode-token` | `LINODE_TOKEN` | None | **required** Linode APIv4 Token (see [here](https://developers.linode.com/api/v4#section/Personal-Access-Token))
54-
| `linode-root-pass` | `LINODE_ROOT_PASSWORD` | None | **required** The Linode Instance `root_pass` (password assigned to the `root` account)
54+
| `linode-root-pass` | `LINODE_ROOT_PASSWORD` | *generated* | The Linode Instance `root_pass` (password assigned to the `root` account)
5555
| `linode-label` | `LINODE_LABEL` | *generated* | The Linode Instance `label`, unless overridden this will match the docker-machine name. This `label` must be unique on the account.
5656
| `linode-region` | `LINODE_REGION` | `us-east` | The Linode Instance `region` (see [here](https://api.linode.com/v4/regions))
5757
| `linode-instance-type` | `LINODE_INSTANCE_TYPE` | `g6-standard-4` | The Linode Instance `type` (see [here](https://api.linode.com/v4/linode/types))
@@ -68,13 +68,14 @@ docker-machine create -d linode --linode-token=<linode-token> --linode-root-pass
6868
## Notes
6969

7070
* When using the `linode/containerlinux` `linode-image`, the `linode-ssh-user` will default to `core`
71+
* A `linode-root-pass` will be generated if not provided. This password will not be shown. Rely on `docker-machine ssh` or [Linode's Rescue features](https://www.linode.com/docs/quick-answers/linode-platform/reset-the-root-password-on-your-linode/) to access the node directly.
7172

7273
## Debugging
7374

7475
Detailed run output will be emitted when using the LinodeGo `LINODE_DEBUG=1` option along with the `docker-machine` `--debug` option.
7576

7677
```bash
77-
LINODE_DEBUG=1 docker-machine --debug create -d linode --linode-token=$LINODE_TOKEN --linode-root-pass=$ROOT_PASS machinename
78+
LINODE_DEBUG=1 docker-machine --debug create -d linode --linode-token=$LINODE_TOKEN machinename
7879
```
7980

8081
## Examples
@@ -83,9 +84,8 @@ LINODE_DEBUG=1 docker-machine --debug create -d linode --linode-token=$LINODE_T
8384

8485
```bash
8586
LINODE_TOKEN=e332cf8e1a78427f1368a5a0a67946ad1e7c8e28e332cf8e1a78427f1368a5a0 # Should be 65 lowercase hex chars
86-
LINODE_ROOT_PASSWORD=$(openssl rand -base64 32); echo Password for root: $LINODE_ROOT_PASSWORD
8787

88-
docker-machine create -d linode --linode-token=$LINODE_TOKEN --linode-root-pass=$LINODE_ROOT_PASSWORD linode
88+
docker-machine create -d linode --linode-token=$LINODE_TOKEN linode
8989
eval $(docker-machine env linode)
9090
docker run --rm -it debian bash
9191
```

pkg/drivers/linode/linode.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package linode
22

33
import (
44
"context"
5+
"crypto/rand"
6+
"encoding/base64"
57
"encoding/json"
68
"errors"
79
"fmt"
@@ -104,6 +106,16 @@ func (d *Driver) getClient() *linodego.Client {
104106
return d.client
105107
}
106108

109+
func createRandomRootPassword() (string, error) {
110+
rawRootPass := make([]byte, 50)
111+
_, err := rand.Read(rawRootPass)
112+
if err != nil {
113+
return "", fmt.Errorf("Failed to generate random password")
114+
}
115+
rootPass := base64.StdEncoding.EncodeToString(rawRootPass)
116+
return rootPass, nil
117+
}
118+
107119
// DriverName returns the name of the driver
108120
func (d *Driver) DriverName() string {
109121
return "linode"
@@ -297,6 +309,15 @@ func (d *Driver) PreCreateCheck() error {
297309

298310
client := d.getClient()
299311

312+
if d.RootPassword == "" {
313+
log.Info("Generating a secure disposable linode-root-pass...")
314+
var err error
315+
d.RootPassword, err = createRandomRootPassword()
316+
if err != nil {
317+
return err
318+
}
319+
}
320+
300321
if d.StackScriptUser != "" {
301322
/* N.B. username isn't on the list of filterable fields, however
302323
adding it doesn't make anything fail, so if it becomes

0 commit comments

Comments
 (0)