Optionally disable password authentication for Linux builds

This commit is contained in:
Paul Meyer 2020-07-16 19:44:01 +00:00
parent 93d4d63121
commit 5fd68374fe
5 changed files with 15 additions and 10 deletions

View File

@ -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
}

View File

@ -126,10 +126,10 @@
]
},
"osProfile": {
"adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[parameters('vmName')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{

View File

@ -87,10 +87,10 @@
]
},
"osProfile": {
"adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[parameters('vmName')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{

View File

@ -132,10 +132,10 @@
]
},
"osProfile": {
"adminPassword": "[parameters('adminPassword')]",
"adminUsername": "[parameters('adminUsername')]",
"computerName": "[parameters('vmName')]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{

View File

@ -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)
}