Chapter 1. Control access to Loki logs
Control which users can access logs stored in Loki by configuring role-based access control.
1.1. Fine grained access for Loki logs Copy linkLink copied to clipboard!
Configure fine-grained access to logs using cluster-wide policies, namespace-scoped policies, or custom admin groups.
The Red Hat OpenShift Logging Operator does not grant all users access to logs by default. As an administrator, configure your users' access unless you upgraded the Operator and prior configurations are in place. Depending on your configuration and need, configure fine-grained access to logs by using the following:
- Cluster wide policies
- Namespace scoped policies
- Creation of custom admin groups
As an administrator, you need to create the role bindings and cluster role bindings appropriate for your deployment. The Red Hat OpenShift Logging Operator provides the following cluster roles:
-
cluster-logging-application-viewgrants permission to read application logs. -
cluster-logging-infrastructure-viewgrants permission to read infrastructure logs. -
cluster-logging-audit-viewgrants permission to read audit logs.
If you have upgraded from a prior version, an additional cluster role logging-application-logs-reader and associated cluster role binding logging-all-authenticated-application-logs-reader provide backward compatibility, allowing any authenticated user read access in their namespaces.
Users with access by namespace must provide a namespace when querying application logs.
1.1.1. Cluster wide access Copy linkLink copied to clipboard!
Cluster role binding resources reference cluster roles, and set permissions cluster wide.
Example ClusterRoleBinding
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: logging-all-application-logs-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-logging-application-view
subjects:
- kind: Group
name: system:authenticated
apiGroup: rbac.authorization.k8s.io
name-
Additional
ClusterRolesarecluster-logging-infrastructure-view, andcluster-logging-audit-view. subjects- Specifies the users or groups this object applies to.
1.1.2. Namespaced access Copy linkLink copied to clipboard!
Use RoleBinding resources with ClusterRole objects to define the namespaces for which a user or group can access logs.
Example RoleBinding for a User
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: allow-read-logs
namespace: log-test-0
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-logging-application-view
subjects:
- kind: User
apiGroup: rbac.authorization.k8s.io
name: testuser-0
namespace-
Specifies the namespace this
RoleBindingapplies to.
Example RoleBinding for a ServiceAccount
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: allow-sa-read-logs
namespace: log-test-0
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-logging-application-view
subjects:
- kind: ServiceAccount
name: log-reader-sa
namespace: log-test-0
namespace-
Specifies the namespace this
RoleBindingapplies to. name-
The
ServiceAccountmust have permission to list projects for namespace-scoped log access.
When granting namespace-scoped access to a ServiceAccount, also grant the service account permission to list projects. Create a ClusterRoleBinding that binds the service account to the self-provisioner cluster role or create a custom ClusterRole with project list permissions.
1.1.3. Custom admin group access Copy linkLink copied to clipboard!
For large deployments with several users who require broader permissions, create a custom group by using the adminGroup field. Users who are members of any group specified in the adminGroups field of the LokiStack CR have administrator permissions.
Administrator users have access to all application logs in all namespaces, if they also get assigned the cluster-logging-application-view role.
To grant cluster-wide log access to a ServiceAccount, add the service account’s group to the adminGroups field in the LokiStack CR. The service account group follows the format system:serviceaccounts:<namespace> for all service accounts in a namespace, or system:serviceaccount:<namespace>:<name> for a specific service account.
Example LokiStack CR
apiVersion: loki.grafana.com/v1
kind: LokiStack
metadata:
name: logging-loki
namespace: openshift-logging
spec:
tenants:
mode: openshift-logging
openshift:
adminGroups:
- cluster-admin
- custom-admin-group
- system:serviceaccount:openshift-logging:log-reader-sa
mode- Custom admin groups are only available in this mode.
adminGroups-
Entering an empty list
[]value for this field disables admin groups. custom-admin-group-
Overrides the default groups (
system:cluster-admins,cluster-admin,dedicated-admin) system:serviceaccount:openshift-logging:log-reader-sa-
Grants cluster-wide log access to a specific
ServiceAccount.
1.2. Create a new group for the cluster-admin user role Copy linkLink copied to clipboard!
Create a new group to assign cluster-admin user role permissions.
Querying application logs for multiple namespaces as a cluster-admin user, where the sum total of characters of all of the namespaces in the cluster is greater than 5120, results in the error Parse error: input size too long (XXXX > 5120). For better control over access to logs in LokiStack, make the cluster-admin user a member of the cluster-admin group. If the cluster-admin group does not exist, create it and add the desired users to it.
Use the following procedure to create a new group for users with cluster-admin permissions.
Procedure
Enter the following command to create a new group:
$ oc adm groups new cluster-adminEnter the following command to add the required user to the
cluster-admingroup:$ oc adm groups add-users cluster-admin <username>Enter the following command to add
cluster-adminuser role to the group:$ oc adm policy add-cluster-role-to-group cluster-admin cluster-admin