Skip to content

Commit

Permalink
disable authorization feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantprateek committed Jul 15, 2024
1 parent 64a648e commit 0f086be
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cyclops-ctrl/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DISABLE_TELEMETRY=true
PORT=8888
CERBOS_URL='localhost:3593'
CERBOS_URL='localhost:3593'
ENABLE_AUTHORIZATION='false'
3 changes: 3 additions & 0 deletions cyclops-ctrl/internal/controller/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ func getTargetGeneration(generation string, module *v1alpha1.Module) (*v1alpha1.
}

func (m *Modules) checkPermission(ctx *gin.Context, kind, resourceName, action string) bool {
if os.Getenv("ENABLE_AUTHORIZATION") == "false" {
return true
}
resource := cerbosSDK.NewResource(kind, "new").
WithAttr("name", resourceName).
WithAttr("action", action)
Expand Down
5 changes: 4 additions & 1 deletion cyclops-ctrl/internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handler

import (
"net/http"
"os"

"github.com/gin-gonic/gin"

Expand Down Expand Up @@ -59,7 +60,9 @@ func (h *Handler) Start() error {
// authentication
h.router.POST("/login", cerbos.Login(h.cerbosClient))

h.router.Use(cerbos.AuthMiddleware(h.cerbosClient))
if os.Getenv("ENABLE_AUTHORIZATION") == "true" {
h.router.Use(cerbos.AuthMiddleware(h.cerbosClient))
}

// templates
h.router.GET("/templates", templatesController.GetTemplate)
Expand Down
1 change: 1 addition & 0 deletions cyclops-ui/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NODE_ENV=production
REACT_APP_CYCLOPS_AUTH=disable
1 change: 1 addition & 0 deletions cyclops-ui/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
window.__RUNTIME_CONFIG__ = {
NODE_ENV: "${NODE_ENV}",
REACT_APP_CYCLOPS_CTRL_HOST: "${REACT_APP_CYCLOPS_CTRL_HOST}",
REACT_APP_CYCLOPS_AUTH: "${REACT_APP_CYCLOPS_AUTH}",
REACT_APP_VERSION: "${REACT_APP_VERSION}",
};
1 change: 1 addition & 0 deletions cyclops-ui/public/env-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
window.__RUNTIME_CONFIG__ = {
NODE_ENV: "development",
REACT_APP_CYCLOPS_CTRL_HOST: "http://localhost:8888",
REACT_APP_CYCLOPS_AUTH: "disable",
REACT_APP_VERSION: "v0.0.0",
};
1 change: 1 addition & 0 deletions cyclops-ui/public/runtime-env.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
window.__RUNTIME_CONFIG__ = {
NODE_ENV: "development",
REACT_APP_CYCLOPS_CTRL_HOST: "http://localhost:8888",
REACT_APP_CYCLOPS_AUTH: "disable",
};
10 changes: 9 additions & 1 deletion cyclops-ui/src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,16 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({
const [isAuthenticated, setIsAuthenticated] = useState(false);

useEffect(() => {
// If authentication is disable pass the authentication check
if (process.env.REACT_APP_CYCLOPS_AUTH === "disable") {
setIsAuthenticated(true);
}

// Check if the user is authenticated
if (Cookies.get("_isAuthenticated") === "true") {
if (
Cookies.get("_isAuthenticated") === "true" &&
process.env.REACT_APP_CYCLOPS_AUTH === "enable"
) {
setIsAuthenticated(true);
}
}, []);
Expand Down

0 comments on commit 0f086be

Please sign in to comment.