0

I'm trying to use libcloud (1.3.0) to connect to my GCE project using the following code:

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

USER_ID = "nnnnnnnn@cloudservices.gserviceaccount.com"
KEYFILE = "./xxxxxxx.json"
PROJECT = "project1"

cls = get_driver(Provider.GCE)
driver = cls(USER_ID, KEYFILE, project = PROJECT)

This just fails with an AttributeError inside PyCrypto (I'm running v2.6.1):

Traceback (most recent call last):
  File "g.py", line 9, in <module>
    driver = cls(USER_ID, KEYFILE, project = PROJECT)
  File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 1348, in __init__
    super(GCENodeDriver, self).__init__(user_id, key, **kwargs)
  File "/usr/lib/python2.7/site-packages/libcloud/common/base.py", line 1179, in __init__
    self.connection = self.connectionCls(*args, **conn_kwargs)
  File "/usr/lib/python2.7/site-packages/libcloud/compute/drivers/gce.py", line 98, in __init__
    credential_file=credential_file, **kwargs)
  File "/usr/lib/python2.7/site-packages/libcloud/common/google.py", line 765, in __init__
    user_id, key, auth_type, credential_file, scopes, **kwargs)
  File "/usr/lib/python2.7/site-packages/libcloud/common/google.py", line 660, in __init__
    self.token = self.oauth2_conn.get_new_token()
  File "/usr/lib/python2.7/site-packages/libcloud/common/google.py", line 530, in get_new_token
    signature = base64.urlsafe_b64encode(signer.sign(hash_func))
  File "/usr/lib/python2.7/site-packages/Crypto/Signature/PKCS1_v1_5.py", line 110, in sign
    em = EMSA_PKCS1_V1_5_ENCODE(mhash, k)
  File "/usr/lib/python2.7/site-packages/Crypto/Signature/PKCS1_v1_5.py", line 211, in EMSA_PKCS1_V1_5_ENCODE
    digestAlgo  = DerSequence([hash.oid, DerNull().encode()])
AttributeError: oid

I've followed all the instructions on the libcloud GCE driver page about setting up the service account, downloading the JSON file etc so I think I am doing the right steps but I can't get past this problem.

1 Answers1

0

I've just tested that on Python 2.7.12 with PyCrypto 2.6.1 and don't see any issues on libcloud 1.3.0. Looking at the hasher, I suspect it's an issue with your service account configuration.

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

USER_ID = "559xxxxxx-compute@developer.gserviceaccount.com"
KEYFILE = "./libcloud-test-xxx.json"
PROJECT = "libcloud-test"

cls = get_driver(Provider.GCE)
driver = cls(USER_ID, KEYFILE, project = PROJECT)
print(driver.auth_type)  # should be SA
print(driver.list_nodes())

From API Manager, I went to Credentials, then selected "Create Credentials" - > "Service Account Key". For Service Account I selected "Compute Engine default service account" and the JSON format.

Compute Engine default service account

enter image description here

Within the credential manager the service account looks like this

enter image description here

Hitesh
  • 3,449
  • 8
  • 39
  • 57
anthony shaw
  • 133
  • 11