Configure SLS DataAgent permissions

Updated at:

Simple Log Service (SLS) DataAgent permissions control two independent sets of access: what the users in your account can create and manage, and what data a DataAgent can read at runtime. If either set is incomplete, DataAgent creation fails or a DataAgent returns a permission error when it queries data. This topic describes how to prepare the DataAgent RAM role, grant permission policies to RAM users, and verify the result.

Permission model

Configure two objects separately: first prepare the RAM role that the DataAgent assumes, then grant management and use permissions to the users.

Object

Permissions to configure

Purpose

Users (Alibaba Cloud accounts or Resource Access Management (RAM) users)

SLS DataAgent management or use permissions, and ram:PassRole for the users who create DataAgents

Controls which models, DataAgents, and sessions a user can create, view, and update, and whether the user can pass a specified role to Simple Log Service

The DataAgent RAM role

SLS data read permissions and the trust policy

Controls which projects, LogStores, and other resources a DataAgent can access at runtime

A DataAgent answers questions based on the models bound to it, so a user who only chats with a DataAgent does not need model management permissions.

The configuration proceeds in the following order:

  1. Prepare the DataAgent RAM role.

  2. Grant permission policies to RAM users.

  3. Use the role ARN when you create a DataAgent.

  4. Verify the permissions.

Usage notes

  • Preview status — SLS DataAgent is in public preview. The RAM actions, the resource ARNs, and the system role name in this topic are tentative and may change before general availability.

  • Operating identity — An Alibaba Cloud account has all management permissions within the account by default. The one-time authorization of the system default role must be completed by the Alibaba Cloud account or by a RAM administrator.

  • Separation of duties — In a production environment, use RAM users and split the authorization by responsibility, for example, administrators, model maintainers, regular users, and auditors.

  • RAM console access — You create custom roles and grant policies in the RAM console.

  • Existing DataAgent — The least-privilege policy applies to a DataAgent that an administrator has already created.

Prepare the DataAgent RAM role

A DataAgent accesses SLS data at runtime through the RAM role that is bound to it. Choose one of the following role types:

  • System default role — The fastest path. Complete a one-time authorization and start using SLS DataAgent.

  • Custom role — Use this role type to limit DataAgent access to a business line, a project, or a LogStore.

Use the system default role

The system default role is aliyunslsdataagentrole. The first time your account uses SLS DataAgent, complete the one-time authorization on the role authorization page with your Alibaba Cloud account, or ask a RAM administrator to complete it.

Use a custom role

Use a custom role to limit the scope to a business line, a project, or a LogStore.

  1. Log on to the RAM console and create a role whose trusted entity type is Alibaba Cloud service.

  2. Set the service principal to Simple Log Service so that the role trusts log.aliyuncs.com.

  3. Grant the role the least privileges that the DataAgent requires to query the target data.

  4. Record the role ARN. You use the ARN when you create a DataAgent.

Important

Do not grant a custom role full write permissions at the account level. SLS DataAgent requires read access only to query and analyze data, so configure read-only permissions for a production role first.

The ram:PassRole permission is granted to the RAM user who creates the DataAgent, not to the DataAgent role. To allow a RAM user to pass the custom role to Simple Log Service, add the following statement to the user policy:

{
  "Version": "1",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "ram:PassRole",
      "Resource": "acs:ram::${accountId}:role/${roleName}",
      "Condition": {
        "StringEquals": {
          "acs:Service": "log.aliyuncs.com"
        }
      }
    }
  ]
}

Replace ${accountId} with the ID of your Alibaba Cloud account and ${roleName} with the name of the role that the RAM user can pass. Narrow Resource to the specific roles. Do not set it to *.

The full-use policy in Grant permission policies to RAM users already contains a ram:PassRole statement for the system default role and for a custom role, so you do not need a separate policy for the same role.

Grant permission policies to RAM users

Grant one of the following policies to your RAM users based on their responsibilities. In the RAM action names, a session is called a thread, for example, log:CreateThread and log:GetThreadData.

Scenario

Policy to grant

Chat only with DataAgents that an administrator has already created

Least privilege: chat with a DataAgent

Generate Source Models, create Context Models, create DataAgents, and chat

Full use: build models and create DataAgents

To grant a policy to a RAM user

  1. Log on to the RAM console.

  2. Create a policy from the JSON document that matches your scenario.

  3. Replace the placeholders in the JSON document with your actual values.

  4. Attach the policy to the target RAM users.

    Replace ${uid} with the ID of your Alibaba Cloud account. In the full-use policy, also replace ${customRoleName} with the name of your custom role.

Least privilege: chat with a DataAgent

