Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enabling host certificate #13

Open
wants to merge 3 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ConfigurationSystem/Client/Helpers/RESTConf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def key():
def setup():
return gConfig.getValue( "/DIRAC/Setup" )

def getValue( path ):
return gConfig.getValue( path )

def generateCAFile():
"""
Generate a single CA file with all the PEMs
Expand Down
31 changes: 31 additions & 0 deletions RESTSystem/API/CS/CSHandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from tornado import web, gen
from RESTDIRAC.RESTSystem.Base.RESTHandler import RESTHandler
from RESTDIRAC.ConfigurationSystem.Client.Helpers import RESTConf

class CSHandler( RESTHandler ):

ROUTE = "/config/(Sections|Options|Value)"

@web.asynchronous
def get( self, reqType ):
if reqType == "Sections":
return self.SectionsAction()
elif reqType == "Options":
return self.OptionsAction()
elif reqType == "Value":
return self.ValueAction()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't so much get the code, but IIUC, out of the above, only "ValueAction" is implemented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I need to finish the implementation.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I marked this as a "WIP" (Work In progress) PR, when finished please remove the tag



@gen.engine
def ValueAction( self ):
args = self.request.arguments
try:
path = args[ 'ValuePath' ][0]
except KeyError:
self.send_error( 400 )
return
condDict = {}
if 'allOwners' not in self.request.arguments:
condDict[ 'Owner' ] = self.getUserName()
result = RESTConf.getValue( path )
self.finish( result )
Empty file added RESTSystem/API/CS/__init__.py
Empty file.
15 changes: 13 additions & 2 deletions RESTSystem/API/oa2/TokenHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ def __getGroups( self, DN = False ):
return WErr( 401, "No certificate received to issue a token" )
DN = credDict[ 'subject' ]
if not credDict[ 'validDN' ]:
return WErr( 401, "Unknown DN %s" % DN )
return WErr( 401, "Unknown DN %s" % DN )
result = Registry.getGroupsForDN( DN )
if not result[ 'OK' ]:
return WErr( 500, result[ 'Message' ] )
return WOK( { 'groups' : result[ 'Value' ] } )

def __getHostProperties ( self, group, DN ):
result = Registry.getPropertiesForEntity( group, dn = DN )
if not result:
return WErr( 500, "Can't get the Property for the host" )
return WOK( { 'groups' : result} )


def groupsAction( self ):
result = self.__getGroups()
if not result.ok:
Expand Down Expand Up @@ -140,7 +147,11 @@ def __clientCredentialsRequest( self ):
if not credDict[ 'validDN' ]:
return WErr( 401, "Unknown DN %s" % DN )
#Check group
result = self.__getGroups( DN )
if 'group' in credDict:
if credDict['group'] == 'hosts':
result = self.__getHostProperties( 'hosts', DN )
else:
result = self.__getGroups( DN )
if not result.ok:
return result
groups = result.data[ 'groups' ]
Expand Down
3 changes: 2 additions & 1 deletion RESTSystem/Base/RESTHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ def prepare( self ):
self.send_error( 401 )
else:
data = result[ 'Value' ]
if data[ 'UserGroup' ] == 'TrustedHost':
data[ 'UserGroup' ] = 'hosts'
self.__uData = { 'DN' : data[ 'UserDN' ],
'username' : data[ 'UserName' ],
'group' : data[ 'UserGroup' ],
Expand All @@ -166,7 +168,6 @@ def prepare( self ):
self.log.info( "Setting DISET for %s" % cs )
elif self.REQUIRE_ACCESS:
raise WErr( 401, "No token provided" )

self.end_prepare()


Expand Down
7 changes: 5 additions & 2 deletions RESTSystem/DB/OATokenDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __initializeDB( self ):
'Code' : 'CHAR(28)',
'Secret' : 'CHAR(28)',
'ClientID' : 'CHAR(28)',
'UserName': 'VARCHAR(16) NOT NULL',
'UserName': 'VARCHAR(32) NOT NULL',
'UserDN': 'VARCHAR(128) NOT NULL',
'UserGroup': 'VARCHAR(16) NOT NULL',
'UserSetup': 'VARCHAR(32) NOT NULL',
Expand Down Expand Up @@ -292,7 +292,10 @@ def generateToken( self, userDN, userGroup, userSetup, scope = "", cid = False,
if code:
inData[ 'Code' ] = code

result = Registry.getUsernameForDN( userDN )
if userGroup == 'TrustedHost':
result = Registry.getHostnameForDN( userDN )
else:
result = Registry.getUsernameForDN( userDN )
if not result[ 'OK' ]:
return result
inData[ 'UserName' ] = result[ 'Value' ]
Expand Down
43 changes: 43 additions & 0 deletions RESTSystem/Test/CStest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Test script that ask a token to the REST SERVER using a trusted host certificate.
Gets the job history using the token.
Gets the pilot commands using the token.
"""
import requests
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The content of this file is a bit too "personal". Please add at least some explanations on what it's for.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do it.

import json


# The REST server url
REST_URL = 'https://0.0.0.0:9910'

###########################################
# Get the access token first

# GET request parameters
params = {'grant_type':'client_credentials',
'group':'TrustedHost',
'setup':'LHCb-Certification'}

# The user certificate, password will be asked for to the user
# before request submission
#certificate = ('/home/cinzia/.globus/usercert.pem',
# '/home/cinzia/.globus/userkey.pem')


certificate = ('/home/cinzia/devRoot/etc/grid-security/hostcert.pem','/home/cinzia/devRoot/etc/grid-security/hostkey.pem')
# proxies=('/tmp/x509up_u1000','/tmp/x509up_u1000')
# result = requests.get(REST_URL+"/oauth2/token",params=params,cert=proxies, verify=False)

result = requests.get(REST_URL+"/oauth2/token",params=params,cert=certificate,verify=False)


# the output is returned as a json encoded string, decode it here
resultDict = json.loads( result.text )
access_token = resultDict['token']

JobHistory = requests.get(REST_URL+'/jobs/history',params={'access_token':access_token},
verify=False)

PilotCommands = requests.get(REST_URL+'/config/Value',params={'access_token':access_token,'ValuePath':'/Operations/LHCb-Certification/Pilot/Commands/BOINC'}, verify=False)

########################################