Skip to content

Commit c9917bb

Browse files
Adding AWS IAM authentication support to clusteradm (#454)
Signed-off-by: Gaurav Jaswal <[email protected]> Co-authored-by: Ramesh Krishna <[email protected]>
1 parent 6d53922 commit c9917bb

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

pkg/cmd/join/cmd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var example = `
1717
%[1]s join --hub-token <tokenID.tokenSecret> --hub-apiserver <hub_apiserver_url> --cluster-name <cluster_name> --mode hosted --managed-cluster-kubeconfig <managed-cluster-kubeconfig-file>
1818
# join a cluster to the hub while the hub provided no valid CA data in kube-public namespace
1919
%[1]s join --hub-token <tokenID.tokenSecret> --hub-apiserver <hub_apiserver_url> --cluster-name <cluster_name> --ca-file <ca-file>
20+
%[1]s join --hub-token <tokenID.tokenSecret> --hub-apiserver <hub_apiserver_url> --cluster-name <cluster_name> --registration-auth awsirsa --hub-cluster-arn arn:aws:eks:us-west-2:123456789012:cluster/hub-cluster-1
2021
`
2122

2223
// NewCmd ...
@@ -77,5 +78,7 @@ func NewCmd(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, stream
7778
cmd.Flags().BoolVar(&o.createNameSpace, "create-namespace", true, "If true, create the operator namespace(open-cluster-management) and the agent namespace(open-cluster-management-agent for Default mode, <klusterlet-name> for Hosted mode), otherwise use existing one")
7879
cmd.Flags().BoolVar(&o.enableSyncLabels, "enable-sync-labels", false, "If true, sync the labels from klusterlet to all agent resources.")
7980
cmd.Flags().Int32Var(&o.clientCertExpirationSeconds, "client-cert-expiration-seconds", 31536000, "clientCertExpirationSeconds represents the seconds of a client certificate to expire.")
81+
cmd.Flags().StringVar(&o.registrationAuth, "registration-auth", "", "The type of authentication to use for registering and authenticating with hub")
82+
cmd.Flags().StringVar(&o.hubClusterArn, "hub-cluster-arn", "", "The arn of the hub cluster(i.e. EKS cluster) to which managed-cluster will join")
8083
return cmd
8184
}

pkg/cmd/join/exec.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"crypto/x509"
88
"encoding/pem"
99
"fmt"
10+
gherrors "github.com/pkg/errors"
1011
"os"
1112
"reflect"
1213
"strings"
@@ -49,8 +50,9 @@ import (
4950
const (
5051
AgentNamespacePrefix = "open-cluster-management-"
5152

52-
OperatorNamesapce = "open-cluster-management"
53-
DefaultOperatorName = "klusterlet"
53+
OperatorNamesapce = "open-cluster-management"
54+
DefaultOperatorName = "klusterlet"
55+
AwsIrsaAuthentication = "awsirsa"
5456
)
5557

5658
func format(s string) string {
@@ -148,6 +150,24 @@ func (o *Options) complete(cmd *cobra.Command, args []string) (err error) {
148150
genericclioptionsclusteradm.SpokeMutableFeatureGate, ocmfeature.DefaultSpokeRegistrationFeatureGates),
149151
ClientCertExpirationSeconds: o.clientCertExpirationSeconds,
150152
}
153+
154+
// set registration auth type
155+
if o.registrationAuth == AwsIrsaAuthentication {
156+
rawConfig, err := o.ClusteradmFlags.KubectlFactory.ToRawKubeConfigLoader().RawConfig()
157+
if err != nil {
158+
klog.Errorf("unable to load managedcluster kubeconfig: %v", err)
159+
return err
160+
}
161+
162+
o.klusterletChartConfig.Klusterlet.RegistrationConfiguration.RegistrationDriver = operatorv1.RegistrationDriver{
163+
AuthType: o.registrationAuth,
164+
AwsIrsa: &operatorv1.AwsIrsa{
165+
HubClusterArn: o.hubClusterArn,
166+
ManagedClusterArn: rawConfig.Contexts[rawConfig.CurrentContext].Cluster,
167+
},
168+
}
169+
}
170+
151171
o.klusterletChartConfig.Klusterlet.WorkConfiguration = operatorv1.WorkAgentConfiguration{
152172
FeatureGates: genericclioptionsclusteradm.ConvertToFeatureGateAPI(
153173
genericclioptionsclusteradm.SpokeMutableFeatureGate, ocmfeature.DefaultSpokeWorkFeatureGates),
@@ -293,6 +313,10 @@ func (o *Options) validate() error {
293313
return err
294314
}
295315

316+
if (o.registrationAuth == AwsIrsaAuthentication) && (o.hubClusterArn == "") {
317+
return gherrors.New("hubClusterArn cannot be empty if registrationAuth type is awsirsa")
318+
}
319+
296320
return nil
297321
}
298322

pkg/cmd/join/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ type Options struct {
8686
enableSyncLabels bool
8787

8888
clientCertExpirationSeconds int32
89+
90+
// The type of authentication to use for registering and authenticating with hub
91+
registrationAuth string
92+
93+
// The arn of hub cluster(i.e. EKS) to which managed-cluster will join
94+
hubClusterArn string
8995
}
9096

9197
func newOptions(clusteradmFlags *genericclioptionsclusteradm.ClusteradmFlags, streams genericiooptions.IOStreams) *Options {

0 commit comments

Comments
 (0)