Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Apresentando um novo autenticador para o JupyterHub

Apresentando um novo autenticador para o JupyterHub

Palestra dada no 47o meetup da Python Floripa

Leticia Portella

May 23, 2020
Tweet

More Decks by Leticia Portella

Other Decks in Technology

Transcript

  1. JupyterHub HTTP Proxy Hub Authenticator Spawners Database All icons where

    obtain on Flaticon /user/<name> /hub/<url> Admin /hub/admin
  2. JupyterHub HTTP Proxy Hub Authenticator Spawners Database Config.py All icons

    where obtain on Flaticon /user/<name> /hub/<url> Admin /hub/admin
  3. JupyterHub HTTP Proxy Hub Authenticator Spawners Database Config.py All icons

    where obtain on Flaticon /user/<name> /hub/<url> Admin /hub/admin
  4. Criando um Autenticador / USERNAME + SENHA LOGIN HANDLER AUTHORIZED

    CLASSE DO AUTHENTICATOR MÉTODO POST POST MÉTODO AUTHENTICATE UNAUTHORIZED
  5. Criando um Autenticador from jupyterhub.auth import Authenticator from tornado import

    gen class NewAuth(Authenticator): # ... @gen.coroutine def authenticate(self, handler, data): if self.can_login: return data['username'] return
  6. Jupyterhub + Tornado class NewAuth(Authenticator): # ... def get_handlers(self, app):

    native_handlers = [ (r'/signup', SignUpHandler), ] return native_handlers
  7. Jupyterhub + Tornado class SignUpHandler(LocalBase): async def get(self): # …

    html = self.render_template(‘signup.html’) self.finish(html) async def post(self): user_info = { 'username': self.get_body_argument(‘username’) 'pw': self.get_body_argument(‘pw') } # do stuff… html = self.render_template(‘signup.html’, message='succesful') self.finish(html)
  8. Criando uma nova usuária from .orm import UserInfo class NewAuth(Authenticator):

    # ... def add_new_table(self): inspector = inspect(self.db.bind) if 'users_info' not in inspector.get_table_names(): UserInfo.__table__.create(self.db.bind)
  9. Native Authenticator /SIGNUP CRIA NOVO USUÁRIO USUÁRIA ESTÁ DESAUTORIZADO /

    USUÁRIA CONSEGUE ACESSO /AUTHORIZE USUÁRIA É AUTORIZADA ADMIN USUÁRIA USUÁRIA
  10. Native Authenticator Features: Permite troca de senha dos usuários Permite

    adicionar checks de segurança de senhas Pedido de informações extras no signup 2fa
  11. Bloqueando múltiplas tentativas de login • Usuária tenta logar X

    vezes ela é bloqueada • Usuária pode tentar de novo depois de X minutos • Usuária tem a contagem zerada quando tem uma tentativa bem sucedida
  12. class NewAuth(Authenticator): # ... @gen.coroutine def authenticate(self, handler, data): #

    pega username e senha… # se não tiver validado… self.add_login_attempt(username) Bloqueando múltiplas tentativas de login
  13. Bloqueando múltiplas tentativas de login class NewAuth(Authenticator): def add_login_attempt(self, username):

    if not self.login_attempts.get(username): self.login_attempts[username] = { 'count': 1, 'time': datetime.now() } else: self.login_attempts[username]['count'] += 1 self.login_attempts[username]['time'] = datetime.now()
  14. class NewAuth(Authenticator): # ... @gen.coroutine def authenticate(self, handler, data): #

    pega username e senha… # antes de validar… if self.is_blocked(username): return Bloqueando múltiplas tentativas de login
  15. Bloqueando múltiplas tentativas de login class NewAuth(Authenticator): def is_blocked(self, username):

    logins = self.login_attempts.get(username) if not logins or logins['count'] < self.allowed_failed_logins: return False if self.can_try_to_login_again(username): return False return True
  16. Bloqueando múltiplas tentativas de login class NewAuth(Authenticator): def is_blocked(self, username):

    logins = self.login_attempts.get(username) if not logins or logins['count'] < self.allowed_failed_logins: return False if self.can_try_to_login_again(username): return False return True PERSONALIZADA!!!
  17. Bloqueando múltiplas tentativas de login class NewAuth(Authenticator): def can_try_to_login_again(self, username):

    login_attempts = self.login_attempts.get(username) if not login_attempts: return True time_last_attempt = datetime.now() - login_attempts['time'] if time_last_attempt.seconds > self.seconds_before_next_try: return True return False
  18. Bloqueando múltiplas tentativas de login class NewAuth(Authenticator): def can_try_to_login_again(self, username):

    login_attempts = self.login_attempts.get(username) if not login_attempts: return True time_last_attempt = datetime.now() - login_attempts['time'] if time_last_attempt.seconds > self.seconds_before_next_try: return True return False PERSONALIZADA!!!
  19. Adicionando configurações personalizadas class NewAuth(Authenticator): # ... allowed_failed_logins = Integer(

    config=True, default=0, help=("Configures the number of failed attempts a user can have before being blocked.”) )
  20. E como EU fui parar aqui? Crie um perfil no

    outreachy.org Seja aceita na primeira etapa de avaliação :) Selecione um projeto que você preenche os requisitos Resolva uma micro-tarefa do projeto Peça ajuda dos mentores! Submita um pull request
  21. E como EU fui parar aqui? Preencha o formulário final

    Aguarde os resultados Seja parte de um time maravilhoso <3