1

I tried pysaml2 and python-saml library on google cloud platform but both are internally using some libraries which are using C extensions or python wrapper on C libraries which is incompatible with app engine as app engine blocks the c implemented libraries in its eco system. Does any one has implemented saml2 protocol in appengine using python?

pysaml2 documentation suggests that its a pure python implementation but it also uses library like pycrytodome or cryptodome which need _ctype library.

Below is the error:

File "/home/***/anaconda2/lib/python2.7/ctypes/_init_.py", line 10, in <module> 
  from _ctypes import Union, Structure, Array  
File "/home/***/sdks/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 963, in load_module 
  raise ImportError('No module named %s' % fullname)
ImportError: No module named _ctypes

Please suggest some other approaches if possible.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
chetan
  • 125
  • 1
  • 12
  • One possibility would be the GAE flexible environment, several of the standard environment sandbox limitations (including the "pure python" one) are lifted in the flex env. – Dan Cornilescu Nov 17 '16 at 15:14
  • Yes you are right flexible environment helps but not only the flexible environment but a custom runtime environment is required where we need to prepare a machine from ubuntu or any linux image instead of from python image and install all the libraries using apt-get . – chetan Nov 28 '16 at 08:52
  • Update please use FROM gcr.io/google_appengine/python-compat-multicore in dockerfile instead of building from ubuntu. – chetan Nov 28 '16 at 16:10
  • You should write an answer to your own question describing a working solution (it sounds like you have one). – Dan Cornilescu Nov 28 '16 at 16:15
  • @DanCornilescu is that possible to run one service in fexible environment and all the others in standard env? Because I have to implement python-saml in my GAE app. – Avinash Raj Mar 23 '17 at 07:30
  • Yes, see http://stackoverflow.com/questions/42469144/custom-runtime-for-non-flexible-environment-app/42469730#42469730 – Dan Cornilescu Mar 23 '17 at 12:53

1 Answers1

0
I figured out what to do if you want to use c libraries in the app engine environment.
First of all you have to use app engine flexible environment instead of standard environment there also use the custom runtime. A sample yaml file is posted below.

app.yaml

runtime: custom  
env: flex  
api_version: 1

handlers:  
- url: /.*  
  script: main.app

The second thing which you need to do is choose a proper base image to build from and install the necessary libraries.

example dockerfile

FROM gcr.io/google_appengine/python-compat-multicore  
RUN apt-get update -y  
RUN apt-get install -y python-pip build-essential libssl-dev libffi-dev python-dev libxml2-dev libxslt1-dev xmlsec1

RUN apt-get install -y curl unzip  
RUN curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz > /tmp/google-cloud-sdk.tar.gz  
RUN mkdir -p /usr/local/gcloud  
RUN tar -C /usr/local/gcloud -xvf /tmp/google-cloud-sdk.tar.gz  
RUN /usr/local/gcloud/google-cloud-sdk/install.sh  

RUN curl https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.40.zip > /tmp/google_appengine_1.9.40.zip  
RUN unzip /tmp/google_appengine_1.9.40.zip -d /usr/local/gae

ENV PATH $PATH:/usr/local/gcloud/google-cloud-sdk/bin  
ENV PATH $PATH:/usr/local/gae/google_appengine/  
COPY . /app  
WORKDIR /app  

ENV MODULE_YAML_PATH app.yaml

RUN pip install -r requirements.txt
chetan
  • 125
  • 1
  • 12