skip to Main Content

I’m trying to have my Flutter app log to a specific google cloud project’s log bucket instead of the developer console. I’m running into a Permission 'logging.logEntries.create' denied on resource (or it may not exist). when I run the code. How can I fix this? The dart code for posting the log is below.

final logEntry = {
    "jsonPayload": {
      "message": {
        "test": "entry",
        "test 2": "entry 2",
      },
    },
    "logName": logName,
    "resource": {
      "type": "global",
      "labels": {
        "project_id": projectId,
      },
    }
  };

  final url = "https://logging.googleapis.com/v2/entries:write";

  http.Response response = await http.post(
    Uri.parse(url),
    headers: {
      HttpHeaders.contentTypeHeader: 'application/json',
      "X-goog-api-key": apiKey,
    },
    body: json.encode(
      {
        "entries": [logEntry],
      },
    ),
  );

The API key I created has no API restrictions, but I did also try restricting it to only use the logging API, but it still has the same error.

2

Answers


  1. You need to give the logging.logEntries.create permission to the Service Account used by your Flutter app.

    From the IAM page in Google Cloud console, you will be able to give a role containing the above permission to your Service Account.

    If you used a custom role, you can also add directly the logging.logEntries.create permission to this custom role.

    Login or Signup to reply.
  2. As mentioned in the document:

    The permission logging.logEntries.create is needed on each project,
    organization, billing account, or folder that is receiving new log
    entries, whether the resource is specified in logName or in an
    individual log entry.

    So, you need to give the logging.logEntries.create permission to the Service Account used by your Flutter app.

    You can also refer the detailed article on Access control guide.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search