Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 2. Managing secrets securely using Secrets Store CSI driver with GitOps
This guide walks you through the process of integrating the Secrets Store Container Storage Interface (SSCSI) driver with the GitOps Operator in OpenShift Container Platform 4.14 and later.
2.1. Overview of managing secrets using Secrets Store CSI driver with GitOps Copier lienLien copié sur presse-papiers!
Some applications need sensitive information, such as passwords and usernames which must be concealed as good security practice. If sensitive information is exposed because role-based access control (RBAC) is not configured properly on your cluster, anyone with API or etcd access can retrieve or modify a secret.
Anyone who is authorized to create a pod in a namespace can use that RBAC to read any secret in that namespace. With the SSCSI Driver Operator, you can use an external secrets store to store and provide sensitive information to pods securely.
The process of integrating the OpenShift Container Platform SSCSI driver with the GitOps Operator consists of the following procedures:
2.1.1. Benefits Copier lienLien copié sur presse-papiers!
Integrating the SSCSI driver with the GitOps Operator provides the following benefits:
- Enhance the security and efficiency of your GitOps workflows
- Facilitate the secure attachment of secrets into deployment pods as a volume
- Ensure that sensitive information is accessed securely and efficiently
2.1.2. Secrets store providers Copier lienLien copié sur presse-papiers!
The following secrets store providers are available for use with the Secrets Store CSI Driver Operator:
- AWS Secrets Manager
- AWS Systems Manager Parameter Store
- Microsoft Azure Key Vault
As an example, consider that you are using AWS Secrets Manager as your secrets store provider with the SSCSI Driver Operator. The following example shows the directory structure in GitOps repository that is ready to use the secrets from AWS Secrets Manager:
Example directory structure in GitOps repository
- 2
- Directory that stores the
aws-provider.yamlfile. - 3
- Configuration file that installs the AWS Secrets Manager provider and deploys resources for it.
- 1
- Configuration file that creates an application and deploys resources for AWS Secrets Manager.
- 4
- Directory that stores the deployment pod and credential requests.
- 5
- Directory that stores the
SecretProviderClassresources to define your secrets store provider. - 6
- Folder that stores the
credentialsrequest.yamlfile. This file contains the configuration for the credentials request to mount a secret to the deployment pod.
2.2. Prerequisites Copier lienLien copié sur presse-papiers!
-
You have access to the cluster with
cluster-adminprivileges. - You have access to the OpenShift Container Platform web console.
-
You have extracted and prepared the
ccoctlbinary. -
You have installed the
jqCLI tool. - Your cluster is installed on AWS and uses AWS Security Token Service (STS).
- You have configured AWS Secrets Manager to store the required secrets.
- SSCSI Driver Operator is installed on your cluster.
- Red Hat OpenShift GitOps Operator is installed on your cluster.
- You have a GitOps repository ready to use the secrets.
- You are logged in to the Argo CD instance by using the Argo CD admin account.
2.3. Storing AWS Secrets Manager resources in GitOps repository Copier lienLien copié sur presse-papiers!
This guide provides instructions with examples to help you use GitOps workflows with the Secrets Store Container Storage Interface (SSCSI) Driver Operator to mount secrets from AWS Secrets Manager to a CSI volume in OpenShift Container Platform.
Using the SSCSI Driver Operator with AWS Secrets Manager is not supported in a hosted control plane cluster.
Prerequisites
-
You have access to the cluster with
cluster-adminprivileges. - You have access to the OpenShift Container Platform web console.
-
You have extracted and prepared the
ccoctlbinary. -
You have installed the
jqCLI tool. - Your cluster is installed on AWS and uses AWS Security Token Service (STS).
- You have configured AWS Secrets Manager to store the required secrets.
- SSCSI Driver Operator is installed on your cluster.
- Red Hat OpenShift GitOps Operator is installed on your cluster.
- You have a GitOps repository ready to use the secrets.
- You are logged in to the Argo CD instance by using the Argo CD admin account.
Procedure
Install the AWS Secrets Manager provider and add resources:
In your GitOps repository, create a directory and add
aws-provider.yamlfile in it with the following configuration to deploy resources for the AWS Secrets Manager provider:ImportantThe AWS Secrets Manager provider for the SSCSI driver is an upstream provider.
This configuration is modified from the configuration provided in the upstream AWS documentation so that it works properly with OpenShift Container Platform. Changes to this configuration might impact functionality.
Example
aws-provider.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add a
secret-provider-app.yamlfile in your GitOps repository to create an application and deploy resources for AWS Secrets Manager:Example
secret-provider-app.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Update the value of the
repoURLfield to point to your GitOps repository.
Synchronize resources with the default Argo CD instance to deploy them in the cluster:
Add a label to the
openshift-cluster-csi-driversnamespace your application is deployed in so that the Argo CD instance in theopenshift-gitopsnamespace can manage it:oc label namespace openshift-cluster-csi-drivers argocd.argoproj.io/managed-by=openshift-gitops
$ oc label namespace openshift-cluster-csi-drivers argocd.argoproj.io/managed-by=openshift-gitopsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the resources in your GitOps repository to your cluster, including the
aws-provider.yamlfile you just pushed:Example output
application.argoproj.io/argo-app created application.argoproj.io/secret-provider-app created ...
application.argoproj.io/argo-app created application.argoproj.io/secret-provider-app created ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow
In the Argo CD UI, you can observe that the csi-secrets-store-provider-aws daemonset continues to synchronize resources. To resolve this issue, you must configure the SSCSI driver to mount secrets from the AWS Secrets Manager.
2.4. Configuring SSCSI driver to mount secrets from AWS Secrets Manager Copier lienLien copié sur presse-papiers!
To store and manage your secrets securely, use GitOps workflows and configure the Secrets Store Container Storage Interface (SSCSI) Driver Operator to mount secrets from AWS Secrets Manager to a CSI volume in OpenShift Container Platform. For example, consider that you want to mount a secret to a deployment pod under the dev namespace which is in the /environments/dev/ directory.
Prerequisites
- You have the AWS Secrets Manager resources stored in your GitOps repository.
Procedure
Grant privileged access to the
csi-secrets-store-provider-awsservice account by running the following command:oc adm policy add-scc-to-user privileged -z csi-secrets-store-provider-aws -n openshift-cluster-csi-drivers
$ oc adm policy add-scc-to-user privileged -z csi-secrets-store-provider-aws -n openshift-cluster-csi-driversCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
clusterrole.rbac.authorization.k8s.io/system:openshift:scc:privileged added: "csi-secrets-store-provider-aws"
clusterrole.rbac.authorization.k8s.io/system:openshift:scc:privileged added: "csi-secrets-store-provider-aws"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Grant permission to allow the service account to read the AWS secret object:
Create a
credentialsrequest-dir-awsfolder under a namespace-scoped directory in your GitOps repository because the credentials request is namespace-scoped. For example, create acredentialsrequest-dir-awsfolder under thedevnamespace which is in the/environments/dev/directory by running the following command:mkdir credentialsrequest-dir-aws
$ mkdir credentialsrequest-dir-awsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a YAML file with the following configuration for the credentials request in the
/environments/dev/credentialsrequest-dir-aws/path to mount a secret to the deployment pod in thedevnamespace:Example
credentialsrequest.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 2
- The namespace for the secret reference. Update the value of this
namespacefield according to your project deployment setup. - 1
- The ARN of your secret in the region where your cluster is on. The
<aws_region>of<aws_secret_arn>has to match the cluster region. If it does not match, create a replication of your secret in the region where your cluster is on.
TipTo find your cluster region, run the command:
oc get infrastructure cluster -o jsonpath='{.status.platformStatus.aws.region}'$ oc get infrastructure cluster -o jsonpath='{.status.platformStatus.aws.region}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
us-west-2
us-west-2Copy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve the OIDC provider by running the following command:
oc get --raw=/.well-known/openid-configuration | jq -r '.issuer'
$ oc get --raw=/.well-known/openid-configuration | jq -r '.issuer'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
https://<oidc_provider_name>
https://<oidc_provider_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the OIDC provider name
<oidc_provider_name>from the output to use in the next step.Use the
ccoctltool to process the credentials request by running the following command:ccoctl aws create-iam-roles \ --name my-role --region=<aws_region> \ --credentials-requests-dir=credentialsrequest-dir-aws \ --identity-provider-arn arn:aws:iam::<aws_account>:oidc-provider/<oidc_provider_name> --output-dir=credrequests-ccoctl-output$ ccoctl aws create-iam-roles \ --name my-role --region=<aws_region> \ --credentials-requests-dir=credentialsrequest-dir-aws \ --identity-provider-arn arn:aws:iam::<aws_account>:oidc-provider/<oidc_provider_name> --output-dir=credrequests-ccoctl-outputCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
2023/05/15 18:10:34 Role arn:aws:iam::<aws_account_id>:role/my-role-my-namespace-aws-creds created 2023/05/15 18:10:34 Saved credentials configuration to: credrequests-ccoctl-output/manifests/my-namespace-aws-creds-credentials.yaml 2023/05/15 18:10:35 Updated Role policy for Role my-role-my-namespace-aws-creds
2023/05/15 18:10:34 Role arn:aws:iam::<aws_account_id>:role/my-role-my-namespace-aws-creds created 2023/05/15 18:10:34 Saved credentials configuration to: credrequests-ccoctl-output/manifests/my-namespace-aws-creds-credentials.yaml 2023/05/15 18:10:35 Updated Role policy for Role my-role-my-namespace-aws-credsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the
<aws_role_arn>from the output to use in the next step. For example,arn:aws:iam::<aws_account_id>:role/my-role-my-namespace-aws-creds.Check the role policy on AWS to confirm the
<aws_region>of"Resource"in the role policy matches the cluster region:Example role policy
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Bind the service account with the role ARN by running the following command:
oc annotate -n <namespace> sa/<app_service_account> eks.amazonaws.com/role-arn="<aws_role_arn>"
$ oc annotate -n <namespace> sa/<app_service_account> eks.amazonaws.com/role-arn="<aws_role_arn>"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example command
oc annotate -n dev sa/default eks.amazonaws.com/role-arn="<aws_role_arn>"
$ oc annotate -n dev sa/default eks.amazonaws.com/role-arn="<aws_role_arn>"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
serviceaccount/default annotated
serviceaccount/default annotatedCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a namespace-scoped
SecretProviderClassresource to define your secrets store provider. For example, you create aSecretProviderClassresource in/environments/dev/apps/app-taxi/services/taxi/base/configdirectory of your GitOps repository.Create a
secret-provider-class-aws.yamlfile in the same directory where the target deployment is located in your GitOps repository:Example
secret-provider-class-aws.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that after pushing this YAML file to your GitOps repository, the namespace-scoped
SecretProviderClassresource is populated in the target application page in the Argo CD UI.NoteIf the Sync Policy of your application is not set to
Auto, you can manually sync theSecretProviderClassresource by clicking Sync in the Argo CD UI.
2.5. Configuring GitOps managed resources to use mounted secrets Copier lienLien copié sur presse-papiers!
You must configure the GitOps managed resources by adding volume mounts configuration to a deployment and configuring the container pod to use the mounted secret.
Prerequisites
- You have the AWS Secrets Manager resources stored in your GitOps repository.
- You have the Secrets Store Container Storage Interface (SSCSI) driver configured to mount secrets from AWS Secrets Manager.
Procedure
Configure the GitOps managed resources. For example, consider that you want to add volume mounts configuration to the deployment of
app-taxiapplication and the100-deployment.yamlfile is in the/environments/dev/apps/app-taxi/services/taxi/base/config/directory.Add the volume mounting to the deployment YAML file and configure the container pod to use the secret provider class resources and mounted secret:
Example YAML file
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Push the updated resource YAML file to your GitOps repository.
- In the Argo CD UI, click REFRESH on the target application page to apply the updated deployment manifest.
- Verify that all the resources are successfully synchronized on the target application page.
Verify that you can you can access the secrets from AWS Secrets manager in the pod volume mount:
List the secrets in the pod mount:
oc exec <deployment_name>-<hash> -n <namespace> -- ls /mnt/secrets-store/
$ oc exec <deployment_name>-<hash> -n <namespace> -- ls /mnt/secrets-store/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example command
oc exec taxi-5959644f9-t847m -n dev -- ls /mnt/secrets-store/
$ oc exec taxi-5959644f9-t847m -n dev -- ls /mnt/secrets-store/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
<secret_name>
<secret_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow View a secret in the pod mount:
oc exec <deployment_name>-<hash> -n <namespace> -- cat /mnt/secrets-store/<secret_name>
$ oc exec <deployment_name>-<hash> -n <namespace> -- cat /mnt/secrets-store/<secret_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example command
oc exec taxi-5959644f9-t847m -n dev -- cat /mnt/secrets-store/testSecret
$ oc exec taxi-5959644f9-t847m -n dev -- cat /mnt/secrets-store/testSecretCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
<secret_value>
<secret_value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow