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

Proof of concept of a common plugin base #47972

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

hugoShaka
Copy link
Contributor

No description provided.

Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-47972.d3pp5qlev8mo18.amplifyapp.com

@hugoShaka hugoShaka changed the title Proof of concept common plugin base Proof of concept of a common plugin base Oct 25, 2024
Copy link
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

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

Overall seems like a decent approach

Comment on lines +74 to +84
func (a *Launcher) checkTeleportVersion(ctx context.Context) (proto.PingResponse, error) {
pong, err := a.teleportClient.Ping(ctx)
if err != nil {
if trace.IsNotImplemented(err) {
return pong, trace.Wrap(err, "server version must be at least %s", minServerVersion)
}
return pong, trace.Wrap(err, "Unable to get Teleport server version")
}
err = utils.CheckMinVersion(pong.ServerVersion, minServerVersion)
return pong, trace.Wrap(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still relevant? The minimum version this would be released in is v15 which seems highly unlikely to be running against a v6 control plane.

return trace.Wrap(err)
}

a.PluginName = a.Conf.PluginName()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be updated?

}

type Service interface {
Run(ctx context.Context, clt teleport.Client, name string /* TODO add status sink */) error
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the name here convey? Why does it need to be given to the service?

return wrapAPIClient(clt), nil
}

// TODO: check if we can get rid of this?
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 - Can teleport.Client be updated to use the matching signature so this can be eliminated?

Comment on lines +51 to +56
group.Go(func() error {
return service.Run(ctx, a.teleportClient, a.PluginName)
})
}

return group.Wait()
Copy link
Contributor

@rosstimothy rosstimothy Oct 30, 2024

Choose a reason for hiding this comment

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

What is the expected behavior if any one of the services fails, causing this to return? Do we expect systemd/kubernetes to restart the plugin?

}

group, ctx := errgroup.WithContext(ctx)
for _, service := range a.Services {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we warn if there are no services configured?

* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package common
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +27 to +45
type accessListReminderService struct {
// provided on creation
notifier Notifier
clock clockwork.Clock

// provided at runtime
pluginName string
teleportClient teleport.Client

// initialized but the service itself
pluginData *pd.CompareAndSwap[pd.AccessListNotificationData]
}

func NewAccessListReminderService(notifier Notifier) launcher.Service {
return &accessListReminderService{
notifier: notifier,
clock: clockwork.NewRealClock(),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: remove the stutter and export the service

https://go.dev/wiki/CodeReviewComments#interfaces
https://go.dev/doc/effective_go#package-names

Suggested change
type accessListReminderService struct {
// provided on creation
notifier Notifier
clock clockwork.Clock
// provided at runtime
pluginName string
teleportClient teleport.Client
// initialized but the service itself
pluginData *pd.CompareAndSwap[pd.AccessListNotificationData]
}
func NewAccessListReminderService(notifier Notifier) launcher.Service {
return &accessListReminderService{
notifier: notifier,
clock: clockwork.NewRealClock(),
}
}
type ReminderService struct {
// provided on creation
notifier Notifier
clock clockwork.Clock
// provided at runtime
pluginName string
teleportClient teleport.Client
// initialized but the service itself
pluginData *pd.CompareAndSwap[pd.AccessListNotificationData]
}
func NewReminderService(notifier Notifier) *ReminderService {
return &ReminderService{
notifier: notifier,
clock: clockwork.NewRealClock(),
}
}

Comment on lines +53 to +56
a.teleportClient = clt
a.pluginName = name

a.pluginData = pd.NewCAS(
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this a bit racy?

Comment on lines +28 to +49
type accessRequestService struct {
// provided on creation
notifier Notifier
approvalUser string
staticRecipients common.RawRecipientsMap

// provided at runtime
pluginName string
teleportClient teleport.Client

// initialized but the service itself
pluginData *pd.CompareAndSwap[PluginData]
accessMonitoringRules *accessmonitoring.RuleHandler
}

func NewAccessRequestService(notifier Notifier, staticRecipients common.RawRecipientsMap, approvalUser string) launcher.Service {
return &accessRequestService{
notifier: notifier,
approvalUser: approvalUser,
staticRecipients: staticRecipients,
}
}
Copy link
Contributor

@rosstimothy rosstimothy Oct 30, 2024

Choose a reason for hiding this comment

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

Same suggestions here as in the other package

Suggested change
type accessRequestService struct {
// provided on creation
notifier Notifier
approvalUser string
staticRecipients common.RawRecipientsMap
// provided at runtime
pluginName string
teleportClient teleport.Client
// initialized but the service itself
pluginData *pd.CompareAndSwap[PluginData]
accessMonitoringRules *accessmonitoring.RuleHandler
}
func NewAccessRequestService(notifier Notifier, staticRecipients common.RawRecipientsMap, approvalUser string) launcher.Service {
return &accessRequestService{
notifier: notifier,
approvalUser: approvalUser,
staticRecipients: staticRecipients,
}
}
type Service struct {
// provided on creation
notifier Notifier
approvalUser string
staticRecipients common.RawRecipientsMap
// provided at runtime
pluginName string
teleportClient teleport.Client
// initialized but the service itself
pluginData *pd.CompareAndSwap[PluginData]
accessMonitoringRules *accessmonitoring.RuleHandler
}
func NewService(notifier Notifier, staticRecipients common.RawRecipientsMap, approvalUser string) *Service {
return &Service{
notifier: notifier,
approvalUser: approvalUser,
staticRecipients: staticRecipients,
}
}

@tigrato tigrato self-requested a review November 5, 2024 19:07
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.

2 participants