Search code examples
node.jsgoogle-cloud-platformgoogle-secret-manager

Google Secret Manager INVALID_ARGUMENT Error


I'm using Google Secret Manager to access/store some secret parameters in an API. I have no problem saving secrets and accessing versions.

But when I send a request to list these secrets, I keep getting this error.

Error: 3 INVALID_ARGUMENT: Invalid resource field value in the request.
  code: 3,
  details: 'Invalid resource field value in the request.',
  metadata: Metadata {
    internalRepr: Map(3) {
      'grpc-server-stats-bin' => [Array],
      'google.rpc.errorinfo-bin' => [Array],
      'grpc-status-details-bin' => [Array]
    },
    options: {}
  },
  statusDetails: [
    ErrorInfo {
      metadata: [Object],
      reason: 'RESOURCE_PROJECT_INVALID',
      domain: 'googleapis.com'
    }
  ],
  reason: 'RESOURCE_PROJECT_INVALID',
  domain: 'googleapis.com',
  errorInfoMetadata: {
    method: 'google.cloud.secretmanager.v1.SecretManagerService.ListSecrets',
    service: 'secretmanager.googleapis.com'
  }
}

I've also checked the docs and tried different queries like in here but no dice...

This is the part of the code I'm running:

import { SecretManagerServiceClient } from "@google-cloud/secret-manager";

const secretClient = new SecretManagerServiceClient({
        keyFile: "foo/bar/google_credentials.json"
    });
const [secrets] = await secretClient.listSecrets({
    filter: `labels.environment=development`
});

Version of the "@google-cloud/secret-manager": "^4.1.2",


Solution

  • Okay, I found the issue. I had to add the parent param to the request body.

    So it should look like this:

    const [secrets] = await SecretManager.secretClient.listSecrets({
    
           parent: "projects/**", <=========== This is the key
           filter: `
                  labels.environment:development AND
                  labels.scope:some-scope AND
                  labels.customer_id:*`
           });