diff --git a/cyclops-ctrl/.env b/cyclops-ctrl/.env index e1310c2f..ae060c7d 100644 --- a/cyclops-ctrl/.env +++ b/cyclops-ctrl/.env @@ -1,3 +1,4 @@ DISABLE_TELEMETRY=true PORT=8888 -CERBOS_URL='localhost:3593' \ No newline at end of file +CERBOS_URL='localhost:3593' +ENABLE_AUTHORIZATION='false' \ No newline at end of file diff --git a/cyclops-ctrl/internal/controller/modules.go b/cyclops-ctrl/internal/controller/modules.go index f00bd26c..69409eb1 100644 --- a/cyclops-ctrl/internal/controller/modules.go +++ b/cyclops-ctrl/internal/controller/modules.go @@ -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) diff --git a/cyclops-ctrl/internal/handler/handler.go b/cyclops-ctrl/internal/handler/handler.go index e2d6b2fd..880dca9c 100644 --- a/cyclops-ctrl/internal/handler/handler.go +++ b/cyclops-ctrl/internal/handler/handler.go @@ -2,6 +2,7 @@ package handler import ( "net/http" + "os" "github.com/gin-gonic/gin" @@ -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) diff --git a/cyclops-ui/.env b/cyclops-ui/.env index cbde1cca..fffc394c 100644 --- a/cyclops-ui/.env +++ b/cyclops-ui/.env @@ -1 +1,2 @@ NODE_ENV=production +REACT_APP_CYCLOPS_AUTH=disable \ No newline at end of file diff --git a/cyclops-ui/env.js b/cyclops-ui/env.js index 04a85aa0..0886fccf 100644 --- a/cyclops-ui/env.js +++ b/cyclops-ui/env.js @@ -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}", }; diff --git a/cyclops-ui/public/env-config.js b/cyclops-ui/public/env-config.js index c50c99da..beb4cc6c 100644 --- a/cyclops-ui/public/env-config.js +++ b/cyclops-ui/public/env-config.js @@ -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", }; diff --git a/cyclops-ui/public/runtime-env.js b/cyclops-ui/public/runtime-env.js index bcf2dd02..f5618ce6 100644 --- a/cyclops-ui/public/runtime-env.js +++ b/cyclops-ui/public/runtime-env.js @@ -1,4 +1,5 @@ window.__RUNTIME_CONFIG__ = { NODE_ENV: "development", REACT_APP_CYCLOPS_CTRL_HOST: "http://localhost:8888", + REACT_APP_CYCLOPS_AUTH: "disable", }; diff --git a/cyclops-ui/src/context/AuthContext.tsx b/cyclops-ui/src/context/AuthContext.tsx index 8fbfc955..8bd5d09e 100644 --- a/cyclops-ui/src/context/AuthContext.tsx +++ b/cyclops-ui/src/context/AuthContext.tsx @@ -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); } }, []);