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

Plugins: Modify interface for plugin validations to allow taking PDC into account #96089

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

papagian
Copy link
Contributor

@papagian papagian commented Nov 8, 2024

it additionally renames validations.PluginRequestValidator to validations.DataSourceRequestValidator

}

err = hs.PluginRequestValidator.Validate(dsURL, c.Req)
err = hs.PluginRequestValidator.Validate(ds, c.Req)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

to my understanding the ds information can come from the cache but this change seems fine since the pCtx.DataSourceInstanceSettings derive from the ds itself (only difference should be that the secrets in DataSourceInstanceSettings are decrypted but we don't use this for any validation

@papagian papagian added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels Nov 12, 2024
@papagian papagian marked this pull request as ready for review November 12, 2024 14:40
@papagian papagian requested review from a team as code owners November 12, 2024 14:40
@papagian papagian requested review from juanicabanas, evictorero, wbrowne, andresmgot and xnyo and removed request for a team November 12, 2024 14:40
@github-actions github-actions bot added this to the 11.4.x milestone Nov 12, 2024
@papagian papagian changed the title Plugins: Introduce interface required for plugin validations Plugins: Modify interface for plugin validations to allow taking PDC into account Nov 12, 2024
Copy link
Member

@wbrowne wbrowne left a comment

Choose a reason for hiding this comment

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

Just a few things to mention!

pkg/services/validations/service.go Outdated Show resolved Hide resolved
pkg/services/datasources/models.go Show resolved Hide resolved
pkg/services/datasources/models.go Show resolved Hide resolved
@papagian papagian requested a review from wbrowne November 15, 2024 11:29
@@ -244,7 +244,7 @@ func (s *ServiceImpl) handleExpressions(ctx context.Context, user identity.Reque
func (s *ServiceImpl) handleQuerySingleDatasource(ctx context.Context, user identity.Requester, parsedReq *parsedRequest) (*backend.QueryDataResponse, error) {
queries := parsedReq.getFlattenedQueries()
ds := queries[0].datasource
if err := s.pluginRequestValidator.Validate(ds.URL, nil); err != nil {
if err := s.dataSourceRequestValidator.Validate(ds, setting.SecureSocksDSProxySettings{}, nil); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Don't we want to pass cfg.ProxySettings here?

@@ -27,7 +29,7 @@ func RedirectLimitMiddleware(reqValidator validations.PluginRequestValidator) sd
return nil, locationErr
}

if validationErr := reqValidator.Validate(location.String(), nil); validationErr != nil {
if validationErr := reqValidator.Validate(&datasources.DataSource{URL: location.String()}, setting.SecureSocksDSProxySettings{}, nil); validationErr != nil {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this is the only place that is problematic 😞 The only escape hatch we have here is that we should have the following labels available via opts sdkhttpclient.Options:

  • Labels["datasource_name"]
  • Labels["datasource_uid"]
  • Labels["datasource_type"]

They should always be populated, but it would probably be a good idea to actually add types/funcs for these on the SDK struct itself (could be done in a follow up). That means we'd have to read the datasource from the DB in this case though. Maybe that's okay since this is only when status code is 3xx.

Aside: I also think we could get away with not having to pass setting.SecureSocksDSProxySettings actually since *cfg.Setting could just become a field over here - since that is the only implementation where it's actually used.

Copy link
Contributor Author

@papagian papagian Nov 18, 2024

Choose a reason for hiding this comment

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

Regarding the 1st point I wonder if it's ever possible the res.Location() (which is what we currently check) to be different from the datasource URL? I think that we intentionally check the location header.
Regarding the 2nd point I agree: that would simplify it a lot

Copy link
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions!

@github-actions github-actions bot added the stale Issue with no recent activity label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes stale Issue with no recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants