Skip to content

Commit

Permalink
fix: simplify auth handling
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Sep 9, 2024
1 parent 491a6a6 commit 6894128
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 37 deletions.
4 changes: 1 addition & 3 deletions cmd/backrest/backrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ func main() {
zap.S().Fatalf("error loading config: %v", err)
}

// Create the authenticator
authenticator := auth.NewAuthenticator(getSecret(), configStore)

var wg sync.WaitGroup

// Create / load the operation log
Expand Down Expand Up @@ -110,6 +107,7 @@ func main() {
logStore,
)

authenticator := auth.NewAuthenticator(getSecret(), configStore)
apiAuthenticationHandler := api.NewAuthenticationHandler(authenticator)

mux := http.NewServeMux()
Expand Down
1 change: 0 additions & 1 deletion cmd/devtools/oplogexport/.gitignore

This file was deleted.

12 changes: 1 addition & 11 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ import (
"golang.org/x/crypto/bcrypt"
)

var (
anonymousUser = &v1.User{
Name: "default",
Password: &v1.User_PasswordBcrypt{PasswordBcrypt: "JDJhJDEwJDNCdzJoNFlhaWFZQy9TSDN3ZGxSRHVPZHdzV2lsNmtBSHdFSmtIWHk1dS8wYjZuUWJrMGFx"}, // default password is "password"
}
defaultUsers = []*v1.User{
anonymousUser,
}
)

type Authenticator struct {
config config.ConfigStore
key []byte
Expand All @@ -43,7 +33,7 @@ func (a *Authenticator) Login(username, password string) (*v1.User, error) {
return nil, fmt.Errorf("get config: %w", err)
}
auth := config.GetAuth()
if auth.GetDisabled() {
if auth == nil || auth.GetDisabled() {
return nil, errors.New("authentication is disabled")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func validatePlan(plan *v1.Plan, repos map[string]*v1.Repo) error {
}

func validateAuth(auth *v1.Auth) error {
if auth.Disabled {
if auth == nil || auth.Disabled {
return nil
}

Expand Down
21 changes: 0 additions & 21 deletions webui/src/views/LoginModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ export const LoginModal = () => {
const [form] = Form.useForm();
const alertApi = useAlertApi()!;

useEffect(() => {
authenticationService
.login(
new LoginRequest({
username: "default",
password: "password",
})
)
.then((loginResponse) => {
alertApi.success(
"No users configured yet, logged in with default credentials",
5
);
setAuthToken(loginResponse.token);
setTimeout(() => {
window.location.reload();
}, 500);
})
.catch((e) => {});
}, []);

const onFinish = async (values: any) => {
const loginReq = new LoginRequest({
username: values.username,
Expand Down

0 comments on commit 6894128

Please sign in to comment.