Skip to content

Commit

Permalink
Add auth for read operation
Browse files Browse the repository at this point in the history
  • Loading branch information
vapopov committed Sep 16, 2024
1 parent d7c3e00 commit 2896303
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
18 changes: 18 additions & 0 deletions lib/auth/autoupdate/autoupdatev1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func NewService(cfg ServiceConfig) (*Service, error) {

// GetAutoUpdateConfig gets the current autoupdate config singleton.
func (s *Service) GetAutoUpdateConfig(ctx context.Context, req *autoupdate.GetAutoUpdateConfigRequest) (*autoupdate.AutoUpdateConfig, error) {
authCtx, err := s.authorizer.Authorize(ctx)
if err != nil {
return nil, trace.Wrap(err)
}

if err := authCtx.CheckAccessToKind(types.KindAutoUpdateConfig, types.VerbRead); err != nil {
return nil, trace.Wrap(err)
}

config, err := s.cache.GetAutoUpdateConfig(ctx)
if err != nil {
return nil, trace.Wrap(err)
Expand Down Expand Up @@ -165,6 +174,15 @@ func (s *Service) DeleteAutoUpdateConfig(ctx context.Context, req *autoupdate.De

// GetAutoUpdateVersion gets the current autoupdate version singleton.
func (s *Service) GetAutoUpdateVersion(ctx context.Context, req *autoupdate.GetAutoUpdateVersionRequest) (*autoupdate.AutoUpdateVersion, error) {
authCtx, err := s.authorizer.Authorize(ctx)
if err != nil {
return nil, trace.Wrap(err)
}

if err := authCtx.CheckAccessToKind(types.KindAutoUpdateVersion, types.VerbRead); err != nil {
return nil, trace.Wrap(err)
}

version, err := s.cache.GetAutoUpdateVersion(ctx)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
24 changes: 16 additions & 8 deletions lib/auth/autoupdate/autoupdatev1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ func TestServiceAccess(t *testing.T) {
allowedVerbs: []string{types.VerbUpdate, types.VerbCreate},
},
{
name: "GetAutoUpdateConfig",
allowedStates: []authz.AdminActionAuthState{},
disallowedStates: []authz.AdminActionAuthState{},
allowedVerbs: []string{types.VerbRead},
name: "GetAutoUpdateConfig",
allowedStates: []authz.AdminActionAuthState{
authz.AdminActionAuthUnauthorized,
authz.AdminActionAuthNotRequired,
authz.AdminActionAuthMFAVerified,
authz.AdminActionAuthMFAVerifiedWithReuse,
},
allowedVerbs: []string{types.VerbRead},
},
{
name: "DeleteAutoUpdateConfig",
Expand Down Expand Up @@ -149,10 +153,14 @@ func TestServiceAccess(t *testing.T) {
allowedVerbs: []string{types.VerbUpdate, types.VerbCreate},
},
{
name: "GetAutoUpdateVersion",
allowedStates: []authz.AdminActionAuthState{},
disallowedStates: []authz.AdminActionAuthState{},
allowedVerbs: []string{types.VerbRead},
name: "GetAutoUpdateVersion",
allowedStates: []authz.AdminActionAuthState{
authz.AdminActionAuthUnauthorized,
authz.AdminActionAuthNotRequired,
authz.AdminActionAuthMFAVerified,
authz.AdminActionAuthMFAVerifiedWithReuse,
},
allowedVerbs: []string{types.VerbRead},
},
{
name: "DeleteAutoUpdateVersion",
Expand Down

0 comments on commit 2896303

Please sign in to comment.