keystone federation

keystone federation的难处在于配置,这里主要记录下IDP与SP在K-K模式下的配置,主要以shibboleth为例。 
 

IDP:

=====

Note: This feature requires installation of the xmlsec1 tool via your distribution packaging system (for instance apt or yum)Example for apt:$ apt-get install xmlsec1

keystone.conf

===========

[saml]

...

需要配置的选项:

certfile = /etc/keystone/ssl/certs/ca.pem

keyfile = /etc/keystone/ssl/private/cakey.pem

idp_entity_id = https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/idp

idp_sso_endpoint = https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/sso

idp_organization_name = Intel

idp_organization_url = http://www.intel.com

idp_contact_company = Intel

idp_contact_name = davechen

idp_contact_surname = chen

idp_contact_email = [email protected]

idp_contact_telephone = 555-55-5555

idp_contact_type = technical

idp_metadata_path = /etc/keystone/saml2_idp_metadata.xml

Generate Metadata

===============

用于与SP进行交换以建立IDP与SP之间的信任关系。

$ keystone-manage saml_idp_metadata > /etc/keystone/saml2_idp_metadata.xml

$ cat /etc/keystone/saml2_idp_metadata.xml

<?xml version='1.0' encoding='UTF-8'?>
<ns0:EntityDescriptor xmlns:ns0="urn:oasis:names:tc:SAML:2.0:metadata" xmlns:ns1="http://www.w3.org/2000/09/xmldsig#" entityID="https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/idp"><ns0:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"><ns0:KeyDescriptor use="signing"><ns1:KeyInfo><ns1:X509Data><ns1:X509Certificate>MIIDgTCCAmmgAwIBAgIJANl0Hwqcej8tMA0GCSqGSIb3DQEBCwUAMFcxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIDAVVbnNldDEOMAwGA1UEBwwFVW5zZXQxDjAMBgNVBAoMBVVuc2V0MRgwFgYDVQQDDA93d3cuZXhhbXBsZS5jb20wHhcNMTYwNjI3MDYyNTQ5WhcNMjYwNjI1MDYyNTQ5WjBXMQswCQYDVQQGEwJVUzEOMAwGA1UECAwFVW5zZXQxDjAMBgNVBAcMBVVuc2V0MQ4wDAYDVQQKDAVVbnNldDEYMBYGA1UEAwwPd3d3LmV4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuZcup+BCt6J17qZB1GuZ4Ktd54LfvVSfxu6R0HIqdFl++1OE/xvXctw/cTO8WN2wFOD4U84EJsvLq8XPZzhMLiNiGhAfpPaP6tHcbCWHYQlsdFIi9TutoFwcmhMSBktFH+UfRdMuHxoU4IK7QJOazathDPNNtpzXGZm7z9vWxLx907NDWXwtrumSz+adklpmkoddQh2s8luRSRer5HKX6uS8YGUekPqKDsMWC2XLQ7VnQv8RRF9QL3/AKxbAUF232khynNuw5vHQRf/cnh6pXDlU83EdadeEI3qkhkNXcvUrOCFN9/miJrk2t7SyqduxoaUThFiq4NL+UgKSirY7TwIDAQABo1AwTjAMBgNVHRMEBTADAQH/MB0GA1UdDgQWBBTCzPqmyZ+DR3D7OykFvuCWi4q5RzAfBgNVHSMEGDAWgBTCzPqmyZ+DR3D7OykFvuCWi4q5RzANBgkqhkiG9w0BAQsFAAOCAQEALI5wyYx6hHxU0HZ/h9/J3Jw+9xCafGrjGHFhrPCi/eQ7aXSKNCzFK3nEnbAtrP7sKuXHpnjds+1JdDIpIBwmuvkYe6ZMfP0TI2jbxAfpHUI2zzWYVccYhHQI1afMwZ1NB5aIjUrIpDhBvp8soZgcXgZGkYNLXh/CDrsm4/DhsidUi6v9KUmr+z0lD3wcqunjqpDxoZYZw0QzMyiVYgak6XhUfeJ2jeJPu64LsJ3GgfMQZGIbMAPS/+52PjIPSdkPz70PHL8MtqLY4Avl3+JLLBB0quCjyeO+8qnuEpSy1my9cpNMVU4bgNFlibi41OX/kk5F5QvAbxU4mWAGUgHihg==</ns1:X509Certificate></ns1:X509Data></ns1:KeyInfo></ns0:KeyDescriptor><ns0:Organization><ns0:OrganizationName xml:lang="en">Intel</ns0:OrganizationName><ns0:OrganizationDisplayName xml:lang="en">OpenStack SAML Identity Provider</ns0:OrganizationDisplayName><ns0:OrganizationURL xml:lang="en">http://www.intel.com</ns0:OrganizationURL></ns0:Organization><ns0:ContactPerson contactType="technical"><ns0:Company>Intel</ns0:Company><ns0:GivenName>davechen</ns0:GivenName><ns0:SurName>chen</ns0:SurName><ns0:EmailAddress>[email protected]</ns0:EmailAddress><ns0:TelephoneNumber>555-55-5555</ns0:TelephoneNumber></ns0:ContactPerson><ns0:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</ns0:NameIDFormat><ns0:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:URI" Location="https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/sso" /></ns0:IDPSSODescriptor></ns0:EntityDescriptor>


DB (Create a Service Provider (SP))

============================

The sp_url will be used when creating a SAML assertion for BETA and signed by the current keystone IdP. The auth_url is used to retrieve the token for BETA once the SAML assertion is sent. Although the enabled field is optional we are passing it set to true otherwise it will be set to false by default.

创建Service Provider

---------------------------

curl -s -X PUT -H "X-Auth-Token: 8d4bdadd037d4476a5b3afaa80ed4a2d" -H "Content-Type: application/json" -d '{"service_provider": {"auth_url": "http://10.239.48.152:5000/v3/OS-FEDERATION/identity_providers/beta/protocols/saml2/auth", "sp_url": "https://10.239.48.152:5000/Shibboleth.sso/SAML2/ECP", "enabled": true}}' http://10.239.159.68:5000/v3/OS-FEDERATION/service_providers/keystone-sp


auth_url指向SP, SP会对发过来的saml assertion进行验证,验证通过后会返回一个token,调用auth_url时通过对SP URL的访问进行重定向来完成的。

mysql> select * from service_provider;
+------------------------------------------------------------------------------------------------+-------------+---------+-------------+----------------------------------------------+--------------------+
| auth_url                                                                                       | id          | enabled | description | sp_url                                       | relay_state_prefix |
+------------------------------------------------------------------------------------------------+-------------+---------+-------------+----------------------------------------------+--------------------+
| http://10.239.48.36:5000/v3/OS-FEDERATION/identity_providers/keystone-idp/protocols/saml2/auth | keystone-sp |       1 | NULL        | http://10.239.48.36/Shibboleth.sso/SAML2/ECP | ss:mem:            |
+------------------------------------------------------------------------------------------------+-------------+---------+-------------+----------------------------------------------+--------------------+

1 row in set (0.00 sec)




Test:


Get SAML assertion

--------------------------

 curl -i -X POST -H "Content-Type:application/json" -d '{"auth": {"scope":{"service_provider": {"id": "keystone-sp"}},"identity": {"token": {"id":"8d4bdadd037d4476a5b3afaa80ed4a2d"}, "methods":["token"]}}}' http://10.239.159.68:5000/v3/auth/OS-FEDERATION/saml2/ecp



SP:

=====



keystone.conf

===========

[auth]


#
# From keystone
#


# Allowed authentication methods. (list value)
methods = external,password,token,oauth1,saml2





Setup Shibboleth

=============

/etc/shibboleth/shibboleth2.xml:


<SPConfig xmlns="urn:mace:shibboleth:2.0:native:sp:config"
    xmlns:conf="urn:mace:shibboleth:2.0:native:sp:config"
    xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
    xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
    xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
    clockSkew="180">


    <!--
    By default, in-memory StorageService, ReplayCache, ArtifactMap, and SessionCache
    are used. See example-shibboleth2.xml for samples of explicitly configuring them.
    -->


    <!--
    To customize behavior for specific resources on Apache, and to link vhosts or
    resources to ApplicationOverride settings below, use web server options/commands.
    See https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPConfigurationElements for help.


    For examples with the RequestMap XML syntax instead, see the example-shibboleth2.xml
    file, and the https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPRequestMapHowTo topic.
    -->


    <!-- The ApplicationDefaults element is where most of Shibboleth's SAML bits are defined. -->
    <ApplicationDefaults entityID="http://10.239.48.36/Shibboleth.sso/SAML2/ECP"> (与IDP数据库中SP的定义sp_url一致 )


        <!--
        Controls session lifetimes, address checks, cookie handling, and the protocol handlers.
        You MUST supply an effectively unique handlerURL value for each of your applications.
        The value defaults to /Shibboleth.sso, and should be a relative path, with the SP computing
        a relative value based on the virtual host. Using handlerSSL="true", the default, will force
        the protocol to be https. You should also set cookieProps to "https" for SSL-only sites.
        Note that while we default checkAddress to "false", this has a negative impact on the
        security of your site. Stealing sessions via cookie theft is much easier with this disabled.
        -->
        <Sessions lifetime="28800" timeout="3600" relayState="ss:mem"
                  checkAddress="false" handlerSSL="false" cookieProps="http">


            <!--
            Configures SSO for a default IdP. To allow for >1 IdP, remove
            entityID property and adjust discoveryURL to point to discovery service.
            (Set discoveryProtocol to "WAYF" for legacy Shibboleth WAYF support.)
            You can also override entityID on /Login query string, or in RequestMap/htaccess.
            -->
            <SSO entityID="https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/idp2" ECP="true"  (这个暂时没用到)
                 discoveryProtocol="SAMLDS" discoveryURL="https://ds.example.org/DS/WAYF">
              SAML2 SAML1
            </SSO>


            <!-- SAML and local-only logout. -->
            <Logout>SAML2 Local</Logout>


            <!-- Extension service that generates "approximate" metadata based on SP configuration. -->
            <Handler type="MetadataGenerator" Location="/Metadata" signing="false"/>


            <!-- Status reporting service. -->
            <Handler type="Status" Location="/Status" acl="127.0.0.1 ::1"/>


            <!-- Session diagnostic service. -->
            <Handler type="Session" Location="/Session" showAttributeValues="false"/>


            <!-- JSON feed of discovery information. -->
            <Handler type="DiscoveryFeed" Location="/DiscoFeed"/>
        </Sessions>


        <!--
        Allows overriding of error template information/filenames. You can
        also add attributes with values that can be plugged into the templates.
        -->
        <Errors supportContact="[email protected]"
            helpLocation="/about.html"
            styleSheet="/shibboleth-sp/main.css"/>


        <!-- Example of remotely supplied batch of signed metadata. -->
        <!--MetadataProvider type="XML" uri="http://10.239.159.68:5000/v3/OS-FEDERATION/saml2/metadata"
              backingFilePath="/etc/shibboleth/saml2_idp_metadata.xml" reloadInterval="7200"-->
        <MetadataProvider type="XML" uri="http://10.239.159.68:5000/v3/OS-FEDERATION/saml2/metadata"  (这个URL可以直接获取到IDP端的SAML文件,不要用backup,否则可能出现问题)
              reloadInterval="7200">
            <!--MetadataFilter type="RequireValidUntil" maxValidityInterval="2419200"/-->
            <!--MetadataFilter type="Signature" certificate="fedsigner.pem"/-->
        </MetadataProvider>


        <!-- Example of locally maintained metadata. -->
        <!--
        <MetadataProvider type="XML" file="partner-metadata.xml"/>
        -->


        <!-- Map to extract attributes from SAML assertions. -->
        <AttributeExtractor type="XML" validate="true" reloadChanges="false" path="attribute-map.xml"/>

        <!-- Use a SAML query if no attributes are supplied during SSO. -->
        <AttributeResolver type="Query" subjectMatch="true"/>


        <!-- Default filtering policy for recognized attributes, lets other data pass. -->
        <AttributeFilter type="XML" validate="true" path="attribute-policy.xml"/>


        <!-- Simple file-based resolver for using a single keypair. -->
        <CredentialResolver type="File" key="sp-key.pem" certificate="sp-cert.pem"/>


        <!--
        The default settings can be overridden by creating ApplicationOverride elements (see
        the https://wiki.shibboleth.net/confluence/display/SHIB2/NativeSPApplicationOverride topic).
        Resource requests are mapped by web server commands, or the RequestMapper, to an
        applicationId setting.


        Example of a second application (for a second vhost) that has a different entityID.
        Resources on the vhost would map to an applicationId of "admin":
        -->
        <!--ApplicationOverride id="keystone-idp" entityID="https://10.239.48.36/shibboleth"-->
        <ApplicationOverride id="keystone-idp" entityID="http://10.239.48.36/Shibboleth.sso/SAML2/ECP"> (这个要与apache中的配置以及数据库中的配置相一致,这份配置中,由于用到的是默认的配置,所以ApplicationOverride id会是default, 而不是keystone-idp)
           <Sessions lifetime="28800" timeout="3600" checkAddress="false"
           relayState="ss:mem" handlerSSL="false">


            <!-- Triggers a login request directly to the TestShib IdP. -->
            <SSO entityID="https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/idp" ECP="true">   (entityID与DB中表idp_remote_idp的remote_id字段保持一致)
            <!--SSO entityID="keystone-idp-remote" ECP="true"-->
                SAML2 SAML1
            </SSO>


            <Logout>SAML2 Local</Logout>
           </Sessions>


           <MetadataProvider type="XML" uri="http://10.239.159.68:5000/v3/OS-FEDERATION/saml2/metadata" (这个URL可以直接获取到IDP端的SAML文件,不要用backup,否则可能出现问题。)
             reloadInterval="180000" />


        </ApplicationOverride>
    </ApplicationDefaults>


    <!-- Policies that determine how to process and authenticate runtime messages. -->
    <SecurityPolicyProvider type="XML" validate="true" path="security-policy.xml"/>
    <!-- Low-level configuration about protocols and bindings available for use. -->
    <ProtocolProvider type="XML" validate="true" reloadChanges="false" path="protocols.xml"/>


</SPConfig>


移除remote user,因为keystone external 认证方法,需要读到这个变量。

sudo sed -r 's/REMOTE_USER="\w*"//' -i /etc/shibboleth/shibboleth2.xml



virtual host配置

===========

Listen 5000
Listen 35357
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %D(us)" keystone_combined


<VirtualHost *:5000>
    ServerName shldeOTCopen005.sh.intel.com
    WSGIDaemonProcess keystone-public processes=5 threads=1 user=dave display-name=%{GROUP}
    WSGIProcessGroup keystone-public
    WSGIScriptAlias / /var/www/keystone/main
    WSGIScriptAliasMatch ^(/v3/OS-FEDERATION/identity_providers/.*?/protocols/.*?/auth)$ /var/www/keystone/main/$1
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    <IfVersion >= 2.4>
      ErrorLogFormat "%{cu}t %M"
    </IfVersion>
    SetEnv Shib-Identity-Provider https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/idp  (keystone需要读到这个数据)
    #SetEnv Shib-Identity-Provider keystone-idp-remote
    ErrorLog /var/log/apache2/keystone.log
    CustomLog /var/log/apache2/keystone_access.log keystone_combined


...

Alias /identity_admin /var/www/keystone/admin
<Location /identity_admin>
    SetHandler wsgi-script
    Options +ExecCGI


    WSGIProcessGroup keystone-admin
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
</Location>


<Location /Shibboleth.sso>
    ProxyPass !
    SetHandler shib
</Location>


<Location ~ "/v3/OS-FEDERATION/identity_providers/.*?/protocols/saml2/auth">  (auth url)
    ShibRequestSetting requireSession 1
    AuthType shibboleth
    #ShibRequestSetting applicationId keystone-idp
    ShibRequestSetting applicationId default  (因为用到的是default设置,这里的idp的ID也是"default")
    #ShibRequireAll On
    #ShibRequireSession On
    ShibExportAssertion Off
    Require valid-user
</Location>


<Location ~ "/v3/auth/OS-FEDERATION/websso/saml2">
  AuthType shibboleth
  Require valid-user
</Location>


<Location ~ "/v3/auth/OS-FEDERATION/identity_providers/keystone-idp/protocols/saml2/websso">
  AuthType shibboleth
  Require valid-user
</Location>



配置‘remote_id_attribute’, 可选,编辑/etc/keystone/keystone.conf,在federation group下加入此配置,例如:

remote_id_attribute = Shib-Identity-Provider


DB

========


通过CURL或者OpenStack CLI创建IDP (略),mapping, protocols。


NOTE: 创建IDP需要指定remote ID,或者后期进行更新:

openstack identity provider set keystone-idp --remote-idhttps://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/idp.


在后期颁发令牌时,需要对remote ID进行验证。




Create mapping

--------------------

curl -g -i -X PUT http://10.239.48.152:35357/v3/OS-FEDERATION/mappings/map_1-H "Content-Type: application/json" -H "Accept:application/json" -H "X-Auth-Token:36182c0f39bd4121abab6be136ee5335" -d '{"mapping":{"rules": [{"local": [{"user": {"name":"{0}"}, "group": {"id":"44dc305d549f400293ffbe1c4e3c9be2"}}],"remote":[{"type": "openstack_user"}, {"type":"OTC_INTEL_GROUPIDS"}]}]}}'




Create Protocols

-----------------------

curl -g -i -X PUT http://10.239.48.152:35357/v3/OS-FEDERATION/identity_providers/keystone-idp/protocols/saml2-H "Content-Type: application/json" -H "Accept:application/json" -H "X-Auth-Token:f85031562b3645169c980f0a91e35c57" -d '{"protocol":{"mapping_id": "map_1"}}'





mysql> select * from identity_provider;
+--------------+---------+-------------+
| id           | enabled | description |
+--------------+---------+-------------+
| idp_fake     |       1 | NULL        |
| keystone-idp |       1 | NULL        |
+--------------+---------+-------------+
2 rows in set (0.01 sec)





mysql> select * from idp_remote_ids;
+--------------+---------------------------------------------------------------+
| idp_id       | remote_id                                                     |
+--------------+---------------------------------------------------------------+
| keystone-idp | https://openstack-dev.sh.intel.com/v3/OS-FEDERATION/saml2/idp |
+--------------+---------------------------------------------------------------+
1 row in set (0.00 sec)



mysql> select * from federation_protocol;
+---------------+--------------+------------+
| id            | idp_id       | mapping_id |
+---------------+--------------+------------+
| protocol_fake | idp_fake     | map_fake   |
| saml2         | keystone-idp | map_1      |
+---------------+--------------+------------+
2 rows in set (0.00 sec)




mysql> select * from mapping;
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id       | rules                                                                                                                                                                                                     |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| map_1    | "[{\"remote\": [{\"type\": \"openstack_user\"}, {\"type\": \"OTC_INTEL_GROUPIDS\"}], \"local\": [{\"group\": {\"id\": \"f25dbfb31c384a339d7318e361f08bf6\"}, \"user\": {\"name\": \"{0}\"}}]}]"           |
| map_fake | "[{\"remote\": [{\"type\": \"UserName\"}, {\"type\": \"orgPersonType\", \"not_any_of\": [\"Contractor\", \"Guest\"]}], \"local\": [{\"user\": {\"name\": \"{0}\"}}, {\"group\": {\"id\": \"0cd5e9\"}}]}]" |
+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+






测试脚本 (用于得到一个unscoped token)

=================================

import json
import os


from keystoneclient import session as ksc_session
from keystoneclient.auth.identity import v3
from keystoneclient.v3 import client as keystone_v3




class K2KClient(object):
    def __init__(self):
        # os sp id need set manually
        #self.sp_id = os.environ.get('OS_SP_ID')
        self.sp_id = 'keystone-sp'
        self.token_id = os.environ.get('OS_TOKEN')
        self.auth_url = os.environ.get('OS_AUTH_URL')
        self.project_id = os.environ.get('OS_PROJECT_ID')
        self.username = os.environ.get('OS_USERNAME')
        self.password = os.environ.get('OS_PASSWORD')
        #self.domain_id = os.environ.get('OS_DOMAIN_ID')
        self.domain = os.environ.get('OS_DOMAIN')


    def v3_authenticate(self):
        auth = v3.Password(auth_url=self.auth_url,
                           username=self.username,
                           password=self.password,
                           user_domain_id='default',
                           project_id=self.project_id)
        self.session = ksc_session.Session(auth=auth, verify=False)
        self.session.auth.get_auth_ref(self.session)
        self.token = self.session.auth.get_token(self.session)


    def _generate_token_json(self):
        return {
            "auth": {
                "identity": {
                    "methods": [
                        "token"
                    ],
                    "token": {
                        #"id": self.token
                        "id": "6b627c39ba05469c9e3a8d52d732709d"
                    }
                },
                "scope": {
                    "service_provider": {
                        "id": self.sp_id
                    }
                }
            }
        }


    def _check_response(self, response):
        if not response.ok:
            raise Exception("Something went wrong, %s" % response.__dict__)


    def get_saml2_ecp_assertion(self):
        token = json.dumps(self._generate_token_json())
        url = self.auth_url + '/auth/OS-FEDERATION/saml2/ecp'
        print "url is: %s"  % url
        print "token is: %s" % token
        r = self.session.post(url=url, data=token, verify=False)
        self._check_response(r)
        #import pdb
        #pdb.set_trace()
        self.assertion = str(r.text)


    def _get_sp(self):
        url = self.auth_url + '/OS-FEDERATION/service_providers/' + self.sp_id
        r = self.session.get(url=url, verify=False)
        self._check_response(r)
        sp = json.loads(r.text)[u'service_provider']
        return sp


    def _handle_http_302_ecp_redirect(self, session, response, location, method, **kwargs):
        #return session.get(location, authenticated=False, data=self.assertion, **kwargs)
        return session.get(location, authenticated=False, **kwargs)
        #location = response.headers['location']
        #print "header is... %s" % location
        #location = response.headers['location']
        #return session.request(location, method, authenticated=False,
        #                       **kwargs)


    def exchange_assertion(self):
        """Send assertion to a Keystone SP and get token."""
        sp = self._get_sp()


        print "#################sp url is: %s" % sp[u'sp_url']
        print "type is... %s" % type(self.assertion)
        print "we need to stop here..."
        response = self.session.post(
            sp[u'sp_url'],
            headers={'Content-Type': 'application/vnd.paos+xml'},
            data=self.assertion,
            authenticated=False,
            redirect=False)
        #import pdb
        #pdb.set_trace()
        self._check_response(response)
        #location = response.headers['location']
        #print "header is... %s" % location


        #r = self._handle_http_302_ecp_redirect(r, sp[u'auth_url'],
        #                                       headers={'Content-Type':
        #                                       'application/vnd.paos+xml'})
        r = self._handle_http_302_ecp_redirect(self.session, response, sp[u'auth_url'],
                                               method='GET',
                                               headers={'Content-Type':
                                               'application/vnd.paos+xml'})
        self.fed_token_id = r.headers['X-Subject-Token']
        self.fed_token = r.text




def main():
    client = K2KClient()
    print "step1"
    client.v3_authenticate()
    print "step2"
    client.get_saml2_ecp_assertion()
    print "step3"
    print('ECP wrapped SAML assertion: %s' % client.assertion)
    client.exchange_assertion()
    print('Unscoped token id: %s' % client.fed_token_id)




if __name__ == "__main__":
    main()





Trouble Shooting

-----------------------

1.  Warning message:

InsecurePlatformWarning: A true SSLContext object is not
available. This prevents urllib3 from configuring SSL appropriately and 
may cause certain SSL connections to fail

Solve it by:

pip install'requests[security]'


2. OpenSSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

错误发生在读取shibboleth的metadata的时候。

dave@shldeOTCopen005:~$ sudo wget --no-check-certificate -O metadata https://10.239.48.36/Shibboleth.sso/Metadata


Solve it by:

> su root
> a2dismod ssl
> a2enmod ssl (then it will be okay)



3. 交换SAML assertion的时候,如果遇到其它SSL的问题,可以将请求改为HTTP协议来规避一下。


Solve it by:

Update the SP url to: http://10.239.48.152/Shibboleth.sso/SAML2/ECP



4.  mapping中不能包含一些未知的变量,否则在evaluate SAML assertion的时候,会失败。

例如:

更新mapping为如下形式:

mysql> select * from mapping;
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id    | rules                                                                                                                                                       |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
| map_1 | "[{\"remote\": [{\"type\": \"openstack_user\"}], \"local\": [{\"group\": {\"id\": \"44dc305d549f400293ffbe1c4e3c9be2\"}, \"user\": {\"name\": \"{0}\"}}]}]" |
+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)



