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

Name of cert token based on site UID #1256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 20 additions & 8 deletions client/connector_token_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ func (cli *VanClient) checkNotEdgeAndGetVersion(ctx context.Context, namespace s
return current.GetSiteMetadata().Version, nil
}

func (cli *VanClient) getSiteConfig(ctx context.Context, namespace string) (*types.SiteConfig, error) {
// get the host and port for inter-router and edge
siteConfig, err := cli.SiteConfigInspect(ctx, nil)
if err != nil {
return nil, err
}
if siteConfig == nil {
return nil, fmt.Errorf("No site config found in %s", namespace)
}
return siteConfig, nil

}

func (cli *VanClient) ConnectorTokenCreateFromTemplate(ctx context.Context, tokenName string, templateName string) (*corev1.Secret, bool, error) {
version, err := cli.checkNotEdgeAndGetVersion(ctx, cli.Namespace)
if err != nil {
Expand Down Expand Up @@ -82,13 +95,10 @@ func (cli *VanClient) ConnectorTokenCreate(ctx context.Context, subject string,

func (cli *VanClient) annotateConnectorToken(ctx context.Context, namespace string, token *corev1.Secret, version string) (bool, error) {
// get the host and port for inter-router and edge
siteConfig, err := cli.SiteConfigInspect(ctx, nil)
siteConfig, err := cli.getSiteConfig(ctx, namespace)
if err != nil {
return false, err
}
if siteConfig == nil {
return false, fmt.Errorf("No site config found in %s", namespace)
}
rslvr, err := resolver.NewResolver(cli, namespace, &siteConfig.Spec)
if err != nil {
return false, err
Expand All @@ -110,9 +120,7 @@ func (cli *VanClient) annotateConnectorToken(ctx context.Context, namespace stri
}
token.ObjectMeta.Labels[types.SkupperTypeQualifier] = types.TypeToken
// Store our siteID in the token, to prevent later self-connection.
if siteConfig != nil {
token.ObjectMeta.Annotations[types.TokenGeneratedBy] = siteConfig.Reference.UID
}
token.ObjectMeta.Annotations[types.TokenGeneratedBy] = siteConfig.Reference.UID
return rslvr.IsLocalAccessOnly(), nil
}

Expand All @@ -125,7 +133,11 @@ func (cli *VanClient) ConnectorTokenCreateFile(ctx context.Context, subject stri
if !res.Allowed {
return res.Err()
}
secret, localOnly, err := cli.ConnectorTokenCreate(ctx, subject, "")
siteConfig, err := cli.getSiteConfig(ctx, cli.Namespace)
if err != nil {
return err
}
secret, localOnly, err := cli.ConnectorTokenCreate(ctx, fmt.Sprintf("%s-%s", subject, siteConfig.Reference.UID), "")
Copy link
Member

Choose a reason for hiding this comment

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

Ideally we would separate the name used in the secret yaml from the subject used in the client certificate within that secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LGTM. I can move the concatenation of subject and site UID into ConnectorTokenCreate, but the function is called at several points in the code (e.g. newGateway and GatewayGenerateBundle). The alternative could be to change the signature of the function.

if err == nil {
return certs.GenerateSecretFile(secretFile, secret, localOnly)
} else {
Expand Down