Skip to content
Merged
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
9 changes: 5 additions & 4 deletions marketplace/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ created. Idempotent: safe to run on every pod start and every upgrade.`,
return fmt.Errorf("resolve workspace path %s: %w", workspacePath, err)
}

result, err := bootstrap.Bootstrap(ctx, target, workspacePath, bootstrap.Options{
opts := bootstrap.Options{
ServerUsers: serverUsers,
ServerGroups: serverGroups,
})
}
result, err := bootstrap.Bootstrap(ctx, target, workspacePath, opts)
if err != nil {
return err
}
Expand All @@ -108,7 +109,7 @@ created. Idempotent: safe to run on every pod start and every upgrade.`,
if err != nil {
return fmt.Errorf("resolve workspace path %s: %w", catalogPath, err)
}
if err := bootstrap.BindCatalog(ctx, catalogCfg, result); err != nil {
if err := bootstrap.BindCatalog(ctx, catalogCfg, result, opts); err != nil {
return fmt.Errorf("bind the Provider API into %s: %w", catalogPath, err)
}
if err := bootstrap.GrantPlatformAdmins(ctx, catalogCfg, adminUsers, adminGroups); err != nil {
Expand All @@ -127,7 +128,7 @@ created. Idempotent: safe to run on every pod start and every upgrade.`,
if err != nil {
return fmt.Errorf("resolve workspace path %s: %w", producersPath, err)
}
if err := bootstrap.BindProvidersParent(ctx, providersCfg, result); err != nil {
if err := bootstrap.BindProvidersParent(ctx, providersCfg, result, opts); err != nil {
return fmt.Errorf("bind the provisioner claim into %s: %w", producersPath, err)
}
logger.Info("producers parent ready", "workspace", producersPath)
Expand Down
45 changes: 42 additions & 3 deletions marketplace/pkg/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,13 @@ func Bootstrap(ctx context.Context, cfg *rest.Config, exportsPath string, opts O

// BindCatalog makes the workspace cfg points at the Producer registry: it
// binds marketplace-catalog, then waits until Producers are servable.
func BindCatalog(ctx context.Context, cfg *rest.Config, result *Result) error {
func BindCatalog(ctx context.Context, cfg *rest.Config, result *Result, opts Options) error {
if err := applyTier(ctx, cfg, result, apiexport.CatalogOrder); err != nil {
return err
}
if err := grantLocator(ctx, cfg, opts); err != nil {
return err
}

dyn, err := dynamic.NewForConfig(cfg)
if err != nil {
Expand All @@ -198,8 +201,44 @@ func BindCatalog(ctx context.Context, cfg *rest.Config, result *Result) error {
// parent: it binds marketplace-provisioner, so producer workspaces can be
// created as its children. Nothing to wait for — the claim adds reach, not
// a servable API.
func BindProvidersParent(ctx context.Context, cfg *rest.Config, result *Result) error {
return applyTier(ctx, cfg, result, apiexport.ProducersOrder)
func BindProvidersParent(ctx context.Context, cfg *rest.Config, result *Result, opts Options) error {
if err := applyTier(ctx, cfg, result, apiexport.ProducersOrder); err != nil {
return err
}
return grantLocator(ctx, cfg, opts)
}

// grantLocator grants the server identities the least they need to find
// out which logical cluster the workspace cfg points at: kcp's workspace
// gate, and a read of the LogicalCluster that names it. The marketplace
// exports address clusters and not paths, so the operator cannot work
// with a hand-bound tier without it.
func grantLocator(ctx context.Context, cfg *rest.Config, opts Options) error {
if len(opts.ServerUsers)+len(opts.ServerGroups) == 0 {
return nil
}
kube, err := kubernetes.NewForConfig(cfg)
if err != nil {
return fmt.Errorf("build kubernetes client: %w", err)
}
role := &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{Name: marketplacev1alpha1.GroupName + ":locator"},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"access"},
NonResourceURLs: []string{"/"},
},
{
APIGroups: []string{"core.kcp.io"},
Resources: []string{"logicalclusters"},
Verbs: []string{"get"},
},
},
}
if err := applyRoleAndBinding(ctx, kube, role, opts.ServerUsers, opts.ServerGroups); err != nil {
return fmt.Errorf("grant the server identities the locator role: %w", err)
}
return nil
}

// applyTier applies one hand-bound tier's assets. These two tiers are the
Expand Down
5 changes: 4 additions & 1 deletion tenancy/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ root down. Idempotent: safe to run on every pod start and every upgrade.`,
if err != nil {
return fmt.Errorf("resolve workspace path %s: %w", tenantsPath, err)
}
if err := bootstrap.BindTenantsParent(ctx, tenantsCfg, result); err != nil {
if err := bootstrap.BindTenantsParent(ctx, tenantsCfg, result, bootstrap.Options{
ServerUsers: serverUsers,
ServerGroups: serverGroups,
}); err != nil {
return fmt.Errorf("bind the provisioner claim into %s: %w", tenantsPath, err)
}
logger.Info("provisioning parent ready", "workspace", tenantsPath)
Expand Down
35 changes: 26 additions & 9 deletions tenancy/pkg/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func BindStore(ctx context.Context, cfg *rest.Config, result *Result, opts Optio
if err != nil {
return fmt.Errorf("build kubernetes client: %w", err)
}
if err := applyStoreLocator(ctx, kube, opts.ServerUsers, opts.ServerGroups); err != nil {
if err := applyLocator(ctx, kube, tenancyv1alpha1.GroupName+":store-locator", opts.ServerUsers, opts.ServerGroups); err != nil {
return fmt.Errorf("grant the server identities the store locator role: %w", err)
}
}
Expand Down Expand Up @@ -214,8 +214,25 @@ func BindStore(ctx context.Context, cfg *rest.Config, result *Result, opts Optio
//
// There is nothing to wait for here — the claim adds no servable API, it
// adds reach — so a readiness probe would have nothing to probe.
func BindTenantsParent(ctx context.Context, cfg *rest.Config, result *Result) error {
return applyTier(ctx, cfg, result, apiexport.TenantsOrder)
//
// The operator creates tenant workspaces under this one through the
// provisioner export, which addresses clusters and not paths, so the
// server identities get the same locator role as in the store.
func BindTenantsParent(ctx context.Context, cfg *rest.Config, result *Result, opts Options) error {
if err := applyTier(ctx, cfg, result, apiexport.TenantsOrder); err != nil {
return err
}
if len(opts.ServerUsers)+len(opts.ServerGroups) == 0 {
return nil
}
kube, err := kubernetes.NewForConfig(cfg)
if err != nil {
return fmt.Errorf("build kubernetes client: %w", err)
}
if err := applyLocator(ctx, kube, tenancyv1alpha1.GroupName+":tenants-locator", opts.ServerUsers, opts.ServerGroups); err != nil {
return fmt.Errorf("grant the server identities the tenants locator role: %w", err)
}
return nil
}

// applyTier applies one hand-bound tier's assets.
Expand Down Expand Up @@ -392,13 +409,13 @@ func applyManifests(ctx context.Context, dyn dynamic.Interface, mapper *restmapp
}
}

// applyStoreLocator grants the least a server needs to find out which
// logical cluster the store workspace is: kcp's workspace gate, and a read
// of the LogicalCluster that names it. Deliberately not the Tenant API —
// tenants are written through the platform export, not through here.
func applyStoreLocator(ctx context.Context, kube kubernetes.Interface, users, groups []string) error {
// applyLocator grants the least a server needs to find out which logical
// cluster a workspace is: kcp's workspace gate, and a read of the
// LogicalCluster that names it. Deliberately not the Tenant API — tenants
// are written through the platform export, not through here.
func applyLocator(ctx context.Context, kube kubernetes.Interface, name string, users, groups []string) error {
role := &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{Name: tenancyv1alpha1.GroupName + ":store-locator"},
ObjectMeta: metav1.ObjectMeta{Name: name},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"access"},
Expand Down
Loading