'juju add-cloud' can panic if badly formatted yaml file is specified

Bug #2038265 reported by Alex Lutay
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Triaged
Critical
Unassigned

Bug Description

Hi,

Accidentally noticed on Demo preparation:

ubuntu@data1-bastion:~$ cat ~/config/mycloud.yaml
clouds:
  mycloud:
    type: openstack
    auth-types: userpass
    regions:
      PartnerCloud1:
        endpoint: https://keystone.pc1.canonical.com:5000/v3
ubuntu@data1-bastion:~$ juju add-cloud mycloud -f ~/config/mycloud.yaml
This operation can be applied to both a copy on this client and to the one on a controller.
No current controller was detected and there are no registered controllers on this client: either bootstrap one or register one.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x88 pc=0x939ad3]

goroutine 1 [running]:
github.com/juju/juju/cloud.cloudFromInternal(0xc0000061a0?)
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cloud/clouds.go:579 +0x53
github.com/juju/juju/cloud.ParseCloudMetadata({0xc000a71c00, 0xb7, 0x200})
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cloud/clouds.go:459 +0x4ca
github.com/juju/juju/cmd/juju/cloud.(*CloudFileReader).ReadCloudFromFile(0xc000b9f8e0, {0x7ffe01d0a1ed, 0x20}, 0xc000b9f940?)
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cmd/juju/cloud/add.go:705 +0x71
github.com/juju/juju/cmd/juju/cloud.(*AddCloudCommand).readCloudFromFile(0xc0008fed00, 0xc000351080?)
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cmd/juju/cloud/add.go:434 +0x7d
github.com/juju/juju/cmd/juju/cloud.(*AddCloudCommand).Run(0xc0008fed00, 0xc0006ebc50?)
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cmd/juju/cloud/add.go:298 +0xcc
github.com/juju/juju/cmd/modelcmd.(*baseCommandWrapper).Run(0xc00096dd60, 0x4?)
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cmd/modelcmd/base.go:554 +0xaf
github.com/juju/cmd/v3.(*SuperCommand).Run(0xc00075cc80, 0xc000351080)
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/vendor/github.com/juju/cmd/v3/supercommand.go:534 +0x378
github.com/juju/cmd/v3.Main({0x4edeeb8, 0xc00075cc80}, 0xc000351080, {0xc0005b6440, 0x4, 0x4})
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/vendor/github.com/juju/cmd/v3/cmd.go:419 +0x25d
github.com/juju/juju/cmd/juju/commands.jujuMain.Run({0xc0000d2140?}, {0xc0000720a0, 0x5, 0x5})
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cmd/juju/commands/main.go:202 +0x8a5
github.com/juju/juju/cmd/juju/commands.Main(...)
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cmd/juju/commands/main.go:125
main.main()
 /build/snapcraft-juju-ed1204c3ada7643123d14744176eee1e/parts/juju/build/cmd/juju/main.go:27 +0x72
ubuntu@data1-bastion:~$

ubuntu@data1-bastion:~$ snap list juju
Name Version Rev Tracking Publisher Notes
juju 3.1.6 24626 3.1/candidate canonical✓ -

The test file is attached.

Revision history for this message
Alex Lutay (taurus) wrote :
Revision history for this message
Ian Booth (wallyworld) wrote :

The cloud yaml is not the expected format. "auth-types" is a list, so it should be

clouds:
  mycloud:
    type: openstack
    auth-types: [userpass]
    regions:
      PartnerCloud1:
        endpoint: https://keystone.pc1.canonical.com:5000/v3

I tried with the incorrect YAML and got an error, not a panic

$ juju add-cloud -f c.yaml
This operation can be applied to both a copy on this client and to the one on a controller.
No current controller was detected and there are no registered controllers on this client: either bootstrap one or register one.
ERROR Invalid cloud metadata map[clouds:map[mycloud:map[auth-types:userpass regions:map[PartnerCloud1:map[endpoint:https://keystone.pc1.canonical.com:5000/v3]] type:openstack]]]

I notice the attached YAML is messed up

clouds:
  mycloud:
  type: openstack
    auth-types: userpass
    regions:
      PartnerCloud1:
        endpoint: https://keystone.pc1.canonical.com:5000/v3

Using this does produce the panic. The panic does need to be fixed for this case.

Changed in juju:
milestone: none → 3.1.7
importance: Undecided → Critical
status: New → Triaged
summary: - 'juju add-cloud' crashes if yaml file is specified
+ 'juju add-cloud' can panic if badly formatted yaml file is specified
Harry Pidcock (hpidcock)
Changed in juju:
milestone: 3.1.7 → 2.9.46
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.