Security and monitoring
Authentication, authorisation and TLS for Data Grid, and the Prometheus metrics and Grafana panels that show whether the cluster is healthy.
The install lab left you with a generated developer user, TLS on the Service, and no view of what the cluster is doing. This lab splits that user into roles, checks the certificate, and scrapes metrics. It is the same shape as the Redis security lab: a non-admin identity, a network boundary, and a graph.
Identities and roles
With security.authorization.enabled: true, every cache operation is checked against a role. The roles Data Grid ships are:
| Role | What it is for |
|---|---|
admin |
The operator and a human. Configuration, caches, backup, ACLs. |
deployer |
Create and remove caches. |
application |
Read and write entries. This is the application. |
observer |
Read entries. |
monitor |
The metrics endpoint, and little else. |
The generated secret's developer user is convenient and too strong once more than one team shares the cluster. Write an identities.yaml and point endpointSecretName at a Secret that contains it. The operator stops managing passwords for you the moment you do. Keep a copy of the file in a password store.
credentials:
- username: app
password: "replace-me"
roles:
- application
- username: monitor
password: "replace-me"
roles:
- monitor
- username: ops
password: "replace-me"
roles:
- admin
oc create secret generic datagrid-identities -n datagrid \
--from-file=identities.yaml=identities.yaml
spec:
security:
endpointAuthentication: true
endpointSecretName: datagrid-identities
authorization:
enabled: true
Roll the pods only if the operator did not do it for you, then:
oc exec -n datagrid example-infinispan-0 -- \
curl -sk -o /dev/null -w '%{http_code}\n' -u 'app:replace-me' \
https://localhost:11222/rest/v2/caches/catalog/sku-42
oc exec -n datagrid example-infinispan-0 -- \
curl -sk -o /dev/null -w '%{http_code}\n' -u 'app:replace-me' \
https://localhost:11222/rest/v2/cluster
The first call is 200 or 404 (the key may be absent). The second is 403. app can use the cache and cannot reconfigure the cluster. monitor should get 200 on /metrics and 403 on a cache write. If app can POST a new cache, it has deployer or admin. Take it off.
Applications read the password from a Secret via an environment variable, as in the connecting lab. Rotating it is a change to identities.yaml and to that Secret, then a restart of Data Grid and of the clients. There is no silent rotation.
TLS and the network
The operator serves HTTPS with a certificate the Service presents. Clients trust service-ca.crt. Do not switch the Service to plain HTTP to unblock a client. Fix the truststore.
oc exec -n datagrid example-infinispan-0 -- \
curl -sv https://example-infinispan:11222/rest/v2/cache-managers 2>&1 \
| awk '/subject:|issuer:|expire /'
A certificate that expires next week is an outage you can schedule. The service CA rotates it. A client that pinned the old leaf, instead of trusting the CA, will break on that rotation. Trust the CA.
A NetworkPolicy should allow 11222 from the application namespaces and from openshift-user-workload-monitoring, and from nowhere else. Prometheus will show every target down if the policy forgets the scraper. That is the same failure mode as a bad ServiceMonitor, so check the policy first when a previously green target goes dark after a lockdown.
Cross-site relays are a second listener. Restrict who can get pods in datagrid. On the current operator, cross-site TLS can place keystore passwords in the Gossip Router arguments, and those arguments are visible to anyone who can read the pod.
Metrics
User-workload monitoring has to be enabled. Data Grid exposes Prometheus text on /metrics over the same HTTPS port, and it demands the monitor user.
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-infinispan
namespace: datagrid
spec:
selector:
matchLabels:
app: infinispan-service
clusterName: example-infinispan
endpoints:
- port: infinispan
path: /metrics
scheme: https
interval: 30s
tlsConfig:
insecureSkipVerify: true
ca:
configMap:
name: kube-root-ca.crt
key: ca.crt
basicAuth:
username:
name: datagrid-identities
key: monitor-user
password:
name: datagrid-identities
key: monitor-password
The selector and the port name have to match oc get svc -n datagrid -o yaml. The generated Service is labelled with the cluster name. If you kept passwords only inside identities.yaml, create two more keys on a Secret (monitor-user, monitor-password) for the ServiceMonitor. Prometheus cannot parse the YAML file. insecureSkipVerify is a lab shortcut. Prefer the service CA bundle the cluster already mounts, so a stray endpoint cannot impersonate Data Grid.
Metrics worth a panel:
| Metric | What a bad value means |
|---|---|
vendor:cache_manager_number_of_entries_in_memory or the cache's entry gauge |
Growth without a matching business reason. A session leak, or an unbounded key. |
| Cache hit and miss counts | A cache that never hits is a hop you can remove. |
| Eviction count | Non-zero on a cache that is supposed to be complete. See cache modes. |
| Cross-site status, once you have a backup location | A site taken offline. The DR is stale until you bring it back. |
Alert on the process being absent, on the cluster not WellFormed, and on a cross-site location offline. Alert on eviction only for the caches where eviction is a defect. Grafana on OpenShift reads the same Prometheus. Four panels are enough: entries, hit ratio, evictions, site status.
A backup that fails will not show up as a cache metric. oc get backup belongs in the same operational check as the dashboard. The platform testing lab is where that check becomes a drill.
What's next
This is the last Data Grid lab. The series starts at the overview. Platform-wide policy around both Redis and Data Grid is Security. Traces of the application calls that miss the cache are Tracing.