Skip to content

Commit

Permalink
fix: [KDL6-190] remove kdladmin user creation (#1073)
Browse files Browse the repository at this point in the history
Remove creation of user kdladmin with admin role
Remove deprecated environment variables
Remove dev auth middleware
  • Loading branch information
igzjaviergil authored Dec 9, 2024
1 parent 2eef971 commit 970a8ba
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 100 deletions.
2 changes: 0 additions & 2 deletions app/api/.env.dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
USER_TOOLS_VSCODE_RUNTIME_IMG_PULLPOLICY=IfNotPresent
USER_TOOLS_VSCODE_RUNTIME_IMG_REPO=localhost:32000/konstellation/jupyter-flavors-kai-python-tf
USER_TOOLS_VSCODE_RUNTIME_IMG_TAG=latest
KDL_ADMIN_EMAIL=[email protected]
KDL_ADMIN_USERNAME=kdladmin
KDL_ENV=dev
KDL_SERVER_MONGODB_URI=mongodb://admin:123456@localhost:27017/admin
MINIO_ENDPOINT=localhost
Expand Down
2 changes: 0 additions & 2 deletions app/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ golangci-lint run --config ../../.github/.golangci.yml --build-tags=integration,

| Environment variable | Default value | Description |
| ---------------------------- | -------------- | ------------------------------------------- |
| KDL_ADMIN_EMAIL | kdladmin | Admin email for the KDL server |
| KDL_ADMIN_PASSWORD | 123456 | Admin password for the KDL server |
| KDL_SERVER_PORT | 8080 | Port for the KDL API |
| BASE_DOMAIN_NAME | kdl.local | Base domain name for the KDL server |
| TLS_ENABLED | true | Enable TLS for the KDL server |
Expand Down
15 changes: 3 additions & 12 deletions app/api/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ func main() {
logger.Error(err, "Unexpected error creating serviceAccount for users")
}

err = userInteractor.CreateAdminUser(cfg.Admin.Username, cfg.Admin.Email)
if err != nil {
logger.Error(err, "Unexpected error creating admin user")
}

projectDeps := &project.InteractorDeps{
Logger: logger,
Repo: projectRepo,
Expand All @@ -114,14 +109,13 @@ func main() {
capabilitiesInteractor,
)

startHTTPServer(logger, cfg.Port, cfg.StaticFilesPath, cfg.Kubernetes.IsInsideCluster, resolvers, userRepo, userInteractor, projectRepo)
startHTTPServer(logger, cfg.Port, cfg.StaticFilesPath, resolvers, userRepo, userInteractor, projectRepo)
}

func startHTTPServer(
logger logr.Logger,
port,
staticFilesPath string,
insideK8Cluster bool,
resolvers generated.ResolverRoot,
userRepo user.Repository,
userInteractor user.UseCase,
Expand All @@ -135,12 +129,9 @@ func startHTTPServer(

authController := controller.NewAuthController(logger, userRepo, projectRepo)

devEnvironment := !insideK8Cluster
authMiddleware := middleware.GenerateMiddleware(devEnvironment)

http.Handle("/", fs)
http.Handle("/api/playground", authMiddleware(pg, userInteractor))
http.Handle(apiQueryPath, authMiddleware(dataloader.Middleware(userRepo, srv), userInteractor))
http.Handle("/api/playground", middleware.AuthMiddleware(pg, userInteractor))
http.Handle(apiQueryPath, middleware.AuthMiddleware(dataloader.Middleware(userRepo, srv), userInteractor))
http.HandleFunc("/api/auth/project", authController.HandleProjectAuth)

logger.Info("Server running", "port", port)
Expand Down
22 changes: 0 additions & 22 deletions app/api/http/middleware/devAuth.go

This file was deleted.

15 changes: 0 additions & 15 deletions app/api/http/middleware/generate.go

This file was deleted.

4 changes: 0 additions & 4 deletions app/api/infrastructure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ type Config struct {
TLS struct {
Enabled bool `envconfig:"TLS_ENABLED"`
}
Admin struct {
Username string `envconfig:"KDL_ADMIN_USERNAME"`
Email string `envconfig:"KDL_ADMIN_EMAIL"`
}
Storage struct {
Size string `envconfig:"USER_TOOLS_STORAGE_SIZE"`
ClassName string `envconfig:"USER_TOOLS_STORAGE_CLASSNAME"`
Expand Down
26 changes: 0 additions & 26 deletions app/api/usecase/user/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,32 +355,6 @@ func (i *Interactor) SynchronizeServiceAccountsForUsers() error {
return nil
}

// CreateAdminUser creates the KDL admin user if not exists.
func (i *Interactor) CreateAdminUser(username, email string) error {
ctx := context.Background()

_, err := i.repo.GetByUsername(ctx, username)
if err == nil {
i.logger.Info("The admin user already exists", "username", username)
return nil
}

if !errors.Is(err, entity.ErrUserNotFound) {
return err
}

i.logger.Info("Creating the admin user", "username", username)

user, err := i.Create(ctx, email, username, entity.AccessLevelAdmin)
if err != nil {
return err
}

i.logger.Info("Admin user created correctly", "username", user.Username, "userEmail", user.Email, "insertedID", user.ID)

return nil
}

// GetKubeconfig returns user kubeconfig.
func (i *Interactor) GetKubeconfig(ctx context.Context, username string) (string, error) {
running, err := i.k8sClient.IsUserToolPODRunning(ctx, username)
Expand Down
1 change: 0 additions & 1 deletion app/api/usecase/user/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Repository interface {
type UseCase interface {
Create(ctx context.Context, email, sub string, accessLevel entity.AccessLevel) (entity.User, error)
UpdateSub(ctx context.Context, user entity.User, sub string) (entity.User, error)
CreateAdminUser(username, email string) error
UpdateAccessLevel(ctx context.Context, userIDs []string, level entity.AccessLevel) ([]entity.User, error)
FindAll(ctx context.Context) ([]entity.User, error)
GetByEmail(ctx context.Context, email string) (entity.User, error)
Expand Down
14 changes: 0 additions & 14 deletions app/api/usecase/user/mocks_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions hack/scripts/helmfile/values/kdl-local/values.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ image:
pullPolicy: Always

env:
KDL_ADMIN_EMAIL: "[email protected]"
KDL_ADMIN_USERNAME: {{ requiredEnv "KEYCLOAK_ADMIN_USER" | quote }}
KDL_SERVER_MONGODB_URI: "mongodb://kdl:123456@mongodb:27017/kdl?authSource=kdl&authMechanism=SCRAM-SHA-256"
KDL_SERVER_PORT: "8080"
MINIO_ACCESS_KEY: "minio"
Expand Down

0 comments on commit 970a8ba

Please sign in to comment.