Skip to content

Commit 62ddaa1

Browse files
committed
Add Workload Identity as an auth mechanism
1 parent 8d6041e commit 62ddaa1

File tree

182 files changed

+3409
-1292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+3409
-1292
lines changed

GettingStarted.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The provider is a gRPC server accessible via the Unix domain socket. It's interf
1111
* [Authentication & Authorization](#authn-authz)
1212
* [User Principal](#auth-user-principal)
1313
* [Instance Princiapl](#auth-instance-principal)
14+
* [Workload Identity](#auth-workload-identity)
1415
* [Access Policies](#access-policies)
1516
* [Deployment](#deployment)
1617
* [Helm](#helm-deployment)
@@ -49,9 +50,10 @@ This section describes steps to deploy and test solution.
4950

5051
<a name="authn-authz"></a>
5152
### Authentication and Authorization
52-
Currently, two modes of authentication is supported. Some AuthN modes are applicable only for a particular variant of cluster.
53+
Currently, three modes of authentication is supported. Some AuthN modes are applicable only for a particular variant of cluster.
5354
* [User Principal](#auth-user-principal)
5455
* [Instance Principal](#auth-instance-principal)
56+
* [Workload Identity](#auth-workload-identity)
5557

5658
<a name="auth-user-principal"></a>
5759
### User Principal
@@ -73,6 +75,15 @@ kubectl create secret generic oci-config \
7375
### Instance Principal
7476
Instance principal would work only on OKE cluster.
7577
Access should be granted using Access Policies(See [Access Policies](#access-polices) section).
78+
79+
<a name="auth-workload-identity"></a>
80+
### Workload Identity
81+
Workload Identity works only in OKE Enhanced clusters.
82+
83+
Access should be granted using Access Policies(See [Access Policies for Workloads](#access-policies-workloads) section).
84+
85+
Worklaod Identity uses a Resource Principal auth, which requires settings a couple ENV variables on the pod, including the region where the cluster is deployed. To achieve this, make sure to specify the `provider.oci.auth.types.workloadIdentity.enabled=true` and `provider.oci.auth.types.workloadIdentity.region=<region>` parameters in the `values.yaml` for the Helm chart deployment, or as an inline parameters.
86+
7687
<a name="access-policies"></a>
7788
### Access Policies
7889
Access to the vault and secrets should be explicity granted using Policies in case of Instance principal authencation or other users(non owner of vault) or groups of tenancy in case of user principal authentication.
@@ -103,6 +114,13 @@ It involves two steps
103114

104115
More information on [Policy](https://docs.oracle.com/en-us/iaas/Content/Identity/Concepts/policysyntax.htm)
105116

117+
<a name="access-policies-workload"></a>
118+
### Access Policies for Workloads
119+
120+
With Workload Identity authentication, only a policy is required, which defines the kubernetes workload the policy works for:
121+
122+
`allow any-user to use secret-family in compartment <compartment-name> where ALL {request.principal.type='workload', request.principal.namespace ='<namespace>', request.principal.service_account = 'oci-secrets-store-csi-driver-provider-sa', request.principal.cluster_id = 'ocid1.cluster.oc1....'}`
123+
106124
<a name="deployment"></a>
107125
### Deployment
108126
Provider and Driver would be deployed as Daemonset. `kube-system` namespace is preferred, but not restricted.
@@ -132,7 +150,7 @@ Default values are provided in `charts/oci-secrets-store-csi-driver-provider/val
132150
kubectl apply -f deploy/provider.daemonset.yaml
133151
kubectl apply -f deploy/provider.serviceaccount.yaml
134152
135-
# if user authention principal is required
153+
# if user authentication principal is required
136154
kubectl apply -f deploy/provider.roles.yaml
137155
```
138156
<a name="provider-verification"></a>

charts/oci-secrets-store-csi-driver-provider/templates/provider.daemonset.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ spec:
4242
name: health-port
4343
- containerPort: {{ .Values.provider.metricsPort }}
4444
name: metrics-port
45+
{{ if .Values.provider.oci.auth.types.workload.enabled }}
46+
env:
47+
- name: OCI_RESOURCE_PRINCIPAL_VERSION
48+
value: {{ .Values.provider.oci.auth.types.workload.resourcePrincipalVersion | quote }}
49+
- name: OCI_RESOURCE_PRINCIPAL_REGION
50+
value: {{ .Values.provider.oci.auth.types.workload.resourcePrincipalRegion }}
51+
{{ end }}
4552
resources:
4653
{{- toYaml .Values.provider.resources | nindent 12 }}
4754
# Container should run as root to mount the hostPath volume and create Unix Domain Socket in that volume.

charts/oci-secrets-store-csi-driver-provider/templates/provider.roles.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,29 @@ subjects:
2727
- kind: ServiceAccount
2828
name: {{ .Chart.Name }}-sa
2929
namespace: {{ .Release.Namespace }}
30-
{{ end }}
30+
{{ end }}
31+
32+
{{ if .Values.provider.oci.auth.types.workload.enabled }}
33+
---
34+
apiVersion: rbac.authorization.k8s.io/v1
35+
kind: ClusterRole
36+
metadata:
37+
name: {{ .Chart.Name }}-workload-identity-cluster-role
38+
rules:
39+
- apiGroups: [""]
40+
resources: ["serviceaccounts/token"]
41+
verbs: ["create"]
42+
---
43+
apiVersion: rbac.authorization.k8s.io/v1
44+
kind: ClusterRoleBinding
45+
metadata:
46+
name: {{ .Chart.Name }}-workload-identity-cluster-rolebinding
47+
roleRef:
48+
apiGroup: rbac.authorization.k8s.io
49+
kind: ClusterRole
50+
name: {{ .Chart.Name }}-workload-identity-cluster-role
51+
subjects:
52+
- kind: ServiceAccount
53+
name: {{ .Chart.Name }}-sa
54+
namespace: {{ .Release.Namespace }}
55+
{{ end }}

charts/oci-secrets-store-csi-driver-provider/values.schema.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@
104104
}
105105
}
106106
},
107+
"workload": {
108+
"description": "Settings for OCI Workload authentication",
109+
"type": "object",
110+
"properties": {
111+
"enabled": {
112+
"description": "Settings for OCI Workload authentication",
113+
"type": "boolean"
114+
},
115+
"resourcePrincipalVersion": {
116+
"description": "Settings for OCI Workload authentication",
117+
"type": "string"
118+
},
119+
"resourcePrincipalRegion": {
120+
"description": "Settings for OCI Workload authentication",
121+
"type": "string"
122+
}
123+
}
124+
},
107125
"additionalProperties": false
108126
}
109127
},

charts/oci-secrets-store-csi-driver-provider/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ provider:
3535
enabled: true
3636
user:
3737
enabled: true
38+
workload:
39+
enabled: true
40+
resourcePrincipalVersion: "2.2"
41+
resourcePrincipalRegion: "sa-bogota-1"
42+
3843

3944
# socket endpoint for connections
4045
endpoint: "unix:///opt/provider/sockets/oci.sock"

deploy/example/app.deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ spec:
2323
labels:
2424
app: nginx
2525
spec:
26+
# serviceAccountName: workload-serviceaccount
27+
# automountServiceAccountToken: true
2628
containers:
2729
- name: nginx
2830
image: nginx:1.21.4-alpine

deploy/example/secret-provider-class.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ spec:
3434
versionNumber: 1
3535
fileName: src-db-password
3636
vaultId: ocid1.vault.oc1..aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
37-
authType: instance # possible values are: user, instance
37+
authType: instance # possible values are: user, instance, workload
3838
authSecretName: oci-config # required if authType is user and this value refers secret name contains user credentials for auth against vault

deploy/provider.daemonset.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ spec:
3636
- --metrics-port=8198
3737
- --enable-pprof=true
3838
- --pprof-port=6060
39+
env:
40+
- name: OCI_RESOURCE_PRINCIPAL_VERSION
41+
value: "2.2"
42+
- name: OCI_RESOURCE_PRINCIPAL_REGION
43+
value: "us-ashburn-1"
3944
resources:
4045
requests:
4146
cpu: 50m

deploy/provider.roles.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ rules:
1313
- apiGroups: [""]
1414
resources: ["secrets"]
1515
verbs: ["get"]
16+
- apiGroups: [""]
17+
resources: ["serviceaccounts/token"]
18+
verbs: ["create"]
1619
---
1720
apiVersion: rbac.authorization.k8s.io/v1
1821
kind: ClusterRoleBinding

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/oracle-samples/oci-secrets-store-csi-driver-provider
33
go 1.19
44

55
require (
6-
github.com/oracle/oci-go-sdk/v65 v65.3.0
6+
github.com/oracle/oci-go-sdk/v65 v65.61.1
77
github.com/pkg/errors v0.9.1
88
github.com/rs/zerolog v1.26.1
99
go.opentelemetry.io/otel v0.20.0
@@ -51,7 +51,7 @@ require (
5151
go.opentelemetry.io/otel/trace v0.20.0 // indirect
5252
golang.org/x/net v0.7.0 // indirect
5353
golang.org/x/oauth2 v0.4.0 // indirect
54-
golang.org/x/sys v0.5.0 // indirect
54+
golang.org/x/sys v0.8.0 // indirect
5555
golang.org/x/term v0.5.0 // indirect
5656
golang.org/x/text v0.7.0 // indirect
5757
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect

0 commit comments

Comments
 (0)