Optionally disable password authentication for Linux builds
This commit is contained in:
parent
93d4d63121
commit
5fd68374fe
|
@ -43,7 +43,7 @@ func NewTemplateBuilder(template string) (*TemplateBuilder, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (s *TemplateBuilder) BuildLinux(sshAuthorizedKey string) error {
|
||||
func (s *TemplateBuilder) BuildLinux(sshAuthorizedKey string, disablePasswordAuthentication bool) error {
|
||||
resource, err := s.getResourceByType(resourceVirtualMachine)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -61,6 +61,11 @@ func (s *TemplateBuilder) BuildLinux(sshAuthorizedKey string) error {
|
|||
},
|
||||
}
|
||||
|
||||
if disablePasswordAuthentication {
|
||||
profile.LinuxConfiguration.DisablePasswordAuthentication = to.BoolPtr(true)
|
||||
profile.AdminPassword = nil
|
||||
}
|
||||
|
||||
s.osType = compute.Linux
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -126,10 +126,10 @@
|
|||
]
|
||||
},
|
||||
"osProfile": {
|
||||
"adminPassword": "[parameters('adminPassword')]",
|
||||
"adminUsername": "[parameters('adminUsername')]",
|
||||
"computerName": "[parameters('vmName')]",
|
||||
"linuxConfiguration": {
|
||||
"disablePasswordAuthentication": true,
|
||||
"ssh": {
|
||||
"publicKeys": [
|
||||
{
|
||||
|
|
|
@ -87,10 +87,10 @@
|
|||
]
|
||||
},
|
||||
"osProfile": {
|
||||
"adminPassword": "[parameters('adminPassword')]",
|
||||
"adminUsername": "[parameters('adminUsername')]",
|
||||
"computerName": "[parameters('vmName')]",
|
||||
"linuxConfiguration": {
|
||||
"disablePasswordAuthentication": true,
|
||||
"ssh": {
|
||||
"publicKeys": [
|
||||
{
|
||||
|
|
|
@ -132,10 +132,10 @@
|
|||
]
|
||||
},
|
||||
"osProfile": {
|
||||
"adminPassword": "[parameters('adminPassword')]",
|
||||
"adminUsername": "[parameters('adminUsername')]",
|
||||
"computerName": "[parameters('vmName')]",
|
||||
"linuxConfiguration": {
|
||||
"disablePasswordAuthentication": true,
|
||||
"ssh": {
|
||||
"publicKeys": [
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ func TestBuildLinux00(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--")
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--", true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func TestBuildLinux01(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--")
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--", false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ func TestBuildLinux02(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
testSubject.BuildLinux("--test-ssh-authorized-key--")
|
||||
testSubject.BuildLinux("--test-ssh-authorized-key--", true)
|
||||
testSubject.SetImageUrl("http://azure/custom.vhd", compute.Linux, compute.CachingTypesReadWrite)
|
||||
testSubject.SetOSDiskSizeGB(100)
|
||||
|
||||
|
@ -189,7 +189,7 @@ func TestSharedImageGallery00(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--")
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--", false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ func TestNetworkSecurityGroup00(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--")
|
||||
err = testSubject.BuildLinux("--test-ssh-authorized-key--", false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ func TestSetIdentity00(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = testSubject.BuildLinux("--test-ssh-authorized-key--"); err != nil {
|
||||
if err = testSubject.BuildLinux("--test-ssh-authorized-key--", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue