Exemple #1
0
    def fill_context(self, request):
        # The request context stores itself in thread-local memory for logging.
        request_context = context.RequestContext(
            request_id=request.environ.get('openstack.request_id'),
            authenticated=False,
            overwrite=True)
        request.environ[context.REQUEST_CONTEXT_ENV] = request_context

        if authorization.AUTH_CONTEXT_ENV in request.environ:
            msg = _LW('Auth context already exists in the request '
                      'environment; it will be used for authorization '
                      'instead of creating a new one.')
            LOG.warning(msg)
            return

        # NOTE(gyee): token takes precedence over SSL client certificates.
        # This will preserve backward compatibility with the existing
        # behavior. Tokenless authorization with X.509 SSL client
        # certificate is effectively disabled if no trusted issuers are
        # provided.

        if request.environ.get(core.CONTEXT_ENV, {}).get('is_admin', False):
            request_context.is_admin = True
            auth_context = {}

        elif CONF.admin_token and request.user_token == CONF.admin_token:
            versionutils.report_deprecated_feature(
                LOG,
                _LW('build_auth_context middleware checking for the admin '
                    'token is deprecated as of the Mitaka release and will be '
                    'removed in the O release. If your deployment requires '
                    'use of the admin token, update keystone-paste.ini so '
                    'that admin_token_auth is before build_auth_context in '
                    'the paste pipelines, otherwise remove the '
                    'admin_token_auth middleware from the paste pipelines.'))

            request_context.is_admin = True
            auth_context = {}

        elif request.token_auth.has_user_token:
            request_context.auth_token = request.user_token
            ref = token_model.KeystoneToken(token_id=request.user_token,
                                            token_data=request.token_info)
            auth_context = authorization.token_to_auth_context(ref)

        elif self._validate_trusted_issuer(request):
            auth_context = self._build_tokenless_auth_context(request)

        else:
            LOG.debug('There is either no auth token in the request or '
                      'the certificate issuer is not trusted. No auth '
                      'context will be set.')
            return

        # set authenticated to flag to keystone that a token has been validated
        request_context.authenticated = True

        # The attributes of request_context are put into the logs. This is a
        # common pattern for all the OpenStack services. In all the other
        # projects these are IDs, so set the attributes to IDs here rather than
        # the name.
        request_context.user_id = auth_context.get('user_id')
        request_context.project_id = auth_context.get('project_id')
        request_context.domain_id = auth_context.get('domain_id')
        request_context.domain_name = auth_context.get('domain_name')
        request_context.user_domain_id = auth_context.get('user_domain_id')
        request_context.roles = auth_context.get('roles')

        project_domain_id = auth_context.get('project_domain_id')
        request_context.project_domain_id = project_domain_id

        is_delegated_auth = auth_context.get('is_delegated_auth', False)
        request_context.is_delegated_auth = is_delegated_auth

        request_context.trust_id = auth_context.get('trust_id')
        request_context.trustor_id = auth_context.get('trustor_id')
        request_context.trustee_id = auth_context.get('trustee_id')

        access_token_id = auth_context.get('access_token_id')
        request_context.oauth_consumer_id = auth_context.get('consumer_id')
        request_context.oauth_acess_token_id = access_token_id

        LOG.debug('RBAC: auth_context: %s', auth_context)
        request.environ[authorization.AUTH_CONTEXT_ENV] = auth_context
Exemple #2
0
    def fill_context(self, request):
        # The request context stores itself in thread-local memory for logging.
        request_context = context.RequestContext(
            request_id=request.environ.get('openstack.request_id'),
            authenticated=False,
            overwrite=True)
        request.environ[context.REQUEST_CONTEXT_ENV] = request_context

        if authorization.AUTH_CONTEXT_ENV in request.environ:
            msg = ('Auth context already exists in the request '
                   'environment; it will be used for authorization '
                   'instead of creating a new one.')
            LOG.warning(msg)
            return

        # NOTE(gyee): token takes precedence over SSL client certificates.
        # This will preserve backward compatibility with the existing
        # behavior. Tokenless authorization with X.509 SSL client
        # certificate is effectively disabled if no trusted issuers are
        # provided.

        if request.environ.get(wsgi.CONTEXT_ENV, {}).get('is_admin', False):
            request_context.is_admin = True
            auth_context = {}

        elif request.token_auth.has_user_token:
            request_context.auth_token = request.user_token
            ref = token_model.KeystoneToken(token_id=request.user_token,
                                            token_data=request.token_info)
            auth_context = authorization.token_to_auth_context(ref)

        elif self._validate_trusted_issuer(request):
            auth_context = self._build_tokenless_auth_context(request)

        else:
            # There is either no auth token in the request or the certificate
            # issuer is not trusted. No auth context will be set. This
            # typically happens on an initial token request.
            return

        # set authenticated to flag to keystone that a token has been validated
        request_context.authenticated = True

        # The attributes of request_context are put into the logs. This is a
        # common pattern for all the OpenStack services. In all the other
        # projects these are IDs, so set the attributes to IDs here rather than
        # the name.
        request_context.user_id = auth_context.get('user_id')
        request_context.project_id = auth_context.get('project_id')
        request_context.domain_id = auth_context.get('domain_id')
        request_context.domain_name = auth_context.get('domain_name')
        request_context.user_domain_id = auth_context.get('user_domain_id')
        request_context.roles = auth_context.get('roles')

        is_admin_project = auth_context.get('is_admin_project', True)
        request_context.is_admin_project = is_admin_project

        project_domain_id = auth_context.get('project_domain_id')
        request_context.project_domain_id = project_domain_id

        is_delegated_auth = auth_context.get('is_delegated_auth', False)
        request_context.is_delegated_auth = is_delegated_auth

        request_context.trust_id = auth_context.get('trust_id')
        request_context.trustor_id = auth_context.get('trustor_id')
        request_context.trustee_id = auth_context.get('trustee_id')

        access_token_id = auth_context.get('access_token_id')
        request_context.oauth_consumer_id = auth_context.get('consumer_id')
        request_context.oauth_acess_token_id = access_token_id

        LOG.debug('RBAC: auth_context: %s', auth_context)
        request.environ[authorization.AUTH_CONTEXT_ENV] = auth_context