Skip to content

Commit 9c16025

Browse files
committed
add linode-authorized-users support
This takes advantage of Linode's SSH Key provisioning by username feature Closes #5
1 parent 6f28a0f commit 9c16025

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ docker-machine create -d linode --linode-token=<linode-token> --linode-root-pass
5252
| --- | --- | --- | ---
5353
| `linode-token` | `LINODE_TOKEN` | None | **required** Linode APIv4 Token (see [here](https://developers.linode.com/api/v4#section/Personal-Access-Token))
5454
| `linode-root-pass` | `LINODE_ROOT_PASSWORD` | *generated* | The Linode Instance `root_pass` (password assigned to the `root` account)
55+
| `linode-authorized-users` | `LINODE_AUTHORIZED_USERS` | None | Linode user accounts (separated by commas) whose Linode SSH keys will be permitted root access to the created node
5556
| `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.
5657
| `linode-region` | `LINODE_REGION` | `us-east` | The Linode Instance `region` (see [here](https://api.linode.com/v4/regions))
5758
| `linode-instance-type` | `LINODE_INSTANCE_TYPE` | `g6-standard-4` | The Linode Instance `type` (see [here](https://api.linode.com/v4/linode/types))

pkg/drivers/linode/linode.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ type Driver struct {
3737
InstanceID int
3838
InstanceLabel string
3939

40-
Region string
41-
InstanceType string
42-
RootPassword string
43-
SSHPort int
44-
InstanceImage string
45-
SwapSize int
40+
Region string
41+
InstanceType string
42+
RootPassword string
43+
AuthorizedUsers string
44+
SSHPort int
45+
InstanceImage string
46+
SwapSize int
4647

4748
StackScriptID int
4849
StackScriptUser string
@@ -151,6 +152,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
151152
Name: "linode-root-pass",
152153
Usage: "Root Password",
153154
},
155+
mcnflag.StringFlag{
156+
EnvVar: "LINODE_AUTHORIZED_USERS",
157+
Name: "linode-authorized-users",
158+
Usage: "Linode user accounts (seperated by commas) whose Linode SSH keys will be permitted root access to the created node",
159+
},
154160
mcnflag.StringFlag{
155161
EnvVar: "LINODE_LABEL",
156162
Name: "linode-label",
@@ -251,6 +257,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
251257
d.APIToken = flags.String("linode-token")
252258
d.Region = flags.String("linode-region")
253259
d.InstanceType = flags.String("linode-instance-type")
260+
d.AuthorizedUsers = flags.String("linode-authorized-users")
254261
d.RootPassword = flags.String("linode-root-pass")
255262
d.SSHPort = flags.Int("linode-ssh-port")
256263
d.SSHUser = flags.String("linode-ssh-user")
@@ -267,10 +274,6 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
267274
return fmt.Errorf("linode driver requires the --linode-token option")
268275
}
269276

270-
if d.RootPassword == "" {
271-
return fmt.Errorf("linode driver requires the --linode-root-pass option")
272-
}
273-
274277
stackScript := flags.String("linode-stackscript")
275278
if stackScript != "" {
276279
sid, err := strconv.Atoi(stackScript)
@@ -380,14 +383,15 @@ func (d *Driver) Create() error {
380383

381384
// Create a linode
382385
createOpts := linodego.InstanceCreateOptions{
383-
Region: d.Region,
384-
Type: d.InstanceType,
385-
Label: d.InstanceLabel,
386-
RootPass: d.RootPassword,
387-
AuthorizedKeys: []string{strings.TrimSpace(publicKey)},
388-
Image: d.InstanceImage,
389-
SwapSize: &d.SwapSize,
390-
PrivateIP: d.CreatePrivateIP,
386+
Region: d.Region,
387+
Type: d.InstanceType,
388+
Label: d.InstanceLabel,
389+
RootPass: d.RootPassword,
390+
AuthorizedUsers: strings.Split(d.AuthorizedUsers, ","),
391+
AuthorizedKeys: []string{strings.TrimSpace(publicKey)},
392+
Image: d.InstanceImage,
393+
SwapSize: &d.SwapSize,
394+
PrivateIP: d.CreatePrivateIP,
391395
}
392396

393397
if d.StackScriptID != 0 {

0 commit comments

Comments
 (0)