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

Basic RBAC using the gauth library #243

Merged
merged 18 commits into from
Dec 9, 2024

Conversation

RabbITCybErSeC
Copy link
Collaborator

Closes #107

@RabbITCybErSeC RabbITCybErSeC linked an issue Nov 1, 2024 that may be closed by this pull request
Copy link

github-actions bot commented Nov 1, 2024

Sigrid maintainability feedback

✅ You wrote maintainable code and achieved your Sigrid objective of 3.8 stars

Show details

Sigrid compared your code against the baseline of 2024-12-09.

👍 What went well?

You fixed or improved 0 refactoring candidates.

👎 What could be better?

Unfortunately, 2 refactoring candidates were introduced or got worse.

Risk System property Location
🟠 Unit Size
(Worsened)
internal/controller/controller.go
initializeCore(app *gin.Engine)
🟡 Unit Complexity
(Introduced)
internal/controller/controller.go
initializeCore(app *gin.Engine)

📚 Remaining technical debt

4 refactoring candidates didn't get better or worse, but are still present in the code you touched.

View this system in Sigrid** to explore your technical debt

⭐️ Sigrid ratings

System property System on 2024-12-09 Before changes New/changed code
Volume 5.4 N/A N/A
Duplication 4.4 5.5 5.5
Unit Size 2.6 1.5 1.7
Unit Complexity 2.8 5.5 3.6
Unit Interfacing 2.8 5.5 5.5
Module Coupling 3.8 N/A N/A
Component Independence 0.5 N/A N/A
Component Entanglement 2.6 N/A N/A
Maintainability 3.2 4.5 3.8

Did you find this feedback helpful?

We would like to know your thoughts to make Sigrid better.
Your username will remain confidential throughout the process.


View this system in Sigrid

Comment on lines 186 to 201
err := mainController.setupDatabase()
err = mainController.setupDatabase()
if err != nil {
log.Error(err)
log.Error("Failed to setup database:", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did this change?

Comment on lines 185 to 204
authEnabledStr := utils.GetEnv("AUTH_ENABLED", "false")
authEnabled, err := strconv.ParseBool(authEnabledStr)
if err != nil {
log.Error(err)
return err
}

var auth *gauth.Authenticator
if authEnabled {
auth, err = gauth.New(gauth.DefaultConfig())
if err != nil {
log.Error("Failed to initialize authenticator:", err)
return err
}
routes.Middlewares(app, auth.LoadAuthContext(), auth.Middleware([]string{"admin", "soarca"}))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This must be in it's own function

internal/controller/controller.go Show resolved Hide resolved
@RabbITCybErSeC RabbITCybErSeC force-pushed the feature/107-rbac-gauth branch 2 times, most recently from 113b84d to cdfbb25 Compare December 6, 2024 08:55
Copy link
Collaborator

@MaartendeKruijf MaartendeKruijf left a comment

Choose a reason for hiding this comment

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

Also fix the Sigrid error

.env.example Show resolved Hide resolved
.env.example Outdated

AUTH_ENABLED: false #OPTIONAL for OIDC Based auth
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment is irrelevant

docker-compose.yaml Show resolved Hide resolved
go.mod Show resolved Hide resolved
Comment on lines 190 to 201

authEnabledStr := utils.GetEnv("AUTH_ENABLED", "false")
authEnabled, err := strconv.ParseBool(authEnabledStr)
if err != nil {
log.Error(err)
return err
}
routes.Cors(app, origins)

err := mainController.setupDatabase()
var auth *gauth.Authenticator
if authEnabled {
auth, err = gauth.New(gauth.DefaultConfig())
if err != nil {
log.Error("Failed to initialize authenticator:", err)
return err
}
app.Use(auth.LoadAuthContext())
app.Use(auth.Middleware([]string{"admin"}))
}

err = mainController.setupDatabase()
if err != nil {
log.Error(err)
log.Error("Failed to setup database:", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not core initialisation it can be moved into a different function

@RabbITCybErSeC RabbITCybErSeC marked this pull request as ready for review December 9, 2024 12:26
@MaartendeKruijf MaartendeKruijf merged commit 1372802 into development Dec 9, 2024
10 checks passed
@MaartendeKruijf MaartendeKruijf deleted the feature/107-rbac-gauth branch December 9, 2024 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: OpenID integration for authentication
2 participants