airflow icon indicating copy to clipboard operation
airflow copied to clipboard

Add Kerberos support

Open garthcn opened this issue 11 years ago • 31 comments

It'd be great if Airflow could add Kerberos support to hooks (e.g. HDFS, etc). The snakebite lib Airflow depends on just added Kerberos support in this PR: https://github.com/spotify/snakebite/pull/153

garthcn avatar Aug 05 '15 18:08 garthcn

I think that an impersonate flag in BaseOperator could be a decent generic way to help around security and attribution of "who is running what", even if Airflow is triggering the job.

The way impersonate would work is that the job on the worker would sudo su {task.owner} prior to running it. This assumes unix based roles and security to be deployed on workers. Of course many systems (take mysql for instance) don't support unix-type authentication.

Impersonate could be forced to True for given operators using the undocumented policy feature described in settings.py

mistercrunch avatar Aug 05 '15 21:08 mistercrunch

Hello @garthcn and @mistercrunch , I would be really interested in having this feature in airflow. Right now the lack of support for kerberos is the main thing that is blocking the adoption of airflow in my project.

I am willing to help in the implementation. Has anybody already started working on it?

txominpelu avatar Aug 10 '15 08:08 txominpelu

Can you describe which part(s) of Airflow you are thinking about integrating with Kerberos? Specific operators? The whole platform!?

mistercrunch avatar Aug 10 '15 18:08 mistercrunch

I'd like to modify some operators (e.g Hive) so that they can be scheduled and run with the right user in a hadoop cluster in secure mode .

txominpelu avatar Aug 11 '15 08:08 txominpelu

#229 is a similar issue. It includes the current workaround I'm using to run workflows as a different user.

pharoson avatar Aug 11 '15 18:08 pharoson

@txominpelu , I'm not sure if you read the impersonation section in here: http://www.cloudera.com/content/cloudera/en/documentation/cdh4/v4-3-0/CDH4-Security-Guide/cdh4sg_topic_9_1.html

You could have a model where the user on their dev box need to provide their kerberos creds, and in production the server has superuser creds and impersonates the owner of the task.

mistercrunch avatar Aug 12 '15 04:08 mistercrunch

I did the work in snakebite. I am also interested in having Kerberos in. And although I need to wrap my mind around how airflow works and how it could be integrated I am Willing to spend some time on it. I would think of something like:

Airflow has its own principal and keytab. This allows it to renew tickets on behalf of users, so it allows users to use their own credentials for "submitting". I'm not sure yet though how the submitting part would work. Or in other words how to make sure scripts executed under the users credentials are secured And someone else cannot impersonate the user. Any ideas?

bolkedebruin avatar Aug 13 '15 19:08 bolkedebruin

Btw having only one super user is not enough in a multi tenant environment. Segregation of duties is required then. Therefore separate users are required

bolkedebruin avatar Aug 13 '15 20:08 bolkedebruin

I was thinking on doing something similar to what hue does in the default setup for cloudera. The hue user is a proxy user that can impersonate others when launching oozie workflows, hive queries, spark jobs, etc. That means that the hue user can do anything (not ideal), but hue users can only schedule and run things by asking hue to impersonate them.

txominpelu avatar Aug 13 '15 22:08 txominpelu

@txominpelu , this should work. The key is users develop using their own credentials locally, and when the code runs on the worker it runs as user airflow that can impersonate the owner of the task.

There needs to be safeguards around source control, and the policy can be inforced with the "policy function" on the worker.

mistercrunch avatar Aug 13 '15 23:08 mistercrunch

@txominpelu actually the hue user is not capable of doing everything except that it is allowed to impersonate other users when the right credential is supplied for that user. Ideally airflow, in a Kerberos context, should never execute under its own principal.

bolkedebruin avatar Aug 14 '15 13:08 bolkedebruin

The question for me is where to start? Basically airflow should not allow unauthenticated users to 1) connect to the webservice (ie present authentication screen) 2) start/schedule jobs of other users. Also how are users going to submit jobs? In the end they cannot copy their code to the server I presume or maybe they can? And what to do with the user administration? Does it need synchronization or externalization?

We can start small of course. First Kerberize the webservice only allow authenticated users, leaving user admin for what it is. Then move on to the command line and jobs and maybe force the user to the one submitting the job?

bolkedebruin avatar Aug 14 '15 17:08 bolkedebruin

One of the first step is for the hook to allow other types of authentication and make the impersonation work. https://github.com/airbnb/airflow/blob/master/airflow/hooks/hive_hooks.py#L329

mistercrunch avatar Aug 14 '15 20:08 mistercrunch

Impersonation is the one of the most complex steps. Ie it requires a service principal, a ticket renewer and verification of the user's credentials.

bolkedebruin avatar Aug 15 '15 10:08 bolkedebruin

Here are a few ideas on things that might work:

  • you could have an extra parameter that would look up credentials from a local file with a specific format, the user would put their creds in a local 600 file
  • add an impersonate flag to the hooks that when it is set to true it changes the behavior of the operator. For BashOperator that might mean adding a sudo su {owner} or chpst somewhere in the bash command
  • use a policy function as defined in settings.py to force the environment on the workers to force impersonate=True when running on the worker and alter the connection to get/use the airflow user and credentials.

mistercrunch avatar Aug 15 '15 14:08 mistercrunch

I'm doing some work in bolkedebruin/airflow kerberos branch. I'm taking the hue approach - ie a key tab file and tickets that are renewed by a separate process (airflow kerberos). This process will be required wherever airflow is running. I haven't thought about it how to implement in with Celery. Sudo I won't touch as this is something else than Kerberos support. To make use of the Kerberos support the different hooks need to updated.

bolkedebruin avatar Aug 19 '15 21:08 bolkedebruin

Hello @bolkedebruin , I've seen you're doing a good job with the ticket generation. If you manage to create a session ticket for the airflow application I think I can have quite easily a hive operator that uses impersonation by leveraging your tickets.

txominpelu avatar Aug 24 '15 11:08 txominpelu

@txominpelu the session tickets is actually already generated. Ie: you should be able to access hive by the credentials that are now available for the "airflow" user (ie the uid under which "airflow kerberos" is running).

Impersonation is something else yet (ie. by delegation tickets (preferred) or proxy)

bolkedebruin avatar Aug 24 '15 12:08 bolkedebruin

I was thinking about using the impersonation mechanism described in the following gist:

https://gist.github.com/txominpelu/65a85524429e9f4e2c25

txominpelu avatar Aug 24 '15 12:08 txominpelu

That is a proxy user and could work. I would say try it

Just to be sure: because airflow currently uses its own user administration you are basically circumventing the whole kerberos authentication. Preferably airflow integrates with LDAP/AD for its users then you get a little bit of security back. In the end delegation tokens are preferred eventually I would say.

bolkedebruin avatar Aug 24 '15 12:08 bolkedebruin