# Buggy code
def spec_check(self, auth_list, fun, form):
    """
    Check special API permissions
    """
    if form != "cloud":
        comps = fun.split(".")
        if len(comps) != 2:
            return False
        mod = comps[0]
        fun = comps[1]
    else:
        mod = fun
    for ind in auth_list:
        if isinstance(ind, six.string_types):
            if ind.startswith("@") and ind[1:] == mod:
                return True
            if ind == "@{0}".format(form):
                return True
            if ind == "@{0}s".format(form):
                return True
        elif isinstance(ind, dict):
            if len(ind) != 1:
                continue
            valid = next(six.iterkeys(ind))
            if valid.startswith("@") and valid[1:] == mod:
                if isinstance(ind[valid], six.string_types):
                    if self.match_check(ind[valid], fun):
                        return True
                elif isinstance(ind[valid], list):
                    for regex in ind[valid]:
                        if self.match_check(regex, fun):
                            return True
    return False


# Traceback (KeyError)
[root@issue1699 ~]# salt-master -l debug
[DEBUG   ] Reading configuration from /etc/salt/master
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: issue1699
[DEBUG   ] Configuration file path: /etc/salt/master
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[INFO    ] Setting up the Salt Master
[DEBUG   ] Loaded master key: /etc/salt/pki/master/master.pem
[PROFILE ] Beginning pwd.getpwall() call in masterarpi access_keys function
[PROFILE ] End pwd.getpwall() call in masterarpi access_keys function
[INFO    ] Preparing the root key for local communication
[DEBUG   ] Removing stale keyfile: /var/cache/salt/master/.root_key
[INFO    ] Preparing the (user1|user2) key for local communication
[DEBUG   ] Removing stale keyfile: /var/cache/salt/master/.(user1|user2)_key
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
KeyError: 'getpwnam(): name not found: (user1|user2)'
Traceback (most recent call last):
File "/usr/bin/salt-master", line 22, in <module>
salt_master()
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 92, in salt_master
master.start()
File "/usr/lib/python2.7/site-packages/salt/cli/daemons.py", line 204, in start
super(Master, self).start()
File "/usr/lib/python2.7/site-packages/salt/utils/parsers.py", line 1032, in start
self.prepare()
File "/usr/lib/python2.7/site-packages/salt/cli/daemons.py", line 185, in prepare
self.master = salt.master.Master(self.config)
File "/usr/lib/python2.7/site-packages/salt/master.py", line 395, in __init__
SMaster.__init__(self, opts)
File "/usr/lib/python2.7/site-packages/salt/master.py", line 120, in __init__
self.key = self.__prep_key()
File "/usr/lib/python2.7/site-packages/salt/master.py", line 144, in __prep_key
return salt.daemons.masterapi.access_keys(self.opts)
File "/usr/lib/python2.7/site-packages/salt/daemons/masterapi.py", line 265, in access_keys
keys[user] = mk_key(opts, user)
File "/usr/lib/python2.7/site-packages/salt/daemons/masterapi.py", line 236, in mk_key
os.chown(keyfile, pwd.getpwnam(user).pw_uid, -1)
KeyError: 'getpwnam(): name not found: (user1|user2)'
Traceback (most recent call last):
File "/usr/bin/salt-master", line 22, in <module>
salt_master()
File "/usr/lib/python2.7/site-packages/salt/scripts.py", line 92, in salt_master
master.start()
File "/usr/lib/python2.7/site-packages/salt/cli/daemons.py", line 204, in start
super(Master, self).start()
File "/usr/lib/python2.7/site-packages/salt/utils/parsers.py", line 1032, in start
self.prepare()
File "/usr/lib/python2.7/site-packages/salt/cli/daemons.py", line 185, in prepare
self.master = salt.master.Master(self.config)
File "/usr/lib/python2.7/site-packages/salt/master.py", line 395, in __init__
SMaster.__init__(self, opts)
File "/usr/lib/python2.7/site-packages/salt/master.py", line 120, in __init__
self.key = self.__prep_key()
File "/usr/lib/python2.7/site-packages/salt/master.py", line 144, in __prep_key
return salt.daemons.masterapi.access_keys(self.opts)
File "/usr/lib/python2.7/site-packages/salt/daemons/masterapi.py", line 265, in access_keys
keys[user] = mk_key(opts, user)
File "/usr/lib/python2.7/site-packages/salt/daemons/masterapi.py", line 236, in mk_key
os.chown(keyfile, pwd.getpwnam(user).pw_uid, -1)
KeyError: 'getpwnam(): name not found: (user1|user2)'

# Fixed code
def spec_check(self, auth_list, fun, form):
    """
    Check special API permissions
    """
    if not auth_list:
        return False
    if form != "cloud":
        comps = fun.split(".")
        if len(comps) != 2:
            return False
        mod = comps[0]
        fun = comps[1]
    else:
        mod = fun
    for ind in auth_list:
        if isinstance(ind, six.string_types):
            if ind.startswith("@") and ind[1:] == mod:
                return True
            if ind == "@{0}".format(form):
                return True
            if ind == "@{0}s".format(form):
                return True
        elif isinstance(ind, dict):
            if len(ind) != 1:
                continue
            valid = next(six.iterkeys(ind))
            if valid.startswith("@") and valid[1:] == mod:
                if isinstance(ind[valid], six.string_types):
                    if self.match_check(ind[valid], fun):
                        return True
                elif isinstance(ind[valid], list):
                    for regex in ind[valid]:
                        if self.match_check(regex, fun):
                            return True
    return False