diff --git a/UPDATING.md b/UPDATING.md index 88dc78c810d2d..814e2e107dc0c 100644 --- a/UPDATING.md +++ b/UPDATING.md @@ -76,6 +76,24 @@ To delete a user: airflow users --delete --username jondoe ``` +### User model changes +This patch changes the `User.superuser` field from a hardcoded boolean to a `Boolean()` database column. `User.superuser` will default to `False`, which means that this privilege will have to be granted manually to any users that may require it. + +For example, open a Python shell and +```python +from airflow import models, settings + +session = settings.Session() +users = session.query(models.User).all() # [admin, regular_user] + +users[1].superuser # False + +admin = users[0] +admin.superuser = True +session.add(admin) +session.commit() +``` + ## Airflow 1.10.1 ### StatsD Metrics diff --git a/airflow/contrib/auth/backends/password_auth.py b/airflow/contrib/auth/backends/password_auth.py index 55f5daf8fdf76..dcdb1d1225d42 100644 --- a/airflow/contrib/auth/backends/password_auth.py +++ b/airflow/contrib/auth/backends/password_auth.py @@ -95,8 +95,7 @@ def data_profiling(self): return True def is_superuser(self): - """Access all the things""" - return True + return hasattr(self, 'user') and self.user.is_superuser() @login_manager.user_loader diff --git a/airflow/migrations/versions/41f5f12752f8_add_superuser_field.py b/airflow/migrations/versions/41f5f12752f8_add_superuser_field.py new file mode 100644 index 0000000000000..6e02582b7e840 --- /dev/null +++ b/airflow/migrations/versions/41f5f12752f8_add_superuser_field.py @@ -0,0 +1,42 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +"""add superuser field + +Revision ID: 41f5f12752f8 +Revises: 03bc53e68815 +Create Date: 2018-12-04 15:50:04.456875 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '41f5f12752f8' +down_revision = '03bc53e68815' +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column('users', sa.Column('superuser', sa.Boolean(), default=False)) + + +def downgrade(): + op.drop_column('users', 'superuser') diff --git a/airflow/models.py b/airflow/models.py index 1bca27cbc8192..a6d0ebbd73e28 100755 --- a/airflow/models.py +++ b/airflow/models.py @@ -601,7 +601,7 @@ class User(Base): id = Column(Integer, primary_key=True) username = Column(String(ID_LEN), unique=True) email = Column(String(500)) - superuser = False + superuser = Column(Boolean(), default=False) def __repr__(self): return self.username