Skip to content

Commit 1849fcc

Browse files
committed
Enable auto-create of firewall rule for SSH (if required).
1 parent c356c43 commit 1849fcc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ You will need:
66

77
* A network domain
88
* A VLAN in that network domain (servers will be attached to this VLAN)
9-
* A firewall rule that permits SSH traffic from your (local) public IPv4 address to the VLAN's IPv4 network
9+
* A firewall rule that permits SSH traffic from your (local) public IPv4 address to the VLAN's IPv4 network
10+
Alternatively, you can use the `--ddcloud-create-ssh-firewall-rule` flag when creating your machine
1011

1112
The driver will allocate a public IP address and NAT rule for each machine that it creates.
1213

@@ -49,6 +50,7 @@ Environment: `DD_COMPUTE_SSH_PORT`
4950
* `ddcloud-ssh-bootstrap-password` - The initial SSH password used to bootstrap SSH key authentication.
5051
This password is removed once the SSH key has been installed
5152
Environment: `DD_COMPUTE_SSH_BOOTSTRAP_PASSWORD`
53+
* `ddcloud-create-ssh-firewall-rule` - Automatically create a firewall rule to enable inbound SSH to the target server?
5254

5355
## Installing the provider
5456

client.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"time"
1010
)
1111

12-
var firewallRuleNameSanitizer = strings.NewReplacer("-", ".", "_", ".")
13-
1412
// Get the CloudControl API client used by the driver.
1513
func (driver *Driver) getCloudControlClient() (client *compute.Client, err error) {
1614
client = driver.client
@@ -461,7 +459,7 @@ func (driver *Driver) createSSHFirewallRule(clientPublicIPAddress string) error
461459
)
462460

463461
ruleConfiguration := compute.FirewallRuleConfiguration{
464-
Name: firewallRuleNameSanitizer.Replace(driver.MachineName),
462+
Name: driver.buildFirewallRuleName("SSH"),
465463
}
466464
ruleConfiguration.Accept()
467465
ruleConfiguration.Enable()
@@ -517,3 +515,13 @@ func (driver *Driver) deleteSSHFirewallRule() error {
517515

518516
return nil
519517
}
518+
519+
// Name sanitiser for firewall rules.
520+
var firewallRuleNameSanitizer = strings.NewReplacer("-", ".", "_", ".")
521+
522+
// Build an acceptable name for a firewall rule.
523+
func (driver *Driver) buildFirewallRuleName(suffix string) string {
524+
return strings.ToLower(
525+
firewallRuleNameSanitizer.Replace(driver.MachineName) + "." + suffix,
526+
)
527+
}

0 commit comments

Comments
 (0)