Skip to content

Commit e7f3ec8

Browse files
Add instanceprincipal clusteridentity support (#315)
* Suport instance principals in Cluster Identity
1 parent 45e5b26 commit e7f3ec8

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

api/v1beta2/ociclusteridentity_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type PrincipalType string
2727
const (
2828
// UserPrincipal represents a user principal.
2929
UserPrincipal PrincipalType = "UserPrincipal"
30+
// InstancePrincipal represents a instance principal.
31+
InstancePrincipal PrincipalType = "InstancePrincipal"
3032
)
3133

3234
// OCIClusterIdentitySpec defines the parameters that are used to create an OCIClusterIdentity.

cloud/util/util.go

+19
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/oracle/cluster-api-provider-oci/cloud/scope"
2929
infrav2exp "github.com/oracle/cluster-api-provider-oci/exp/api/v1beta2"
3030
"github.com/oracle/oci-go-sdk/v65/common"
31+
"github.com/oracle/oci-go-sdk/v65/common/auth"
3132
"github.com/pkg/errors"
3233
corev1 "k8s.io/api/core/v1"
3334
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -136,6 +137,24 @@ func GetOrBuildClientFromIdentity(ctx context.Context, c client.Client, identity
136137
OciAuthConfigProvider: conf,
137138
ClientOverrides: clientOverrides})
138139

140+
if err != nil {
141+
return nil, err
142+
}
143+
return clientProvider, nil
144+
} else if identity.Spec.Type == infrastructurev1beta2.InstancePrincipal {
145+
provider, err := auth.InstancePrincipalConfigurationProvider()
146+
if err != nil {
147+
return nil, err
148+
}
149+
pool, err := getOCIClientCertPool(ctx, c, namespace, clientOverrides)
150+
if err != nil {
151+
return nil, err
152+
}
153+
clientProvider, err := scope.NewClientProvider(scope.ClientProviderParams{
154+
CertOverride: pool,
155+
OciAuthConfigProvider: provider,
156+
ClientOverrides: clientOverrides})
157+
139158
if err != nil {
140159
return nil, err
141160
}

docs/src/gs/multi-tenancy.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,21 @@ An empty `allowedNamespaces` object indicates that `OCIClusters` can use this id
6767
If this object is `nil`, no namespaces will be allowed, which is the default behavior of the field if not specified.
6868
> Note: NamespaceList will take precedence over Selector if both are set.
6969

70-
[iam-user]: https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#Required_Keys_and_OCIDs
70+
## Cluster Identity using Instance Principals
71+
72+
Cluster Identity also supports [Instance Principals][instance-principals]. The example `OCIClusterIdentity`
73+
spec shown below uses Instance Principals.
74+
75+
```yaml
76+
---
77+
kind: OCIClusterIdentity
78+
metadata:
79+
name: cluster-identity
80+
namespace: default
81+
spec:
82+
type: InstancePrincipal
83+
allowedNamespaces: {}
84+
```
85+
86+
[iam-user]: https://docs.oracle.com/en-us/iaas/Content/API/Concepts/apisigningkey.htm#Required_Keys_and_OCIDs
87+
[instance-principals]: https://docs.oracle.com/en-us/iaas/Content/Identity/Tasks/callingservicesfrominstances.htm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
2+
kind: OCIClusterIdentity
3+
metadata:
4+
name: cluster-identity-instance-principal
5+
spec:
6+
type: InstancePrincipal
7+
allowedNamespaces: {}
8+
---

test/e2e/data/infrastructure-oci/v1beta2/cluster-template-managed-virtual/cluster.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ metadata:
2525
name: "${CLUSTER_NAME}"
2626
spec:
2727
compartmentId: "${OCI_COMPARTMENT_ID}"
28+
identityRef:
29+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
30+
kind: OCIClusterIdentity
31+
name: cluster-identity-instance-principal
32+
namespace: "${NAMESPACE}"
2833
---
2934
kind: OCIManagedControlPlane
3035
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
bases:
1+
resources:
22
- ./cluster.yaml
33
- ./machine-pool.yaml
4+
- ./cluster-identity.yaml
45

56

0 commit comments

Comments
 (0)