5. 找不到remote  ID identifier,这个不配置也可以,但是如果配置,则需要在apache2的配置文件中进行定义。

例如:

[federation]


#
# From keystone
#


# environment. For `mod_shib`, this would be `Shib-Identity-Provider`. For For
# `mod_auth_openidc`, this could be `HTTP_OIDC_ISS`. For `mod_auth_mellon`,
# this could be `MELLON_IDP`. (string value)
#remote_id_attribute = <None>
remote_id_attribute = Shib-Identity-Provider


6. OpenSAML.SecurityPolicyRule.MessageFlow [1]: rejected expired message, timestamp (1435761510), oldest allowed

这些信息是在shibboleth文件中找到的,终端抛出的是Internal Error.

这主要是SP和IDP的时间不一致导致的,可以通过调整时间,或者跟新shibboleth的配置来解决。

例如:修改配置 clockSkew="7200"


Reference:

http://shibboleth.net/pipermail/users/2015-July/022528.html



Shibboleth的日志文件存放位置:

/var/log/shibboleth/shibd.log



参考资料:

【1】http://docs.openstack.org/developer/keystone/configure_federation.html

【2】Useful docs:http://docs.openstack.org/developer/keystone/federation/websso.html

【3】shibboleth configure:http://docs.openstack.org/developer/keystone/federation/shibboleth.html

【4】 IBM 配置参考 https://www.ibm.com/support/knowledgecenter/en/SST55W_4.3.0/liaca/liaca_configuring_keystone-to-keystone_federation.html

猜你喜欢

转载自blog.csdn.net/chenwei8280/article/details/49560963