Skip to content

Commit 0f086be

Browse files
disable authorization feature added
1 parent 64a648e commit 0f086be

File tree

8 files changed

+22
-3
lines changed

8 files changed

+22
-3
lines changed

cyclops-ctrl/.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
DISABLE_TELEMETRY=true
22
PORT=8888
3-
CERBOS_URL='localhost:3593'
3+
CERBOS_URL='localhost:3593'
4+
ENABLE_AUTHORIZATION='false'

cyclops-ctrl/internal/controller/modules.go

+3
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ func getTargetGeneration(generation string, module *v1alpha1.Module) (*v1alpha1.
709709
}
710710

711711
func (m *Modules) checkPermission(ctx *gin.Context, kind, resourceName, action string) bool {
712+
if os.Getenv("ENABLE_AUTHORIZATION") == "false" {
713+
return true
714+
}
712715
resource := cerbosSDK.NewResource(kind, "new").
713716
WithAttr("name", resourceName).
714717
WithAttr("action", action)

cyclops-ctrl/internal/handler/handler.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package handler
22

33
import (
44
"net/http"
5+
"os"
56

67
"github.com/gin-gonic/gin"
78

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

62-
h.router.Use(cerbos.AuthMiddleware(h.cerbosClient))
63+
if os.Getenv("ENABLE_AUTHORIZATION") == "true" {
64+
h.router.Use(cerbos.AuthMiddleware(h.cerbosClient))
65+
}
6366

6467
// templates
6568
h.router.GET("/templates", templatesController.GetTemplate)

cyclops-ui/.env

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
NODE_ENV=production
2+
REACT_APP_CYCLOPS_AUTH=disable

cyclops-ui/env.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
window.__RUNTIME_CONFIG__ = {
33
NODE_ENV: "${NODE_ENV}",
44
REACT_APP_CYCLOPS_CTRL_HOST: "${REACT_APP_CYCLOPS_CTRL_HOST}",
5+
REACT_APP_CYCLOPS_AUTH: "${REACT_APP_CYCLOPS_AUTH}",
56
REACT_APP_VERSION: "${REACT_APP_VERSION}",
67
};

cyclops-ui/public/env-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
window.__RUNTIME_CONFIG__ = {
22
NODE_ENV: "development",
33
REACT_APP_CYCLOPS_CTRL_HOST: "http://localhost:8888",
4+
REACT_APP_CYCLOPS_AUTH: "disable",
45
REACT_APP_VERSION: "v0.0.0",
56
};

cyclops-ui/public/runtime-env.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
window.__RUNTIME_CONFIG__ = {
22
NODE_ENV: "development",
33
REACT_APP_CYCLOPS_CTRL_HOST: "http://localhost:8888",
4+
REACT_APP_CYCLOPS_AUTH: "disable",
45
};

cyclops-ui/src/context/AuthContext.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ export const AuthProvider: React.FC<{ children: ReactNode }> = ({
2222
const [isAuthenticated, setIsAuthenticated] = useState(false);
2323

2424
useEffect(() => {
25+
// If authentication is disable pass the authentication check
26+
if (process.env.REACT_APP_CYCLOPS_AUTH === "disable") {
27+
setIsAuthenticated(true);
28+
}
29+
2530
// Check if the user is authenticated
26-
if (Cookies.get("_isAuthenticated") === "true") {
31+
if (
32+
Cookies.get("_isAuthenticated") === "true" &&
33+
process.env.REACT_APP_CYCLOPS_AUTH === "enable"
34+
) {
2735
setIsAuthenticated(true);
2836
}
2937
}, []);

0 commit comments

Comments
 (0)