Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added changes required for dex setup for litmus 3.0.0-beta11 #4163

Merged
merged 5 commits into from Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 50 additions & 1 deletion chaoscenter/authentication/api/handlers/rest/dex_auth_handler.go
Expand Up @@ -2,6 +2,7 @@ package rest

import (
"context"
"github.com/google/uuid"
"net/http"
"time"

Expand Down Expand Up @@ -122,6 +123,54 @@ func DexCallback(userService services.ApplicationService) gin.HandlerFunc {
c.JSON(utils.ErrorStatusCodes[utils.ErrServerError], presenter.CreateErrorResponse(utils.ErrServerError))
return
}
c.Redirect(http.StatusPermanentRedirect, "/login?jwtToken="+jwtToken)

var defaultProject string
ownerProjects, err := userService.GetOwnerProjectIDs(c, signedInUser.ID)

if len(ownerProjects) > 0 {
defaultProject = ownerProjects[0].ID
} else {
// Adding user as project owner in project's member list
newMember := &entities.Member{
UserID: signedInUser.ID,
Role: entities.RoleOwner,
Invitation: entities.AcceptedInvitation,
Username: signedInUser.Username,
Name: signedInUser.Name,
Email: signedInUser.Email,
JoinedAt: time.Now().Unix(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please convert it to UnixMilli()

}
var members []*entities.Member
members = append(members, newMember)
state := "active"
newProject := &entities.Project{
ID: uuid.Must(uuid.NewRandom()).String(),
Name: signedInUser.Username + "'s project",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace name with - instead of 's

Members: members,
State: &state,
Audit: entities.Audit{
IsRemoved: false,
CreatedAt: time.Now().Unix(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use UnixMilli instead of Unix in all the places

CreatedBy: entities.UserDetailResponse{
Username: signedInUser.Username,
UserID: signedInUser.ID,
Email: signedInUser.Email,
},
UpdatedAt: time.Now().Unix(),
UpdatedBy: entities.UserDetailResponse{
Username: signedInUser.Username,
UserID: signedInUser.ID,
Email: signedInUser.Email,
},
},
}
err := userService.CreateProject(newProject)
if err != nil {
return
}
defaultProject = newProject.ID
}

c.Redirect(http.StatusPermanentRedirect, "/login?jwtToken="+jwtToken+"&projectID="+defaultProject+"&projectRole="+string(entities.RoleOwner))
}
}
3 changes: 3 additions & 0 deletions chaoscenter/dex-server/Dockerfile
@@ -0,0 +1,3 @@
FROM ghcr.io/dexidp/dex:latest
ENV DEX_FRONTEND_DIR=/srv/dex/web
COPY --chown=root:root web /srv/dex/web
139 changes: 139 additions & 0 deletions chaoscenter/dex-server/dex-deployment.yaml
@@ -0,0 +1,139 @@
# ConfigMap for DexServer
---
apiVersion: v1
kind: ConfigMap
metadata:
name: dex-server-admin-config
namespace: litmus
data:
config.yaml: |
issuer: http://<Your Domain>:32000 # Replace your domain here

storage:
type: kubernetes
config:
inCluster: true

web:
http: 0.0.0.0:5556

staticClients:
- id: LitmusPortalAuthBackend
redirectURIs:
- '/auth/dex/callback'
- 'http://localhost:8080/auth/dex/callback' # Included for local testing purposes
name: 'LitmusPortalAuthBackend'
secret: ZXhhbXBsZS1hcHAtc2VjcmV0

oauth2:
skipApprovalScreen: true

connectors:
- type: google
id: google
name: Google
config:
clientID: # Add your Google Client ID here
clientSecret: # Add your Google Client Secret here
redirectURI: http://<Your Domain>:32000 # Replace your domain here

- type: github
id: github
name: GitHub
config:
clientID: # Add your GitHub Client ID here
clientSecret: # Add your GitHub Client Secret here
redirectURI: http://<Your Domain>:32000/callback # Replace your domain here

---
# ClusterRole for DexServer
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: litmus-dex-server
rules:
- apiGroups: [dex.coreos.com]
resources:
[
authcodes,
authrequests,
connectors,
devicerequests,
connectors,
devicerequests,
devicetokens,
oauth2clients,
offlinesessionses,
passwords,
refreshtokens,
signingkeies,
]
verbs: [delete, deletecollection, get, list, patch, create, update, watch]
---
# ClusterRoleBinding for DexServer
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: litmus-dex-server-crb
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: litmus-dex-server
subjects:
- kind: ServiceAccount
name: litmus-server-account
namespace: litmus
---
# Deployment for DexServer
apiVersion: apps/v1
kind: Deployment
metadata:
name: litmusportal-dex-server
namespace: litmus
labels:
component: litmusportal-dex-server
spec:
replicas: 1
selector:
matchLabels:
component: litmusportal-dex-server
template:
metadata:
labels:
component: litmusportal-dex-server
spec:
serviceAccountName: litmus-server-account
containers:
- name: litmus-dex
imagePullPolicy: IfNotPresent
image: litmuschaos/litmusportal-dex-server:ci
command: ["/usr/local/bin/dex", "serve", "/etc/dex/cfg/config.yaml"]
ports:
- containerPort: 5556
volumeMounts:
- name: config
mountPath: /etc/dex/cfg
volumes:
- name: config
configMap:
name: dex-server-admin-config
items:
- key: config.yaml
path: config.yaml
---
# Exposed service for DexServer
apiVersion: v1
kind: Service
metadata:
name: litmusportal-dex-service
namespace: litmus
spec:
type: NodePort
ports:
- name: dex-server
port: 80
protocol: TCP
targetPort: 5556
nodePort: 32000
selector:
component: litmusportal-dex-server
17 changes: 17 additions & 0 deletions chaoscenter/dex-server/web/static/img/atlassian-crowd-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions chaoscenter/dex-server/web/static/img/bitbucket-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions chaoscenter/dex-server/web/static/img/email-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions chaoscenter/dex-server/web/static/img/github-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions chaoscenter/dex-server/web/static/img/gitlab-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions chaoscenter/dex-server/web/static/img/google-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions chaoscenter/dex-server/web/static/img/keystone-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions chaoscenter/dex-server/web/static/img/ldap-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.