salt icon indicating copy to clipboard operation
salt copied to clipboard

PKI external_auth

Open drawsmcgraw opened this issue 13 years ago • 18 comments

What would a PKI external_auth look like? Would you pass it a DN from a user's cert? The email address? What configs would it need?

I'm thinking more of how a PKI login would work for Halite (from https://github.com/saltstack/halite/issues/48) than managing user permissions for issuing the salt command. This would make Halite implementation for large enterprises running their own PKI ecosystem much easier.

drawsmcgraw avatar Oct 12 '13 19:10 drawsmcgraw

What this would look like is that the auth function in the external auth module would PROBABLY accept the user certificate as an argument (passed in as a string). Then the auth system would validate said cert. Is this what you are asking?

thatch45 avatar Oct 15 '13 16:10 thatch45

This is exactly what I'm asking. Thanks. I'll try do to some more digging around when I get the chance to see how, exactly, the auth function would work.

Thanks!

drawsmcgraw avatar Oct 15 '13 17:10 drawsmcgraw

Thanks! I think this would be a great thing to have in eauth!

thatch45 avatar Oct 15 '13 17:10 thatch45

I vaguely remember hearing that Salt is trying to move away from one of the Python crypto libraries. If this is true, which one is it, so I don't create another dependency on it?

drawsmcgraw avatar Oct 16 '13 02:10 drawsmcgraw

M2Crypto is the one we're trying to deprecate. If you need a crypto library, please use PyCrypto. Though in any case it will be an optional dependency.

basepi avatar Oct 16 '13 22:10 basepi

Noted. Thanks!

drawsmcgraw avatar Oct 17 '13 03:10 drawsmcgraw

I have a first cut here.

This version takes in a pem-encoded user cert and a CA cert. Returns True if the CA signed the user cert; False otherwise. The final version would pull the CA cert from a location specified by the master config.

Thoughts? Is this the direction you see this going? I'll work on pulling the CA cert from a specified location next.

drawsmcgraw avatar Oct 22 '13 02:10 drawsmcgraw

I've updated the gist (link) to where the module pulls the CA cert from a file specified in the Master config. I'm currently learning the Salt testing ecosystem so I can give it a proper test.

drawsmcgraw avatar Jan 08 '14 04:01 drawsmcgraw

I'm very interested in this.

jalons avatar Jan 14 '14 22:01 jalons

Have you tested it on the latest version? I can't get it work...

kottenator avatar Jul 02 '15 20:07 kottenator

@kottenator Can you describe how you're testing it and what you're seeing?

drawsmcgraw avatar Jul 03 '15 00:07 drawsmcgraw

I configure pki auth in master config:

external_auth:
  pki:
    ca_file: /path/to/root-ca.pem

Then I try to execute:

salt -a pki --pem="`cat user.crt`" '*' test.ping

It gives an error: no such option: --pem

How can I pass the certificate?

kottenator avatar Jul 03 '15 01:07 kottenator

@kottenator Salt may not be recognizing the 'pki' eauth option. I'm seeing this in the man page:

       -a EAUTH, --auth=EAUTH
              Pass in an external authentication medium to validate against. The credentials will be prompted for. The options are auto, keystone, ldap, pam, and stormpath. Can be used with the -T option.

I'd have to dig into the code to confirm this suspicion though.

drawsmcgraw avatar Jul 03 '15 01:07 drawsmcgraw

Yes, it prompts to enter "pem" if it's not passed. But I want to automate it so prompt is not an option, I guess

kottenator avatar Jul 03 '15 01:07 kottenator

Oh. Well that's interesting. I wonder if something has to be done to the pki_auth module in order to expose those options...

drawsmcgraw avatar Jul 03 '15 01:07 drawsmcgraw

Another problem is: even if I pass the certificate contents into the prompt, it still doesn't work. The pki.auth function doesn't fire at all.

I took a look into salt auth: it considers the first param of the pki.auth as the username and tries to find it in ACL for selected eauth... but it's the CRT contents, not the username, so salt doesn't find such user and thus it doesn't trigger the pki.auth function.

To make it work, it should be def auth(username, pem, **kwargs): (even if you don't do anything with username) and you should specify ACL for the user in master config:

external_auth:
  pki:
    ca_file: /path/to/root-ca.pem
    user:
      - .*

Then you need to run:

salt -a pki --username=user '*' test.ping
pem: CRT CONTENTS

And then it would trigger the pki.auth function. And I still need to get rid of the prompt :)

kottenator avatar Jul 03 '15 02:07 kottenator

Here is my pull-request. I haven't found a better way to make it work with CLI/API other than to use username and password keywords:

  • username is required in any case. Without it pki.auth(...) function will not be triggered at all
  • password is only for CLI usage (we can pass pem to API but not to CLI)

Please, improve it if possible

kottenator avatar Jul 06 '15 21:07 kottenator

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 Nov 28 '17 01:11 stale[bot]