Skip to content

Bootstrap with pre-defined identities #3400

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gman0
Copy link
Contributor

@gman0 gman0 commented May 7, 2025

Summary

This PR adds a way to inject identities from a file while performing phase0 bootstrapping, making it possible to override core identities with pre-defined ones.

The file is expected to by YAML-formatted, passed via --core-identities-file kcp command line flag; its structure is rather simple, see the linked issue for reference.

What Type of PR Is This?

/kind feature

Related Issue(s)

Fixes #3320

Release Notes

Adds a new --core-identities-file kcp flag

Adds a new --core-identities-file kcp flag.

On-behalf-of: @SAP [email protected]
Signed-off-by: Robert Vasek <[email protected]>
@kcp-ci-bot kcp-ci-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 7, 2025
@kcp-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign sttts for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kcp-ci-bot
Copy link
Contributor

@gman0: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kcp-test-e2e-shared d343e91 link true /test pull-kcp-test-e2e-shared

Full PR test history

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Comment on lines +54 to +61
var coreIdentities coreIdentitiesFile
bs, err := os.ReadFile(identitiesFilename)
if err != nil {
return fmt.Errorf("failed to read core identities file %s: %v", identitiesFilename, err)
}
if err = yaml.UnmarshalStrict(bs, &coreIdentities); err != nil {
return fmt.Errorf("failed to parse YAML file %s: %v", identitiesFilename, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var coreIdentities coreIdentitiesFile
bs, err := os.ReadFile(identitiesFilename)
if err != nil {
return fmt.Errorf("failed to read core identities file %s: %v", identitiesFilename, err)
}
if err = yaml.UnmarshalStrict(bs, &coreIdentities); err != nil {
return fmt.Errorf("failed to parse YAML file %s: %v", identitiesFilename, err)
}
bs, err := os.ReadFile(identitiesFilename)
if err != nil {
return fmt.Errorf("failed to read core identities file %s: %v", identitiesFilename, err)
}
var coreIdentities coreIdentitiesFile
if err := yaml.UnmarshalStrict(bs, &coreIdentities); err != nil {
return fmt.Errorf("failed to parse YAML file %s: %v", identitiesFilename, err)
}

s.BootstrapApiExtensionsClusterClient.Cluster(core.RootCluster.Path()).Discovery(),
s.DynamicClusterClient.Cluster(core.RootCluster.Path()),
s.KubeClusterClient.Cluster(core.RootCluster.Path()),
s.Options.Extra.CoreIdentitiesFile,
Copy link
Member

Choose a reason for hiding this comment

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

E.g. here the file is read pkg/server and then the contents are handed off:

kcp/pkg/server/config.go

Lines 369 to 389 in e2ba960

if opts.Extra.ShardClientCertFile != "" && opts.Extra.ShardClientKeyFile != "" && opts.Extra.ShardVirtualWorkspaceCAFile != "" {
caCert, err := os.ReadFile(opts.Extra.ShardVirtualWorkspaceCAFile)
if err != nil {
return nil, fmt.Errorf("failed to read CA file %q: %w", opts.Extra.ShardVirtualWorkspaceCAFile, err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
cert, err := tls.LoadX509KeyPair(opts.Extra.ShardClientCertFile, opts.Extra.ShardClientKeyFile)
if err != nil {
return nil, fmt.Errorf("failed to load client certificate %q or key %q: %w", opts.Extra.ShardClientCertFile, opts.Extra.ShardClientKeyFile, err)
}
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
}
virtualWorkspaceServerProxyTransport = transport
}

Might also make it easier to test config without having to write the contents out to a file rather than just passing the bytes.

@@ -166,6 +167,7 @@ func (o *Options) AddFlags(fss *cliflag.NamedFlagSets) {
fs.StringVar(&o.Extra.ShardClientKeyFile, "shard-client-key-file", o.Extra.ShardClientKeyFile, "Path to a client certificate key file the shard uses to communicate with other system components.")
fs.StringVar(&o.Extra.LogicalClusterAdminKubeconfig, "logical-cluster-admin-kubeconfig", o.Extra.LogicalClusterAdminKubeconfig, "Kubeconfig holding system:kcp:logical-cluster-admin credentials for connecting to other shards. Defaults to the loopback client")
fs.StringVar(&o.Extra.ExternalLogicalClusterAdminKubeconfig, "external-logical-cluster-admin-kubeconfig", o.Extra.ExternalLogicalClusterAdminKubeconfig, "Kubeconfig holding system:kcp:external-logical-cluster-admin credentials for connecting to the external address (e.g. the front-proxy). Defaults to the loopback client")
fs.StringVar(&o.Extra.CoreIdentitiesFile, "core-identities-file", "", "Path to a YAML file with APIExport - Identity secret Identity key pairs. Defaults to empty, i.e. all identities are generated.")
Copy link
Member

Choose a reason for hiding this comment

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

the format must be documented. In the docs, and If it's super simple, then here too.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe you mean that in the description. Maybe `.... with a map where keys are X and values are Y. What are the keys? What is a identity secret? Are these write 1:1 to the secret of the same name? Try to be clear and precise.

Copy link
Member

Choose a reason for hiding this comment

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

Also it must be very clear what happens if the secrets are pre-existing.

@@ -166,6 +167,7 @@ func (o *Options) AddFlags(fss *cliflag.NamedFlagSets) {
fs.StringVar(&o.Extra.ShardClientKeyFile, "shard-client-key-file", o.Extra.ShardClientKeyFile, "Path to a client certificate key file the shard uses to communicate with other system components.")
fs.StringVar(&o.Extra.LogicalClusterAdminKubeconfig, "logical-cluster-admin-kubeconfig", o.Extra.LogicalClusterAdminKubeconfig, "Kubeconfig holding system:kcp:logical-cluster-admin credentials for connecting to other shards. Defaults to the loopback client")
fs.StringVar(&o.Extra.ExternalLogicalClusterAdminKubeconfig, "external-logical-cluster-admin-kubeconfig", o.Extra.ExternalLogicalClusterAdminKubeconfig, "Kubeconfig holding system:kcp:external-logical-cluster-admin credentials for connecting to the external address (e.g. the front-proxy). Defaults to the loopback client")
fs.StringVar(&o.Extra.CoreIdentitiesFile, "core-identities-file", "", "Path to a YAML file with APIExport - Identity secret Identity key pairs. Defaults to empty, i.e. all identities are generated.")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fs.StringVar(&o.Extra.CoreIdentitiesFile, "core-identities-file", "", "Path to a YAML file with APIExport - Identity secret Identity key pairs. Defaults to empty, i.e. all identities are generated.")
fs.StringVar(&o.Extra.CoreIdentitiesFile, "core-identities-file", "", "Path to a YAML file with APIExport - identity secret identity key pairs. Defaults to empty, i.e. all identities are generated.")

@@ -0,0 +1,43 @@
/*
Copyright 2022 The KCP Authors.
Copy link
Member

Choose a reason for hiding this comment

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

2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has signed the DCO. kind/feature Categorizes issue or PR as related to a new feature. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: static root APIExport identities hashes
4 participants