EUDAT-B2STAGE / http-api

RESTful HTTP-API for the B2STAGE service inside the EUDAT project
https://eudat-b2stage.github.io/http-api/
MIT License
7 stars 7 forks source link

Test the GSI auth with the Flask server #1

Closed pdonorio closed 8 years ago

pdonorio commented 8 years ago

Become a different iRODS user via certificate on each HTTP request.

pdonorio commented 8 years ago

To use the environment set in plumbum (just like passing the env to Popen):

https://plumbum.readthedocs.org/en/latest/local_machine.html#guide-local-machine

muccix commented 8 years ago

With plumbum the env varibles can be set in 2 ways:

  1. setting the vatiables to a command with the with_env(self, **envvars) function: ls = local["ls"].with_env(TEST="env_vale")
  2. with the command local.env["TEST"] = "env_vale"
muccix commented 8 years ago

I have tried to use the icommands without setting a "~/.irods/irods_environment.json" file and setting environment variables but I wasn't able to make it work. Also, I haven't find anything about this in the user documentation. @akrause2014 how did you manage to do that in your client.py? I also tried it but it doesn't seem to work without an irods_environment.json. Thanks!

akrause2014 commented 8 years ago

All parameters in irods_environment.json must be translated into upper-case environment variables to provide when running the client. In my example client the environment would be the following:

    local.env['IRODS_USER_NAME'] = 'newuser'
    local.env['IRODS_HOST'] = 'rodserver'
    local.env['IRODS_PORT'] = '1247'
    local.env['IRODS_AUTHENTICATION_SCHEME'] = 'gsi'
    local.env['IRODS_DEFAULT_RESOURCE'] = "demoResc"
    local.env['IRODS_ZONE'] = 'tempZone'

etc.

And the location of the X509 proxy (if it's not created on the fly or located in the standard path):

    local.env['X509_USER_PROXY'] = '/path/to/proxy'

Then you don't need an irods_environment.json file. (Note that my example client wasn't using the correct variable names - I'll need to fix that! - but the ones above work and I've just tested it.)

muccix commented 8 years ago

Thanks @akrause2014 !

So with plumbum we can manage the environment in two ways. Here is the script that I used:

# -*- coding: utf-8 -*-
import os
from plumbum import local

irods_env = os.environ.copy()
irods_env['IRODS_USER_NAME'] = 'guest'
irods_env['IRODS_HOST'] = 'rodserver'
irods_env['IRODS_PORT'] = '1247'
irods_env['IRODS_AUTHENTICATION_SCHEME'] = 'gsi'
irods_env['IRODS_ZONE'] = 'tempZone'
irods_env['IRODS_HOME'] = '/tempZone/home/guest'

ils = local['ils'].with_env(**irods_env)
print(ils())

#----------------

local.env['IRODS_USER_NAME'] = 'guest'
local.env['IRODS_HOST'] = 'rodserver'
local.env['IRODS_PORT'] = '1247'
local.env['IRODS_AUTHENTICATION_SCHEME'] = 'gsi'
local.env['IRODS_ZONE'] = 'tempZone'
local.env['IRODS_HOME'] = '/tempZone/home/guest'

ils = local['ils']
print(ils())
pdonorio commented 8 years ago

ils = local['ils'].with_env(**irods_env)

I prefer this version. Will do this week :smiley:

pdonorio commented 8 years ago

To automatize the creation of users in our tests, i shall make a script that takes the username as parameter and creates the certificates, register into irods, save it in a docker shared folder.

Since the basic error is:

        | The host key could not be found in:
        | 1) env. var. X509_USER_KEY
        | 2) /etc/grid-security/hostkey.pem
        | 3) $GLOBUS_LOCATION/etc/hostkey.pem
        | 4) $HOME/.globus/hostkey.pem

i'd go with X509_USER_KEY env var to specify the certificate on irods client side before launching the command.

pdonorio commented 8 years ago

Closing this with commit b5b46eebd810ae333e95dd34d6663f49debab17e

See this piece of code to check how i pass the certificates to the flask server before any icommand.