mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
auth: wire service account proxy (#77215)
* Add interface verification compliance * rework service account api to a provider * wire the service accounts api * rewire the implementation of sa srv for the proxy --------- Co-authored-by: Misi <mgyongyosi@users.noreply.github.com>
This commit is contained in:
parent
dcdd334663
commit
c50ada3a1a
@ -123,6 +123,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/extsvcaccounts"
|
||||
serviceaccountsmanager "github.com/grafana/grafana/pkg/services/serviceaccounts/manager"
|
||||
serviceaccountsproxy "github.com/grafana/grafana/pkg/services/serviceaccounts/proxy"
|
||||
serviceaccountsretriever "github.com/grafana/grafana/pkg/services/serviceaccounts/retriever"
|
||||
"github.com/grafana/grafana/pkg/services/shorturls"
|
||||
"github.com/grafana/grafana/pkg/services/shorturls/shorturlimpl"
|
||||
@ -288,7 +289,8 @@ var wireBasicSet = wire.NewSet(
|
||||
ossaccesscontrol.ProvideServiceAccountPermissions,
|
||||
wire.Bind(new(accesscontrol.ServiceAccountPermissionsService), new(*ossaccesscontrol.ServiceAccountPermissionsService)),
|
||||
serviceaccountsmanager.ProvideServiceAccountsService,
|
||||
wire.Bind(new(serviceaccounts.Service), new(*serviceaccountsmanager.ServiceAccountsService)),
|
||||
serviceaccountsproxy.ProvideServiceAccountsProxy,
|
||||
wire.Bind(new(serviceaccounts.Service), new(*serviceaccountsproxy.ServiceAccountsProxy)),
|
||||
expr.ProvideService,
|
||||
featuremgmt.ProvideManagerService,
|
||||
featuremgmt.ProvideToggles,
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/kvstore"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/usagestats"
|
||||
@ -14,7 +13,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/api"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/database"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/secretscan"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
@ -39,15 +37,12 @@ type ServiceAccountsService struct {
|
||||
|
||||
func ProvideServiceAccountsService(
|
||||
cfg *setting.Cfg,
|
||||
ac accesscontrol.AccessControl,
|
||||
routeRegister routing.RouteRegister,
|
||||
usageStats usagestats.Service,
|
||||
store *sqlstore.SQLStore,
|
||||
apiKeyService apikey.Service,
|
||||
kvStore kvstore.KVStore,
|
||||
userService user.Service,
|
||||
orgService org.Service,
|
||||
permissionService accesscontrol.ServiceAccountPermissionsService,
|
||||
accesscontrolService accesscontrol.Service,
|
||||
) (*ServiceAccountsService, error) {
|
||||
serviceAccountsStore := database.ProvideServiceAccountsStore(
|
||||
@ -70,9 +65,6 @@ func ProvideServiceAccountsService(
|
||||
|
||||
usageStats.RegisterMetricsFunc(s.getUsageMetrics)
|
||||
|
||||
serviceaccountsAPI := api.NewServiceAccountsAPI(cfg, s, ac, accesscontrolService, routeRegister, permissionService)
|
||||
serviceaccountsAPI.RegisterAPIEndpoints()
|
||||
|
||||
s.secretScanEnabled = cfg.SectionWithEnvOverrides("secretscan").Key("enabled").MustBool(false)
|
||||
s.secretScanInterval = cfg.SectionWithEnvOverrides("secretscan").
|
||||
Key("interval").MustDuration(defaultSecretScanInterval)
|
||||
@ -146,6 +138,8 @@ func (sa *ServiceAccountsService) Run(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
var _ serviceaccounts.Service = (*ServiceAccountsService)(nil)
|
||||
|
||||
func (sa *ServiceAccountsService) CreateServiceAccount(ctx context.Context, orgID int64, saForm *serviceaccounts.CreateServiceAccountForm) (*serviceaccounts.ServiceAccountDTO, error) {
|
||||
if err := validOrgID(orgID); err != nil {
|
||||
return nil, err
|
||||
|
@ -4,12 +4,16 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/api"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/extsvcaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts/manager"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
|
||||
// ServiceAccountsProxy is a proxy for the serviceaccounts.Service interface
|
||||
@ -23,14 +27,23 @@ type ServiceAccountsProxy struct {
|
||||
}
|
||||
|
||||
func ProvideServiceAccountsProxy(
|
||||
cfg *setting.Cfg,
|
||||
ac accesscontrol.AccessControl,
|
||||
accesscontrolService accesscontrol.Service,
|
||||
features *featuremgmt.FeatureManager,
|
||||
permissionService accesscontrol.ServiceAccountPermissionsService,
|
||||
proxiedService *manager.ServiceAccountsService,
|
||||
routeRegister routing.RouteRegister,
|
||||
) (*ServiceAccountsProxy, error) {
|
||||
s := &ServiceAccountsProxy{
|
||||
log: log.New("serviceaccounts.proxy"),
|
||||
proxiedService: proxiedService,
|
||||
isProxyEnabled: features.IsEnabled(featuremgmt.FlagExternalServiceAccounts) || features.IsEnabled(featuremgmt.FlagExternalServiceAuth),
|
||||
}
|
||||
|
||||
serviceaccountsAPI := api.NewServiceAccountsAPI(cfg, s, ac, accesscontrolService, routeRegister, permissionService)
|
||||
serviceaccountsAPI.RegisterAPIEndpoints()
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user