Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
idanovo committed May 22, 2024
1 parent 29e0022 commit 6838cf9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
21 changes: 11 additions & 10 deletions pkg/auth/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package auth

import (
"context"
"crypto/subtle"
"fmt"

"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -55,15 +54,17 @@ func NewBuiltinAuthenticator(service Service) *BuiltinAuthenticator {
}

func (ba *BuiltinAuthenticator) AuthenticateUser(ctx context.Context, username, password string) (string, error) {
// Look user up in DB. username is really the access key ID.
cred, err := ba.creds.GetCredentials(ctx, username)
if err != nil {
return InvalidUserID, err
}
if subtle.ConstantTimeCompare([]byte(password), []byte(cred.SecretAccessKey)) != 1 {
return InvalidUserID, ErrInvalidSecretAccessKey
}
return cred.Username, nil
//// Look user up in DB. username is really the access key ID.
//cred, err := ba.creds.GetCredentials(ctx, username)

Check failure on line 58 in pkg/auth/authenticator.go

View workflow job for this annotation

GitHub Actions / Build and push Docker image

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 58 in pkg/auth/authenticator.go

View workflow job for this annotation

GitHub Actions / Run Linters and Checkers

commentFormatting: put a space between `//` and comment text (gocritic)
//if err != nil {
// return InvalidUserID, err
//}
//if subtle.ConstantTimeCompare([]byte(password), []byte(cred.SecretAccessKey)) != 1 {
// return InvalidUserID, ErrInvalidSecretAccessKey
//}
//return cred.Username, nil

return "test-user", nil
}

func (ba *BuiltinAuthenticator) String() string {
Expand Down
32 changes: 16 additions & 16 deletions pkg/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1914,22 +1914,22 @@ func (a *APIAuthService) ListGroupPolicies(ctx context.Context, groupID string,
}

func (a *APIAuthService) Authorize(ctx context.Context, req *AuthorizationRequest) (*AuthorizationResponse, error) {
policies, _, err := a.ListEffectivePolicies(ctx, req.Username, &model.PaginationParams{
After: "", // all
Amount: -1, // all
})
if err != nil {
return nil, err
}

allowed := checkPermissions(ctx, req.RequiredPermissions, req.Username, policies)

if allowed != CheckAllow {
return &AuthorizationResponse{
Allowed: false,
Error: ErrInsufficientPermissions,
}, nil
}
//policies, _, err := a.ListEffectivePolicies(ctx, req.Username, &model.PaginationParams{

Check failure on line 1917 in pkg/auth/service.go

View workflow job for this annotation

GitHub Actions / Build and push Docker image

commentFormatting: put a space between `//` and comment text (gocritic)

Check failure on line 1917 in pkg/auth/service.go

View workflow job for this annotation

GitHub Actions / Run Linters and Checkers

commentFormatting: put a space between `//` and comment text (gocritic)
// After: "", // all
// Amount: -1, // all
//})
//if err != nil {
// return nil, err
//}
//
//allowed := checkPermissions(ctx, req.RequiredPermissions, req.Username, policies)
//
//if allowed != CheckAllow {
// return &AuthorizationResponse{
// Allowed: false,
// Error: ErrInsufficientPermissions,
// }, nil
//}

// we're allowed!
return &AuthorizationResponse{Allowed: true}, nil
Expand Down

0 comments on commit 6838cf9

Please sign in to comment.