Verified Commit 8b8dd45e authored by Marek Veselý's avatar Marek Veselý
Browse files

use PassphraseGenerator, add exerciseId to username

parent c229066d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ def create_exercise(
    create_drive_permissions(teams, definition.files.filter(is_drive=True))

    if exercise.technical:
        create_opensearch_exercise(teams)
        create_opensearch_exercise(teams, exercise.id)

    return exercise

+8 −7
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@ from opensearchpy import OpenSearch
from django.conf import settings
from exercise.models import OpenSearchAccess

from user.lib.passphrase_generator import PassphraseGenerator


def get_opensearch_client():
    host = settings.OPENSEARCH_HOST
@@ -16,7 +18,7 @@ def get_opensearch_client():
    )


def create_opensearch_exercise(teams):
def create_opensearch_exercise(teams, exercise_id):
    """
        For each team:
    `
@@ -36,10 +38,11 @@ def create_opensearch_exercise(teams):
    for team in teams:
        team_id = team.id

        index_name = f"team-{team_id}--index"
        username = f"team-{team_id}"
        # TODO: Generate a strong password for each user (configure opensearch password policy)
        password = f"v&ery6#7st*ong78288732-pass889329word-aVUfg9{team_id}"
        username = f"exercise-{exercise_id}--team-{team_id}"
        index_name = f"{username}--index"
        role_name = f"{username}--role"
        # TODO: ensure that the password will be strong enough to pass the OpenSearch verification
        password = PassphraseGenerator.generate_passphrase()

        opensearch_access_list.append(
            OpenSearchAccess(
@@ -50,8 +53,6 @@ def create_opensearch_exercise(teams):
            )
        )

        role_name = f"team-{team_id}--role"

        try:
            client.indices.create(index=index_name)