Skip to content

Commit d9cd72a

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

File tree

185 files changed

+3507
-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.

185 files changed

+3507
-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+
Workload Identity uses a Resource Principal auth, which requires settings a couple of ENV variables on the provider pod, including the region where the cluster is deployed. To achieve this, make sure to specify the `provider.oci.auth.types.workload.resourcePrincipalVersion=<version>` and `provider.oci.auth.types.workload.resourcePrincipalRegion=<region>` parameters in the `values.yaml` for the Helm chart deployment, or as 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: "us-ashburn-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
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# OCI Secrets Store CSI Driver Provider
3+
#
4+
# Copyright (c) 2022 Oracle America, Inc. and its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
#
7+
8+
# This Deployment is used as a reference example of how to mount secrets into the pod
9+
# via Secrets Store CSI Driver and OCI Vault Provider.
10+
11+
apiVersion: apps/v1
12+
kind: Deployment
13+
metadata:
14+
name: nginx
15+
namespace: workload
16+
labels:
17+
app: nginx
18+
spec:
19+
selector:
20+
matchLabels:
21+
app: nginx
22+
template:
23+
metadata:
24+
labels:
25+
app: nginx
26+
spec:
27+
serviceAccountName: workload-sa
28+
automountServiceAccountToken: true
29+
containers:
30+
- name: nginx
31+
image: nginx:1.21.4-alpine
32+
ports:
33+
- containerPort: 80
34+
resources:
35+
limits:
36+
memory: 128Mi
37+
cpu: 200m
38+
volumeMounts:
39+
- name: 'some-creds'
40+
mountPath: '/mnt/secrets-store' # here are mounted secrets
41+
readOnly: true
42+
volumes:
43+
- name: some-creds
44+
csi:
45+
driver: 'secrets-store.csi.k8s.io'
46+
readOnly: true
47+
volumeAttributes:
48+
secretProviderClass: 'test-oci-provider-class' # here we reference particular SecretProviderClass
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# OCI Secrets Store CSI Driver Provider
3+
#
4+
# Copyright (c) 2022 Oracle America, Inc. and its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
#
7+
8+
# SecretProviderClass is a custom resource to provide driver configurations and
9+
# provider-specific parameters to the CSI driver.
10+
#
11+
# On pod start and restart, the driver will communicate with the provider to retrieve the secret content
12+
# from the external Secrets Store you have specified in the SecretProviderClass resource.
13+
#
14+
# For more information check: https://secrets-store-csi-driver.sigs.k8s.io/getting-started/usage.html
15+
#
16+
# This SecretProviderClass is used as a reference example of how to configure the OCI Vault provider.
17+
# Each SecretProviderClass enumerates secrets to mount into the pod.
18+
# So, multiple SecretProviderClass resources could exist in a single Kubernetes cluster.
19+
20+
apiVersion: secrets-store.csi.x-k8s.io/v1
21+
kind: SecretProviderClass
22+
metadata:
23+
name: test-oci-provider-class # SecretProviderClass name is referenced from pod definition
24+
namespace: workload
25+
spec:
26+
provider: oci # `provider` value is used as the provider socket name, must be constant
27+
parameters:
28+
# Each secret could be identified with `name` and either `stage` or `versionNumber`.
29+
# If both `stage` and `versionNumber` are omitted, default stage CURRENT is used.
30+
# Secret names could not be duplicated, since `name` field is used as a file name during the mounting.
31+
secrets: |
32+
- name: Secret-1
33+
stage: CURRENT
34+
- name: Secret-2
35+
versionNumber: 1
36+
fileName: src-db-password
37+
vaultId: ocid1.vault.oc1.phx.efszzxxbaabz6.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
38+
authType: workload # possible values are: user, instance, workload
39+
authSecretName: oci-config # required if authType is user and this value refers secret name contains user credentials for auth against vault
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# OCI Secrets Store CSI Driver Provider
3+
#
4+
# Copyright (c) 2022 Oracle America, Inc. and its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
#
7+
---
8+
apiVersion: v1
9+
kind: Namespace
10+
metadata:
11+
name: workload
12+
---
13+
apiVersion: v1
14+
kind: ServiceAccount
15+
metadata:
16+
name: workload-sa
17+
namespace: workload

0 commit comments

Comments
 (0)