简体   繁体   中英

Python implementation of SAML2 protocol for app engine on Google cloud platform

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM