Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Calling table.insert() with missing permission will cause UncaughtException #1814

@per-johansson1

Description

@per-johansson1

If the service account is missing the permission spanner.databases.beginOrRollbackReadWriteTransaction when executing the table.insert(data) method, the node process will crash in an unhandledRejection (ignoring "the catch").
If the service account is only (or also) missing the permission spanner.sessions.create however, or if the project / instance / database doesn't exist, the catch will be hit with the following error:
7 PERMISSION_DENIED: Caller is missing IAM permission spanner.sessions.create on resource.

Something similar was reported (and fixed) here, but this is slightly different as it requires the spanner.sessions.create permission to exist for the requested resource.

Environment details

  • OS: windows
  • Node.js version: 18.12.1
  • npm version: 8.19.2
  • @google-cloud/spanner version: 6.7.2

Steps to reproduce

  1. The account should have all the required permissions to run the code below (like spanner.sessions.create) but should NOT have the permission spanner.databases.beginOrRollbackReadWriteTransaction
  2. The project, instance and database must exist.
  3. Running the following code will give an UncaughtException 'Caller is missing IAM permission spanner.databases.beginOrRollbackReadWriteTransaction on resource projects/.../instances/.../databases/...:
const {Spanner} = require("@google-cloud/spanner");

const spanner = new Spanner({
    projectId: 'an-existing-project',
});
const instance = spanner.instance("a-real-instance");
const database = instance.database("an-actual-database");
const table =  database.table("SpannerTest");

const insertData = async () => {
    try {
        await table.insert([{name: "asdf"}]);
    } catch (e) {
        // Will not be hit
        console.error('caught exception', e.message);
    }
}

insertData();

Thanks!

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/nodejs-spanner API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions