DEV Community

KILLALLSKYWALKER
KILLALLSKYWALKER

Posted on

May the Auth Be With You: Securing Mage AI

Previously i talk how easier to get start with Mage AI and ready it for prod . By default Mage AI can be access without any authentication . This makes it quick and convenient to get started during development, but it also means that anyone who can access the instance has full control. For production environments, this is not secure. In this article, we go through how to enable and configure user authentication in Mage AI to properly secure your pipelines .

It still easy , what you need to is just ensure your env contain this env variable

REQUIRE_USER_AUTHENTICATION=1
Enter fullscreen mode Exit fullscreen mode

By default the user will be set as

Email    :      admin@admin.com
Password :  admin
Enter fullscreen mode Exit fullscreen mode

You can change the default one by providing this environment

DEFAULT_OWNER_EMAIL
DEFAULT_OWNER_PASSWORD
DEFAULT_OWNER_USERNAME
Enter fullscreen mode Exit fullscreen mode

But here the catch , at the moment there is no official reset password yet for open source version . So it will be little bit tricky when you forgot your owner password where you cannot reset other user password etc .

You can generate new hash and salt using this

import bcrypt


def generate_salt() -> str:
    return bcrypt.gensalt(14)

def create_bcrypt_hash(password: str, salt: str) -> str:
    password_bytes = password.encode()
    password_hash_bytes = bcrypt.hashpw(password_bytes, salt)
    password_hash_str = password_hash_bytes.decode()
    return password_hash_str

password = "MyNewSecret123!"


password_salt=generate_salt()
password_hash=create_bcrypt_hash(password, password_salt)

print(password_salt,password_hash)
Enter fullscreen mode Exit fullscreen mode

Once you get this , you can update the user password but of course it can be update by admin of database only :)

Top comments (0)