![]() |
VOOZH | about |
For enhanced security, the Datadog Operator can retrieve Datadog credentials (API key and application key) using Secrets.
Choose one of the following methods to set up Secrets:
This method is recommended for testing purposes only.
Add your API and application keys to the DatadogAgent spec:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:credentials:apiKey:<DATADOG_API_KEY>appKey:<DATADOG_APP_KEY># ...The credentials provided here are stored in a Secret created by the Operator. By properly setting the RBAC on the DatadogAgent CRD, you can limit who is able to see those credentials.
Create your Secrets:
apiVersion:v1kind:Secretmetadata:name:datadog-api-secretdata:api_key:<DATADOG_API_KEY>---apiVersion:v1kind:Secretmetadata:name:datadog-app-secretdata:app_key:<DATADOG_APP_KEY>Provide the names of these Secrets in your DatadogAgent resource:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:credentials:apiSecret:secretName:datadog-api-secretkeyName:api-keyappSecret:secretName:datadog-app-secretkeyName:app-key# ...Note: You can also use the same Secret to store both credentials:
---apiVersion:v1kind:Secretmetadata:name:datadog-secretdata:api_key:<DATADOG_API_KEY>app_key:<DATADOG_APP_KEY>Then, in your DatadogAgent resource:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:credentials:apiSecret:secretName:datadog-secretkeyName:api-keyappSecret:secretName:datadog-secretkeyName:app-key# ...The Datatog Operator is compatible with the secret backend.
Create a Datadog Operator container image that contains the secret backend command.
If you’d like to build your own, the following Dockerfile example takes the latest image as the base image and copies the my-secret-backend.sh script file:
FROMgcr.io/datadoghq/operator:latestCOPY ./my-secret-backend.sh /my-secret-backend.shRUN chmod 755 /my-secret-backend.shThen, run:
docker build -t datadog-operator-with-secret-backend:latest .
Install or update the Datadog Operator deployment with the .Values.secretBackend.command parameter set to the secret backend command path (inside the container). If you are using a custom image, update the image.
$ helm [install|upgrade] dd-operator --set "secretBackend.command=/my-secret-backend.sh" --set "image.repository=datadog-operator-with-secret-backend" ./chart/datadog-operator
Note: Requires Datadog Operator v0.5.0+.
Kubernetes supports exposing Secrets as files inside a pod. Datadog provides a helper script in the Datadog Operator image to read the Secrets from files.
Mount the Secret in the Operator container. For example, you can mount it at /etc/secret-volume.
Install or update the Datadog Operator deployment with the .Values.secretBackend.command parameter set to /readsecret.sh and the .Values.secretBackend.arguments parameter set to /etc/secret-volume:
helm [install|upgrade] dd-operator --set "secretBackend.command=/readsecret.sh" --set "secretBackend.arguments=/etc/secret-volume" ./chart/datadog-operator
Note: Requires Datadog Operator v1.11+.
If you are using a custom script, create a Datadog Agent (or Cluster Agent) image and specify credentials using ENC[<placeholder>], and specify the secret backend command in spec.global.secretBackend.command:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:credentials:apiKey:ENC[<api-key-secret-id>]appKey:ENC[<app-key-secret-id>]secretBackend:command:"/my-secret-backend.sh"# ...The environment variable DD_SECRET_BACKEND_COMMAND from this configuration is automatically applied to all the deployed components: node Agent, Cluster Agent, and Cluster Checks Runners. Ensure the image you are using for all the components includes your command.
For convenience, the Datadog Agent and its sibling Cluster Agent images include a readsecret_multiple_providers.sh helper function that can be used to read from both files as well as Kubernetes Secrets. After you create the Secret, set spec.global.secretBackend.command to "/readsecret_multiple_providers.sh".
For instance, to use the secret backend for the Agent and Cluster Agent, create a Secret called “test-secret”:
kubectl create secret generic test-secret --from-literal=api_key='<api-key>' --from-literal=app_key='<app-key>'
And then set the DatadogAgent spec:
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:secretBackend:command:"/readsecret_multiple_providers.sh"credentials:apiKey:ENC[k8s_secret@default/test-secret/api_key]appKey:ENC[k8s_secret@default/test-secret/app_key]Datadog Agent also can be integrated with other secret management solutions, such as AWS Secrets Manager, HashiCorp Vault, GCP Secret Manager and more. Configurations depend on each backend type. Please see the instructions for more information.
The "/readsecret_multiple_providers.sh" helper enables the Agent to directly read Kubernetes Secrets across both its own and other namespaces. Ensure that the associated ServiceAccount has the necessary permissions by assigning the appropriate Roles and RoleBindings. You can set these manually, or by using the following options:
global.secretBackend.enableGlobalPermissions: Determines if a ClusterRole is created that enables the Agents to read all Kubernetes Secrets.
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:secretBackend:command:"/readsecret_multiple_providers.sh"enableGlobalPermissions:true# ...global.secretBackend.roles: Replaces enableGlobalPermissions, detailing the list of namespace/secrets to which the Agents should have access.
apiVersion:datadoghq.com/v2alpha1kind:DatadogAgentmetadata:name:datadogspec:global:secretBackend:command:"/readsecret_multiple_providers.sh"roles:- namespace:rabbitmq-systemsecrets:- "rabbitmqcluster-sample-default-user"# ...In this example, a Role is created granting read access to the Secret rabbitmqcluster-sample-default-user in the rabbitmq-system namespace.
Note: Each namespace in the roles list must also be configured in the WATCH_NAMESPACE or DD_AGENT_WATCH_NAMESPACE environment variable on the Datadog Operator deployment.
For the Agent and Cluster Agent, there are other configuration options for the secret backend command:
global.secretBackend.args: These arguments are supplied to the command when the Agent executes the secret backend command.global.secretBackend.timeout: Secret backend execution timeout in seconds. The default value is 30 seconds.For versions prior to Operator 1.11, spec.global.secretBackend is unavailable. You should follow these instructions instead.
| |