Exemple #1
0
    def kinit(self, principal, password, ccache_name, use_armor=True):
        if use_armor:
            # get anonymous ccache as an armor for FAST to enable OTP auth
            armor_path = os.path.join(paths.IPA_CCACHES,
                                      "armor_{}".format(os.getpid()))

            logger.debug('Obtaining armor in ccache %s', armor_path)

            try:
                kinit_armor(
                    armor_path,
                    pkinit_anchors=[paths.KDC_CERT, paths.KDC_CA_BUNDLE_PEM],
                )
            except RuntimeError as e:
                logger.error("Failed to obtain armor cache")
                # We try to continue w/o armor, 2FA will be impacted
                armor_path = None
        else:
            armor_path = None

        try:
            kinit_password(unicode(principal),
                           password,
                           ccache_name,
                           armor_ccache_name=armor_path,
                           enterprise=True,
                           lifetime=self.api.env.kinit_lifetime)

            if armor_path:
                logger.debug('Cleanup the armor ccache')
                ipautil.run([paths.KDESTROY, '-A', '-c', armor_path],
                            env={'KRB5CCNAME': armor_path},
                            raiseonerr=False)
        except RuntimeError as e:
            if ('kinit: Cannot read password while '
                    'getting initial credentials') in str(e):
                raise PasswordExpired(principal=principal, message=unicode(e))
            elif ('kinit: Client\'s entry in database'
                  ' has expired while getting initial credentials') in str(e):
                raise KrbPrincipalExpired(principal=principal,
                                          message=unicode(e))
            elif ('kinit: Clients credentials have been revoked '
                  'while getting initial credentials') in str(e):
                raise UserLocked(principal=principal, message=unicode(e))
            elif ('kinit: Error constructing AP-REQ armor: '
                  'Matching credential not found') in str(e):
                raise KrbPrincipalWrongFAST(principal=principal)
            raise InvalidSessionPassword(principal=principal,
                                         message=unicode(e))
Exemple #2
0
    def kinit(self, user, realm, password, ccache_name):
        # Format the user as a kerberos principal
        principal = krb5_format_principal_name(user, realm)

        (stdout, stderr,
         returncode) = ipautil.run(['/usr/bin/kinit', principal],
                                   env={'KRB5CCNAME': ccache_name},
                                   stdin=password,
                                   raiseonerr=False)
        self.debug('kinit: principal=%s returncode=%s, stderr="%s"', principal,
                   returncode, stderr)

        if returncode != 0:
            raise InvalidSessionPassword(principal=principal,
                                         message=unicode(stderr))
Exemple #3
0
    def kinit(self, user, realm, password, ccache_name):
        # get http service ccache as an armor for FAST to enable OTP authentication
        armor_principal = str(
            krb5_format_service_principal_name('HTTP', self.api.env.host,
                                               realm))
        keytab = paths.IPA_KEYTAB
        armor_name = "%sA_%s" % (krbccache_prefix, user)
        armor_path = os.path.join(krbccache_dir, armor_name)

        self.debug('Obtaining armor ccache: principal=%s keytab=%s ccache=%s',
                   armor_principal, keytab, armor_path)

        try:
            ipautil.kinit_keytab(armor_principal, paths.IPA_KEYTAB, armor_path)
        except gssapi.exceptions.GSSError as e:
            raise CCacheError(message=unicode(e))

        # Format the user as a kerberos principal
        principal = krb5_format_principal_name(user, realm)

        try:
            ipautil.kinit_password(principal,
                                   password,
                                   ccache_name,
                                   armor_ccache_name=armor_path)

            self.debug('Cleanup the armor ccache')
            ipautil.run([paths.KDESTROY, '-A', '-c', armor_path],
                        env={'KRB5CCNAME': armor_path},
                        raiseonerr=False)
        except RuntimeError as e:
            if ('kinit: Cannot read password while '
                    'getting initial credentials') in str(e):
                raise PasswordExpired(principal=principal, message=unicode(e))
            elif ('kinit: Client\'s entry in database'
                  ' has expired while getting initial credentials') in str(e):
                raise KrbPrincipalExpired(principal=principal,
                                          message=unicode(e))
            elif ('kinit: Clients credentials have been revoked '
                  'while getting initial credentials') in str(e):
                raise UserLocked(principal=principal, message=unicode(e))
            raise InvalidSessionPassword(principal=principal,
                                         message=unicode(e))
Exemple #4
0
    def kinit(self, user, realm, password, ccache_name):
        # get anonymous ccache as an armor for FAST to enable OTP auth
        armor_path = os.path.join(paths.IPA_CCACHES,
                                  "armor_{}".format(os.getpid()))

        self.debug('Obtaining armor in ccache %s', armor_path)

        try:
            kinit_armor(armor_path)
        except RuntimeError as e:
            self.error("Failed to obtain armor cache")
            # We try to continue w/o armor, 2FA will be impacted
            armor_path = None

        # Format the user as a kerberos principal
        principal = krb5_format_principal_name(user, realm)

        try:
            kinit_password(principal,
                           password,
                           ccache_name,
                           armor_ccache_name=armor_path)

            if armor_path:
                self.debug('Cleanup the armor ccache')
                ipautil.run([paths.KDESTROY, '-A', '-c', armor_path],
                            env={'KRB5CCNAME': armor_path},
                            raiseonerr=False)
        except RuntimeError as e:
            if ('kinit: Cannot read password while '
                    'getting initial credentials') in str(e):
                raise PasswordExpired(principal=principal, message=unicode(e))
            elif ('kinit: Client\'s entry in database'
                  ' has expired while getting initial credentials') in str(e):
                raise KrbPrincipalExpired(principal=principal,
                                          message=unicode(e))
            elif ('kinit: Clients credentials have been revoked '
                  'while getting initial credentials') in str(e):
                raise UserLocked(principal=principal, message=unicode(e))
            raise InvalidSessionPassword(principal=principal,
                                         message=unicode(e))