This policy covers chatting with a DataAgent that an administrator has already created, including session management and retrieving answers and artifacts. It does not cover the management operations of Source Models, Context Models, or DataAgents. A DataAgent answers questions based on the Context Models bound to it, so a user who only chats does not need management permissions on those models.

{
  "Version": "1",
  "Statement": [{
    "Effect": "Allow",
    "Action": [
      "log:GetDataAgent",
      "log:ListDataAgents",
      "log:CreateThread",
      "log:ListThreads",
      "log:GetThread",
      "log:GetThreadData",
      "log:UpdateThread",
      "log:DeleteThread",
      "log:ListArtifacts",
      "log:GetArtifact",
      "log:GetArtifactDownloadUrl"
    ],
    "Resource": "acs:log:*:${uid}:dataagent/*"
  }]
}

Full use: build models and create DataAgents

This policy covers the end-to-end setup and use: generate and manage Source Models, create and manage Context Models, create and manage DataAgents, and chat.

{
  "Version": "1",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "log:CreateSourceModel",
        "log:DeleteSourceModel",
        "log:UpsertSourceModel",
        "log:RegenerateSourceModel",
        "log:DeleteSourceModelElement",
        "log:QuerySourceModel",
        "log:GetSourceModelStatus",
        "log:ListSourceModels"
      ],
      "Resource": "acs:log:*:${uid}:project/*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "log:CreateContextModel",
        "log:UpdateContextModel",
        "log:DeleteContextModel",
        "log:UpsertContextModel",
        "log:DeleteContextModelElement",
        "log:SyncContextModel",
        "log:GetContextModel",
        "log:ListContextModels",
        "log:QueryContextModel"
      ],
      "Resource": "acs:log:*:${uid}:contextmodel/*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "log:ListDataAgents",
        "log:CreateDataAgent",
        "log:GetDataAgent",
        "log:UpdateDataAgent",
        "log:DeleteDataAgent",
        "log:CreateThread",
        "log:ListThreads",
        "log:GetThread",
        "log:GetThreadData",
        "log:UpdateThread",
        "log:DeleteThread",
        "log:ListArtifacts",
        "log:GetArtifactDownloadUrl",
        "log:GetArtifact"
      ],
      "Resource": "acs:log:*:${uid}:dataagent/*"
    },
    {
      "Effect": "Allow",
      "Action": "ram:PassRole",
      "Resource": [
        "acs:ram::${uid}:role/aliyunslsdataagentrole",
        "acs:ram::${uid}:role/${customRoleName}"
      ],
      "Condition": {
        "StringEquals": {
          "acs:Service": "log.aliyuncs.com"
        }
      }
    }
  ]
}

Least privilege recommendations

  • Split the user policies by model management and by chat usage.

  • Create a separate RAM role for each business line of DataAgents.

  • Narrow the Source Model resources in the full-use policy from project/* to the projects that require modeling, such as project/my-project.

  • Narrow the Context Model resources and the DataAgent resources to a specific model name (contextmodel/orders) and a specific DataAgent name (dataagent/order-system-expert).

  • Narrow ram:PassRole to the roles that RAM users actually pass, which are the system default role aliyunslsdataagentrole or your custom role.

  • Grant the DataAgent role read-only SLS permissions whenever possible.

  • Regularly clean up the DataAgents, the roles, and the granted policies that are no longer in use.

Verify permissions

After you prepare the DataAgent RAM role and grant the permission policies, verify the following items in order.

Configuration step

Verification

Expected result

Grant permission policies to RAM users

A RAM user views or creates the objects within the scope of the responsibilities assigned to the user.

The operation succeeds.

Grant permission policies to RAM users

A RAM user manages the models or the DataAgents outside the scope of the responsibilities assigned to the user.

The operation is denied.

Prepare the DataAgent RAM role

The specified role queries the allowed projects and LogStores.

The query succeeds.

Prepare the DataAgent RAM role

A user queries data that the role is not authorized to access.

A clear permission error is returned.

Change the role bound to a DataAgent

Start a new session after the change.

The new session runs with the new permissions.

Modify a role or a model binding

Verify one allowed scenario and one denied scenario.

The allowed scenario succeeds and the denied scenario is rejected.

FAQ

Insufficient permissions are reported when you create a DataAgent

In the RAM console, check the policy that is attached to your RAM user for the log:CreateDataAgent permission. Confirm that the same policy grants ram:PassRole on the role that you selected for the DataAgent.

The DataAgent is created, but a permission error is reported when data is queried

The user management permissions and the DataAgent runtime permissions are two separate sets of permissions. Check whether the RAM role that is bound to the DataAgent has the read permissions on the target projects and LogStores.

The default role still fails

Confirm that your account has completed the one-time system role authorization on the role authorization page. Then check in the RAM console whether the role aliyunslsdataagentrole exists and whether its trusted principal is log.aliyuncs.com.