-
Notifications
You must be signed in to change notification settings - Fork 110
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
[liqoctl] generate peering-user #2911
base: master
Are you sure you want to change the base?
Conversation
Hi @claudiolor. Thanks for your PR! I am @adamjensenbot.
Make sure this PR appears in the liqo changelog, adding one of the following labels:
|
f19a67a
to
3ea3943
Compare
0f0e212
to
f203cff
Compare
2be20b4
to
e162a78
Compare
6bb3540
to
063dd70
Compare
/test |
b3928aa
to
064a423
Compare
91f6e27
to
90029fe
Compare
eba2b29
to
b33f8f5
Compare
This patch introduces a set of commands allowing to generate a user with the minimum permissions to create a peering from the cluster with the specified cluster ID
b33f8f5
to
e703e11
Compare
@@ -86,7 +86,7 @@ func (o *Options) RunPeer(ctx context.Context) error { | |||
// Ensure networking | |||
if !o.NetworkingDisabled { | |||
if err := ensureNetworking(ctx, o); err != nil { | |||
o.LocalFactory.PrinterGlobal.Error.Println("unable to ensure networking") | |||
o.LocalFactory.PrinterGlobal.Error.Printfln("Unable to ensure networking: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do the same also for ensureAuthentication and ensureOffloading?
if bidirectional && !o.KeepNamespaces { | ||
err = fmt.Errorf("cannot unpeer bidirectional peering without keeping namespaces, please set the --keep-namespaces flag") | ||
if bidirectional && o.DeleteNamespace { | ||
err = fmt.Errorf("cannot delete the tenant namespace when a bidirectional is enabled, please remote the --delete-namespaces flag") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = fmt.Errorf("cannot delete the tenant namespace when a bidirectional is enabled, please remote the --delete-namespaces flag") | |
err = fmt.Errorf("cannot delete the tenant namespace when a bidirectional is enabled, please remove the --delete-namespaces flag") |
if err := cl.List(ctx, &secrets, &client.ListOptions{ | ||
Namespace: tenantNamespace, | ||
LabelSelector: labels.SelectorFromSet(map[string]string{ | ||
consts.RemoteClusterID: string(remoteClusterID), | ||
consts.NonceSecretLabelKey: "true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor issue here but can you use the same method to pass the ListOptions in GetNonceSecretByClusterID
and GetSignedNonceSecretByClusterID
?
return fmt.Sprintf("liqo-peer-user-%s", clusterID) | ||
} | ||
|
||
func generateKubeconfig(clusterID string, ca, cert, private []byte, apiAddr string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We basically do the same here.
Maybe not in this PR, but for the future we can export that function in a util package and reuse the same function.
I also noticed that the other function accept a optional namespace argument to set default the scope of the requests. It may be useful to use it by defaulting to the tenant namespace to further indiciate that scope of the kubeconfig is limited to the tenant namespace.
APIGroups: []string{"ipam.liqo.io"}, | ||
Resources: []string{"networks"}, | ||
Verbs: []string{"get", "list"}, | ||
}, | ||
{ | ||
APIGroups: []string{"networking.liqo.io"}, | ||
Resources: []string{"configurations", "gatewayclients", "gatewayservers", "publickeies"}, | ||
Verbs: []string{"get", "list"}, | ||
}, | ||
{ | ||
APIGroups: []string{"core.liqo.io"}, | ||
Resources: []string{"foreignclusters"}, | ||
Verbs: []string{"get", "list"}, | ||
}, | ||
{ | ||
APIGroups: []string{"authentication.liqo.io"}, | ||
Resources: []string{"tenants"}, | ||
Verbs: []string{"create", "list"}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the exported costants in our API?
E.g.:
{
APIGroups: []string{liqov1beta1.GroupVersion.Group},
Resources: []string{liqov1beta1.ForeignClusterResource},
Verbs: []string{"get", "list"},
},
APIGroups: []string{"authentication.liqo.io"}, | ||
Resources: []string{"tenants"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
} | ||
|
||
// RemovePermissions removes the permissions related to the user. | ||
func RemovePermissions(ctx context.Context, c client.Client, clusterID liqov1beta1.ClusterID) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use client.IgnoreNotFound for the deletions? Could it be problematic when re-running this command if an error occured in the middle when run for the first time?
roleBindingList := &rbacv1.RoleBindingList{} | ||
|
||
if err := c.List(ctx, roleBindingList, &client.ListOptions{ | ||
LabelSelector: getUserLabelSelector(userName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LabelSelector: getUserLabelSelector(userName), | |
LabelSelector: userLabelSelector, |
Description
This PR introduces a set of commands allowing to generate a user with the minimum permissions to create a peering from the cluster with the specified cluster ID.
To create an user with the minimum permissions to peer with the current cluster from a cluster with ID $CLUSTER_ID:
to remove all the permissions to the user: