salt icon indicating copy to clipboard operation
salt copied to clipboard

Salt-cloud deploy to EC2. 403 error is not managed correctly

Open iplux opened this issue 9 years ago • 2 comments

Description of Issue/Question

When I tried to add an iam role profile to a salt-cloud profile, salt-cloud returns a non relevant error:

[ERROR   ] Error creating myinstance on EC2 when trying to run the initial deployment:
encode() argument 1 must be string, not None
[ERROR   ] There was a profile error: encode() argument 1 must be string, not None

Looking in the debug logs, the real error was in my case a 403 due to missing Passrole role in the AWS user I was using. Salt-cloud should more clearly state the error in this case

Setup

Configure salt-cloud to use a AWS user with EC2 permission, but without the IAM Passrole role. Create a profile like:

myprofile:
  provider: ec2
  image: ami-e68f82fb
  size: t2.nano
  ssh_username: centos
  iam_profile: 'arn:aws:iam::ACCOUNTNUMBER:instance-profile/webservices-role'
  sync_after_install: grains
  block_device_mappings:
    - DeviceName: /dev/sda1
      Ebs.VolumeSize: 10
      Ebs.VolumeType: gp2
  del_all_vol_on_destroy: True
  network_interfaces:
    - DeviceIndex: 0
      SubnetId: subnet-xyz
      SecurityGroupId:
        - sg-xyz

Steps to Reproduce Issue

Execute: salt-cloud -p myprofile myinstance -l debug

The system shows the following debug logs at the end:

[DEBUG ] "GET /?Action=RunInstances&BlockDeviceMapping.0.DeviceName=%2Fdev%2Fsda1&BlockDeviceMapping.0.Ebs.VolumeSize=10&BlockDeviceMapping.0.Ebs.VolumeType =gp2&IamInstanceProfile.Arn=arn%3Aaws%3Aiam%3A%REDACTED%3Ainstance-profile%2Fwebservices-role&ImageId=ami-e68f82fb&InstanceType=t2.nano&KeyName=REDACTED &MaxCount=1&MinCount=1&NetworkInterface.0.DeviceIndex=0&NetworkInterface.0.NetworkInterfaceId=REDACTED&Placement.AvailabilityZone=REDACTED&Version=20 14-10-01 HTTP/1.1" 403 None [DEBUG ] AWS Response Status Code: 403 [ERROR ] Error creating REDACTED on EC2 when trying to run the initial deployment: encode() argument 1 must be string, not None Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/ec2.py", line 1921, in request_instance sigver='4') File "/usr/lib/python2.7/dist-packages/salt/utils/aws.py", line 463, in query result.text.encode(result.encoding) TypeError: encode() argument 1 must be string, not None [ERROR ] There was a profile error: encode() argument 1 must be string, not None Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/salt/cloud/cli.py", line 284, in run self.config.get('names') File "/usr/lib/python2.7/dist-packages/salt/cloud/init.py", line 1458, in run_profile ret[name] = self.create(vm_) File "/usr/lib/python2.7/dist-packages/salt/cloud/init.py", line 1288, in create output = self.cloudsfunc File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/ec2.py", line 2510, in create data, vm_ = request_instance(vm_, location) File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/ec2.py", line 1921, in request_instance sigver='4') File "/usr/lib/python2.7/dist-packages/salt/utils/aws.py", line 463, in query result.text.encode(result.encoding)

Versions Report

Salt Version:
           Salt: 2016.11.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.2.2
       dateutil: 2.6.0
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: 1.4.3
       M2Crypto: 0.21.1
           Mako: 0.9.1
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
         pygit2: Not Installed
         Python: 2.7.6 (default, Oct 26 2016, 20:30:19)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.4.0
           RAET: Not Installed
          smmap: 0.8.2
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 3.13.0-48-generic
         system: Linux
        version: Ubuntu 14.04 trusty

iplux avatar Feb 28 '17 12:02 iplux

This error message should be fixed in 2016.11.3

gtmanfred avatar Mar 01 '17 16:03 gtmanfred

This is a duplicate of https://github.com/saltstack/salt/issues/38287

gtmanfred avatar Mar 01 '17 16:03 gtmanfred