salt icon indicating copy to clipboard operation
salt copied to clipboard

Unable to parse parameters for cmd.run in external_auth

Open jdshewey opened this issue 8 years ago • 8 comments

Description of Issue/Question

I'm not quite sure if this should be a documentation bug, or is an actual bug, but either way,

I am working to restrict users to a few specific commands using pam and external_auth. The actual external_auth is working correctly - I can successfully restrict user access to a specific module:

external_auth:
  pam:
    jshewey:
                 - '*': 
        - cmd.run

results in:

[TRACE ] Compiled auth_list: [{'*': ['cmd.run']}] [DEBUG ] Minion tokenized user = "jshewey" <---- Yahoo! Looks good and I get my results [DEBUG ] LazyLoaded local_cache.prep_jid

However, if I try to lock that down at all with:

external_auth:
  pam:
    jshewey:
      - '*':
        - cmd.run:
         args:
           - '*'

or

external_auth:
  pam:
    jshewey:
      - '*':
        - cmd.run:
         args:
           - '.*'

or

external_auth:
  pam:
    jshewey:
      - '*':
        - cmd.run:
         args:
           - '*'

or

external_auth:
  pam:
    jshewey:
      - '*':
        - cmd.run:
         args:
           - '*'

or

external_auth:
  pam:
    jshewey:
      - '*':
        - cmd.run:
          - cat.*

These all fail with results like:

[TRACE   ] IPCServer: Handling connection to address:
[TRACE   ] Clear payload received with command publish
[TRACE   ] Compiled auth_list: [{'*': [{'cmd.run': ['.*']}]}]
[WARNING ] Authentication failure of type "token" occurred.

or

[TRACE   ] IPCServer: Handling connection to address:
[TRACE   ] Clear payload received with command publish
[TRACE   ] Compiled auth_list: [{'*': [{'cmd.run': ['*']}]}]
[WARNING ] Authentication failure of type "token" occurred.

Versions Report

Salt Version:
           Salt: 2017.7.4

Dependency Versions:
           cffi: 1.6.0
       cherrypy: unknown
       dateutil: 1.5
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: 0.24.6
        libnacl: Not Installed
       M2Crypto: 0.21.1
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.1
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: 3.4.3
         pygit2: 0.24.2
         Python: 2.7.5 (default, Aug  4 2017, 00:39:18)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.4.1708 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-693.2.2.el7.x86_64
         system: Linux
        version: CentOS Linux 7.4.1708 Core

jdshewey avatar May 15 '18 17:05 jdshewey

I think you might be missing another space where args is:

so try to change this:

external_auth:
  pam:
    jshewey:
      - '*':
        - cmd.run:
         args:
           - '*'

to this:

external_auth:
  pam:
    jshewey:
      - '*':
        - cmd.run:
          args:
            - '*'

Ch3LL avatar May 16 '18 12:05 Ch3LL

@Ch3LL, This was just a copy/paste error from when I formatted the YAML for this ticket. If I actually have a missing space, upon trying to run the command, I get errors:

[ERROR   ] Error parsing configuration file: /etc/salt/master.d/f_defaults.conf - while parsing a block mapping
  in "<string>", line 111, column 9:
          - '*':
            ^
expected <block end>, but found '<block mapping start>'
  in "<string>", line 113, column 10:
             args:
             ^
[ERROR   ] Error parsing configuration file: /etc/salt/master.d/f_defaults.conf - while parsing a block mapping
  in "<string>", line 111, column 9:
          - '*':
            ^
expected <block end>, but found '<block mapping start>'
  in "<string>", line 113, column 10:
             args:
             ^
[ERROR   ] Error parsing configuration file: /etc/salt/master.d/f_defaults.conf - while parsing a block mapping
  in "<string>", line 111, column 9:
          - '*':
            ^
expected <block end>, but found '<block mapping start>'
  in "<string>", line 113, column 10:
             args:
             ^
[ERROR   ] Error parsing configuration file: /etc/salt/master.d/f_defaults.conf - while parsing a block mapping
  in "<string>", line 111, column 9:
          - '*':
            ^
expected <block end>, but found '<block mapping start>'
  in "<string>", line 113, column 10:
             args:
             ^

I think it is apparent is is being converted to JSON and therefore linting correctly by the Compiled auth_list line from the log though.

jdshewey avatar May 16 '18 16:05 jdshewey

thanks for verifying that for me. I am able to replicate this using this config in the master config:

external_auth:
  pam:
    saltdev:
      - '*':
        - cmd.run:
             args:
               - '*'

When I run:

[root@9992e49b315f testing]# salt '*' cmd.run 'echo test' -a pam --username=saltdev --password=saltdev        
Failed to authenticate! This is most likely because this user is not permitted to execute commands, but there is a small possibility that a disk error occurred (check disk/inode usage).

I see this in the master log:

2018-05-17 14:19:45,480 [salt.utils.minions                       :728 ][ERROR   ][8668] Invalid regular expression: *

But if i set the configuration like this:

external_auth:
  pam:
    saltdev:
      - '*':
        - cmd.run:
             args:
               - 'echo test'

it works jsut fine:

[root@9992e49b315f testing]# salt '*' cmd.run 'echo test' -a pam --username=saltdev --password=saltdev 
c6c2e89d6b0b:
    test
[root@9992e49b315f testing]# salt '*' cmd.run 'echo issue' -a pam --username=saltdev --password=saltdev 
Failed to authenticate! This is most likely because this user is not permitted to execute commands, but there is a small possibility that a disk error occurred (check disk/inode usage).

or even this works:

external_auth:
  pam:
    saltdev:
      - '*':
        - cmd.run:
             args:
               - 'echo*'

ping @DmitryKuzmenko looks like you added this feature initially. Any ideas here to allo the regex '*' ?

Also here is a docker container to easily replicate this issue:

  1. docker run -it -v ~/git/salt:/testing/ ch3ll/issues:47663 (where ~/git/salt is a local cloned git repo)
  2. salt-master -d; salt-minion -d
  3. salt '*' cmd.run 'echo test' -a pam --username=saltdev --password=saltdev

Ch3LL avatar May 17 '18 14:05 Ch3LL

I'm also hitting above problem.

My configuration:

external_auth:
  pam:
    msciciel:
      - '*':
        - cmd.run:
          args:
            - 'echo test'

And I always get:

Failed to authenticate! This is most likely because this user is not permitted to execute commands, but there is a small possibility that a disk error occurred (check disk/inode usage).

I've added logging of retval inside authenticate function in salt.auth.pam and it always return 0.

Salt Version:
           Salt: 2017.7.6

Dependency Versions:
           cffi: Not Installed
       cherrypy: unknown
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.14 (default, Jan 31 2018, 02:12:13)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.5.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: centos 6.9 Final
         locale: UTF-8
        machine: x86_64
        release: 2.6.32-696.30.1.el6.x86_64
         system: Linux
        version: CentOS 6.9 Final

msciciel avatar Aug 01 '18 10:08 msciciel

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Jan 10 '20 08:01 stale[bot]

Bump

jdshewey avatar Jan 13 '20 18:01 jdshewey

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Jan 13 '20 18:01 stale[bot]

Closing this issue due to age and lack of activity. Please test this on version 3006.2 and create a new issue if the problem persists. The new issue template has more information and will allow us to track and reproduce the issue more effectively. Thanks!

twangboy avatar Sep 06 '23 17:09 twangboy