Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lib/cache/access_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Teleport
// Copyright (C) 2025 Gravitational, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package cache

import (
"context"

"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/services"
)

func newAccessRequestCollection(upstream services.DynamicAccessCore, w types.WatchKind) (*collection[types.AccessRequest, string], error) {
if upstream == nil {
return nil, trace.BadParameter("missing parameter DynamicAccess")
}

return &collection[types.AccessRequest, string]{
store: newStore(map[string]func(types.AccessRequest) string{
"default": func(types.AccessRequest) string { return "default" },
}),
fetcher: func(ctx context.Context, loadSecrets bool) ([]types.AccessRequest, error) {
return nil, nil
},
Comment on lines +34 to +39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I'm very out of my depth here, but this is somewhat suspicious.

From what I've seen for the store index we usually have something like:

		store: newStore(map[proxyServerIndex]func(types.Server) string{
			proxyServerNameIndex: func(u types.Server) string {
				return u.GetName()
			},
		}),

Isn't that needed here?

Also why is the fetcher returning nil?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Access requests in the cache are weird because the auth doesn't actually cache them but they must be usable in watchers; we should make it more explicit that this is what's happening, or find a better way to deal with resource kinds that are watchable and fanned out but not actually handled by the cache.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some comment could be useful

headerTransform: func(hdr *types.ResourceHeader) types.AccessRequest {
return &types.AccessRequestV3{
Kind: hdr.Kind,
Version: hdr.Version,
Metadata: types.Metadata{
Name: hdr.GetName(),
},
}
},
watch: w,
}, nil
}
7 changes: 7 additions & 0 deletions lib/cache/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ func setupCollections(c Config) (*collections, error) {
resourceKind := resourceKindFromWatchKind(watch)

switch watch.Kind {
case types.KindAccessRequest:
collect, err := newAccessRequestCollection(c.DynamicAccess, watch)
if err != nil {
return nil, trace.Wrap(err)
}

out.byKind[resourceKind] = collect
case types.KindToken:
collect, err := newProvisionTokensCollection(c.Provisioner, watch)
if err != nil {
Expand Down
31 changes: 0 additions & 31 deletions lib/cache/legacy_collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ func setupLegacyCollections(c *Cache, watches []types.WatchKind) (*legacyCollect
for _, watch := range watches {
resourceKind := resourceKindFromWatchKind(watch)
switch watch.Kind {
case types.KindAccessRequest:
if c.DynamicAccess == nil {
return nil, trace.BadParameter("missing parameter DynamicAccess")
}
collections.byKind[resourceKind] = &genericCollection[types.AccessRequest, noReader, accessRequestExecutor]{cache: c, watch: watch}
case types.KindDatabaseObject:
if c.DatabaseObjects == nil {
return nil, trace.BadParameter("missing parameter DatabaseObject")
Expand Down Expand Up @@ -280,32 +275,6 @@ func (r resourceKind) String() string {
return fmt.Sprintf("%s/%s", r.kind, r.subkind)
}

type accessRequestExecutor struct{}

func (accessRequestExecutor) getAll(ctx context.Context, cache *Cache, loadSecrets bool) ([]types.AccessRequest, error) {
return cache.DynamicAccess.GetAccessRequests(ctx, types.AccessRequestFilter{})
}

func (accessRequestExecutor) upsert(ctx context.Context, cache *Cache, resource types.AccessRequest) error {
return cache.dynamicAccessCache.UpsertAccessRequest(ctx, resource)
}

func (accessRequestExecutor) deleteAll(ctx context.Context, cache *Cache) error {
return cache.dynamicAccessCache.DeleteAllAccessRequests(ctx)
}

func (accessRequestExecutor) delete(ctx context.Context, cache *Cache, resource types.Resource) error {
return cache.dynamicAccessCache.DeleteAccessRequest(ctx, resource.GetName())
}

func (accessRequestExecutor) isSingleton() bool { return false }

func (accessRequestExecutor) getReader(_ *Cache, _ bool) noReader {
return noReader{}
}

var _ executor[types.AccessRequest, noReader] = accessRequestExecutor{}

type userExecutor struct{}

func (userExecutor) getAll(ctx context.Context, cache *Cache, loadSecrets bool) ([]types.User, error) {
Expand Down
Loading